⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tmfat32private.h

📁 PNX1500上Fat32文件系统源代码
💻 H
📖 第 1 页 / 共 2 页
字号:

// File delete operations

#define DELETE_FILE_CONTENT      0x01
#define DELETE_FILE_DIRECTORY    0x02
#define DELETE_FILE_TRUNCATE     0x04

// Cache constants

#define FAT_CACHE               0
#define DATA_CACHE              1

#define MIN_FAT_CACHE_SECTORS   4   // Min number of FAT cache sectors we'll live with
#define MIN_DATA_CACHE_CLUSTERS 4   // Min number of DATA cache clusters we'll live with

#define PARTIAL_FLUSH           0   // Flush a selected sector or cluster
#define FULL_FLUSH              1   // Flush all sectors or clusters

// File I/O functions
 
typedef tmErrorCode_t  (*tmFat32_IOD_Init   )  ( void );
typedef tmErrorCode_t  (*tmFat32_IOD_Term   )  ( void );
typedef Int32 (*tmFat32_IOD_Open  )( String path, Int32 oflag,  Int32 mode);
typedef Int32 (*tmFat32_IOD_Stat  )( String path, struct stat *buf);
typedef Int32 (*tmFat32_IOD_Close )( Int32 file);
typedef Int32 (*tmFat32_IOD_Read  )( Int32 file,  Pointer buf,  Int32 nbyte);
typedef Int32 (*tmFat32_IOD_Write )( Int32 file,  Pointer buf,  Int32 nbyte);
typedef Int32 (*tmFat32_IOD_Seek  )( Int32 file,  Int32 offset, Int32 whence);
typedef Int32 (*tmFat32_IOD_Fstat )( Int32 file,  struct stat *buf);
typedef Int32 (*tmFat32_IOD_Fcntl )( Int32 file,  Int32 cmd,    Int32 flags);
typedef Int32 (*tmFat32_IOD_Sync  )( );
typedef Int32 (*tmFat32_IOD_FSync )( Int32 file );
typedef Int32 (*tmFat32_IOD_Unlink)( String path );
typedef Int32 (*tmFat32_IOD_Move  )( String src,  String dest );
typedef Int32 (*tmFat32_IOD_Link  )( String src,  String dest );
typedef Int32 (*tmFat32_IOD_Mkdir )( String path, Int32 mode );
typedef Int32 (*tmFat32_IOD_Rmdir )( String path );
typedef Int32 (*tmFat32_IOD_Access)( String path, Int32 mode );
typedef DIR*            (*tmFat32_IOD_Opendir  )( ConstString path );
typedef Int32           (*tmFat32_IOD_Closedir )( DIR*   dir  );
typedef void            (*tmFat32_IOD_Rewinddir)( DIR*   dir  );
typedef struct dirent*  (*tmFat32_IOD_Readdir  )( DIR*   dir  );


#if defined(__TCS__)

typedef struct tmFat32_dirent 
{
   long		d_ino;			/* Not used (0). */
   long		d_namelen;
   char	    d_name[TM_FAT32_MAX_LONG_NAME+1]; /* Null terminated name */

} tmFat32_dirent_t, *ptmFat32_dirent_t;

#else

typedef struct dirent	tmFat32_dirent_t;
typedef struct dirent*	ptmFat32_dirent_t;

#endif

/*
 * Useful information about an instance of the tmFat32 File System
 */
