17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * GRUB -- GRand Unified Bootloader 37c478bd9Sstevel@tonic-gate * Copyright (C) 2001 Free Software Foundation, Inc. 47c478bd9Sstevel@tonic-gate * 57c478bd9Sstevel@tonic-gate * This program is free software; you can redistribute it and/or modify 67c478bd9Sstevel@tonic-gate * it under the terms of the GNU General Public License as published by 77c478bd9Sstevel@tonic-gate * the Free Software Foundation; either version 2 of the License, or 87c478bd9Sstevel@tonic-gate * (at your option) any later version. 97c478bd9Sstevel@tonic-gate * 107c478bd9Sstevel@tonic-gate * This program is distributed in the hope that it will be useful, 117c478bd9Sstevel@tonic-gate * but WITHOUT ANY WARRANTY; without even the implied warranty of 127c478bd9Sstevel@tonic-gate * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 137c478bd9Sstevel@tonic-gate * GNU General Public License for more details. 147c478bd9Sstevel@tonic-gate * 157c478bd9Sstevel@tonic-gate * You should have received a copy of the GNU General Public License 167c478bd9Sstevel@tonic-gate * along with this program; if not, write to the Free Software 177c478bd9Sstevel@tonic-gate * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 187c478bd9Sstevel@tonic-gate */ 197c478bd9Sstevel@tonic-gate 207c478bd9Sstevel@tonic-gate 217c478bd9Sstevel@tonic-gate /* 227c478bd9Sstevel@tonic-gate * Defines for the FAT BIOS Parameter Block (embedded in the first block 237c478bd9Sstevel@tonic-gate * of the partition. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate typedef __signed__ char __s8; 277c478bd9Sstevel@tonic-gate typedef unsigned char __u8; 287c478bd9Sstevel@tonic-gate typedef __signed__ short __s16; 297c478bd9Sstevel@tonic-gate typedef unsigned short __u16; 307c478bd9Sstevel@tonic-gate typedef __signed__ int __s32; 317c478bd9Sstevel@tonic-gate typedef unsigned int __u32; 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate /* Note that some shorts are not aligned, and must therefore 347c478bd9Sstevel@tonic-gate * be declared as array of two bytes. 357c478bd9Sstevel@tonic-gate */ 367c478bd9Sstevel@tonic-gate struct fat_bpb { 377c478bd9Sstevel@tonic-gate __s8 ignored[3]; /* Boot strap short or near jump */ 387c478bd9Sstevel@tonic-gate __s8 system_id[8]; /* Name - can be used to special case 397c478bd9Sstevel@tonic-gate partition manager volumes */ 407c478bd9Sstevel@tonic-gate __u8 bytes_per_sect[2]; /* bytes per logical sector */ 417c478bd9Sstevel@tonic-gate __u8 sects_per_clust;/* sectors/cluster */ 427c478bd9Sstevel@tonic-gate __u8 reserved_sects[2]; /* reserved sectors */ 437c478bd9Sstevel@tonic-gate __u8 num_fats; /* number of FATs */ 447c478bd9Sstevel@tonic-gate __u8 dir_entries[2]; /* root directory entries */ 457c478bd9Sstevel@tonic-gate __u8 short_sectors[2]; /* number of sectors */ 467c478bd9Sstevel@tonic-gate __u8 media; /* media code (unused) */ 477c478bd9Sstevel@tonic-gate __u16 fat_length; /* sectors/FAT */ 487c478bd9Sstevel@tonic-gate __u16 secs_track; /* sectors per track */ 497c478bd9Sstevel@tonic-gate __u16 heads; /* number of heads */ 507c478bd9Sstevel@tonic-gate __u32 hidden; /* hidden sectors (unused) */ 517c478bd9Sstevel@tonic-gate __u32 long_sectors; /* number of sectors (if short_sectors == 0) */ 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate /* The following fields are only used by FAT32 */ 547c478bd9Sstevel@tonic-gate __u32 fat32_length; /* sectors/FAT */ 557c478bd9Sstevel@tonic-gate __u16 flags; /* bit 8: fat mirroring, low 4: active fat */ 567c478bd9Sstevel@tonic-gate __u8 version[2]; /* major, minor filesystem version */ 577c478bd9Sstevel@tonic-gate __u32 root_cluster; /* first cluster in root directory */ 587c478bd9Sstevel@tonic-gate __u16 info_sector; /* filesystem info sector */ 597c478bd9Sstevel@tonic-gate __u16 backup_boot; /* backup boot sector */ 607c478bd9Sstevel@tonic-gate __u16 reserved2[6]; /* Unused */ 617c478bd9Sstevel@tonic-gate }; 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate #define FAT_CVT_U16(bytarr) (* (__u16*)(bytarr)) 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate /* 667c478bd9Sstevel@tonic-gate * Defines how to differentiate a 12-bit and 16-bit FAT. 677c478bd9Sstevel@tonic-gate */ 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate #define FAT_MAX_12BIT_CLUST 4087 /* 4085 + 2 */ 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate /* 727c478bd9Sstevel@tonic-gate * Defines for the file "attribute" byte 737c478bd9Sstevel@tonic-gate */ 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate #define FAT_ATTRIB_OK_MASK 0x37 767c478bd9Sstevel@tonic-gate #define FAT_ATTRIB_NOT_OK_MASK 0xC8 777c478bd9Sstevel@tonic-gate #define FAT_ATTRIB_DIR 0x10 787c478bd9Sstevel@tonic-gate #define FAT_ATTRIB_LONGNAME 0x0F 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate /* 817c478bd9Sstevel@tonic-gate * Defines for FAT directory entries 827c478bd9Sstevel@tonic-gate */ 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate #define FAT_DIRENTRY_LENGTH 32 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate #define FAT_DIRENTRY_ATTRIB(entry) \ 877c478bd9Sstevel@tonic-gate (*((unsigned char *) (entry+11))) 887c478bd9Sstevel@tonic-gate #define FAT_DIRENTRY_VALID(entry) \ 897c478bd9Sstevel@tonic-gate ( ((*((unsigned char *) entry)) != 0) \ 907c478bd9Sstevel@tonic-gate && ((*((unsigned char *) entry)) != 0xE5) \ 917c478bd9Sstevel@tonic-gate && !(FAT_DIRENTRY_ATTRIB(entry) & FAT_ATTRIB_NOT_OK_MASK) ) 927c478bd9Sstevel@tonic-gate #define FAT_DIRENTRY_FIRST_CLUSTER(entry) \ 937c478bd9Sstevel@tonic-gate ((*((unsigned short *) (entry+26)))+(*((unsigned short *) (entry+20)) << 16)) 947c478bd9Sstevel@tonic-gate #define FAT_DIRENTRY_FILELENGTH(entry) \ 957c478bd9Sstevel@tonic-gate (*((unsigned long *) (entry+28))) 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate #define FAT_LONGDIR_ID(entry) \ 987c478bd9Sstevel@tonic-gate (*((unsigned char *) (entry))) 997c478bd9Sstevel@tonic-gate #define FAT_LONGDIR_ALIASCHECKSUM(entry) \ 1007c478bd9Sstevel@tonic-gate (*((unsigned char *) (entry+13))) 101