1 | /* |
---|
2 | * GRUB -- GRand Unified Bootloader |
---|
3 | * Copyright (C) 2001 Free Software Foundation, Inc. |
---|
4 | * |
---|
5 | * This program is free software; you can redistribute it and/or modify |
---|
6 | * it under the terms of the GNU General Public License as published by |
---|
7 | * the Free Software Foundation; either version 2 of the License, or |
---|
8 | * (at your option) any later version. |
---|
9 | * |
---|
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 General Public License for more details. |
---|
14 | * |
---|
15 | * You should have received a copy of the GNU General Public License |
---|
16 | * along with this program; if not, write to the Free Software |
---|
17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
18 | */ |
---|
19 | |
---|
20 | |
---|
21 | /* |
---|
22 | * Defines for the FAT BIOS Parameter Block (embedded in the first block |
---|
23 | * of the partition. |
---|
24 | */ |
---|
25 | |
---|
26 | typedef __signed__ char __s8; |
---|
27 | typedef unsigned char __u8; |
---|
28 | typedef __signed__ short __s16; |
---|
29 | typedef unsigned short __u16; |
---|
30 | typedef __signed__ int __s32; |
---|
31 | typedef unsigned int __u32; |
---|
32 | |
---|
33 | /* Note that some shorts are not aligned, and must therefore |
---|
34 | * be declared as array of two bytes. |
---|
35 | */ |
---|
36 | struct fat_bpb { |
---|
37 | __s8 ignored[3]; /* Boot strap short or near jump */ |
---|
38 | __s8 system_id[8]; /* Name - can be used to special case |
---|
39 | partition manager volumes */ |
---|
40 | __u8 bytes_per_sect[2]; /* bytes per logical sector */ |
---|
41 | __u8 sects_per_clust;/* sectors/cluster */ |
---|
42 | __u8 reserved_sects[2]; /* reserved sectors */ |
---|
43 | __u8 num_fats; /* number of FATs */ |
---|
44 | __u8 dir_entries[2]; /* root directory entries */ |
---|
45 | __u8 short_sectors[2]; /* number of sectors */ |
---|
46 | __u8 media; /* media code (unused) */ |
---|
47 | __u16 fat_length; /* sectors/FAT */ |
---|
48 | __u16 secs_track; /* sectors per track */ |
---|
49 | __u16 heads; /* number of heads */ |
---|
50 | __u32 hidden; /* hidden sectors (unused) */ |
---|
51 | __u32 long_sectors; /* number of sectors (if short_sectors == 0) */ |
---|
52 | |
---|
53 | /* The following fields are only used by FAT32 */ |
---|
54 | __u32 fat32_length; /* sectors/FAT */ |
---|
55 | __u16 flags; /* bit 8: fat mirroring, low 4: active fat */ |
---|
56 | __u8 version[2]; /* major, minor filesystem version */ |
---|
57 | __u32 root_cluster; /* first cluster in root directory */ |
---|
58 | __u16 info_sector; /* filesystem info sector */ |
---|
59 | __u16 backup_boot; /* backup boot sector */ |
---|
60 | __u16 reserved2[6]; /* Unused */ |
---|
61 | }; |
---|
62 | |
---|
63 | #define FAT_CVT_U16(bytarr) (* (__u16*)(bytarr)) |
---|
64 | |
---|
65 | /* |
---|
66 | * Defines how to differentiate a 12-bit and 16-bit FAT. |
---|
67 | */ |
---|
68 | |
---|
69 | #define FAT_MAX_12BIT_CLUST 4087 /* 4085 + 2 */ |
---|
70 | |
---|
71 | /* |
---|
72 | * Defines for the file "attribute" byte |
---|
73 | */ |
---|
74 | |
---|
75 | #define FAT_ATTRIB_OK_MASK 0x37 |
---|
76 | #define FAT_ATTRIB_NOT_OK_MASK 0xC8 |
---|
77 | #define FAT_ATTRIB_DIR 0x10 |
---|
78 | #define FAT_ATTRIB_LONGNAME 0x0F |
---|
79 | |
---|
80 | /* |
---|
81 | * Defines for FAT directory entries |
---|
82 | */ |
---|
83 | |
---|
84 | #define FAT_DIRENTRY_LENGTH 32 |
---|
85 | |
---|
86 | #define FAT_DIRENTRY_ATTRIB(entry) \ |
---|
87 | (*((__u8 *) (entry+11))) |
---|
88 | #define FAT_DIRENTRY_VALID(entry) \ |
---|
89 | ( ((*((__u8 *) entry)) != 0) \ |
---|
90 | && ((*((__u8 *) entry)) != 0xE5) \ |
---|
91 | && !(FAT_DIRENTRY_ATTRIB(entry) & FAT_ATTRIB_NOT_OK_MASK) ) |
---|
92 | #define FAT_DIRENTRY_FIRST_CLUSTER(entry) \ |
---|
93 | ((*((__u16 *) (entry+26)))+(*((__u16 *) (entry+20)) << 16)) |
---|
94 | #define FAT_DIRENTRY_FILELENGTH(entry) \ |
---|
95 | (*((__u32 *) (entry+28))) |
---|
96 | |
---|
97 | #define FAT_LONGDIR_ID(entry) \ |
---|
98 | (*((__u8 *) (entry))) |
---|
99 | #define FAT_LONGDIR_ALIASCHECKSUM(entry) \ |
---|
100 | (*((__u8 *) (entry+13))) |
---|