typedef struct tmFat32_FS 
{
#if USE_MML
    tmmlMmspHandle_t        heap;      // tmml heap for this volume
#endif
    /* Dispatch file I/O functions. */
  
    tmFat32_IOD_Init        Init;
    tmFat32_IOD_Term        Term;        
    tmFat32_IOD_Open        Open;
    tmFat32_IOD_Close       Close;
    tmFat32_IOD_Read        Read;
    tmFat32_IOD_Write       Write;
    tmFat32_IOD_Seek        Seek;
    tmFat32_IOD_Fstat       Fstat;        
    tmFat32_IOD_Fcntl       Fcntl;        
    tmFat32_IOD_Stat        Stat;    
    tmFat32_IOD_Sync        Sync;
    tmFat32_IOD_FSync       FSync;         
    tmFat32_IOD_Unlink      Unlink; 
    tmFat32_IOD_Link        Link;          
    tmFat32_IOD_Mkdir       Mkdir;         
    tmFat32_IOD_Rmdir       Rmdir;         
    tmFat32_IOD_Access      Access;         
    tmFat32_IOD_Opendir     Opendir; 
    tmFat32_IOD_Closedir    Closedir; 
    tmFat32_IOD_Rewinddir   Rewinddir;        
    tmFat32_IOD_Readdir     Readdir;  
    tmFat32_IOD_Move        Move;         

    /* Control info. */
    
    tmFat32_Control_t       ctl;
     
    /* Information about the device driver. */

    ptmFat32_DeviceDriver_t dev;
        
    /* Information about this volume (partition). */

    int             partIndex;          // Partition index

    tmFat32_FSType_t fsType;            // FAT32/FAT16/FAT12

    Bool            removable;          // Is device removable?
    Bool            cleanDismount;      // Was it dismounted cleanly the last time?
    Bool            hardwareErrors;     // Any disk read/write errors encountered
                                        // the last time it was mounted?
        
    UInt32          numSectors;         // Total number of sectors
    UInt32          maxCluster;         // Maximum valid cluster number. If N is the total
                                        // number of clusters then the valid range of cluster
                                        // numbers referenced by the FAT and directories is
                                        // [rootDirCluster, rootDirCluster + N - FAT_RESERVED_CLUSTERS]

    UInt64          partitionBase;      // Sector where partition begins (boot sector)
    UInt32          partitionBackup;    // Sector for backup copy of boot sector
    
    UInt64          extPartitionBase;   // Sector where extention partition begins

    UInt64          fsiBase;            // File System Information sector
    UInt32          fsiBackup;          // Sector for backup copy of FSI sector
    
    UInt32          sectorsPerCluster;  // Number of sectors per cluster
    UInt32          bytesPerCluster;    // Bytes per cluster
        
    UInt64          fatBase;            // Sector number for first FAT
    UInt32          fatSize;            // Sectors per FAT
    UInt32          fatCount;           // Number of FAT's
    UInt16          activeFat;          // Zero-based number of active FAT, valid
                                        // only if FAT mirroring is disabled.
    Bool            fatMirroring;       // If True, FAT is mirrored at runtime
                                        // to all FAT copies of the FAT.

    
    UInt64          dataAreaBase;       // Sector number for start of data area
                                        
    UInt32          rootDirCluster;     // Cluster number for start of root
                                        // Almost (?) always 2 for FAT32

    UInt32          freeClustersIn;     // Number of free clusters on mount, could be UNKNOWN_FSI_INFO
    UInt32          nextFreeClusterIn;  // Hint for next free cluster on mount, could be UNKNOWN_FSI_INFO
    
    UInt32          freeClusters;       // Number of free clusters on dismount
    UInt32          nextFreeCluster;    // Hint for next free cluster on dismount

    char            mountName[TM_FAT32_MAX_VOLUME_NAME+1];   // Mount name we use to recognize
    char            volumeName[TM_FAT32_MAX_VOLUME_NAME+1];  // DOS volume name from disk
    
    int             prefixLen;          // Length of prefix string of full path. E.g.,
                                        // length of "ABC:/foo/bar.txt" is 4.
    
    /* FAT cache. */
    
    Bool    fatCity;             // If true, entire FAT is in memory
    UInt32  fatNumSectors;       // Number of sectors in FAT cache
    UInt32  fatLockSectors;      // Number of sectors locked in FAT cache
    UInt32  fatCacheNext;        // Next available sector index
    Bool    *fatSectorDirty;     // Array of sector dirty flags
    UInt64  *fatSector;          // Array of sector numbers in FAT cache
    UInt32  *fatCache;           // Start of FAT cache, aligned for media I/O
   
    /* Data area cache. */

    UInt32  dataNumClusters;     // Number of clusters in data cache
    UInt32  dataLockClusters;    // Number of locked clusters in data cache
    UInt32  dataCacheNext;       // Next available cluster index
    Bool    *dataClusterDirty;   // Array of cluster dirty flags
    UInt32  *dataCluster;        // Array of clusters numbers in data cache
    UInt8   *dataCache;          // Start of data area cache, aligned for media I/O
    UInt8   *tempCluster;        // Scratch cluster

    /* Root directory cache -- FAT12/FAT16 only. */

    UInt32  rootDirNumSectors;   // Number of sectors in root directory cache
    Bool    *rootDirSectorDirty; // Array of root directory sector dirty flags
    UInt8   *rootDirCache;       // Start of root directory cache, aligned for media I/O

    /* Open files. */
    UInt    numOpenFiles;        // Number of open files.
    struct tmFat32_File_t  *openFilesList;    // Linked list of open files

    /* Helpers for finding files. */
    
    char    lastKnownDir[PATH_MAX+1]; // Last known 'current directory' location. Any
                                      // directory renames or deletions voids this.
    int     lastKnownLen;             // Length of lastKnownDir
    UInt32  lastKnownCluster;         // Cluster corresponding to this directory
        
    /* Linkage and other stuff. */

    struct tmFat32_FS  *next;    // Next tmFat32_FS block
    struct tmFat32_FS  *prev;    // Previous tmFat32_FS block

    UInt32		   iodriver;     // I/O driver instance, really an opaque
                                 // handle to UID_Driver for TriMedia

    Bool    terminated;          // If True Fat32_Term was called but files
                                 // may still be open.
	                             
} tmFat32_FS_t, *ptmFat32_FS_t;

