1 /* dosfsck.h - Common data structures and global variables 2 3 Copyright (C) 1993 Werner Almesberger <werner.almesberger@lrc.di.epfl.ch> 4 Copyright (C) 1998 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> 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 On Debian systems, the complete text of the GNU General Public License 20 can be found in /usr/share/common-licenses/GPL-3 file. 21 */ 22 23 /* FAT32, VFAT, Atari format support, and various fixes additions May 1998 24 * by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> */ 25 26 27 #ifndef _DOSFSCK_H 28 #define _DOSFSCK_H 29 30 #include <sys/types.h> 31 #define _LINUX_STAT_H /* hack to avoid inclusion of <linux/stat.h> */ 32 #define _LINUX_STRING_H_ /* hack to avoid inclusion of <linux/string.h>*/ 33 #define _LINUX_FS_H /* hack to avoid inclusion of <linux/fs.h> */ 34 35 # include <asm/types.h> 36 # include <asm/byteorder.h> 37 38 #include <linux/msdos_fs.h> 39 40 #undef CF_LE_W 41 #undef CF_LE_L 42 #undef CT_LE_W 43 #undef CT_LE_L 44 45 #if defined __arm__ 46 #undef __BYTE_ORDER 47 #define __BYTE_ORDER __LITTLE_ENDIAN 48 #endif 49 50 #if __BYTE_ORDER == __BIG_ENDIAN 51 #include <byteswap.h> 52 #define CF_LE_W(v) bswap_16(v) 53 #define CF_LE_L(v) bswap_32(v) 54 #define CT_LE_W(v) CF_LE_W(v) 55 #define CT_LE_L(v) CF_LE_L(v) 56 #else 57 #define CF_LE_W(v) (v) 58 #define CF_LE_L(v) (v) 59 #define CT_LE_W(v) (v) 60 #define CT_LE_L(v) (v) 61 #endif /* __BIG_ENDIAN */ 62 63 #define VFAT_LN_ATTR (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME) 64 65 /* ++roman: Use own definition of boot sector structure -- the kernel headers' 66 * name for it is msdos_boot_sector in 2.0 and fat_boot_sector in 2.1 ... */ 67 struct boot_sector { 68 __u8 ignored[3]; /* Boot strap short or near jump */ 69 __u8 system_id[8]; /* Name - can be used to special case 70 partition manager volumes */ 71 __u8 sector_size[2]; /* bytes per logical sector */ 72 __u8 cluster_size; /* sectors/cluster */ 73 __u16 reserved; /* reserved sectors */ 74 __u8 fats; /* number of FATs */ 75 __u8 dir_entries[2]; /* root directory entries */ 76 __u8 sectors[2]; /* number of sectors */ 77 __u8 media; /* media code (unused) */ 78 __u16 fat_length; /* sectors/FAT */ 79 __u16 secs_track; /* sectors per track */ 80 __u16 heads; /* number of heads */ 81 __u32 hidden; /* hidden sectors (unused) */ 82 __u32 total_sect; /* number of sectors (if sectors == 0) */ 83 84 /* The following fields are only used by FAT32 */ 85 __u32 fat32_length; /* sectors/FAT */ 86 __u16 flags; /* bit 8: fat mirroring, low 4: active fat */ 87 __u8 version[2]; /* major, minor filesystem version */ 88 __u32 root_cluster; /* first cluster in root directory */ 89 __u16 info_sector; /* filesystem info sector */ 90 __u16 backup_boot; /* backup boot sector */ 91 __u8 reserved2[12]; /* Unused */ 92 93 __u8 drive_number; /* Logical Drive Number */ 94 __u8 reserved3; /* Unused */ 95 96 __u8 extended_sig; /* Extended Signature (0x29) */ 97 __u32 serial; /* Serial number */ 98 __u8 label[11]; /* FS label */ 99 __u8 fs_type[8]; /* FS Type */ 100 101 /* fill up to 512 bytes */ 102 __u8 junk[422]; 103 } __attribute__ ((packed)); 104 105 struct boot_sector_16 { 106 __u8 ignored[3]; /* Boot strap short or near jump */ 107 __u8 system_id[8]; /* Name - can be used to special case 108 partition manager volumes */ 109 __u8 sector_size[2]; /* bytes per logical sector */ 110 __u8 cluster_size; /* sectors/cluster */ 111 __u16 reserved; /* reserved sectors */ 112 __u8 fats; /* number of FATs */ 113 __u8 dir_entries[2]; /* root directory entries */ 114 __u8 sectors[2]; /* number of sectors */ 115 __u8 media; /* media code (unused) */ 116 __u16 fat_length; /* sectors/FAT */ 117 __u16 secs_track; /* sectors per track */ 118 __u16 heads; /* number of heads */ 119 __u32 hidden; /* hidden sectors (unused) */ 120 __u32 total_sect; /* number of sectors (if sectors == 0) */ 121 122 __u8 drive_number; /* Logical Drive Number */ 123 __u8 reserved2; /* Unused */ 124 125 __u8 extended_sig; /* Extended Signature (0x29) */ 126 __u32 serial; /* Serial number */ 127 __u8 label[11]; /* FS label */ 128 __u8 fs_type[8]; /* FS Type */ 129 130 /* fill up to 512 bytes */ 131 __u8 junk[450]; 132 } __attribute__ ((packed)); 133 134 struct info_sector { 135 __u32 magic; /* Magic for info sector ('RRaA') */ 136 __u8 junk[0x1dc]; 137 __u32 reserved1; /* Nothing as far as I can tell */ 138 __u32 signature; /* 0x61417272 ('rrAa') */ 139 __u32 free_clusters; /* Free cluster count. -1 if unknown */ 140 __u32 next_cluster; /* Most recently allocated cluster. */ 141 __u32 reserved2[3]; 142 __u16 reserved3; 143 __u16 boot_sign; 144 }; 145 146 typedef struct { 147 __u8 name[8],ext[3]; /* name and extension */ 148 __u8 attr; /* attribute bits */ 149 __u8 lcase; /* Case for base and extension */ 150 __u8 ctime_ms; /* Creation time, milliseconds */ 151 __u16 ctime; /* Creation time */ 152 __u16 cdate; /* Creation date */ 153 __u16 adate; /* Last access date */ 154 __u16 starthi; /* High 16 bits of cluster in FAT32 */ 155 __u16 time,date,start;/* time, date and first cluster */ 156 __u32 size; /* file size (in bytes) */ 157 } DIR_ENT; 158 159 typedef struct _dos_file { 160 DIR_ENT dir_ent; 161 char *lfn; 162 loff_t offset; 163 struct _dos_file *parent; /* parent directory */ 164 struct _dos_file *next; /* next entry */ 165 struct _dos_file *first; /* first entry (directory only) */ 166 } DOS_FILE; 167 168 typedef struct { 169 unsigned long value; 170 unsigned long reserved; 171 DOS_FILE *owner; 172 int prev; /* number of previous clusters */ 173 } FAT_ENTRY; 174 175 typedef struct { 176 int nfats; 177 loff_t fat_start; 178 unsigned int fat_size; /* unit is bytes */ 179 unsigned int fat_bits; /* size of a FAT entry */ 180 unsigned int eff_fat_bits; /* # of used bits in a FAT entry */ 181 unsigned long root_cluster; /* 0 for old-style root dir */ 182 loff_t root_start; 183 unsigned int root_entries; 184 loff_t data_start; 185 unsigned int cluster_size; 186 unsigned long clusters; 187 loff_t fsinfo_start; /* 0 if not present */ 188 long free_clusters; 189 loff_t backupboot_start; /* 0 if not present */ 190 FAT_ENTRY *fat; 191 char *label; 192 } DOS_FS; 193 194 #ifndef offsetof 195 #define offsetof(t,e) ((int)&(((t *)0)->e)) 196 #endif 197 198 extern int interactive,list,verbose,test,write_immed; 199 extern int atari_format; 200 extern unsigned n_files; 201 extern void *mem_queue; 202 203 /* value to use as end-of-file marker */ 204 #define FAT_EOF(fs) ((atari_format ? 0xfff : 0xff8) | FAT_EXTD(fs)) 205 #define FAT_IS_EOF(fs,v) ((unsigned long)(v) >= (0xff8|FAT_EXTD(fs))) 206 /* value to mark bad clusters */ 207 #define FAT_BAD(fs) (0xff7 | FAT_EXTD(fs)) 208 /* range of values used for bad clusters */ 209 #define FAT_MIN_BAD(fs) ((atari_format ? 0xff0 : 0xff7) | FAT_EXTD(fs)) 210 #define FAT_MAX_BAD(fs) ((atari_format ? 0xff7 : 0xff7) | FAT_EXTD(fs)) 211 #define FAT_IS_BAD(fs,v) ((v) >= FAT_MIN_BAD(fs) && (v) <= FAT_MAX_BAD(fs)) 212 213 /* return -16 as a number with fs->fat_bits bits */ 214 #define FAT_EXTD(fs) (((1 << fs->eff_fat_bits)-1) & ~0xf) 215 216 #endif 217 218 /* Local Variables: */ 219 /* tab-width: 8 */ 220 /* End: */ 221