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);
88 // --- Node Caching ---
89 // NOTE: FAT uses its own node cache that references by cluster (not the inode value that the Inode_* cache uses)
90 // because tVFS_Node.Inode contains the parent directory inode
91 extern tVFS_Node *FAT_int_CreateNode(tVFS_Node *Parent, fat_filetable *Entry);
92 extern tVFS_Node *FAT_int_CreateIncompleteDirNode(tFAT_VolInfo *Disk, Uint32 Cluster);
93 extern tVFS_Node *FAT_int_GetNode(tFAT_VolInfo *Disk, Uint32 Cluster);
94 extern void FAT_int_DerefNode(tVFS_Node *Node);
95 extern void FAT_int_ClearNodeCache(tFAT_VolInfo *Disk);
98 extern Uint32 FAT_int_GetFatValue(tFAT_VolInfo *Disk, Uint32 Cluster);
100 extern Uint32 FAT_int_AllocateCluster(tFAT_VolInfo *Disk, Uint32 Previous);
101 extern Uint32 FAT_int_FreeCluster(tFAT_VolInfo *Disk, Uint32 Cluster);
103 extern void FAT_int_ReadCluster(tFAT_VolInfo *Disk, Uint32 Cluster, int Length, void *Buffer);
104 extern void FAT_int_WriteCluster(tFAT_VolInfo *Disk, Uint32 Cluster, const void *Buffer);
106 // --- Directory Access ---
107 extern char *FAT_ReadDir(tVFS_Node *Node, int ID);
108 extern tVFS_Node *FAT_FindDir(tVFS_Node *Node, const char *Name);
109 extern tVFS_Node *FAT_GetNodeFromINode(tVFS_Node *Root, Uint64 Inode);
110 extern int FAT_int_GetEntryByCluster(tVFS_Node *DirNode, Uint32 Cluster, fat_filetable *Entry);
112 extern int FAT_int_WriteDirEntry(tVFS_Node *Node, int ID, fat_filetable *Entry);
113 extern int FAT_Mknod(tVFS_Node *Node, const char *Name, Uint Flags);
114 extern int FAT_Link(tVFS_Node *DirNode, const char *NewName, tVFS_Node *Node);
115 extern int FAT_Unlink(tVFS_Node *DirNode, const char *OldName);
117 extern void FAT_CloseFile(tVFS_Node *node);
120 extern tVFS_NodeType gFAT_DirType;
121 extern tVFS_NodeType gFAT_FileType;