]> git.ozlabs.org Git - minimigmac.git/blob - pic/fat16_defs.h
Initial commit
[minimigmac.git] / pic / fat16_defs.h
1 #ifndef __FAT_DEFS_H__
2 #define __FAT_DEFS_H__
3
4 /* Partition Type Defninition */
5 #define PARTITION_TYPE_FREE             0x00    /* The partition table entry is not used. */
6 #define PARTITION_TYPE_FAT12            0x01    /* The partition contains a FAT12 filesystem. */
7 #define PARTITION_TYPE_FAT16_32MB       0x04    /* The partition contains a FAT16 filesystem with
8                                                    32MB maximum. */
9 #define PARTITION_TYPE_EXTENDED         0x05    /* The partition is an extended partition with its own
10                                                    partition table. */
11 #define PARTITION_TYPE_FAT16            0x06    /* The partition contains a FAT16 filesystem. */
12 #define PARTITION_TYPE_FAT32            0x0b    /* The partition contains a FAT32 filesystem. */
13 #define PARTITION_TYPE_FAT32_LBA        0x0c    /* The partition contains a FAT32 filesystem with LBA. */
14 #define PARTITION_TYPE_FAT16_LBA        0x0e    /* The partition contains a FAT16 filesystem with LBA. */
15 #define PARTITION_TYPE_EXTENDED_LBA     0x0f    /* The partition is an extended partition with LBA. */
16 #define PARTITION_TYPE_UNKNOWN          0xff    /* The partition has an unknown type. */
17
18
19 /* File Attributes */
20 #define FAT_ATTRIB_READONLY     (1 << 0)        // The file is read-only.
21 #define FAT_ATTRIB_HIDDEN       (1 << 1)        // The file is hidden.
22 #define FAT_ATTRIB_SYSTEM       (1 << 2)        // The file is a system file.
23 #define FAT_ATTRIB_VOLUME       (1 << 3)        // The file is empty and has the volume label as its name.
24 #define FAT_ATTRIB_DIR          (1 << 4)        // The file is a directory.
25 #define FAT_ATTRIB_ARCHIVE      (1 << 5)        // The file has to be archived.
26 #define FAT_ATTRIB_LFN_TEXT     (FAT_ATTRIB_VOLUME | FAT_ATTRIB_SYSTEM | FAT_ATTRIB_HIDDEN |\
27                                  FAT_ATTRIB_READONLY)   // 0x0F Long filename entry
28
29 #define FAT_LFN_LAST_MASK       0x40            // Last long entry flag
30
31 /* First Characters in Fat name */
32 #define FAT_ENTRY_FREE                  0x00    /* Fat entry is free */
33 #define FAT_ENTRY_KANJI                 0x05    /* Fat entry is kanji */
34 #define FAT_ENTRY_PARENT_DIRECTORY      0x2E    /* Fat entry is directory or parent direcotry */
35 #define FAT_ENTRY_DELETED               0xE5    /* Fat entry is deleted */
36
37
38 /* Define partition structure */
39 struct PRIMARY_Partition
40 {
41         unsigned char Status;                           // Partition status
42         unsigned char CHSFirstBlock[3];
43         unsigned char Type;                             // Partition type
44         unsigned char CHSLastBlock[3];
45         unsigned long LBAFirst;                         // First LBA block
46         unsigned long LBABlocks;                        // Number of LBA blocks in partition
47 };
48
49
50 /* Define Master Boot Record */
51 struct MBR_Disk
52 {
53         unsigned char                   bootCode[440];  // Code Area
54         unsigned long                   diskSignature;  // Optional Disk signature
55         unsigned short                  reserved;       // Usually Nulls; 0x0000
56         struct PRIMARY_Partition        partitions[4];  // Table of primary partitions
57                                                         // (Four 16-byte entries, IBM Partition Table scheme)
58         unsigned short                  signature;      // MBR signature; 0xAA55
59 };
60
61
62 /* FAT 16 Extened bios parametars block */
63 struct FAT16_ExtBiosParams
64 {
65         unsigned char   physicalDriveNo;                // Physical drive number 
66         unsigned char   reserved;                       // Reserved ("current head") In Windows NT bit 0 is 
67                                                         // a dirty flag to request chkdsk at boot time.
68                                                         // bit 1 requests surface scan too.[28]
69         unsigned char   extBootSignature;               // Extended boot signature.Value is 0x29[27] or 0x28.
70         unsigned long   ID;                             // ID (serial number)
71         unsigned char   volumeLabel[11];                // Volume Label, padded with blanks (0x20).     
72         unsigned char   FATFileSystemType[8];           // FAT file system type, padded with blanks (0x20),
73                                                         // e.g.: "FAT12   ", "FAT16   ". This is not meant
74                                                         // to be used to determine drive type, however,
75                                                         // some utilities use it in this way.
76         unsigned char   OsBootCode[448];                // Operating system boot code
77 };
78
79
80 /* FAT32 Extended parametars block */
81 struct FAT32_ExtBiosParams
82 {
83         unsigned long   sectorsPerFAT;                  // Sectors per file allocation table 
84         unsigned short  flags;                          // FAT Flags 
85         unsigned short  version;                        // Version
86         unsigned long   rootDirCluster;                 // Cluster number of root directory start
87         unsigned short  fsInformationSector;            // Sector number of FS Information Sector 
88         unsigned short  bootSectorCopy;                 // Sector number of a copy of this boot sector 
89         unsigned char   reserved1[12];                  // Reserved 
90         unsigned char   physicalDriveNo;                // Physical drive number 
91         unsigned char   reserved2;                      // Reserved 
92         unsigned char   extBootSignature;               // Extended boot signature. 
93         unsigned long   ID;                             // ID (serial number) 
94         unsigned char   volumeLabel[11];                // Volume Label 
95         unsigned char   FATFileSystemType[8];           // FAT file system type: "FAT32   " 
96         unsigned char   OsBootCode[420];                // Operating system boot code 
97 };
98
99
100 /* Fat Boot Sector */
101 struct FAT_Boot_Sector
102 {
103         unsigned char   jumpInstruction[3];             // Jump instruction. This instruction will be executed and will skip past the rest of the (non-executable) header if the partition is booted from. See Volume Boot Record. If the jump is two-byte near jmp it is followed by a NOP instruction. 
104         unsigned char   oemName[8];                     // OEM Name (padded with spaces). This value determines in which system disk was formatted. MS-DOS checks this field to determine which other parts of the boot record can be relied on.[25][26] Common values are IBM  3.3 (with two spaces between the "IBM" and the "3.3"), MSDOS5.0 and MSWIN4.1 and mkdosfs. 
105         unsigned short  bytesPerSector;                 // Bytes per sector. A common value is 512, especially for file systems on IDE (or compatible) disks. The BIOS Parameter Block starts here. 
106         unsigned char   sectorsPerCluster;              // Sectors per cluster. Allowed values are powers of two from 1 to 128. However, the value must not be such that the number of bytes per cluster becomes greater than 32 KB. 
107         unsigned short  reservedSectorCount;            // Reserved sector count. The number of sectors before the first FAT in the file system image. Should be 1 for FAT12/FAT16. Usually 32 for FAT32. 
108         unsigned char   noOfFATs;                       // Number of file allocation tables. Almost always 2.
109         unsigned short  maxRootEntries;                 // Maximum number of root directory entries. Only used on FAT12 and FAT16, where the root directory is handled specially. Should be 0 for FAT32. This value should always be such that the root directory ends on a sector boundary (i.e. such that its size becomes a multiple of the sector size). 224 is typical for floppy disks. 
110         unsigned short  totalSectorsFAT16;              // Total sectors (if zero, use 4 byte value at offset totalSectorsFAT32) 
111         unsigned char   mediaDescriptor;                // Media descriptor 0xF8 Fixed disk (i.e. Hard disk).
112         unsigned short  sectorsPerFAT;                  // Sectors per File Allocation Table for FAT12/FAT16 
113         unsigned short  sectorsPerTrack;                // Sectors per track 
114         unsigned short  noHeads;                        // Number of heads 
115         unsigned long   hiddenSectors;                  // Hidden sectors 
116         unsigned long   totalSectorsFAT32;              // Total sectors (if greater than 65535; otherwise, see offset totalSectorsFAT16) 
117         union
118         {
119                 struct FAT16_ExtBiosParams      fat16Ext;
120                 struct FAT32_ExtBiosParams      fat32Ext;
121         } extParams;
122         unsigned short  signature;                      // Boot sector signature (0x55 0xAA)
123 };
124
125
126 // FAT Directory Entry
127 struct FAT_dirEntryDefault
128 {
129         struct
130         {
131                 unsigned char name[8];          // File name
132                 unsigned char ext[3];           // File name extension
133         } shortName;                            // Short file name
134         unsigned char attributes;               // File attributes
135         unsigned char reserved;                 // Reserved
136         unsigned char createTimeFineRes;        // Create time fine resolution 10ms
137         unsigned short createTime;              // Create time
138         unsigned short createDate;              // Create date
139         unsigned short lastAccessDate;          // Last access date
140         unsigned short firstClusterHigh;        // First cluster high two bytes (FAT32 only)
141         unsigned short modifiedTime;            // Last modified time
142         unsigned short modifiedDate;            // Last modified date
143         unsigned short firstClusterLow;         // First cluster low two bytes
144         unsigned long length;                   // File length
145 };
146
147
148 // FAT LFN Directory entry structure
149 struct  FAT_dirEntryLFN
150 {
151         unsigned char   sequenceNo;             // Sequence number for long file name entry
152         unsigned short  fiveUTF16[5];           // Five UTF16 characters
153         unsigned char   attributes;             // Attributes always 0x0F
154         unsigned char   type;                   // LFN entry type always 0x00
155         unsigned char   checksum;               // Dos file name checksum
156         unsigned short  sixUTF16[6];            // Six UTF16 characters
157         unsigned short  firstCluster;           // First cluster always 0x0000
158         unsigned short  twoUTF16[2];            // Two UTF16 characters
159 };
160
161
162 // FAT file entry structure all possible structures combined
163 union FAT_directoryEntry
164 {
165         struct  FAT_dirEntryDefault     entry;          // Default File Entry
166         struct  FAT_dirEntryLFN         LFN;            // FAT LFN file entry structure
167         unsigned char                   bytes[32];      // Simple Byte Buffer
168 };
169
170
171 #endif /*  __FAT_DEFS_H__ */