/*
 * Useful directory information about a file or directory.
 */

typedef struct tmFat32_Dir 
{
    tmFat32_dirent_t    dirent;     // Our mapping of dirent for readdir
    char  shortName[8+3+1+1];       // 8.3 plus terminating Null
    UInt8 shortDir[DIR_ENTRY_SIZE]; // Short directory entry as it appears on disk
                                    // For root directory this is the volume id
                                    // record -- the first entry in the root directory

    UInt32  short_cluster;          // Cluster where the short entry is
    UInt32  short_offset;           // Offset into short cluster for this dir
    UInt32  long_cluster;           // Cluster where the first long entry is
    UInt32  long_offset;            // Offset into long cluster for this dir
    
    UInt8   slots;                  // Total number of DIR_ENTRY_SIZE slots for
                                    // this directory. It's 1 for short name
                                    // directories and greater than 1 for long
                                    // name directories. For short name directories
                                    // short_cluster equals long_cluster and short_offset
                                    // long_offset.
} tmFat32_Dir_t, *ptmFat32_Dir_t;

/*
 * Useful information about a file. (Directories are also files).
 */
typedef struct tmFat32_File 
{
    struct tmFat32_File_t  *next;       // Next tmFat32_File_t structure
    struct tmFat32_File_t  *prev;       // Previous tmFat32_File_t structure

    struct tmFat32_FS  *fs;             // Pointer to this file's tmFat32 file system. 

                                        
    String    fullname;                 // Pointer to full pathname of this file, e.g.,
                                        // e.g., "MYDISK:/foo/bar/x.txt"
                                        // For root directory fullname is Null
                                        
    Int32     oflag;                    // Flag when opened.
    Int32     mode;                     // Mode when opened.

    Bool      isDir;                    // Is this file a directory?
    Bool      isRootDir;                // Is this file a root directory? For FAT12/FAT16
    Bool      isOpen;                   // Is this file open?
    Bool      isContiguous;             // Is this file not fragmented?
    
    struct tmFat32_File_t  *fileInfo;   // Pointer to this structure if the file
                                        // is open. Otherwise it's Null.        
                                        
    UInt32    size;                     // Size in bytes
    
    UInt32    curpos;                   // Current position for reading or writing
    UInt32    seekpos;                  // Current seek position. The same as curpos unless
                                        // lseek position is beyond the end of the file.
                                        
    UInt32    cur_cluster;              // Cluster for current position
    UInt32    cur_offset;               // Offset into cluster for current position. Could be
                                        // size of cluster. If so, for write it means that the
                                        // next write will allocate a new cluster. For read, 
                                        // it means the file size is a multiple of cluster size
                                        // and the curpos is the end of file.

    UInt32    base_cluster;             // First cluster for the file

    tmFat32_Dir_t   dir;                // File's directory information
    
} tmFat32_File_t, *ptmFat32_File_t;

/* -------------------------------------------------------------------------- */
/*    Exported functions:                                                     */
/* -------------------------------------------------------------------------- */

//-----------------------------------------------------------------------------
// FUNCTION:    tmFat32_Mount
//
// DESCRIPTION: 
//
// RETURN:      tmErrorCode_t: Status of operation (TM_OK = PASS)
//
// NOTES:       
//-----------------------------------------------------------------------------
//

tmErrorCode_t
tmFat32_Mount (
    ptmFat32_FS_t  p    // I: Pointer to tmFat32_FS_t structure
    );
    
//-----------------------------------------------------------------------------
// FUNCTION:    tmFat32_Dismount
//
// DESCRIPTION: 
//
// RETURN:      tmErrorCode_t: Status of operation (TM_OK = PASS)
//
// NOTES:       
//-----------------------------------------------------------------------------
//

tmErrorCode_t
tmFat32_Dismount (
    ptmFat32_FS_t  p    // I: Pointer to tmFat32_FS_t structure
    );

//-----------------------------------------------------------------------------
// FUNCTION:    tmFat32_Find_Volume
//
// DESCRIPTION: Given a mount name find the mounted tmFat32 file system.
//
// RETURN:      Return Null if not found, otherwise return a pointer to
//              the mounted tmFat32 file system.
//
// NOTES:       
//-----------------------------------------------------------------------------
//

tmFat32_FS_t * tmFat32_Find_Volume(char *name);

/* -------------------------------------------------------------------------- */
/* End of extern c for C++ prototypes                                         */
/* -------------------------------------------------------------------------- */

#if defined(__cplusplus)
}
#endif

#endif	/* !defined(_TMFAT32PRIVATE_H_) */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -