|
SWILIB API (SG)
|
Functions for working with filesystem.
Usage: #include <swilib.h> or #include <swilib/file.h>
Data Structures | |
| struct | DIR_ENTRY |
| Directory entry. More... | |
| struct | FSTATS |
| Information about a file or directory. More... | |
| struct | FILE_PROP |
| Extended file properties. More... | |
| struct | TWavLen |
| .wav duration info. More... | |
| struct | FS_OPS |
| File system driver methods (see FS_DRIVER and FS_DRIVE). More... | |
| struct | FS_DRIVER |
| File system driver (see RamFsDrivers). More... | |
| struct | FS_DRIVE |
| File system drive (see RamFsDrives). More... | |
Typedefs | |
| typedef struct DIR_ENTRY | DIR_ENTRY |
| typedef struct FSTATS | FSTATS |
| typedef struct FILE_PROP | FILE_PROP |
| typedef struct TWavLen | TWavLen |
| typedef struct FS_DRIVE | FS_DRIVE |
| typedef struct FS_DRIVER | FS_DRIVER |
| typedef struct FS_OPS | FS_OPS |
Enumerations | |
| enum | FileAttributes { FA_READONLY = 0x0001 , FA_HIDDEN = 0x0002 , FA_SYSTEM = 0x0004 , FA_DIRECTORY = 0x0010 , FA_ARCHIVE = 0x0020 } |
| Attributes for a file or directory. More... | |
| enum | FileSeekOrigin { S_SET = 0 , S_CUR = 1 , S_END = 2 } |
| Modes for seek() More... | |
| enum | FilePermissionMode { P_WRITE = 0x100 , P_READ = 0x080 } |
| Request permissions for file operations. More... | |
| enum | FilePropTypeID { FILE_PROP_TYPE_VIDEO = 0x4000 , FILE_PROP_TYPE_PICTURE = 0x8000 , FILE_PROP_TYPE_AUDIO = 0x2000 } |
| enum | FileAccessMode { A_ReadOnly = 0x0000 , A_WriteOnly = 0x0001 , A_ReadWrite = 0x0002 , A_NoShare = 0x0004 , A_Append = 0x0008 , A_Exclusive = 0x0010 , A_MMCStream = 0x0020 , A_Create = 0x0100 , A_Truncate = 0x0200 , A_FailCreateOnExist = 0x0400 , A_FailOnReopen = 0x0800 , A_TXT = 0x4000 , A_BIN = 0x8000 } |
| File access mode. More... | |
Functions | |
| int | sys_open (const char *path, uint32_t mode, uint32_t permission, uint32_t *err) |
| Open the file. | |
| int | sys_read (int fd, void *buffer, int length, uint32_t *err) |
| Read data from a file. | |
| int | sys_write (int fd, const void *buffer, int length, uint32_t *err) |
| Write data to a file. | |
| int | sys_close (int fd, uint32_t *err) |
| Close file descriptor. | |
| int | sys_fflush (int fd, uint32_t *err) |
| Force write data from the OS write buffer. | |
| long | sys_lseek (int fd, int32_t offset, uint32_t origin, uint32_t *err, uint32_t *err2) |
| Move to the desired position within the file. | |
| int | sys_mkdir (const char *dirname, uint32_t *err) |
| Create a new directory. | |
| int | sys_mkdir_ws (const WSHDR *dirname, uint32_t *err) |
| Create a new directory. | |
| int | sys_rmdir (const char *dirname, uint32_t *err) |
| Remove directory. | |
| int | sys_rmdir_ws (const WSHDR *path, uint32_t *err) |
| Remove directory. | |
| int | sys_rename (const char *old_name, const char *new_name, uint32_t *err) |
| Rename file or directory. | |
| int | sys_rename_ws (const WSHDR *old_name, const WSHDR *new_name, uint32_t *err) |
| Rename file or directory. | |
| int | sys_unlink (const char *path, uint32_t *err) |
| Remove file. | |
| int | sys_unlink_ws (const WSHDR *path, uint32_t *err) |
| Remove file. | |
| int | sys_truncate (int fd, int length, uint32_t *err) |
| Truncate the file to the given size. | |
| int | sys_stat (const char *path, FSTATS *stat, uint32_t *err) |
| Get information about the file or directory. | |
| int | sys_stat_ws (const WSHDR *path, FSTATS *stat, uint32_t *err) |
| Get information about the file or directory. | |
| int | sys_fstat (int fd, FSTATS *stat, uint32_t *err) |
| Get information about the file or directory by fd. | |
| int | sys_format (uint16_t drive, uint32_t *err) |
| Format drive by index. | |
| int | sys_mount (uint16_t drive, uint32_t *err) |
| Mount drive by index. | |
| int | sys_unmount (uint16_t drive, uint32_t *err) |
| Unmount drive by index. | |
| int | setfilesize (int fd, uint32_t length, uint32_t *err) |
| Truncate or grow the file to the given size. | |
| int | setfiletime (int fd, uint16_t date, uint16_t time, uint32_t *err) |
| Set file date and time. | |
| int | fmove (const char *old_name, const char *new_name, uint32_t *err) |
| Rename file or directory. | |
| int | isdir (const char *path, uint32_t *err) |
| Check whether a directory exists at the given path. | |
| int | isdir_ws (const WSHDR *path, uint32_t *err) |
| Check whether a directory exists at the given path. | |
| int | fexists (WSHDR *path) |
| Check if a regular file exists. | |
| int | GetFileAttrib (const char *path, uint8_t *attr, uint32_t *err) |
| Get attributes of the file or directory. | |
| int | GetFileAttrib_ws (const WSHDR *path, uint8_t *attr, uint32_t *err) |
| Get attributes of the file or directory. | |
| int | SetFileAttrib (const char *path, uint8_t attr, uint32_t *err) |
| Set attributes for the file or directory. | |
| int | SetFileAttrib_ws (const WSHDR *path, uint8_t attr, uint32_t *err) |
| Set attributes for the file or directory. | |
| int | GetFileProp (FILE_PROP *props, const WSHDR *file, const WSHDR *path) |
| Get extended file properties. | |
| int | GetWavLen (TWavLen *wav_info) |
| Get duration of the .wav file. | |
| int | FindFirstFile (DIR_ENTRY *dir_entry, const char *mask, uint32_t *err) |
| Open search session and get first result. | |
| int | FindFirstFile_ws (DIR_ENTRY *dir_entry, const WSHDR *mask, uint32_t *err) |
| Open search session and get first result. | |
| int | FindNextFile (DIR_ENTRY *dir_entry, uint32_t *err) |
| Continue searching for files and get next result. | |
| int | GetPathOfFoundFile (DIR_ENTRY *dir_entry, void *file_info) |
| Convert a directory-search result to the SG/X75 file-list record. | |
| int | FindClose (DIR_ENTRY *dir_entry, uint32_t *err) |
| Close search session. | |
| int | GetFreeFlexSpace (int drive, uint32_t *err) |
| Get free space on a specified disk. | |
| int | GetTotalFlexSpace (int drive, uint32_t *err) |
| Get total space on a specified disk. | |
Legacy names for old GCC code. | |
These functions have a bad underscore name, which is bad for the public API. | |
| int | GetFileStats (const char *path, FSTATS *stat, uint32_t *err) |
| Get information about the file or directory. | |
| int | _open (const char *path, uint32_t mode, uint32_t permission, uint32_t *err) |
| Open the file. | |
| int | _read (int fd, void *buffer, int length, uint32_t *err) |
| Read data from a file. | |
| int | _write (int fd, const void *buffer, int length, uint32_t *err) |
| Write data to a file. | |
| int | _close (int fd, uint32_t *err) |
| Close file descriptor. | |
| int | _flush (int fd, uint32_t *err) |
| Force write data from the OS write buffer. | |
| long | _lseek (int fd, uint32_t offset, uint32_t origin, uint32_t *err, uint32_t *err2) |
| Move to the desired position within the file. | |
| int | _mkdir (const char *dirname, uint32_t *err) |
| Create a new directory. | |
| int | _rmdir (const char *dirname, uint32_t *err) |
| Remove directory. | |
| int | _unlink (const char *path, uint32_t *err) |
| Remove file. | |
| int | _truncate (int fd, int length, uint32_t *err) |
| Truncate the file to the given size. | |
File system drivers | |
| void * | FS_MemAlloc (int size) |
| Allocate memory from the file system heap. | |
| FS_DRIVER * | RamFsDrivers (void) |
| Get the file system driver table. | |
| FS_DRIVE * | RamFsDrives (void) |
| Get the file system drive table. | |
Legacy names for old IAR code. | |
These functions are disabled by default, because they have ambiguous names which conflict with stdio.h api. But you can always enable these functions using the | |
| int | fopen (const char *path, uint32_t mode, uint32_t permission, uint32_t *err) |
| Open the file. | |
| int | fread (int fd, void *buffer, int length, uint32_t *err) |
| Read data from a file. | |
| int | fclose (int fd, uint32_t *err) |
| Close file descriptor. | |
| int | fflush (int fd, uint32_t *err) |
| Force write data from the OS write buffer. | |
| int | fwrite (int fd, const void *buffer, int length, uint32_t *err) |
| Write data to a file. | |
| long | lseek (int fd, uint32_t offset, uint32_t origin, uint32_t *err, uint32_t *err2) |
| Move to the desired position within the file. | |
| int | mkdir (const char *dirname, uint32_t *err) |
| Create a new directory. | |
| int | rmdir (const char *dirname, uint32_t *err) |
| Remove directory. | |
| int | unlink (const char *path, uint32_t *err) |
| Remove file. | |
| int | truncate (int fd, int length, uint32_t *err) |
| Truncate the file to the given size. | |
| struct DIR_ENTRY |
| struct FSTATS |
| struct FILE_PROP |
| struct TWavLen |
| struct FS_OPS |
| struct FS_DRIVER |
| struct FS_DRIVE |
| enum FileAttributes |
| enum FileSeekOrigin |
| enum FilePermissionMode |
| enum FilePropTypeID |
| enum FileAccessMode |
File access mode.
| int sys_open | ( | const char * | path, |
| uint32_t | mode, | ||
| uint32_t | permission, | ||
| uint32_t * | err ) |
Open the file.
| path | path to the file |
| mode | bitmask from FileAccessMode |
| permission | bitmask from FilePermissionMode |
| err | error code |
| int sys_read | ( | int | fd, |
| void * | buffer, | ||
| int | length, | ||
| uint32_t * | err ) |
Read data from a file.
| fd | file descriptor | |
| buffer | pointer to a buffer for the read data | |
| length | maximum size for read | |
| [out] | err | error code |
| int sys_write | ( | int | fd, |
| const void * | buffer, | ||
| int | length, | ||
| uint32_t * | err ) |
Write data to a file.
| fd | file descriptor | |
| buffer | pointer to a buffer with data to be written | |
| length | maximum size for write | |
| [out] | err | error code |
| int sys_close | ( | int | fd, |
| uint32_t * | err ) |
Close file descriptor.
| fd | file descriptor | |
| [out] | err | error code |
| int sys_fflush | ( | int | fd, |
| uint32_t * | err ) |
Force write data from the OS write buffer.
| fd | file descriptor | |
| [out] | err | error code |
| long sys_lseek | ( | int | fd, |
| int32_t | offset, | ||
| uint32_t | origin, | ||
| uint32_t * | err, | ||
| uint32_t * | err2 ) |
Move to the desired position within the file.
| fd | file descriptor | |
| offset | signed offset | |
| origin | see FileSeekOrigin | |
| [out] | err | error code |
| [out] | err2 | error code |
| int sys_mkdir | ( | const char * | dirname, |
| uint32_t * | err ) |
Create a new directory.
| dirname | path of the new directory | |
| [out] | err | error code |
Create a new directory.
| dirname | path of the new directory | |
| [out] | err | error code |
| int sys_rmdir | ( | const char * | dirname, |
| uint32_t * | err ) |
Remove directory.
| dirname | path to the directory | |
| [out] | err | error code |
Remove directory.
| dirname | path to the directory | |
| [out] | err | error code |
Rename file or directory.
| old_name | old file/dir name (full path) |
| new_name | new file/dir name (full path) |
| err | error code |
Rename file or directory.
| old_name | old file/dir name (full path) |
| new_name | new file/dir name (full path) |
| err | error code |
| int sys_unlink | ( | const char * | path, |
| uint32_t * | err ) |
Remove file.
| path | path to the file | |
| [out] | err | error code |
Remove file.
| path | path to the file | |
| [out] | err | error code |
| int sys_truncate | ( | int | fd, |
| int | length, | ||
| uint32_t * | err ) |
Truncate the file to the given size.
| fd | file descriptor | |
| length | new size of the file | |
| [out] | err | error code |
Get information about the file or directory.
| path | path to the file or directory. | |
| stat | pointer where the information will be written (FSTATS) | |
| [out] | err | error code |
Get information about the file or directory.
| path | path to the file or directory. | |
| stat | pointer where the information will be written (FSTATS) | |
| [out] | err | error code |
| int sys_fstat | ( | int | fd, |
| FSTATS * | stat, | ||
| uint32_t * | err ) |
Get information about the file or directory by fd.
| fd | file descriptor | |
| stat | pointer where the information will be written (FSTATS) | |
| [out] | err | error code |
| int sys_format | ( | uint16_t | drive, |
| uint32_t * | err ) |
Format drive by index.
| drive | drive index (0 - 0:, 1 - 1:, 2 - 2:, 3 - 4:) | |
| [out] | err | error code |
| int sys_mount | ( | uint16_t | drive, |
| uint32_t * | err ) |
Mount drive by index.
| drive | drive number (only drive 4 is supported) | |
| [out] | err | error code |
| int sys_unmount | ( | uint16_t | drive, |
| uint32_t * | err ) |
Unmount drive by index.
| drive | drive number (only drive 4 is supported) | |
| [out] | err | error code |
| int setfilesize | ( | int | fd, |
| uint32_t | length, | ||
| uint32_t * | err ) |
Truncate or grow the file to the given size.
| fd | file descriptor | |
| length | new size of the file | |
| [out] | err | error code |
| int setfiletime | ( | int | fd, |
| uint16_t | date, | ||
| uint16_t | time, | ||
| uint32_t * | err ) |
Set file date and time.
| fd | file descriptor | |
| date | date in DOS (FAT) format | |
| time | time in DOS (FAT) format | |
| [out] | err | error code |
Rename file or directory.
| old_name | old file/dir name (full path) |
| new_name | new file/dir name (full path) |
| err | error code |
| int isdir | ( | const char * | path, |
| uint32_t * | err ) |
Check whether a directory exists at the given path.
| path | the path we are checking | |
| [out] | err | error code |
Check whether a directory exists at the given path.
| path | the path we are checking | |
| [out] | err | error code |
| int fexists | ( | WSHDR * | path | ) |
Check if a regular file exists.
Directories return 0.
| path | path to the file |
| int GetFileAttrib | ( | const char * | path, |
| uint8_t * | attr, | ||
| uint32_t * | err ) |
Get attributes of the file or directory.
| path | path to the file or directory. | |
| attr | pointer where the attributes will be written | |
| [out] | err | error code |
Get attributes of the file or directory.
| path | path to the file or directory. | |
| attr | pointer where the attributes will be written | |
| [out] | err | error code |
| int SetFileAttrib | ( | const char * | path, |
| uint8_t | attr, | ||
| uint32_t * | err ) |
Set attributes for the file or directory.
| path | path to the file or directory. | |
| attr | bitmask: FileAttributes | |
| [out] | err | error code |
Set attributes for the file or directory.
| path | path to the file or directory. | |
| attr | bitmask: FileAttributes | |
| [out] | err | error code |
Get extended file properties.
See description of FILE_PROP for additional information.
| [out] | props | pointer to the extended properties structure |
| file | name of the file, example: "beans_recipe.jpg" | |
| path | path to the file, example: "0:\\Pictures\\" |
| int GetWavLen | ( | TWavLen * | wav_info | ) |
Get duration of the .wav file.
| [out] | wav_info | path to the TWavLen |
Open search session and get first result.
DIR_ENTRY is both a search result and an search session.
| dir_entry | pointer to the search session | |
| mask | search mask (pattern with * as wildcard) | |
| [out] | err | error code |
dir_entry contains first result of the search Open search session and get first result.
DIR_ENTRY is both a search result and an search session.
| dir_entry | pointer to the search session | |
| mask | search mask (pattern with * as wildcard) | |
| [out] | err | error code |
dir_entry contains first result of the search | int FindNextFile | ( | DIR_ENTRY * | dir_entry, |
| uint32_t * | err ) |
Continue searching for files and get next result.
| dir_entry | pointer to the search session | |
| [out] | err | error code |
dir_entry contains next result of the search | int GetPathOfFoundFile | ( | DIR_ENTRY * | dir_entry, |
| void * | file_info ) |
Convert a directory-search result to the SG/X75 file-list record.
| dir_entry | directory-search result | |
| [out] | file_info | output buffer of at least 0x110 bytes |
| int FindClose | ( | DIR_ENTRY * | dir_entry, |
| uint32_t * | err ) |
Close search session.
| dir_entry | pointer to the search session | |
| [out] | err | error code |
| int GetFreeFlexSpace | ( | int | drive, |
| uint32_t * | err ) |
Get free space on a specified disk.
| drive | number of the drive: 0-4 | |
| [out] | err | error code |
| int GetTotalFlexSpace | ( | int | drive, |
| uint32_t * | err ) |
Get total space on a specified disk.
| drive | number of the drive: 0-4 |
| err | unused |
Get information about the file or directory.
| path | path to the file or directory. | |
| stat | pointer where the information will be written (FSTATS) | |
| [out] | err | error code |
| int _open | ( | const char * | path, |
| uint32_t | mode, | ||
| uint32_t | permission, | ||
| uint32_t * | err ) |
Open the file.
| path | path to the file |
| mode | bitmask from FileAccessMode |
| permission | bitmask from FilePermissionMode |
| err | error code |
| int _read | ( | int | fd, |
| void * | buffer, | ||
| int | length, | ||
| uint32_t * | err ) |
Read data from a file.
| fd | file descriptor | |
| buffer | pointer to a buffer for the read data | |
| length | maximum size for read | |
| [out] | err | error code |
| int _write | ( | int | fd, |
| const void * | buffer, | ||
| int | length, | ||
| uint32_t * | err ) |
Write data to a file.
| fd | file descriptor | |
| buffer | pointer to a buffer with data to be written | |
| length | maximum size for write | |
| [out] | err | error code |
| int _close | ( | int | fd, |
| uint32_t * | err ) |
Close file descriptor.
| fd | file descriptor | |
| [out] | err | error code |
| int _flush | ( | int | fd, |
| uint32_t * | err ) |
Force write data from the OS write buffer.
| fd | file descriptor | |
| [out] | err | error code |
| long _lseek | ( | int | fd, |
| uint32_t | offset, | ||
| uint32_t | origin, | ||
| uint32_t * | err, | ||
| uint32_t * | err2 ) |
Move to the desired position within the file.
| fd | file descriptor | |
| offset | signed offset | |
| origin | see FileSeekOrigin | |
| [out] | err | error code |
| [out] | err2 | error code |
| int _mkdir | ( | const char * | dirname, |
| uint32_t * | err ) |
Create a new directory.
| dirname | path of the new directory | |
| [out] | err | error code |
| int _rmdir | ( | const char * | dirname, |
| uint32_t * | err ) |
Remove directory.
| dirname | path to the directory | |
| [out] | err | error code |
| int _unlink | ( | const char * | path, |
| uint32_t * | err ) |
Remove file.
| path | path to the file | |
| [out] | err | error code |
| int _truncate | ( | int | fd, |
| int | length, | ||
| uint32_t * | err ) |
Truncate the file to the given size.
| fd | file descriptor | |
| length | new size of the file | |
| [out] | err | error code |
| void * FS_MemAlloc | ( | int | size | ) |
Allocate memory from the file system heap.
Asynchronous file system calls answer with message 0x1A2 whose payload +4 points to such a block {callback, u16 error, result}; the receiver frees it.
| size | size in bytes |
| FS_DRIVER * RamFsDrivers | ( | void | ) |
Get the file system driver table.
| FS_DRIVE * RamFsDrives | ( | void | ) |
Get the file system drive table.
| int fopen | ( | const char * | path, |
| uint32_t | mode, | ||
| uint32_t | permission, | ||
| uint32_t * | err ) |
Open the file.
| path | path to the file |
| mode | bitmask from FileAccessMode |
| permission | bitmask from FilePermissionMode |
| err | error code |
| int fread | ( | int | fd, |
| void * | buffer, | ||
| int | length, | ||
| uint32_t * | err ) |
Read data from a file.
| fd | file descriptor | |
| buffer | pointer to a buffer for the read data | |
| length | maximum size for read | |
| [out] | err | error code |
| int fclose | ( | int | fd, |
| uint32_t * | err ) |
Close file descriptor.
| fd | file descriptor | |
| [out] | err | error code |
| int fflush | ( | int | fd, |
| uint32_t * | err ) |
Force write data from the OS write buffer.
| fd | file descriptor | |
| [out] | err | error code |
| int fwrite | ( | int | fd, |
| const void * | buffer, | ||
| int | length, | ||
| uint32_t * | err ) |
Write data to a file.
| fd | file descriptor | |
| buffer | pointer to a buffer with data to be written | |
| length | maximum size for write | |
| [out] | err | error code |
| long lseek | ( | int | fd, |
| uint32_t | offset, | ||
| uint32_t | origin, | ||
| uint32_t * | err, | ||
| uint32_t * | err2 ) |
Move to the desired position within the file.
| fd | file descriptor | |
| offset | signed offset | |
| origin | see FileSeekOrigin | |
| [out] | err | error code |
| [out] | err2 | error code |
| int mkdir | ( | const char * | dirname, |
| uint32_t * | err ) |
Create a new directory.
| dirname | path of the new directory | |
| [out] | err | error code |
| int rmdir | ( | const char * | dirname, |
| uint32_t * | err ) |
Remove directory.
| dirname | path to the directory | |
| [out] | err | error code |
| int unlink | ( | const char * | path, |
| uint32_t * | err ) |
Remove file.
| path | path to the file | |
| [out] | err | error code |
| int truncate | ( | int | fd, |
| int | length, | ||
| uint32_t * | err ) |
Truncate the file to the given size.
| fd | file descriptor | |
| length | new size of the file | |
| [out] | err | error code |