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 (ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | ATTR_VOLUME_ID)
35#define ATTR_LONG_NAME_MASK \
36 (ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | ATTR_VOLUME_ID | ATTR_DIRECTORY | ATTR_ARCHIVE)
37
39enum FatType { FAT12 = 0, FAT16, FAT32 };
40
46struct Superblock {
47 uint8_t BS_jmpBoot[3];
48 uint8_t BS_OEMName[8];
49 uint16_t BPB_BytsPerSec;
50 uint8_t BPB_SecPerClus;
51 uint16_t BPB_RsvdSecCnt;
52 uint8_t BPB_NumFATs;
53 uint16_t BPB_RootEntCnt;
54 uint16_t BPB_TotSec16;
55 uint8_t BPB_Media;
56 uint16_t BPB_FATSz16;
57 uint16_t BPB_SecPerTrk;
58 uint16_t BPB_NumHeads;
59 uint32_t BPB_HiddSec;
60 uint32_t BPB_TotSec32;
61} __attribute__((packed));
62
65 uint32_t BPB_FATSz32;
66 uint16_t BPB_ExtFlags;
67 uint16_t BPB_FsVer;
68 uint32_t BPB_RootClus;
69 uint16_t BPB_FsInfo;
70 uint16_t BPB_BkBootSec;
71 uint8_t BPB_Reserved[12];
72 uint8_t BS_DrvNum;
73 uint8_t BS_Reserved1;
74 uint8_t BS_BootSig;
75 uint32_t BS_VolID;
76 uint8_t BS_VolLab[11];
77 uint8_t BS_FilSysType[8];
78} __attribute__((packed));
79
82 uint8_t BS_DrvNum;
83 uint8_t BS_Reserved1;
84 uint8_t BS_BootSig;
85 uint32_t BS_VolID;
86 int8_t BS_VolLab[11];
87 int8_t BS_FilSysType[8];
88} __attribute__((packed));
89
91struct FSInfo32 {
92 uint32_t FSI_LeadSig; // always 0x41615252
93 uint8_t FSI_Reserved1[480];
94 uint32_t FSI_StrucSig; // always 0x61417272
95 uint32_t FSI_Free_Count; // free cluster count, 0xFFFFFFFF if unknown
96 uint32_t FSI_NxtFree;
97 uint8_t FSI_Reserved2[12];
98 uint32_t FSI_TrailSig; // always 0xAA550000
99} __attribute__((packed));
100
102struct Dir {
103 uint8_t DIR_Name[11];
104 uint8_t DIR_Attr;
105 uint8_t DIR_NTRes;
106 uint8_t DIR_CrtTimeTenth;
107 uint16_t DIR_CrtTime;
108 uint16_t DIR_CrtDate;
109 uint16_t DIR_LstAccDate;
110 uint16_t DIR_FstClusHI;
111 uint16_t DIR_WrtTime;
112 uint16_t DIR_WrtDate;
113 uint16_t DIR_FstClusLO;
114 uint32_t DIR_FileSize;
115} __attribute__((packed));
116
119 uint8_t LDIR_Ord;
120 uint8_t LDIR_Name1[10];
121 uint8_t LDIR_Attr;
122 uint8_t LDIR_Type; // always zero for LFN entries
123 uint8_t LDIR_Chksum;
124 uint8_t LDIR_Name2[12];
125 uint16_t LDIR_FstClusLO; // meaningless, and MUST be zero
126 uint8_t LDIR_Name3[4];
127} __attribute__((packed));
128
130struct Timestamp {
131 uint32_t secCount : 5;
132 uint32_t minutes : 6;
133 uint32_t hours : 5;
134} __attribute__((packed));
135
137struct Date {
138 uint32_t day : 5;
139 uint32_t month : 4;
140 uint32_t years : 7; // years from 1980, not 1970
141} __attribute__((packed));
142
145 Time::Timestamp accessedTime;
146 Time::Timestamp modifiedTime;
147 Time::Timestamp creationTime;
148};
149
150#endif
Definition fat.h:137
Definition ext2.h:201
Definition fat.h:91