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 RootSector; //!< Root Offset (sectors)
47 Uint32 ClusterCount; //!< Total Cluster Count
48 fat_bootsect bootsect; //!< Boot Sector
49 tVFS_Node rootNode; //!< Root Node
50 size_t BytesPerCluster;
53 tFAT_CachedNode *NodeCache;
55 tMutex lFAT; //!< Lock to prevent double-writing to the FAT
57 Uint32 *FATCache; //!< FAT Cache
63 * \brief Long-Filename cache entry
65 struct sFAT_LFNCacheEnt
71 * \brief Long-Filename cache
76 tFAT_LFNCacheEnt Entries[];
80 struct sFAT_CachedNode
82 struct sFAT_CachedNode *Next;
86 // --- General Helpers ---
87 extern int FAT_int_GetAddress(tVFS_Node *Node, Uint64 Offset, Uint64 *Addr, Uint32 *Cluster);
88 extern tTime FAT_int_GetAcessTimestamp(Uint16 Date, Uint16 Time, Uint8 MS);
89 extern void FAT_int_GetFATTimestamp(tTime AcessTimestamp, Uint16 *Date, Uint16 *Time, Uint8 *MS);
91 // --- Node Caching ---
92 // NOTE: FAT uses its own node cache that references by cluster (not the inode value that the Inode_* cache uses)
93 // because tVFS_Node.Inode contains the parent directory inode
94 extern tVFS_Node *FAT_int_CreateNode(tVFS_Node *Parent, fat_filetable *Entry);
95 extern tVFS_Node *FAT_int_CreateIncompleteDirNode(tFAT_VolInfo *Disk, Uint32 Cluster);
96 extern tVFS_Node *FAT_int_GetNode(tFAT_VolInfo *Disk, Uint32 Cluster);
97 extern int FAT_int_DerefNode(tVFS_Node *Node);
98 extern void FAT_int_ClearNodeCache(tFAT_VolInfo *Disk);
100 // --- FAT Access ---
101 #define GETFATVALUE_EOC 0xFFFFFFFF
102 extern Uint32 FAT_int_GetFatValue(tFAT_VolInfo *Disk, Uint32 Cluster);
104 extern Uint32 FAT_int_AllocateCluster(tFAT_VolInfo *Disk, Uint32 Previous);
105 extern Uint32 FAT_int_FreeCluster(tFAT_VolInfo *Disk, Uint32 Cluster);
107 extern void FAT_int_ReadCluster(tFAT_VolInfo *Disk, Uint32 Cluster, int Length, void *Buffer);
108 extern void FAT_int_WriteCluster(tFAT_VolInfo *Disk, Uint32 Cluster, const void *Buffer);
110 // --- Directory Access ---
111 extern int FAT_ReadDir(tVFS_Node *Node, int ID, char Dest[FILENAME_MAX]);
112 extern tVFS_Node *FAT_FindDir(tVFS_Node *Node, const char *Name, Uint Flags);
113 extern tVFS_Node *FAT_GetNodeFromINode(tVFS_Node *Root, Uint64 Inode);
114 extern int FAT_int_GetEntryByCluster(tVFS_Node *DirNode, Uint32 Cluster, fat_filetable *Entry);
116 extern int FAT_int_WriteDirEntry(tVFS_Node *Node, int ID, fat_filetable *Entry);
117 extern tVFS_Node *FAT_Mknod(tVFS_Node *Node, const char *Name, Uint Flags);
118 extern int FAT_Link(tVFS_Node *DirNode, const char *NewName, tVFS_Node *Node);
119 extern int FAT_Unlink(tVFS_Node *DirNode, const char *OldName);
121 extern void FAT_CloseFile(tVFS_Node *node);
124 extern tVFS_NodeType gFAT_DirType;
125 extern tVFS_NodeType gFAT_FileType;