Major revamp to FAT code, fixing LFN issues and other bugs
[tpg/acess2.git] / Modules / Filesystems / FAT / fs_fat.h
1 /*\r
2  * Acess2\r
3  * FAT12/16/32 Driver\r
4  * vfs/fs/fs_fat.h\r
5  */\r
6 #ifndef _FS_FAT_H_\r
7 #define _FS_FAT_H_\r
8 \r
9 // === On Disk Structures ===\r
10 /**\r
11  * \struct fat_bootsect_s\r
12  * \brief Bootsector format\r
13  */\r
14 struct fat_bootsect_s\r
15 {\r
16         Uint8   jmp[3]; //!< Jump Instruction\r
17         char    oemname[8];     //!< OEM Name. Typically MSDOS1.1\r
18         Uint16  bps;    //!< Bytes per Sector. Assumed to be 512\r
19         Uint8   spc;            //!< Sectors per Cluster\r
20         Uint16  resvSectCount;  //!< Number of reserved sectors at beginning of volume\r
21         Uint8   fatCount;       //!< Number of copies of the FAT\r
22         Uint16  files_in_root;  //!< Count of files in the root directory\r
23         Uint16  totalSect16;    //!< Total sector count (FAT12/16)\r
24         Uint8   mediaDesc;      //!< Media Desctiptor\r
25         Uint16  fatSz16;        //!< FAT Size (FAT12/16)\r
26         Uint16  spt;    //!< Sectors per track. Ignored (Acess uses LBA)\r
27         Uint16  heads;  //!< Heads. Ignored (Acess uses LBA)\r
28         Uint32  hiddenCount;    //!< ???\r
29         Uint32  totalSect32;    //!< Total sector count (FAT32)\r
30         union {\r
31                 struct {\r
32                         Uint8   drvNum; //!< Drive Number. BIOS Drive ID (E.g. 0x80)\r
33                         Uint8   resv;   //!< Reserved byte\r
34                         Uint8   bootSig;        //!< Boot Signature. ???\r
35                         Uint32  volId;  //!< Volume ID\r
36                         char    label[11];      //!< Disk Label\r
37                         char    fsType[8];      //!< FS Type. ???\r
38                 } __attribute__((packed)) fat16;        //!< FAT16 Specific information\r
39                 struct {\r
40                         Uint32  fatSz32;        //!< 32-Bit FAT Size\r
41                         Uint16  extFlags;       //!< Extended flags\r
42                         Uint16  fsVer;  //!< Filesystem Version\r
43                         Uint32  rootClust;      //!< Root Cluster ID\r
44                         Uint16  fsInfo; //!< FS Info. ???\r
45                         Uint16  backupBS;       //!< Backup Bootsector Sector Offset\r
46                         char    resv[12];       //!< Reserved Data\r
47                         Uint8   drvNum; //!< Drive Number\r
48                         char    resv2;  //!< Reserved Data\r
49                         Uint8   bootSig;        //!< Boot Signature. ???\r
50                         Uint32  volId;  //!< Volume ID\r
51                         char    label[11];      //!< Disk Label\r
52                         char    fsType[8];      //!< Filesystem Type. ???\r
53                 } __attribute__((packed)) fat32;        //!< FAT32 Specific Information\r
54         }__attribute__((packed)) spec;  //!< Non Shared Data\r
55         char pad[512-90];       //!< Bootsector Data (Code/Boot Signature 0xAA55)\r
56 } __attribute__((packed));\r
57 \r
58 /**\r
59  \struct fat_filetable_s\r
60  \brief Format of a 8.3 file entry on disk\r
61 */\r
62 struct fat_filetable_s {\r
63         char    name[11];       //!< 8.3 Name\r
64         Uint8   attrib; //!< File Attributes.\r
65         Uint8   ntres;  //!< Reserved for NT - Set to 0\r
66         Uint8   ctimems;        //!< 10ths of a second ranging from 0-199 (2 seconds)\r
67         Uint16  ctime;  //!< Creation Time\r
68         Uint16  cdate;  //!< Creation Date\r
69         Uint16  adate;  //!< Accessed Date. No Time feild though\r
70         Uint16  clusterHi;      //!< High Cluster. 0 for FAT12 and FAT16\r
71         Uint16  mtime;  //!< Last Modified Time\r
72         Uint16  mdate;  //!< Last Modified Date\r
73         Uint16  cluster;        //!< Low Word of First cluster\r
74         Uint32  size;   //!< Size of file\r
75 } __attribute__((packed));\r
76 \r
77 /**\r
78  * \struct fat_longfilename_s\r
79  * \brief Format of a long file name entry on disk\r
80  */\r
81 struct fat_longfilename_s {\r
82         Uint8   id;     //!< ID of entry. Bit 6 is set for last entry\r
83         Uint16  name1[5];       //!< 5 characters of name\r
84         Uint8   attrib; //!< Attributes. Must be ATTR_LFN\r
85         Uint8   type;   //!< Type. ???\r
86         Uint8   checksum;       //!< Checksum\r
87         Uint16  name2[6];       //!< 6 characters of name\r
88         Uint16  firstCluster;   //!< Used for non LFN compatability. Set to 0\r
89         Uint16  name3[2];       //!< Last 2 characters of name\r
90 } __attribute__((packed));\r
91 \r
92 /**\r
93  * \name File Attributes\r
94  * \brief Flag values for ::fat_filetable_s.attrib\r
95  * \{\r
96  */\r
97 #define ATTR_READONLY   0x01    //!< Read-only file\r
98 #define ATTR_HIDDEN             0x02    //!< Hidden File\r
99 #define ATTR_SYSTEM             0x04    //!< System File\r
100 #define ATTR_VOLUMEID   0x08    //!< Volume ID (Deprecated)\r
101 #define ATTR_DIRECTORY  0x10    //!< Directory\r
102 /**\r
103  * \brief File needs archiving\r
104  * \note User set flag, no significance to the FS driver\r
105  */\r
106 #define ATTR_ARCHIVE    0x20\r
107 /**\r
108  * \brief Meta Attribute \r
109  * \r
110  * If ::fat_filetable_s.attrib equals ATTR_LFN the file is a LFN entry\r
111  */\r
112 #define ATTR_LFN                (ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | ATTR_VOLUMEID)\r
113 /**\r
114  * \}\r
115  */\r
116 \r
117 /**\r
118  * \brief Internal IDs for FAT types\r
119  */\r
120 enum eFatType\r
121 {\r
122         FAT12,  //!< FAT12 Volume\r
123         FAT16,  //!< FAT16 Volume\r
124         FAT32,  //!< FAT32 Volume\r
125 };\r
126 \r
127 /**\r
128  * \name End of Cluster marks\r
129  * \brief FAT values that indicate the end of a cluster chain in\r
130  *        different versions.\r
131  * \{\r
132  */\r
133 #define EOC_FAT12       0x0FFF  //!< FAT-12 Mark\r
134 #define EOC_FAT16       0xFFFF  //!< FAT-16 Mark\r
135 #define EOC_FAT32       0x00FFFFFF      //!< FAT-32 Mark\r
136 /**\r
137  * \}\r
138  */\r
139 \r
140 typedef struct fat_bootsect_s fat_bootsect;\r
141 typedef struct fat_filetable_s fat_filetable;\r
142 typedef struct fat_longfilename_s fat_longfilename;\r
143 \r
144 // === Memory Structures ===\r
145 /**\r
146  * \struct drv_fat_volinfo_s\r
147  * \brief Representation of a volume in memory\r
148  */\r
149 struct drv_fat_volinfo_s\r
150 {\r
151          int    fileHandle;     //!< File Handle\r
152          int    type;   //!< FAT Type. See eFatType\r
153         char    name[12];       //!< Volume Name (With NULL Terminator)\r
154         tSpinlock       lFAT;   //!< Lock to prevent double-writing to the FAT\r
155         Uint32  firstDataSect;  //!< First data sector\r
156         Uint32  rootOffset;     //!< Root Offset (clusters)\r
157         Uint32  ClusterCount;   //!< Total Cluster Count\r
158         fat_bootsect    bootsect;       //!< Boot Sector\r
159         tVFS_Node       rootNode;       //!< Root Node\r
160          int    BytesPerCluster;\r
161          int    inodeHandle;    //!< Inode Cache Handle\r
162         #if CACHE_FAT\r
163         Uint32  *FATCache;      //!< FAT Cache\r
164         #endif\r
165 };\r
166 \r
167 typedef struct drv_fat_volinfo_s tFAT_VolInfo;\r
168 \r
169 #endif\r

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