2 * Acess2 FAT Filesystem Driver
3 * - By John Hodge (thePowersGang)
6 * - FAT internal common header
8 #ifndef _FS__FAT__COMMON_H_
9 #define _FS__FAT__COMMON_H_
14 #define CACHE_FAT 0 //!< Caches the FAT in memory
15 #define USE_LFN 1 //!< Enables the use of Long File Names
16 #define SUPPORT_WRITE 1 //!< Enables write support
18 #define FAT_FLAG_DIRTY 0x10000
19 #define FAT_FLAG_DELETE 0x20000
21 typedef struct sFAT_VolInfo tFAT_VolInfo;
23 typedef struct sFAT_LFNCacheEnt tFAT_LFNCacheEnt;
24 typedef struct sFAT_LFNCache tFAT_LFNCache;
26 typedef struct sFAT_CachedNode tFAT_CachedNode;
29 * \brief Internal IDs for FAT types
33 FAT12, //!< FAT12 Volume
34 FAT16, //!< FAT16 Volume
35 FAT32, //!< FAT32 Volume
41 int fileHandle; //!< File Handle
42 enum eFatType type; //!< FAT Variant
43 char name[12]; //!< Volume Name (With NULL Terminator)
44 Uint32 firstDataSect; //!< First data sector
45 Uint32 rootOffset; //!< Root Offset (clusters)
46 Uint32 ClusterCount; //!< Total Cluster Count
47 fat_bootsect bootsect; //!< Boot Sector
48 tVFS_Node rootNode; //!< Root Node
52 tFAT_CachedNode *NodeCache;
54 tMutex lFAT; //!< Lock to prevent double-writing to the FAT
56 Uint32 *FATCache; //!< FAT Cache
62 * \brief Long-Filename cache entry
64 struct sFAT_LFNCacheEnt
70 * \brief Long-Filename cache
75 tFAT_LFNCacheEnt Entries[];
79 struct sFAT_CachedNode
81 struct sFAT_CachedNode *Next;
85 // --- General Helpers ---
86 extern int FAT_int_GetAddress(tVFS_Node *Node, Uint64 Offset, Uint64 *Addr, Uint32 *Cluster);
87 extern tTime FAT_int_GetAcessTimestamp(Uint16 Date, Uint16 Time, Uint8 MS);
88 extern void FAT_int_GetFATTimestamp(tTime AcessTimestamp, Uint16 *Date, Uint16 *Time, Uint8 *MS);
90 // --- Node Caching ---
91 // NOTE: FAT uses its own node cache that references by cluster (not the inode value that the Inode_* cache uses)
92 // because tVFS_Node.Inode contains the parent directory inode
93 extern tVFS_Node *FAT_int_CreateNode(tVFS_Node *Parent, fat_filetable *Entry);
94 extern tVFS_Node *FAT_int_CreateIncompleteDirNode(tFAT_VolInfo *Disk, Uint32 Cluster);
95 extern tVFS_Node *FAT_int_GetNode(tFAT_VolInfo *Disk, Uint32 Cluster);
96 extern int FAT_int_DerefNode(tVFS_Node *Node);
97 extern void FAT_int_ClearNodeCache(tFAT_VolInfo *Disk);
100 extern Uint32 FAT_int_GetFatValue(tFAT_VolInfo *Disk, Uint32 Cluster);
102 extern Uint32 FAT_int_AllocateCluster(tFAT_VolInfo *Disk, Uint32 Previous);
103 extern Uint32 FAT_int_FreeCluster(tFAT_VolInfo *Disk, Uint32 Cluster);
105 extern void FAT_int_ReadCluster(tFAT_VolInfo *Disk, Uint32 Cluster, int Length, void *Buffer);
106 extern void FAT_int_WriteCluster(tFAT_VolInfo *Disk, Uint32 Cluster, const void *Buffer);
108 // --- Directory Access ---
109 extern char *FAT_ReadDir(tVFS_Node *Node, int ID);
110 extern tVFS_Node *FAT_FindDir(tVFS_Node *Node, const char *Name);
111 extern tVFS_Node *FAT_GetNodeFromINode(tVFS_Node *Root, Uint64 Inode);
112 extern int FAT_int_GetEntryByCluster(tVFS_Node *DirNode, Uint32 Cluster, fat_filetable *Entry);
114 extern int FAT_int_WriteDirEntry(tVFS_Node *Node, int ID, fat_filetable *Entry);
115 extern int FAT_Mknod(tVFS_Node *Node, const char *Name, Uint Flags);
116 extern int FAT_Link(tVFS_Node *DirNode, const char *NewName, tVFS_Node *Node);
117 extern int FAT_Unlink(tVFS_Node *DirNode, const char *OldName);
119 extern void FAT_CloseFile(tVFS_Node *node);
122 extern tVFS_NodeType gFAT_DirType;
123 extern tVFS_NodeType gFAT_FileType;