Kernel - VFS API Update - ReadDir caller provided buffer
[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  ClusterCount;   //!< Total Cluster Count
47         fat_bootsect    bootsect;       //!< Boot Sector
48         tVFS_Node       rootNode;       //!< Root Node
49         size_t  BytesPerCluster;
50         
51         tMutex  lNodeCache;
52         tFAT_CachedNode *NodeCache;
53         
54         tMutex  lFAT;           //!< Lock to prevent double-writing to the FAT
55         #if CACHE_FAT
56         Uint32  *FATCache;      //!< FAT Cache
57         #endif
58 };
59
60 #if USE_LFN
61 /**
62  * \brief Long-Filename cache entry
63  */
64 struct sFAT_LFNCacheEnt
65 {
66          int    ID;
67         Uint16  Data[256];
68 };
69 /**
70  * \brief Long-Filename cache
71  */
72 struct sFAT_LFNCache
73 {
74          int    NumEntries;
75         tFAT_LFNCacheEnt        Entries[];
76 };
77 #endif
78
79 struct sFAT_CachedNode
80 {
81         struct sFAT_CachedNode  *Next;
82         tVFS_Node       Node;
83 };
84
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);
89
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);
98
99 // --- FAT Access ---
100 extern Uint32   FAT_int_GetFatValue(tFAT_VolInfo *Disk, Uint32 Cluster);
101 #if SUPPORT_WRITE
102 extern Uint32   FAT_int_AllocateCluster(tFAT_VolInfo *Disk, Uint32 Previous);
103 extern Uint32   FAT_int_FreeCluster(tFAT_VolInfo *Disk, Uint32 Cluster);
104 #endif
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);
107
108 // --- Directory Access ---
109 extern int      FAT_ReadDir(tVFS_Node *Node, int ID, char Dest[FILENAME_MAX]);
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);
113 #if SUPPORT_WRITE
114 extern int      FAT_int_WriteDirEntry(tVFS_Node *Node, int ID, fat_filetable *Entry);
115 extern tVFS_Node        *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);
118 #endif
119 extern void     FAT_CloseFile(tVFS_Node *node);
120
121 // === GLOBALS ===
122 extern tVFS_NodeType    gFAT_DirType;
123 extern tVFS_NodeType    gFAT_FileType;
124
125 #endif
126

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