📄 fs_fat32.h
字号:
# define FSI_GETSTRUCTSIG(p) fat_getuint32(UBYTE_PTR(p,FSI_STRUCTSIG))# define FSI_GETFREECOUNT(p) fat_getuint32(UBYTE_PTR(p,FSI_FREECOUNT))# define FSI_GETNXTFREE(p) fat_getuint32(UBYTE_PTR(p,FSI_NXTFREE))# define FSI_GETTRAILSIG(p) fat_getuint32(UBYTE_PTR(p,FSI_TRAILSIG))# define DIR_GETCRTIME(p) fat_getuint16(UBYTE_PTR(p,DIR_CRTIME))# define DIR_GETCRDATE(p) fat_getuint16(UBYTE_PTR(p,DIR_CRDATE))# define DIR_GETLASTACCDATE(p) fat_getuint16(UBYTE_PTR(p,DIR_LASTACCDATE))# define DIR_GETFSTCLUSTHI(p) fat_getuint16(UBYTE_PTR(p,DIR_FSTCLUSTHI))# define DIR_GETWRTTIME(p) fat_getuint16(UBYTE_PTR(p,DIR_WRTTIME))# define DIR_GETWRTDATE(p) fat_getuint16(UBYTE_PTR(p,DIR_WRTDATE))# define DIR_GETFSTCLUSTLO(p) fat_getuint16(UBYTE_PTR(p,DIR_FSTCLUSTLO))# define DIR_GETFILESIZE(p) fat_getuint32(UBYTE_PTR(p,DIR_FILESIZE))# define FSI_GETLEADSIG(p) fat_getuint32(UBYTE_PTR(p,FSI_LEADSIG))# define FSI_GETSTRUCTSIG(p) fat_getuint32(UBYTE_PTR(p,FSI_STRUCTSIG))# define FSI_GETFREECOUNT(p) fat_getuint32(UBYTE_PTR(p,FSI_FREECOUNT))# define FSI_GETNXTFREE(p) fat_getuint32(UBYTE_PTR(p,FSI_NXTFREE))# define FSI_GETTRAILSIG(p) fat_getuint32(UBYTE_PTR(p,FSI_TRAILSIG))# define FAT_GETFAT16(p,i) fat_getuint16(UBYTE_PTR(p,i))# define FAT_GETFAT32(p,i) fat_getuint32(UBYTE_PTR(p,i))# define MBR_PUTRESVDSECCOUNT(p,v) fat_putuint16(UBYTE_PTR(p,BS_RESVDSECCOUNT,v))# define MBR_PUTFATSZ16(p,v) fat_putuint16(UBYTE_PTR(p,BS_FATSZ16,v))# define MBR_PUTSECPERTRK(p,v) fat_putuint16(UBYTE_PTR(p,BS_SECPERTRK,v))# define MBR_PUTNUMHEADS(p,v) fat_putuint16(UBYTE_PTR(p,BS_NUMHEADS,v))# define MBR_PUTHIDSEC(p,v) fat_putuint32(UBYTE_PTR(p,BS_HIDSEC,v))# define MBR_PUTTOTSEC32(p,v) fat_putuint32(UBYTE_PTR(p,BS_TOTSEC32,v))# define MBR_PUTFATSZ32(p,v) fat_putuint32(UBYTE_PTR(p,BS32_FATSZ32,v))# define MBR_PUTEXTFLAGS(p,v) fat_putuint16(UBYTE_PTR(p,BS32_EXTFLAGS,v))# define MBR_PUTFSVER(p,v) fat_putuint16(UBYTE_PTR(p,BS32_FSVER,v))# define MBR_PUTROOTCLUS(p,v) fat_putuint32(UBYTE_PTR(p,BS32_ROOTCLUS,v))# define MBR_PUTFSINFO(p,v) fat_putuint16(UBYTE_PTR(p,BS32_FSINFO,v))# define MBR_PUTBKBOOTSEC(p,v) fat_putuint16(UBYTE_PTR(p,BS32_BKBOOTSEC,v))# define MBR_PUTSIGNATURE(p,v) fat_getuint16(UBYTE_PTR(p,BS_SIGNATURE),v)# define FSI_PUTLEADSIG(p,v) fat_putuint32(UBYTE_PTR(p,FSI_LEADSIG),v)# define FSI_PUTSTRUCTSIG(p,v) fat_putuint32(UBYTE_PTR(p,FSI_STRUCTSIG),v)# define FSI_PUTFREECOUNT(p,v) fat_putuint32(UBYTE_PTR(p,FSI_FREECOUNT),v)# define FSI_PUTNXTFREE(p,v) fat_putuint32(UBYTE_PTR(p,FSI_NXTFREE),v)# define FSI_PUTTRAILSIG(p,v) fat_putuint32(UBYTE_PTR(p,FSI_TRAILSIG),v)# define DIR_PUTCRTIME(p,v) fat_putuint16(UBYTE_PTR(p,DIR_CRTIME),v)# define DIR_PUTCRDATE(p,v) fat_putuint16(UBYTE_PTR(p,DIR_CRDATE),v)# define DIR_PUTLASTACCDATE(p,v) fat_putuint16(UBYTE_PTR(p,DIR_LASTACCDATE),v)# define DIR_PUTFSTCLUSTHI(p,v) fat_putuint16(UBYTE_PTR(p,DIR_FSTCLUSTHI),v)# define DIR_PUTWRTTIME(p,v) fat_putuint16(UBYTE_PTR(p,DIR_WRTTIME),v)# define DIR_PUTWRTDATE(p,v) fat_putuint16(UBYTE_PTR(p,DIR_WRTDATE),v)# define DIR_PUTFSTCLUSTLO(p,v) fat_putuint16(UBYTE_PTR(p,DIR_FSTCLUSTLO),v)# define DIR_PUTFILESIZE(p,v) fat_putuint32(UBYTE_PTR(p,DIR_FILESIZE),v)# define FSI_PUTLEADSIG(p,v) fat_putuint32(UBYTE_PTR(p,FSI_LEADSIG),v)# define FSI_PUTSTRUCTSIG(p,v) fat_putuint32(UBYTE_PTR(p,FSI_STRUCTSIG),v)# define FSI_PUTFREECOUNT(p,v) fat_putuint32(UBYTE_PTR(p,FSI_FREECOUNT),v)# define FSI_PUTNXTFREE(p,v) fat_putuint32(UBYTE_PTR(p,FSI_NXTFREE),v)# define FSI_PUTTRAILSIG(p,v) fat_putuint32(UBYTE_PTR(p,FSI_TRAILSIG),v)# define FAT_PUTFAT16(p,i,v) fat_putuint16(UBYTE_PTR(p,i),v)# define FAT_PUTFAT32(p,i,v) fat_putuint32(UBYTE_PTR(p,i),v)#else/* But nothing special has to be done for the little endian-case for access * to aligned mulitbyte values. */# define MBR_GETRESVDSECCOUNT(p) UINT16_VAL(p,BS_RESVDSECCOUNT)# define MBR_GETFATSZ16(p) UINT16_VAL(p,BS_FATSZ16)# define MBR_GETSECPERTRK(p) UINT16_VAL(p,BS_SECPERTRK)# define MBR_GETNUMHEADS(p) UINT16_VAL(p,BS_NUMHEADS)# define MBR_GETHIDSEC(p) UINT32_VAL(p,BS_HIDSEC)# define MBR_GETTOTSEC32(p) UINT32_VAL(p,BS_TOTSEC32)# define MBR_GETFATSZ32(p) UINT32_VAL(p,BS32_FATSZ32)# define MBR_GETEXTFLAGS(p) UINT16_VAL(p,BS32_EXTFLAGS)# define MBR_GETFSVER(p) UINT16_VAL(p,BS32_FSVER)# define MBR_GETROOTCLUS(p) UINT32_VAL(p,BS32_ROOTCLUS)# define MBR_GETFSINFO(p) UINT16_VAL(p,BS32_FSINFO)# define MBR_GETBKBOOTSEC(p) UINT16_VAL(p,BS32_BKBOOTSEC)# define MBR_GETSIGNATURE(p) UINT16_VAL(p,BS_SIGNATURE)# define MBR_GETPARTSECTOR(s) (*((uint32*)(s)))# define FSI_GETLEADSIG(p) UINT32_VAL(p,FSI_LEADSIG)# define FSI_GETSTRUCTSIG(p) UINT32_VAL(p,FSI_STRUCTSIG)# define FSI_GETFREECOUNT(p) UINT32_VAL(p,FSI_FREECOUNT)# define FSI_GETNXTFREE(p) UINT32_VAL(p,FSI_NXTFREE)# define FSI_GETTRAILSIG(p) UINT32_VAL(p,FSI_TRAILSIG)# define DIR_GETCRTIME(p) UINT16_VAL(p,DIR_CRTIME)# define DIR_GETCRDATE(p) UINT16_VAL(p,DIR_CRDATE)# define DIR_GETLASTACCDATE(p) UINT16_VAL(p,DIR_LASTACCDATE)# define DIR_GETFSTCLUSTHI(p) UINT16_VAL(p,DIR_FSTCLUSTHI)# define DIR_GETWRTTIME(p) UINT16_VAL(p,DIR_WRTTIME)# define DIR_GETWRTDATE(p) UINT16_VAL(p,DIR_WRTDATE)# define DIR_GETFSTCLUSTLO(p) UINT16_VAL(p,DIR_FSTCLUSTLO)# define DIR_GETFILESIZE(p) UINT32_VAL(p,DIR_FILESIZE)# define FSI_GETLEADSIG(p) UINT32_VAL(p,FSI_LEADSIG)# define FSI_GETSTRUCTSIG(p) UINT32_VAL(p,FSI_STRUCTSIG)# define FSI_GETFREECOUNT(p) UINT32_VAL(p,FSI_FREECOUNT)# define FSI_GETNXTFREE(p) UINT32_VAL(p,FSI_NXTFREE)# define FSI_GETTRAILSIG(p) UINT32_VAL(p,FSI_TRAILSIG)# define FAT_GETFAT16(p,i) UINT16_VAL(p,i)# define FAT_GETFAT32(p,i) UINT32_VAL(p,i)# define MBR_PUTRESVDSECCOUNT(p,v) UINT16_PUT(p,BS_RESVDSECCOUNT,v)# define MBR_PUTFATSZ16(p,v) UINT16_PUT(p,BS_FATSZ16,v)# define MBR_PUTSECPERTRK(p,v) UINT16_PUT(p,BS_SECPERTRK,v)# define MBR_PUTNUMHEADS(p,v) UINT16_PUT(p,BS_NUMHEADS,v)# define MBR_PUTHIDSEC(p,v) UINT32_PUT(p,BS_HIDSEC,v)# define MBR_PUTTOTSEC32(p,v) UINT32_PUT(p,BS_TOTSEC32,v)# define MBR_PUTFATSZ32(p,v) UINT32_PUT(p,BS32_FATSZ32,v)# define MBR_PUTEXTFLAGS(p,v) UINT16_PUT(p,BS32_EXTFLAGS,v)# define MBR_PUTFSVER(p,v) UINT16_PUT(p,BS32_FSVER,v)# define MBR_PUTROOTCLUS(p,v) UINT32_PUT(p,BS32_ROOTCLUS,v)# define MBR_PUTFSINFO(p,v) UINT16_PUT(p,BS32_FSINFO,v)# define MBR_PUTBKBOOTSEC(p,v) UINT16_PUT(p,BS32_BKBOOTSEC,v)# define MBR_PUTSIGNATURE(p,v) UINT16_PUT(p,BS_SIGNATURE,v)# define FSI_PUTLEADSIG(p,v) UINT32_PUT(p,FSI_LEADSIG,v)# define FSI_PUTSTRUCTSIG(p,v) UINT32_PUT(p,FSI_STRUCTSIG,v)# define FSI_PUTFREECOUNT(p,v) UINT32_PUT(p,FSI_FREECOUNT,v)# define FSI_PUTNXTFREE(p,v) UINT32_PUT(p,FSI_NXTFREE,v)# define FSI_PUTTRAILSIG(p,v) UINT32_PUT(p,FSI_TRAILSIG,v)# define DIR_PUTCRTIME(p,v) UINT16_PUT(p,DIR_CRTIME,v)# define DIR_PUTCRDATE(p,v) UINT16_PUT(p,DIR_CRDATE,v)# define DIR_PUTLASTACCDATE(p,v) UINT16_PUT(p,DIR_LASTACCDATE,v)# define DIR_PUTFSTCLUSTHI(p,v) UINT16_PUT(p,DIR_FSTCLUSTHI,v)# define DIR_PUTWRTTIME(p,v) UINT16_PUT(p,DIR_WRTTIME,v)# define DIR_PUTWRTDATE(p,v) UINT16_PUT(p,DIR_WRTDATE,v)# define DIR_PUTFSTCLUSTLO(p,v) UINT16_PUT(p,DIR_FSTCLUSTLO,v)# define DIR_PUTFILESIZE(p,v) UINT32_PUT(p,DIR_FILESIZE,v)# define FSI_PUTLEADSIG(p,v) UINT32_PUT(p,FSI_LEADSIG,v)# define FSI_PUTSTRUCTSIG(p,v) UINT32_PUT(p,FSI_STRUCTSIG,v)# define FSI_PUTFREECOUNT(p,v) UINT32_PUT(p,FSI_FREECOUNT,v)# define FSI_PUTNXTFREE(p,v) UINT32_PUT(p,FSI_NXTFREE,v)# define FSI_PUTTRAILSIG(p,v) UINT32_PUT(p,FSI_TRAILSIG,v)# define FAT_PUTFAT16(p,i,v) UINT16_PUT(p,i,v)# define FAT_PUTFAT32(p,i,v) UINT32_PUT(p,i,v)#endif/**************************************************************************** * Public Types ****************************************************************************//* This structure represents the overall mountpoint state. An instance of this * structure is retained as inode private data on each mountpoint that is * mounted with a fat32 filesystem. */struct fat_file_s;struct fat_mountpt_s{ struct inode *fs_blkdriver; /* The block driver inode that hosts the FAT32 fs */ struct fat_file_s *fs_head; /* A list to all files opened on this mountpoint */ sem_t fs_sem; /* Used to assume thread-safe access */ size_t fs_hwsectorsize; /* HW: Sector size reported by block driver*/ size_t fs_hwnsectors; /* HW: The number of sectors reported by the hardware */ size_t fs_fatbase; /* Logical block of start of filesystem (past resd sectors) */ size_t fs_rootbase; /* MBR: Cluster no. of 1st cluster of root dir */ size_t fs_database; /* Logical block of start data sectors */ size_t fs_fsinfo; /* MBR: Sector number of FSINFO sector */ size_t fs_currentsector; /* The sector number buffered in fs_buffer */ uint32 fs_nclusters; /* Maximum number of data clusters */ uint32 fs_nfatsects; /* MBR: Count of sectors occupied by one fat */ uint32 fs_fattotsec; /* MBR: Total count of sectors on the volume */ uint32 fs_fsifreecount; /* FSI: Last free cluster count on volume */ uint32 fs_fsinextfree; /* FSI: Cluster number of 1st free cluster */ uint16 fs_fatresvdseccount; /* MBR: The total number of reserved sectors */ uint16 fs_rootentcnt; /* MBR: Count of 32-bit root directory entries */ boolean fs_mounted; /* TRUE: The file system is ready */ boolean fs_dirty; /* TRUE: fs_buffer is dirty */ boolean fs_fsidirty; /* TRUE: FSINFO sector must be written to disk */ ubyte fs_type; /* FSTYPE_FAT12, FSTYPE_FAT16, or FSTYPE_FAT32 */ ubyte fs_fatnumfats; /* MBR: Number of FATs (probably 2) */ ubyte fs_fatsecperclus; /* MBR: Sectors per allocation unit: 2**n, n=0..7 */ ubyte *fs_buffer; /* This is an allocated buffer to hold one sector * from the device */};/* This structure represents on open file under the mountpoint. An instance * of this structure is retained as struct file specific information on each * opened file. */struct fat_file_s{ struct fat_file_s *ff_next; /* Retained in a singly linked list */ boolean ff_open; /* TRUE: The file is (still) open */ ubyte ff_bflags; /* The file buffer flags */ ubyte ff_oflags; /* Flags provided when file was opened */ ubyte ff_sectorsincluster; /* Sectors remaining in cluster */ uint16 ff_dirindex; /* Index into ff_dirsector to directory entry */ uint32 ff_currentcluster; /* Current cluster being accessed */ size_t ff_dirsector; /* Sector containing the directory entry */ size_t ff_position; /* File position for read/write/seek in bytes */ size_t ff_size; /* Size of the file in bytes */ size_t ff_startcluster; /* Start cluster of file on media */ size_t ff_currentsector; /* Current sector in the file buffer */ ubyte *ff_buffer; /* File buffer (for partial sector accesses) */};/* This structure is used internally for describing directory entries */struct fat_dirinfo_s{ ubyte fd_name[8+3]; /* Filename -- directory format*/#ifdef CONFIG_FAT_LCNAMES ubyte fd_ntflags; /* NTRes lower case flags */#endif struct fs_fatdir_s dir; /* Used with opendir, readdir, etc. */ ubyte *fd_entry; /* A pointer to the raw 32-byte entry */};/**************************************************************************** * Global Variables ****************************************************************************//**************************************************************************** * Public Function Prototypes ****************************************************************************/#undef EXTERN#if defined(__cplusplus)#define EXTERN extern "C"extern "C" {#else#define EXTERN extern#endif/* Utitilies to handle unaligned or byte swapped accesses */EXTERN uint16 fat_getuint16(ubyte *ptr);EXTERN uint32 fat_getuint32(ubyte *ptr);EXTERN void fat_putuint16(ubyte *ptr, uint16 value16);EXTERN void fat_putuint32(ubyte *ptr, uint32 value32);/* Manage the per-mount semaphore that protects access to shared resources */EXTERN void fat_semtake(struct fat_mountpt_s *fs);EXTERN void fat_semgive(struct fat_mountpt_s *fs);/* Get the current time for FAT creation and write times */EXTERN uint32 fat_systime2fattime(void);EXTERN time_t fat_fattime2systime(uint16 time, uint16 date);/* Handle hardware interactions for mounting */EXTERN int fat_mount(struct fat_mountpt_s *fs, boolean writeable);EXTERN int fat_checkmount(struct fat_mountpt_s *fs);/* low-level hardware access */EXTERN int fat_hwread(struct fat_mountpt_s *fs, ubyte *buffer, size_t sector, unsigned int nsectors);EXTERN int fat_hwwrite(struct fat_mountpt_s *fs, ubyte *buffer, size_t sector, unsigned int nsectors);/* Cluster / cluster chain access helpers */EXTERN ssize_t fat_cluster2sector(struct fat_mountpt_s *fs, uint32 cluster );EXTERN ssize_t fat_getcluster(struct fat_mountpt_s *fs, uint32 clusterno);EXTERN int fat_putcluster(struct fat_mountpt_s *fs, uint32 clusterno, size_t startsector);EXTERN int fat_removechain(struct fat_mountpt_s *fs, uint32 cluster);EXTERN sint32 fat_extendchain(struct fat_mountpt_s *fs, uint32 cluster);#define fat_createchain(fs) fat_extendchain(fs, 0)/* Help for traversing directory trees */EXTERN int fat_nextdirentry(struct fat_mountpt_s *fs, struct fs_fatdir_s *dir);EXTERN int fat_finddirentry(struct fat_mountpt_s *fs, struct fat_dirinfo_s *dirinfo, const char *path);EXTERN int fat_allocatedirentry(struct fat_mountpt_s *fs, struct fat_dirinfo_s *dirinfo);EXTERN int fat_dirname2path(char *path, ubyte *direntry);/* File creation and removal helpers */EXTERN int fat_dirtruncate(struct fat_mountpt_s *fs, struct fat_dirinfo_s *dirinfo);EXTERN int fat_dircreate(struct fat_mountpt_s *fs, struct fat_dirinfo_s *dirinfo);EXTERN int fat_remove(struct fat_mountpt_s *fs, const char *relpath, boolean directory);/* Mountpoint and file buffer cache (for partial sector accesses) */EXTERN int fat_fscacheflush(struct fat_mountpt_s *fs);EXTERN int fat_fscacheread(struct fat_mountpt_s *fs, size_t sector);EXTERN int fat_ffcacheflush(struct fat_mountpt_s *fs, struct fat_file_s *ff);EXTERN int fat_ffcacheread(struct fat_mountpt_s *fs, struct fat_file_s *ff, size_t sector);EXTERN int fat_ffcacheinvalidate(struct fat_mountpt_s *fs, struct fat_file_s *ff);/* FSINFO sector support */EXTERN int fat_updatefsinfo(struct fat_mountpt_s *fs);EXTERN int fat_nfreeclusters(struct fat_mountpt_s *fs, size_t *pfreeclusters);#undef EXTERN#if defined(__cplusplus)}#endif#endif /* __FS_FAT_FS_FAT32_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -