The Pedigree Project  0.1
fat.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef FAT_H
21 #define FAT_H
22 
23 #include "pedigree/kernel/processor/types.h"
24 #include "pedigree/kernel/time/Time.h"
25 
26 // FAT Attributes
27 #define ATTR_READONLY 0x01
28 #define ATTR_HIDDEN 0x02
29 #define ATTR_SYSTEM 0x04
30 #define ATTR_VOLUME_ID 0x08
31 #define ATTR_DIRECTORY 0x10
32 #define ATTR_ARCHIVE 0x20
33 
34 #define ATTR_LONG_NAME \
35  (ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | ATTR_VOLUME_ID)
36 #define ATTR_LONG_NAME_MASK \
37  (ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | ATTR_VOLUME_ID | \
38  ATTR_DIRECTORY | ATTR_ARCHIVE)
39 
41 enum FatType
42 {
43  FAT12 = 0,
44  FAT16,
45  FAT32
46 };
47 
53 struct Superblock
54 {
55  uint8_t BS_jmpBoot[3];
56  uint8_t BS_OEMName[8];
57  uint16_t BPB_BytsPerSec;
58  uint8_t BPB_SecPerClus;
59  uint16_t BPB_RsvdSecCnt;
60  uint8_t BPB_NumFATs;
61  uint16_t BPB_RootEntCnt;
62  uint16_t BPB_TotSec16;
63  uint8_t BPB_Media;
64  uint16_t BPB_FATSz16;
65  uint16_t BPB_SecPerTrk;
66  uint16_t BPB_NumHeads;
67  uint32_t BPB_HiddSec;
68  uint32_t BPB_TotSec32;
69 } __attribute__((packed));
70 
73 {
74  uint32_t BPB_FATSz32;
75  uint16_t BPB_ExtFlags;
76  uint16_t BPB_FsVer;
77  uint32_t BPB_RootClus;
78  uint16_t BPB_FsInfo;
79  uint16_t BPB_BkBootSec;
80  uint8_t BPB_Reserved[12];
81  uint8_t BS_DrvNum;
82  uint8_t BS_Reserved1;
83  uint8_t BS_BootSig;
84  uint32_t BS_VolID;
85  uint8_t BS_VolLab[11];
86  uint8_t BS_FilSysType[8];
87 } __attribute__((packed));
88 
91 {
92  uint8_t BS_DrvNum;
93  uint8_t BS_Reserved1;
94  uint8_t BS_BootSig;
95  uint32_t BS_VolID;
96  int8_t BS_VolLab[11];
97  int8_t BS_FilSysType[8];
98 } __attribute__((packed));
99 
101 struct FSInfo32
102 {
103  uint32_t FSI_LeadSig; // always 0x41615252
104  uint8_t FSI_Reserved1[480];
105  uint32_t FSI_StrucSig; // always 0x61417272
106  uint32_t FSI_Free_Count; // free cluster count, 0xFFFFFFFF if unknown
107  uint32_t FSI_NxtFree;
108  uint8_t FSI_Reserved2[12];
109  uint32_t FSI_TrailSig; // always 0xAA550000
110 } __attribute__((packed));
111 
113 struct Dir
114 {
115  uint8_t DIR_Name[11];
116  uint8_t DIR_Attr;
117  uint8_t DIR_NTRes;
118  uint8_t DIR_CrtTimeTenth;
119  uint16_t DIR_CrtTime;
120  uint16_t DIR_CrtDate;
121  uint16_t DIR_LstAccDate;
122  uint16_t DIR_FstClusHI;
123  uint16_t DIR_WrtTime;
124  uint16_t DIR_WrtDate;
125  uint16_t DIR_FstClusLO;
126  uint32_t DIR_FileSize;
127 } __attribute__((packed));
128 
131 {
132  uint8_t LDIR_Ord;
133  uint8_t LDIR_Name1[10];
134  uint8_t LDIR_Attr;
135  uint8_t LDIR_Type; // always zero for LFN entries
136  uint8_t LDIR_Chksum;
137  uint8_t LDIR_Name2[12];
138  uint16_t LDIR_FstClusLO; // meaningless, and MUST be zero
139  uint8_t LDIR_Name3[4];
140 } __attribute__((packed));
141 
143 struct Timestamp
144 {
145  uint32_t secCount : 5;
146  uint32_t minutes : 6;
147  uint32_t hours : 5;
148 } __attribute__((packed));
149 
151 struct Date
152 {
153  uint32_t day : 5;
154  uint32_t month : 4;
155  uint32_t years : 7; // years from 1980, not 1970
156 } __attribute__((packed));
157 
160 {
161  Time::Timestamp accessedTime;
162  Time::Timestamp modifiedTime;
163  Time::Timestamp creationTime;
164 };
165 
166 #endif
Definition: ext2.h:175
Definition: fat.h:101
Definition: fat.h:151
Definition: fat.h:143