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
60#define FAT_BOOT_CODE_LENGTH 128
61
62struct __attribute__ ((packed)) _FatBootSector {
63 uint8_t boot_jump[3]; /* 00: Boot strap short or near jump */
64 uint8_t system_id[8]; /* 03: system name */
65 uint16_t sector_size; /* 0b: bytes per logical sector */
66 uint8_t cluster_size; /* 0d: sectors/cluster */
67 uint16_t reserved; /* 0e: reserved sectors */
68 uint8_t fats; /* 10: number of FATs */
69 uint16_t dir_entries; /* 11: number of root directory entries */
70 uint16_t sectors; /* 13: if 0, total_sect supersedes */
71 uint8_t media; /* 15: media code */
72 uint16_t fat_length; /* 16: sectors/FAT for FAT12/16 */
73 uint16_t secs_track; /* 18: sectors per track */
74 uint16_t heads; /* 1a: number of heads */
75 uint32_t hidden; /* 1c: hidden sectors (partition start) */
76 uint32_t sector_count; /* 20: no. of sectors (if sectors == 0) */
77
78 union __attribute__ ((packed)) {
79 /* FAT16 fields */
80 struct __attribute__ ((packed)) {
81 uint8_t drive_num; /* 24: */
82 uint8_t empty_1; /* 25: */
83 uint8_t ext_signature; /* 26: always 0x29 */
84 uint32_t serial_number; /* 27: */
85 uint8_t volume_name [11]; /* 2b: */
86 uint8_t fat_name [8]; /* 36: */
87 uint8_t boot_code[448]; /* 3f: Boot code (or message) */
88 } fat16;
89 /* FAT32 fields */
90 struct __attribute__ ((packed)) {
91 uint32_t fat_length; /* 24: size of FAT in sectors */
92 uint16_t flags; /* 28: bit8: fat mirroring, low4: active fat */
93 uint16_t version; /* 2a: minor * 256 + major */
94 uint32_t root_dir_cluster; /* 2c: */
95 uint16_t info_sector; /* 30: */
96 uint16_t backup_sector; /* 32: */
97 uint8_t empty_1 [12]; /* 34: */
98 uint16_t drive_num; /* 40: */
99 uint8_t ext_signature; /* 42: always 0x29 */
100 uint32_t serial_number; /* 43: */
101 uint8_t volume_name [11]; /* 47: */
102 uint8_t fat_name [8]; /* 52: */
103 uint8_t boot_code[420]; /* 5a: Boot code (or message) */
104 } fat32;
105 } u;
106
107 uint16_t boot_sign; /* 1fe: always 0xAA55 */
108};
109
110struct __attribute__ ((packed)) _FatInfoSector {
111 uint32_t signature_1; /* should be 0x41615252 */
112 uint8_t unused [480];
113 uint32_t signature_2; /* should be 0x61417272 */
114 uint32_t free_clusters;
115 uint32_t next_cluster; /* most recently allocated cluster */
116 uint8_t unused2 [0xe];
117 uint16_t signature_3; /* should be 0xaa55 */
118};
119
120int fat_boot_sector_read (FatBootSector** bs, const PedGeometry* geom);
122 const PedGeometry* geom);
124
125
126#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
Structure describing file system.
Definition: filesys.h:68
Geometry of the partition.
Definition: geom.h:35