📄 fsprivate.h
字号:
typedef struct cache_entry CacheEntry;
struct file
{
void (*acquire)(const FILE *file, int rwcode);
void (*release)(const FILE *file, int rwcode);
void *handle; /* self handle to be passed to ioctl */
void *volume; /* file system file/dir belongs to */
void *pos; /* directory position; used for readdir */
void *(*ioctl)(FILE *stream, int code, ...);
int (*read)(FILE *stream, ui8 *buf, ui32 len);
int (*write)(FILE *stream, const ui8 *buf, ui32 len);
int hold_char;
int errcode;
struct dirent dent; /* to be used for readdir() */
CacheEntry *cached; /* pointer to current cached sector */
fpos_t curr_ptr; /* current position in file */
fpos_t old_ptr; /* previous position in file */
ui32 flags; /* file/dir specific flags */
ui32 parent; /* parent directory */
};
/*
** Ioctl() Commands
*/
typedef enum
{
FFLUSH = 4, FSEEK, FTELL, FOPEN, FEOF, FGETPOS, FCLOSE, FREOPEN,
FSETPOS, REMOVE, FSEARCH, SETVBUF, CHDIR, GETCWD, MKDIR, RMDIR,
STAT, UTIME, OPENDIR, READDIR, CLOSEDIR, CLOSE, LINK, OPEN, TMPFILE,
TMPNAM, FSTAT, CURR_PTR, STATS, UNMOUNT, VSTAT, CHMOD, CHOWN,
ACCESS, DUP, ENABLE_SYNC, DISABLE_SYNC, FTRUNCATE, TRUNCATE,
SET_FL, GET_FL, CREATN, RENAME, VCLEAN, CHDIR_DEC, SORTDIR, ATTRIB,
GET_FSUID, GET_NAME, GET_QUOTAM, GET_QUOTA
} IOCTLS;
/*
** FAT Events
*/
typedef enum
{
FAT_MOUNT, FAT_UNMOUNT
} FAT_EVENTS;
typedef struct f_f_e FFSEnt;
typedef struct r_f_e RFSEnt;
typedef struct
{
ui16 sector;
ui16 offset;
} OffLoc;
/*
** Represents structure of common info between dir and file in RAM
*/
typedef struct
{
FFSEnt *addr; /* entry location in RAM */
time_t mod_time; /* last modified time for entry */
time_t ac_time; /* last access time for entry */
ui32 size; /* size of file (0 for dirs) */
ui32 fileno; /* file/dir number */
ui32 attrib; /* FsAttribute() field */
uid_t user_id; /* used ID */
gid_t group_id; /* group ID */
mode_t mode; /* file/dir create mode */
ui8 links; /* number of links to file/dir */
ui8 open_links; /* number of open links to file/dir */
ui8 open_mode; /* file/dir open mode */
OffLoc one_past_last; /* pointer to one past the EOF */
ui16 frst_sect; /* first sector for files (0 for dirs) */
ui16 last_sect; /* last sector for files (0 for dirs) */
} FCOM_T;
/*
** RFS variation of comm (MUST agree with FCOM_T up to mode_t)
** otherwise SetPerm() and CheckPerm() won't work
*/
typedef struct
{
RFSEnt *addr; /* entry location in RAM */
time_t mod_time; /* last modified time for entry */
time_t ac_time; /* last access time for entry */
ui32 size; /* size of file (0 for dirs) */
ui32 fileno; /* file/dir number */
ui32 attrib; /* FsAttribute() field */
uid_t user_id; /* user ID */
gid_t group_id; /* group ID */
mode_t mode; /* file/dir create mode */
ui8 links; /* number of links to file/dir */
ui8 open_links; /* number of open links to file/dir */
ui8 open_mode; /* file/dir open mode */
ui32 one_past_last; /* offset within last sector */
void *frst_sect; /* first sector in file */
void *last_sect; /* last sector in file */
ui8 temp; /* indicates temporary file */
} RCOM_T;
/*
** Represents structure of a link to a file as it is used in RAM
*/
typedef struct
{
char name[FILENAME_MAX+1];/* link name */
FFSEnt *next; /* next entry in parent directory */
FFSEnt *prev; /* prev entry in parent directory */
FCOM_T *comm; /* pointer to actual file info */
FFSEnt *parent_dir; /* pointer to parent directory */
FILE *file; /* FILE* associated with this link */
} FFIL_T;
/*
** RFS variation of link
*/
typedef struct
{
char name[FILENAME_MAX+1];/* link name */
RFSEnt *next; /* next entry in parent directory */
RFSEnt *prev; /* prev entry in parent directory */
RCOM_T *comm; /* pointer to actual file info */
RFSEnt *parent_dir; /* pointer to parent directory */
FILE *file; /* FILE* associated with this link */
} RFIL_T;
/*
** Represents structure of a link to a dir as it is used in RAM
*/
typedef struct
{
char name[FILENAME_MAX+1];/* directory name */
FFSEnt *next; /* next entry in parent directory */
FFSEnt *prev; /* prev entry in parent directory */
FCOM_T *comm; /* pointer to actual dir info */
FFSEnt *parent_dir; /* pointer to parent directory */
DIR *dir; /* DIR* associated with this link */
FFSEnt *first; /* head of contents list for dir */
ui32 cwds; /* current working directory count */
#if QUOTA_ENABLED
ui32 max_q; /* max quota */
ui32 min_q; /* min quota */
ui32 used; /* used space */
ui32 free; /* free space */
ui32 free_below; /* free space below */
ui32 res_below; /* reserved below */
#endif /* QUOTA_ENABLED */
} FDIR_T;
/*
** RFS variation of dir
*/
typedef struct
{
char name[FILENAME_MAX+1];/* directory name */
RFSEnt *next; /* next entry in parent directory */
RFSEnt *prev; /* prev entry in parent directory */
RCOM_T *comm; /* pointer to actual dir info */
RFSEnt *parent_dir; /* pointer to parent directory */
DIR *dir; /* DIR* associated with this link */
RFSEnt *first; /* head of contents list for dir */
ui32 cwds; /* current working directory count */
} RDIR_T;
/*
** Represents the type for an entry in RAM (dir, file or link)
*/
union f_file_entry
{
FDIR_T dir;
FCOM_T comm;
FFIL_T file;
};
/*
** Represents the type for an entry for RFS (dif, file or link)
*/
union r_file_entry
{
RDIR_T dir;
RCOM_T comm;
RFIL_T file;
};
/*
** An entry in RAM consists of its type and value as a union
*/
struct f_f_e
{
union f_file_entry entry;
ui8 type;
};
/*
** An entry in RFS consists of its type and value as a union
*/
struct r_f_e
{
union r_file_entry entry;
ui8 type;
};
/*
** Holds a table full of entries, pointers to next and prev, num free
*/
typedef struct flash_entries FFSEnts;
struct flash_entries
{
FFSEnt tbl[FNUM_ENT];
FFSEnts *next_tbl;
FFSEnts *prev_tbl;
int free;
};
typedef struct ram_entries RFSEnts;
struct ram_entries
{
RFSEnt tbl[FNUM_ENT];
RFSEnts *next_tbl;
RFSEnts *prev_tbl;
int free;
};
/*
** Type of an entry in the Sectors table
*/
typedef struct
{
ui16 next; /* index of next sector in list of used sectors */
ui16 prev; /* index of prev sector in list of used sectors */
} Sectors;
/*
** Structure to cast all volume structures to, to retrieve ioctl_func
*/
typedef struct
{
FileSys sys;
} FsVolume;
/***********************************************************************/
/* Variable Declarations */
/***********************************************************************/
#define Files FilesFFS
extern FILE Files[FOPEN_MAX + 1];
#define MountedList MountedListFFS
extern HeadEntry MountedList;
#define FileSysSem FileSysSemFFS
extern SEM FileSysSem;
#define FSPath FSPathFFS
extern const char *FSPath;
#define CurrFixedVols CurrFixedVolsFFS
extern int CurrFixedVols;
/***********************************************************************/
/* Function Prototypes */
/***********************************************************************/
#define InvalidName InvalidNameFFS
int InvalidName(const char *name, int ignore_last);
void FileSysInit(void);
#define IsLast IsLastFFS
ui32 IsLast(const char *name, ui32 *incr);
int FsNorAddVol(const FfsVol *vol);
int FsNandAddVol(const FfsVol *vol);
int FatAddVol(const FatVol *vol);
int FtlNandAddVol(FtlNandVol *ftl_drvr, FatVol *fat_drvr);
#define FSearch FSearchFS
void *FSearch(void *handle, const char **path, int dir_lookup);
#define FSearchFSUID FSearchFSUIDFS
char *FSearchFSUID(ui32 fsuid, char *buf, size_t size, int lookup);
#define CheckPerm CheckPermFFS
int CheckPerm(FCOM_T *comm_ptr, int permissions);
#define SetPerm SetPermFFS
void SetPerm(FCOM_T *comm_ptr, mode_t mode);
#define FsInitFCB FsInitFCBFFS
void FsInitFCB(FILE *file, ui32 type);
int ReadPartitions(const FatVol *fat_vol, Partition *partitions,
int max_partitions);
int WritePartitions(const FatVol *fat_vol, Partition *partitions,
int num_partitions);
void GenEccTable(void);
void EncodeEcc(const ui32 *page, ui8 *ecc);
int DecodeEcc(ui32 *page, const ui8 *ecc);
void FtlNandEncode(const ui8 *data, ui8 *ecc);
int FtlNandDecode(ui8 *data, const ui8 *ecc);
#define QuickSort QuickSortFFS
void QuickSort(FFSEnt **head, FFSEnt **tail, DirEntry *e1,
DirEntry *e2, int (*cmp) (const DirEntry *,
const DirEntry *));
#ifdef __cplusplus
}
#endif
#endif /* _FSPRIVATE_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -