fat: new license (LGPL)
[meinos.git] / apps / fat / bootsector.h
blob0960878031377c4c80ba83e53ae943f38d859b6a
1 /*
2 fat - A FAT* CDI driver
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef _BOOTSECTOR_H_
20 #define _BOOTSECTOR_H_
22 #include <stdint.h>
24 #include "fat_cdi.h"
26 #define FAT_BOOTSECTOR_START 0
28 #define fat_num_sectors(bs) ((bs)->num_sectors_small!=0?(bs)->num_sectors_small:(bs)->num_sectors)
30 #define fat_fat_start(bs,n) (((uint64_t)(bs)->reserved_sectors)*(bs)->sector_size+fat_fat_size(bs)*n)
31 #define fat_fat_sectors(bs) ((uint64_t)((bs)->fat_size_small!=0?(bs)->fat_size_small:(bs)->fat32.fat_size))
32 #define fat_fat_size(bs) (fat_fat_sectors(bs)*(bs)->sector_size)
34 /// FAT bootsector
35 struct fat_bootsector {
36 /// Jump code
37 uint8_t jump_code[3];
39 /// OEM name
40 uint8_t oem_name[8];
42 /// Sector size
43 uint16_t sector_size;
45 /// Sectors per Cluster
46 uint8_t cluster_size;
48 /// Reserved sectors
49 uint16_t reserved_sectors;
51 /// FAT copies
52 uint8_t num_fats;
54 /// Maximum amount of directory entries in root directory
55 uint16_t rootdir_max_ent;
57 /// Absolute amount of sectors (small)
58 uint16_t num_sectors_small;
60 /// Media Descriptor Byte
61 uint8_t media_desc;
63 /// Sectors per FAT (small)
64 uint16_t fat_size_small;
66 /// Sectors per Track
67 uint16_t track_size;
69 /// Heads
70 uint16_t num_heads;
72 /// Sectors between MBR and boot sector
73 uint32_t hidden_sectors;
75 /// Absolute amount of sectors
76 uint32_t num_sectors;
78 union {
79 struct {
80 /// Bios driver number
81 uint8_t bios_drive;
83 /// Reserved
84 uint8_t res0;
86 /// Extended boot signature
87 uint8_t ext_bootsig;
89 /// Filesystem ID
90 uint32_t fs_id;
92 /// Filesystem Name
93 uint8_t fs_name[11];
95 /// FAT type
96 uint8_t fat_type[8];
98 /// Bootloader code
99 uint8_t bootloader_code[448];
101 /// Boot signature
102 uint8_t bootsig[2];
103 } __attribute__ ((packed)) fat12_16;
104 struct {
105 /// Sectors per FAT
106 uint32_t fat_size;
108 /// FAT flags
109 uint16_t fat_flags;
111 /// FAT32 version
112 uint16_t fat32_version;
114 /// Cluster of root directory
115 uint32_t root_cluster;
117 /// FS information sector
118 uint16_t info_sector;
120 /// Sector of bootsector copy
121 uint16_t bootsector_copy;
123 /// Reserved
124 uint32_t res0[3];
126 /// Bios driver number
127 uint8_t bios_drive;
129 /// Reserved
130 uint8_t res1;
132 /// Extended boot signature
133 uint8_t ext_bootsig;
135 /// Filesystem ID
136 uint32_t fs_id;
138 /// Filesystem Name
139 uint8_t fs_name[11];
141 /// FAT type
142 uint8_t fat_type[8];
144 /// Bootloader code
145 uint8_t bootloader_code[420];
147 /// Boot signature
148 uint8_t bootsig[2];
149 } __attribute__ ((packed)) fat32;
151 } __attribute__ ((packed));
153 struct fat_bootsector *fat_bootsector_load(struct cdi_fs_filesystem *fs);
155 #endif