SWILIB API (X75)    
Loading...
Searching...
No Matches
file.h File Reference
#include "base.h"
#include "wstring.h"

Go to the source code of this file.

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 -DSWILIB_LEGACY_COMPAT define.

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.