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_
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)
35 struct fat_bootsector
{
45 /// Sectors per Cluster
49 uint16_t reserved_sectors
;
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
63 /// Sectors per FAT (small)
64 uint16_t fat_size_small
;
72 /// Sectors between MBR and boot sector
73 uint32_t hidden_sectors
;
75 /// Absolute amount of sectors
80 /// Bios driver number
86 /// Extended boot signature
99 uint8_t bootloader_code
[448];
103 } __attribute__ ((packed
)) fat12_16
;
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
;
126 /// Bios driver number
132 /// Extended boot signature
145 uint8_t bootloader_code
[420];
149 } __attribute__ ((packed
)) fat32
;
151 } __attribute__ ((packed
));
153 struct fat_bootsector
*fat_bootsector_load(struct cdi_fs_filesystem
*fs
);