HPGCC3 Documentation 3.0 R003
|
FileSystem main header. More...
#include <time.h>
Go to the source code of this file.
Data Structures | |
struct | __frag |
struct | __buffer |
struct | __file |
Main structure FS_FILE. More... | |
Defines | |
#define | FSATTR_RDONLY 1 |
Read only file attribute. | |
#define | FSATTR_HIDDEN 2 |
Hidden file attribute. | |
#define | FSATTR_SYSTEM 4 |
System file attribute. | |
#define | FSATTR_VOLUME 8 |
Volume file attribute. | |
#define | FSATTR_DIR 16 |
Directory file attribute. | |
#define | FSATTR_ARCHIVE 32 |
Archive file attribute. | |
#define | FSATTR_LONGNAME 0xf |
Special attribute value for long filename entries. | |
#define | FSATTR_LONGMASK 0x3f |
Long filename attribute mask. | |
#define | FSMODE_READ 0 |
Read only mode. | |
#define | FSMODE_WRITE 2 |
Write mode. | |
#define | FSMODE_APPEND 4 |
Append mode. | |
#define | FSMODE_MODIFY 8 |
Modify mode. | |
#define | FSMODE_NOGROW 16 |
No-growth mode. | |
#define | FSMODE_NOCREATE 32 |
Don't create file. | |
#define | FS_OK 1 |
Error code: Returned by all functions when there are no errors. | |
#define | FS_ERROR 0 |
Error code: Indicates a hardware error or an unknown error. | |
#define | FS_EOF -1 |
Error code: Indicates end-of-file was reached. | |
#define | FS_BADNAME -2 |
Error code: Indicates an invalid file name was given. | |
#define | FS_BADVOLUME -3 |
Error code: Returned when the volume requested doesn't exist. | |
#define | FS_NOTFOUND -4 |
Error code: File not found. | |
#define | FS_CANTWRITE -5 |
Error code: Write operation failed or not permitted. | |
#define | FS_NOCARD -6 |
Error code: No card is currently inserted. | |
#define | FS_CHANGED -7 |
Error code: User has changed the card without unmounting the volumes. | |
#define | FS_MAXFILES -8 |
Error code: Max. number of open files has been reached. | |
#define | FS_OPENDIR -9 |
Error code: The name given correspond to an open directory. | |
#define | FS_OPENFILE -9 |
Error code: The name given corresponds to an open file. | |
#define | FS_USED -9 |
Error code: File/directory is open/referenced/locked. | |
#define | FS_DISKFULL -10 |
Error code: Disk is full. | |
#define | FS_EXIST -11 |
Error code: File already exists. | |
#define | FS_INVHANDLE -12 |
Error code: Invalid Handle. | |
#define | FSCASE_SENS 0 |
Case sensitivity mode: RAW case sensitive. | |
#define | FSCASE_SENSHP 1 |
Case sensitivity mode: HP compatible case sensitive. | |
#define | FSCASE_INSENS 2 |
Case sensitivity mode: Case insensitive. | |
#define | FSCASE_SENSHPTRUE 3 |
Case sensitivity mode: HP compatible case sensitive. | |
#define | FSNAME_HASVOL 1 |
Name constant: Name includes volume specification. | |
#define | FSNAME_HASPATH 2 |
Name constant: Name includes path information. | |
#define | FSNAME_ABSPATH 4 |
Name constant: Name has an absolute path. | |
#define | FSNAME_ENDSLASH 8 |
Name constant: Name is a directory ended in slash. | |
#define | FSNAME_VOLHP 16 |
Name constant: Drive specification is HP style (:x:) | |
#define | FSNAME_EMPTY 32 |
Name constant: Name/path does not have a file name. | |
#define | FSNAME_INVALID -1 |
Name constant: Invalid filename. | |
#define | __ICASE(a) ( ((a>96)&&(a<123))? (a&0xdf):a) |
#define | __UPPER(a) ( ((a>96)&&(a<123))? (a&0xdf):a) |
#define | __LOWER(a) ( ((a>64)&&(a<91))? (a|0x20):a) |
Typedefs | |
typedef struct __frag | FS_FRAGMENT |
typedef struct __buffer | FS_BUFFER |
typedef struct __file | FS_FILE |
Functions | |
int | FSShutdown () |
Shutdown file system, close all open files and unmount all volumes. | |
int | FSRestart () |
Shutdown and reinitialize the file system. | |
void | FSSleep () |
Stops the clock to the SD card to preserve power. | |
void | FSWakeUp () |
Restarts the clock to the SD card. | |
int | FSVolumeMounted (int VolNumber) |
Checks if a specified volume is currently mounted. | |
int | FSVolumeInserted (int VolNumber) |
Checks if a specified volume is mounted and inserted. | |
int | FSSetCurrentVolume (int VolNumber) |
Set the current working volume. | |
int | FSGetCurrentVolume () |
Get the current working volume. | |
int | FSGetVolumeSize (int Volnumber) |
Get the total size of a volume. | |
int | FSGetVolumeFree (int Volnumber) |
Get the free space on a volume. | |
int | FSMkdir (char *name) |
Creates a directory. | |
int | FSRmdir (char *name) |
Delete a directory. | |
int | FSChdir (char *name) |
Changes current working directory. | |
char * | FSGetcwd (int Volume) |
Returns the current work directory for the specified volume. | |
int | FSOpenDir (char *name, FS_FILE **fileptr) |
Open a directory for entry scanning. | |
int | FSGetNextEntry (FS_FILE *entry, FS_FILE *dir) |
Get the next entry from a directory. | |
void | FSReleaseEntry (FS_FILE *file) |
Release dynamically allocated memory on a FS_FILE structure. | |
int | FSCreate (char *name, int attr, FS_FILE **fileptr) |
Create a file. | |
int | FSOpen (char *name, int mode, FS_FILE **fileptr) |
Open a file. Create if it doesn't exist. | |
int | FSClose (FS_FILE *file) |
Close an open file. | |
int | FSCloseAndDelete (FS_FILE *file) |
Close an open file and delete it. | |
int | FSSeek (FS_FILE *file, int Offset, int position) |
Move the current position pointer for read/write. | |
int | FSTell (FS_FILE *file) |
Get the current position pointer for read/write. | |
int | FSRead (char *buffer, int nbytes, FS_FILE *file) |
Read data from a file. | |
int | FSWrite (char *buffer, int nbytes, FS_FILE *file) |
Write data to a file. | |
int | FSEof (FS_FILE *file) |
Detect end-of-file condition. | |
int | FSDelete (char *name) |
Delete a file. | |
int | FSRename (char *oldname, char *newname) |
Rename a file. | |
int | FSNameCompare (char *name1, char *name2, int caseflags) |
Compare two file names. | |
char * | FSGetFileName (FS_FILE *file, int pathflags) |
Obtain the file name. | |
int | FSGetNameType (char *name) |
Get information about a file name. | |
void | FSStripSemi (char *name) |
Strip trailing semicolons. | |
char * | FSGetErrorMsg (int errornum) |
Get error message. | |
int | FSChMode (FS_FILE *file, int newmode) |
Change file access mode. | |
int | FSChAttr (FS_FILE *file, int newattr) |
Change file attributes. | |
int | FSAttr (FS_FILE *file) |
Get file attributes. | |
int | FSFileLength (FS_FILE *file) |
Get file size. | |
void | FSSetCaseMode (int casemode) |
Set the case sensitivity mode. | |
void | FSGetCreatTime (FS_FILE *file, struct tm *timedate) |
Get file creation time and date. | |
void | FSGetWriteTime (FS_FILE *file, struct tm *timedate) |
Get file write time and date. | |
void | FSGetAccessDate (FS_FILE *file, struct tm *timedate) |
Get file access date (no time) | |
int | FSGetHandle (FS_FILE *file) |
Get file handle number for given file. | |
int | FSGetFileFromHandle (int handle, FS_FILE **fileptr) |
Get a FS_FILE structure that correspond to the given handle. |
FileSystem main header.
Definition in file fsystem.h.
#define FS_BADNAME -2 |
#define FS_BADVOLUME -3 |
#define FS_CANTWRITE -5 |
#define FS_CHANGED -7 |
#define FS_EOF -1 |
#define FS_ERROR 0 |
#define FS_MAXFILES -8 |
#define FS_NOCARD -6 |
#define FS_OK 1 |
#define FS_OPENDIR -9 |
#define FS_OPENFILE -9 |
#define FS_USED -9 |
#define FSATTR_LONGNAME 0xf |
#define FSCASE_INSENS 2 |
#define FSCASE_SENS 0 |
Case sensitivity mode: RAW case sensitive.
In this mode, names are case-sensitive: "testfile.dat" and "TestFile.dat" are considered different files. However, the FAT specification indicates that two names that differ only in case cannot coexist in the disk. For example, given a disk with only one file called "TestFile.dat": Trying to open "testfile.dat" will fail (file not found). Trying to create "testfile.dat" will fail (conflicting file name).
#define FSCASE_SENSHP 1 |
Case sensitivity mode: HP compatible case sensitive.
In this mode, names are case-sensitive: "testfile.dat" and "TestFile.dat" are considered different files. However, the FAT specification indicates that two names that differ only in case cannot coexist in the disk. The file system will add trailing semicolons to the names of conflicting files. Trailing semicolons are ignored in name comparisons and handled transparently. The only consideration that the user must keep in mind is that names having trailing semicolons will be visible on the disk when the disk is either read by another OS, or read in a different case-sensitivity mode. For example, given a disk with only one file called "TestFile.dat": Trying to open "TestFile.dat;" wil open the file "TestFile.dat" Trying to open "TestFile.dat;;;;" will open the file "TestFile.dat" Trying to create "TestFile.dat;" will fail (file already exists) Trying to create "testfile.dat" will create "testfile.dat;" Assuming that "testfile.dat;" exists, trying to open "testfile.dat" will open "testfile.dat;" All directory access functions in this mode will report that the files are "TestFile.dat" and "testfile.dat". All trailing semicolons will be stripped. In case of multiple conflicting files, the system will add multiple trailing semicolons. For example: Create "hello world", OK Create "HELLO world" creates "HELLO world;" Create "HELLO WORLD" creates "HELLO WORLD;;"
#define FSCASE_SENSHPTRUE 3 |
Case sensitivity mode: HP compatible case sensitive.
This mode provides case-sensitivity with trailing semicolon handling similar to the mode described in FSCASE_SENSHP. The only difference is that file names returned by directory functions will be "true" names. Trailing semicolons will not be stripped, and the name returned matches exactly the name stored in the disk.
#define FSMODE_APPEND 4 |
#define FSMODE_MODIFY 8 |
#define FSMODE_NOCREATE 32 |
#define FSMODE_NOGROW 16 |
#define FSMODE_READ 0 |
#define FSMODE_WRITE 2 |
#define FSNAME_ABSPATH 4 |
#define FSNAME_EMPTY 32 |
#define FSNAME_ENDSLASH 8 |
#define FSNAME_HASPATH 2 |
#define FSNAME_HASVOL 1 |
#define FSNAME_INVALID -1 |
#define FSNAME_VOLHP 16 |
typedef struct __frag FS_FRAGMENT |
int FSAttr | ( | FS_FILE * | file | ) |
Get file attributes.
Return attribute of a file.
file | (FS_FILE *) pointer obtained from FSOpen or entry obtained from FSGetNextEntry |
int FSChAttr | ( | FS_FILE * | file, |
int | newattr | ||
) |
Change file attributes.
Change the attributes of a file. It does not check for validity of the attribute, so any combination can be used. If the attribute FSATTR_RDONLY is set, the file access mode will be forced to FSMODE_READ.
file | (FS_FILE *) pointer obtained from FSOpen or entry obtained from FSGetNextEntry |
newmode | One or more FSATTR_XXX constants |
int FSChdir | ( | char * | name | ) |
Changes current working directory.
Changes the current directory. If the name includes a volume, it changes the current directory for that volume but it does not affect the current volume. See FSGetNameType for details about naming conventions.
name | Name of the directory to change to |
int FSChMode | ( | FS_FILE * | file, |
int | newmode | ||
) |
int FSClose | ( | FS_FILE * | file | ) |
Close an open file.
Use this function to close a file or directory opened with FSCreate, FSOpen or FSOpenDir. All buffers will be flushed when the file is closed. Important
: If FSClose fails to close a file, data may be lost. The user should check for errors and only consider the file closed if FS_OK is returned. On error condition, the user should fix the error and retry.
file | (FS_FILE *) pointer obtained from FSOpen |
int FSCloseAndDelete | ( | FS_FILE * | file | ) |
int FSCreate | ( | char * | name, |
int | attr, | ||
FS_FILE ** | fileptr | ||
) |
Create a file.
This function creates a file with the given attribute. It allocates a FS_FILE structure and passes a pointer using the fileptr parameter. ONLY when the function returns FS_OK, *fileptr contains a valid FS_FILE pointer. If the file already exists, returns an error and the file won't be overwritten. File is created in write mode. See FSGetNameType for details about naming conventions.
name | Name of the file to create. Paths allowed. |
attr | File attribute |
fileptr | Address of a (FS_FILE *) pointer to be filled. |
int FSDelete | ( | char * | name | ) |
Delete a file.
This function deletes a file. See FSGetNameType for details about naming conventions.
name | Name of the file to delete. |
int FSEof | ( | FS_FILE * | file | ) |
int FSFileLength | ( | FS_FILE * | file | ) |
Get file size.
Return file length in bytes.
file | (FS_FILE *) pointer obtained from FSOpen or entry obtained from FSGetNextEntry |
Get file access date (no time)
Return time and date in a tm struct allocated by the user. Time fields of the structure will be zero-filled, since only date is returned. The value corresponds to the last time the user opened the file for either read or write.
file | (FS_FILE *) pointer obtained from FSOpen or entry obtained from FSGetNextEntry |
timedate | Pointer to tm structure to fill in |
Get file creation time and date.
Return time and date in a tm struct allocated by the user.
file | (FS_FILE *) pointer obtained from FSOpen or entry obtained from FSGetNextEntry |
timedate | Pointer to tm structure to fill in |
int FSGetCurrentVolume | ( | ) |
Get the current working volume.
When using multiple volumes on a card, it returns the volume used by default on all operations.
char* FSGetcwd | ( | int | Volume | ) |
Returns the current work directory for the specified volume.
Allocates a string and returns the current work directory for the specified volume as a text string. The string won't have an ending slash. Use FSGetCurrentVolume() to get the current directory of the current volume.
Volume | Number of the volume to use (0-3) |
char* FSGetErrorMsg | ( | int | errornum | ) |
Get error message.
This function returns a pointer to a static string containing an error message.
errornum | Error number. |
int FSGetFileFromHandle | ( | int | handle, |
FS_FILE ** | fileptr | ||
) |
Get a FS_FILE structure that correspond to the given handle.
handle | Handle of a currently open file. |
fileptr | Pointer to a (FS_FILE *) that will be filled in with the requested file data. |
char* FSGetFileName | ( | FS_FILE * | file, |
int | pathflags | ||
) |
Obtain the file name.
This function allocates a string, store a copy of the file name and returns a pointer. The user is responsible for freeing the string. May return NULL if insufficient memory to allocate the string. The user can specify the type of output using FSNAME_XXX constants. If FSNAME_ABSPATH is not specified, the path will be relative to the current directory. If the file is not under the current directory, the path will be absolute.
file | Pointer to the file's FS_FILE structure |
pathflags | Any combination of FSNAME_XXX constants |
int FSGetHandle | ( | FS_FILE * | file | ) |
Get file handle number for given file.
file | Pointer to a FS_FILE structure corresponding to an open file. |
int FSGetNameType | ( | char * | name | ) |
Get information about a file name.
This function analyzes a file name, and return a collection of flags. The file system naming convention is as follows: Volumes (drives): Are specified using either a letter or a port number. The four volumes in a card will be mounted to letters C: D: E: F:, and port numbers 3: 4: 5: 6:. Both DOS syntax (C:) and HP calculator syntax (:3:) are accepted and considered equivalent (3: is the same as :3:) Drive letters are case insensitive (c: and C: are the same). Directories: Both forward slash and back slash are accepted and considered equivalent. Names: File and directory names can have up to 255 characters (including a period and the file extension if any). There's no distinction between long and short names. Valid characters are the same as any FAT file system, with the exception of the semicolon, which receives special treatment when working in HP compatible case-sensitive mode. In such mode, trailing semicolons are ignored. See the FSCASE_XXX constants for more details. Examples of valid filenames: 3:\mydir\Hello world.dat :3:/mydir/Hello world.dat :C:mydir\Hello world.dat C:/mydir\Hello world.dat ..\Hello world.dat :c:Hello world.dat
name | Name to analyze. |
Get the next entry from a directory.
This function returns the next valid directory entry at the current offset within the directory. It fills a FS_FILE structure allocated by the user and passed as a parameter. All members in the FS_FILE structure will be filled, including date/time, attributes, file length, etc. The FS_FILE structure contains dynamically allocated members that need to be freed using FSReleaseEntry. For every call to this function there should be a corresponding call to FSReleaseEntry. Failure to do so will result in memory leaks. This function returns FS_EOF when there are no more entries in the directory. The FS_FILE structure will contain valid data ONLY when the function returns FS_OK.
entry | Pointer to a FS_FILE structure to fill. The caller is responsible for allocating the FS_FILE structure. |
dir | Pointer to a FS_FILE structure obtained from FSOpenDir |
int FSGetVolumeFree | ( | int | Volnumber | ) |
Get the free space on a volume.
Get volume total free space, in bytes.
Volnumber | Number of the volume (0-3) |
int FSGetVolumeSize | ( | int | Volnumber | ) |
Get the total size of a volume.
Get volume total size, in bytes.
Volnumber | Number of the volume (0-3) |
Get file write time and date.
Return time and date in a tm struct allocated by the user. This corresponds to the last time the user opened the file for writing.
file | (FS_FILE *) pointer obtained from FSOpen or entry obtained from FSGetNextEntry |
timedate | Pointer to tm structure to fill in |
int FSMkdir | ( | char * | name | ) |
Creates a directory.
Creates a directory. See the documentation on FSGetNameType for details about naming conventions.
name | Name for the new directory |
int FSNameCompare | ( | char * | name1, |
char * | name2, | ||
int | caseflags | ||
) |
Compare two file names.
This function compares two names, according to the case sensitivity mode. In FSCASE_SENS mode, it performs a standard case-sensitive comparison. In FSCASE_SENSHP oR FSCASE_SENSHPTRUE mode, it performs a fully case-sensitive comparison, but trailing semicolons are neglected. In FSCASE_INSENS mode, it performs a case-insensitive comparison.
name1 | Name of a file to compare |
name2 | Name of a file to compare |
caseflags | One of the FSCASE_XXX constants |
int FSOpen | ( | char * | name, |
int | mode, | ||
FS_FILE ** | fileptr | ||
) |
Open a file. Create if it doesn't exist.
This function opens a file in the given mode (see FSMODE_XXX constants) It allocates a FS_FILE structure and passes a pointer using the fileptr parameter. ONLY when the function returns FS_OK, *fileptr contains a valid FS_FILE pointer. If the file is open for writing and it doesn't exist then it creates the file. If the file is open in FSMODE_WRITE mode, the file is truncated to length zero if it exists. In FSMODE_APPEND, all write operations will be forced at the end of the file. In FSMODE_MODIFY, write operations can happen anywhere on the file. The initial position will be set at the beginning of the file, same as in write mode but the file won't be truncated. See FSGetNameType for details about naming conventions.
name | Name of the file to create. Paths allowed. |
mode | Read/Write mode (one or more FSMODE_XXX constants) |
fileptr | Address of a (FS_FILE *) pointer to be filled. |
int FSOpenDir | ( | char * | name, |
FS_FILE ** | fileptr | ||
) |
Open a directory for entry scanning.
Opens a directory for read, to be scanned using FSGetNextEntry. Use FSClose to close an open directory. See FSGetNameType for details about naming conventions.
name | Name of the directory |
fileptr | Address of a (FS_FILE *) pointer to be filled with the address of a newly created FS_FILE structure |
int FSRead | ( | char * | buffer, |
int | nbytes, | ||
FS_FILE * | file | ||
) |
Read data from a file.
Read the requested number of bytes into the given buffer, starting at the current position. Position is updated. Trying to read beyond end-of-file will result on a number of bytes read that is lower than the requested number or a zero.
buffer | Byte-aligned buffer to store requested data |
nbytes | Number of bytes requested |
file | (FS_FILE *) pointer obtained from FSOpen |
void FSReleaseEntry | ( | FS_FILE * | file | ) |
Release dynamically allocated memory on a FS_FILE structure.
This function releases any memory allocated within the FS_FILE structure. The FS_FILE structure itself is NOT freed. Data in the structure should be considered invalid after calling this function.
file | Pointer to a FS_FILE structure to release. |
int FSRename | ( | char * | oldname, |
char * | newname | ||
) |
Rename a file.
This function moves/renames a file. See FSGetNameType for details about naming conventions. If the target name already exists, returns an error. Files must be in the same volume to be moved.
name | Name of the file to delete. |
int FSRestart | ( | ) |
Shutdown and reinitialize the file system.
This function forces to close all files, unmount all volumes and remount if a card is inserted. It is usually called whenever a card change is detected. However, if any files are open and the card was changed, data will be lost, so use it with caution.
int FSRmdir | ( | char * | name | ) |
Delete a directory.
Delete an empty directory, it will fail if the directory contains any files, or if the directory is the current directory. See the documentation on FSGetNameType for details about naming conventions.
name | Name for the new directory |
int FSSeek | ( | FS_FILE * | file, |
int | Offset, | ||
int | position | ||
) |
Move the current position pointer for read/write.
Change the current position within the file, to a given offset counting from the specified position (one of the SEEK_XXX constants). Setting a position beyond end-of-file is OK. Negative positions will be set to the beginning of the file.
file | (FS_FILE *) pointer obtained from FSOpen |
Offset | Number of bytes to move |
position | Starting position (one of the SEEK_XXX constants) |
void FSSetCaseMode | ( | int | casemode | ) |
Set the case sensitivity mode.
Change the case sensitivity mode for all volumes. See the FSCASE_XXX constants for a detailed explanation of the modes.
casemode | New case mode. One of the FSCASE_XXX constants |
int FSSetCurrentVolume | ( | int | VolNumber | ) |
Set the current working volume.
When using multiple volumes on a card, set the volume used by default on all operations.
VolNumber | Volume number (from 0 to 3), being volume zero the first existing volume in the card |
int FSShutdown | ( | ) |
Shutdown file system, close all open files and unmount all volumes.
This function may be called when the program exits or when the file system will no longer be used (recomended to preserve batteries). If the program exits normally by exit() or by returning from main(), this function will be called automatically.
void FSSleep | ( | ) |
Stops the clock to the SD card to preserve power.
If the file system will not be used for a while, use this function to preserve batteries. The clock needs to be restarted using FSWakeUp.
void FSStripSemi | ( | char * | name | ) |
Strip trailing semicolons.
This function removes all trailing semicolons in the given string. It modifies the original buffer.
name | Name of a file to strip |
int FSTell | ( | FS_FILE * | file | ) |
int FSVolumeInserted | ( | int | VolNumber | ) |
Checks if a specified volume is mounted and inserted.
This function verifies that the volume number given as a parameter is a valid mounted volume and the SD card that contains the volume is currently inserted.
VolNumber | Volume number (from 0 to 3), being volume zero the first existing volume in the card |
int FSVolumeMounted | ( | int | VolNumber | ) |
Checks if a specified volume is currently mounted.
This function verifies that the volume number given as a parameter is a valid mounted volume.
VolNumber | Volume number (from 0 to 3), being volume zero the first existing volume in the card |
void FSWakeUp | ( | ) |
Restarts the clock to the SD card.
Use this function to recover when FSSleep was used
int FSWrite | ( | char * | buffer, |
int | nbytes, | ||
FS_FILE * | file | ||
) |
Write data to a file.
Write the requested number of bytes into the given file, starting at the current position. Position is updated. In FSMODE_WRITE mode, file length will be truncated after the written block of data. In FSMODE_APPEND the current position will be moved to the end of the file before writing. If the file was open for read-only, it returns zero.
buffer | Byte-aligned buffer with data to write |
nbytes | Number of bytes requested |
file | (FS_FILE *) pointer obtained from FSOpen |