libparted 3.6
Loading...
Searching...
No Matches
bootsector.h
Go to the documentation of this file.
1/*
2 libparted
3 Copyright (C) 1998-2000, 2007, 2009-2014, 2019-2023 Free Software
4 Foundation, Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef PED_FAT_BOOTSECTOR_H
21#define PED_FAT_BOOTSECTOR_H
22
23typedef struct _FatBootSector FatBootSector;
24typedef struct _FatInfoSector FatInfoSector;
25
26#include "fat.h"
27
28#define FAT32_INFO_MAGIC1 0x41615252
29#define FAT32_INFO_MAGIC2 0x61417272
30#define FAT32_INFO_MAGIC3 0xaa55
31
32/* stolen from mkdosfs, by Dave Hudson */
33
34#define FAT_BOOT_MESSAGE \
35"This partition does not have an operating system loader installed on it.\n\r"\
36"Press a key to reboot..."
37
38#define FAT_BOOT_JUMP "\xeb\x58\x90" /* jmp +5a */
39
40#define FAT_BOOT_CODE "\x0e" /* push cs */ \
41 "\x1f" /* pop ds */ \
42 "\xbe\x74\x7e" /* mov si, offset message */ \
43 /* write_msg_loop: */ \
44 "\xac" /* lodsb */ \
45 "\x22\xc0" /* and al, al */ \
46 "\x74\x06" /* jz done (+8) */ \
47 "\xb4\x0e" /* mov ah, 0x0e */ \
48 "\xcd\x10" /* int 0x10 */ \
49 "\xeb\xf5" /* jmp write_msg_loop */ \
50 /* done: */ \
51 "\xb4\x00" /* mov ah, 0x00 */ \
52 "\xcd\x16" /* int 0x16 */ \
53 "\xb4\x00" /* mov ah, 0x00 */ \
54 "\xcd\x19" /* int 0x19 */ \
55 "\xeb\xfe" /* jmp +0 - in case int 0x19 */ \
56 /* doesn't work */ \
57 /* message: */ \
58 FAT_BOOT_MESSAGE
59
60struct __attribute__ ((packed)) _FatBootSector {
61 uint8_t boot_jump[3]; /* 00: Boot strap short or near jump */
62 uint8_t system_id[8]; /* 03: system name */
63 uint16_t sector_size; /* 0b: bytes per logical sector */
64 uint8_t cluster_size; /* 0d: sectors/cluster */
65 uint16_t reserved; /* 0e: reserved sectors */
66 uint8_t fats; /* 10: number of FATs */
67 uint16_t dir_entries; /* 11: number of root directory entries */
68 uint16_t sectors; /* 13: if 0, total_sect supersedes */
69 uint8_t media; /* 15: media code */
70 uint16_t fat_length; /* 16: sectors/FAT for FAT12/16 */
71 uint16_t secs_track; /* 18: sectors per track */
72 uint16_t heads; /* 1a: number of heads */
73 uint32_t hidden; /* 1c: hidden sectors (partition start) */
74 uint32_t sector_count; /* 20: no. of sectors (if sectors == 0) */
75
76 union __attribute__ ((packed)) {
77 /* FAT16 fields */
78 struct __attribute__ ((packed)) {
79 uint8_t drive_num; /* 24: */
80 uint8_t empty_1; /* 25: */
81 uint8_t ext_signature; /* 26: always 0x29 */
82 uint32_t serial_number; /* 27: */
83 uint8_t volume_name [11]; /* 2b: */
84 uint8_t fat_name [8]; /* 36: */
85 uint8_t boot_code[448]; /* 3f: Boot code (or message) */
86 } fat16;
87 /* FAT32 fields */
88 struct __attribute__ ((packed)) {
89 uint32_t fat_length; /* 24: size of FAT in sectors */
90 uint16_t flags; /* 28: bit8: fat mirroring, low4: active fat */
91 uint16_t version; /* 2a: minor * 256 + major */
92 uint32_t root_dir_cluster; /* 2c: */
93 uint16_t info_sector; /* 30: */
94 uint16_t backup_sector; /* 32: */
95 uint8_t empty_1 [12]; /* 34: */
96 uint16_t drive_num; /* 40: */
97 uint8_t ext_signature; /* 42: always 0x29 */
98 uint32_t serial_number; /* 43: */
99 uint8_t volume_name [11]; /* 47: */
100 uint8_t fat_name [8]; /* 52: */
101 uint8_t boot_code[420]; /* 5a: Boot code (or message) */
102 } fat32;
103 } u;
104
105 uint16_t boot_sign; /* 1fe: always 0xAA55 */
106};
107
108struct __attribute__ ((packed)) _FatInfoSector {
109 uint32_t signature_1; /* should be 0x41615252 */
110 uint8_t unused [480];
111 uint32_t signature_2; /* should be 0x61417272 */
112 uint32_t free_clusters;
113 uint32_t next_cluster; /* most recently allocated cluster */
114 uint8_t unused2 [0xe];
115 uint16_t signature_3; /* should be 0xaa55 */
116};
117
118int fat_boot_sector_read (FatBootSector** bs, const PedGeometry* geom);
120 const PedGeometry* geom);
125
129
130#endif /* PED_FAT_BOOTSECTOR_H */
char unused[172]
Definition: bsd.c:2
typedef __attribute__
Definition: vtoc.h:80
char boot_code[440]
Definition: dos.c:0
uint16_t volume_name[F2FS_MAX_VOLUME_NAME]
Definition: f2fs.h:28
struct _FatInfoSector FatInfoSector
Definition: bootsector.h:24
struct _FatBootSector FatBootSector
Definition: bootsector.h:23
int fat_boot_sector_read(FatBootSector **bs, const PedGeometry *geom)
Definition: bootsector.c:39
FatType fat_boot_sector_probe_type(const FatBootSector *bs, const PedGeometry *geom)
Definition: bootsector.c:90
int fat_boot_sector_analyse(FatBootSector *bs, PedFileSystem *fs)
Definition: bootsector.c:139
enum _FatType FatType
Definition: fat.h:49
unsigned char reserved
Definition: fdasd.h:2
int fat_boot_sector_set_boot_code(FatBootSector **bs, const PedFileSystem *fs)
Definition: bootsector.c:272
int fat_boot_sector_write(const FatBootSector *bs, PedFileSystem *fs)
Definition: bootsector.c:368
int fat_info_sector_write(const FatInfoSector *is, PedFileSystem *fs)
Definition: bootsector.c:431
int fat_boot_sector_generate(FatBootSector **bs, const PedFileSystem *fs)
Definition: bootsector.c:287
int fat_info_sector_generate(FatInfoSector **is, const PedFileSystem *fs)
Definition: bootsector.c:409
int fat_info_sector_read(FatInfoSector **is, const PedFileSystem *fs)
Definition: bootsector.c:385
Structure describing file system.
Definition: filesys.h:68
Geometry of the partition.
Definition: geom.h:35