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