Kernel - Added 'Flags' param to VFS Read/Write/FindDir
[tpg/acess2.git] / KernelLand / Modules / Filesystems / FAT / common.h
1 /*
2  * Acess2 FAT Filesystem Driver
3  * - By John Hodge (thePowersGang)
4  * 
5  * common.h
6  * - FAT internal common header
7  */
8 #ifndef _FS__FAT__COMMON_H_
9 #define _FS__FAT__COMMON_H_
10
11 #include "fs_fat.h"
12 #include <vfs.h>
13
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
17
18 #define FAT_FLAG_DIRTY  0x10000
19 #define FAT_FLAG_DELETE 0x20000
20
21 typedef struct sFAT_VolInfo tFAT_VolInfo;
22 #if USE_LFN
23 typedef struct sFAT_LFNCacheEnt tFAT_LFNCacheEnt;
24 typedef struct sFAT_LFNCache    tFAT_LFNCache;
25 #endif
26 typedef struct sFAT_CachedNode  tFAT_CachedNode;
27
28 /**
29  * \brief Internal IDs for FAT types
30  */
31 enum eFatType
32 {
33         FAT12,  //!< FAT12 Volume
34         FAT16,  //!< FAT16 Volume
35         FAT32,  //!< FAT32 Volume
36 };
37
38 // === TYPES ===
39 struct sFAT_VolInfo
40 {
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;
51         
52         tMutex  lNodeCache;
53         tFAT_CachedNode *NodeCache;
54         
55         tMutex  lFAT;           //!< Lock to prevent double-writing to the FAT
56         #if CACHE_FAT
57         Uint32  *FATCache;      //!< FAT Cache
58         #endif
59 };
60
61 #if USE_LFN
62 /**
63  * \brief Long-Filename cache entry
64  */
65 struct sFAT_LFNCacheEnt
66 {
67          int    ID;
68         Uint16  Data[256];
69 };
70 /**
71  * \brief Long-Filename cache
72  */
73 struct sFAT_LFNCache
74 {
75          int    NumEntries;
76         tFAT_LFNCacheEnt        Entries[];
77 };
78 #endif
79
80 struct sFAT_CachedNode
81 {
82         struct sFAT_CachedNode  *Next;
83         tVFS_Node       Node;
84 };
85
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);
90
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);
99
100 // --- FAT Access ---
101 #define GETFATVALUE_EOC 0xFFFFFFFF
102 extern Uint32   FAT_int_GetFatValue(tFAT_VolInfo *Disk, Uint32 Cluster);
103 #if SUPPORT_WRITE
104 extern Uint32   FAT_int_AllocateCluster(tFAT_VolInfo *Disk, Uint32 Previous);
105 extern Uint32   FAT_int_FreeCluster(tFAT_VolInfo *Disk, Uint32 Cluster);
106 #endif
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);
109
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);
115 #if SUPPORT_WRITE
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);
120 #endif
121 extern void     FAT_CloseFile(tVFS_Node *node);
122
123 // === GLOBALS ===
124 extern tVFS_NodeType    gFAT_DirType;
125 extern tVFS_NodeType    gFAT_FileType;
126
127 #endif
128

UCC git Repository :: git.ucc.asn.au