1 /* fsck.fat.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 Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch> 6 Copyright (C) 2015 Andreas Bombe <aeb@debian.org> 7 8 This program is free software: you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation, either version 3 of the License, or 11 (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program. If not, see <http://www.gnu.org/licenses/>. 20 21 The complete text of the GNU General Public License 22 can be found in /usr/share/common-licenses/GPL-3 file. 23 */ 24 25 /* FAT32, VFAT, Atari format support, and various fixes additions May 1998 26 * by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> */ 27 28 #ifndef _DOSFSCK_H 29 #define _DOSFSCK_H 30 31 #ifndef __REACTOS__ 32 #include <sys/types.h> 33 #include <fcntl.h> 34 #include <stddef.h> 35 #endif 36 #include <stdint.h> 37 38 #ifdef __REACTOS__ 39 #ifdef _WIN32 40 41 typedef unsigned int __u32; 42 typedef unsigned __int64 __u64; 43 44 #define le16toh(v) (v) 45 #define le32toh(v) (v) 46 #define htole16(v) (v) 47 #define htole32(v) (v) 48 49 #endif 50 51 #ifdef _M_IX86 52 #include "byteorder.h" 53 #endif 54 55 #if __BYTE_ORDER == __BIG_ENDIAN 56 #include "byteswap.h" 57 #else 58 #define le16toh(v) (v) 59 #define le32toh(v) (v) 60 #define htole16(v) (v) 61 #define htole32(v) (v) 62 #endif /* __BIG_ENDIAN */ 63 64 #endif 65 66 #ifndef __REACTOS__ 67 #include "endian_compat.h" 68 #else 69 #ifndef offsetof 70 #define offsetof(t,e) ((int)&(((t *)0)->e)) 71 #endif 72 73 #include "rosglue.h" 74 #endif 75 76 #include "msdos_fs.h" 77 78 #define VFAT_LN_ATTR (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME) 79 80 #define FAT_STATE_DIRTY 0x01 81 82 #ifdef __REACTOS__ 83 #include <pshpack1.h> 84 #endif 85 86 /* ++roman: Use own definition of boot sector structure -- the kernel headers' 87 * name for it is msdos_boot_sector in 2.0 and fat_boot_sector in 2.1 ... */ 88 struct boot_sector { 89 uint8_t ignored[3]; /* Boot strap short or near jump */ 90 uint8_t system_id[8]; /* Name - can be used to special case 91 partition manager volumes */ 92 uint8_t sector_size[2]; /* bytes per logical sector */ 93 uint8_t cluster_size; /* sectors/cluster */ 94 uint16_t reserved; /* reserved sectors */ 95 uint8_t fats; /* number of FATs */ 96 uint8_t dir_entries[2]; /* root directory entries */ 97 uint8_t sectors[2]; /* number of sectors */ 98 uint8_t media; /* media code (unused) */ 99 uint16_t fat_length; /* sectors/FAT */ 100 uint16_t secs_track; /* sectors per track */ 101 uint16_t heads; /* number of heads */ 102 uint32_t hidden; /* hidden sectors (unused) */ 103 uint32_t total_sect; /* number of sectors (if sectors == 0) */ 104 105 /* The following fields are only used by FAT32 */ 106 uint32_t fat32_length; /* sectors/FAT */ 107 uint16_t flags; /* bit 8: fat mirroring, low 4: active fat */ 108 uint8_t version[2]; /* major, minor filesystem version */ 109 uint32_t root_cluster; /* first cluster in root directory */ 110 uint16_t info_sector; /* filesystem info sector */ 111 uint16_t backup_boot; /* backup boot sector */ 112 uint8_t reserved2[12]; /* Unused */ 113 114 uint8_t drive_number; /* Logical Drive Number */ 115 uint8_t reserved3; /* Unused */ 116 117 uint8_t extended_sig; /* Extended Signature (0x29) */ 118 uint32_t serial; /* Serial number */ 119 uint8_t label[11]; /* FS label */ 120 uint8_t fs_type[8]; /* FS Type */ 121 122 /* fill up to 512 bytes */ 123 uint8_t junk[422]; 124 } __attribute__ ((packed)); 125 126 struct boot_sector_16 { 127 uint8_t ignored[3]; /* Boot strap short or near jump */ 128 uint8_t system_id[8]; /* Name - can be used to special case 129 partition manager volumes */ 130 uint8_t sector_size[2]; /* bytes per logical sector */ 131 uint8_t cluster_size; /* sectors/cluster */ 132 uint16_t reserved; /* reserved sectors */ 133 uint8_t fats; /* number of FATs */ 134 uint8_t dir_entries[2]; /* root directory entries */ 135 uint8_t sectors[2]; /* number of sectors */ 136 uint8_t media; /* media code (unused) */ 137 uint16_t fat_length; /* sectors/FAT */ 138 uint16_t secs_track; /* sectors per track */ 139 uint16_t heads; /* number of heads */ 140 uint32_t hidden; /* hidden sectors (unused) */ 141 uint32_t total_sect; /* number of sectors (if sectors == 0) */ 142 143 uint8_t drive_number; /* Logical Drive Number */ 144 uint8_t reserved2; /* Unused */ 145 146 uint8_t extended_sig; /* Extended Signature (0x29) */ 147 uint32_t serial; /* Serial number */ 148 uint8_t label[11]; /* FS label */ 149 uint8_t fs_type[8]; /* FS Type */ 150 151 /* fill up to 512 bytes */ 152 uint8_t junk[450]; 153 } __attribute__ ((packed)); 154 155 struct info_sector { 156 uint32_t magic; /* Magic for info sector ('RRaA') */ 157 uint8_t reserved1[480]; 158 uint32_t signature; /* 0x61417272 ('rrAa') */ 159 uint32_t free_clusters; /* Free cluster count. -1 if unknown */ 160 uint32_t next_cluster; /* Most recently allocated cluster. */ 161 uint8_t reserved2[12]; 162 uint32_t boot_sign; 163 }; 164 165 typedef struct { 166 uint8_t name[MSDOS_NAME]; /* name including extension */ 167 uint8_t attr; /* attribute bits */ 168 uint8_t lcase; /* Case for base and extension */ 169 uint8_t ctime_ms; /* Creation time, milliseconds */ 170 uint16_t ctime; /* Creation time */ 171 uint16_t cdate; /* Creation date */ 172 uint16_t adate; /* Last access date */ 173 uint16_t starthi; /* High 16 bits of cluster in FAT32 */ 174 uint16_t time, date, start; /* time, date and first cluster */ 175 uint32_t size; /* file size (in bytes) */ 176 } __attribute__ ((packed)) DIR_ENT; 177 178 #ifdef __REACTOS__ 179 #include <poppack.h> 180 #endif 181 182 typedef struct _dos_file { 183 DIR_ENT dir_ent; 184 char *lfn; 185 off_t offset; 186 off_t lfn_offset; 187 struct _dos_file *parent; /* parent directory */ 188 struct _dos_file *next; /* next entry */ 189 struct _dos_file *first; /* first entry (directory only) */ 190 } DOS_FILE; 191 192 typedef struct { 193 uint32_t value; 194 uint32_t reserved; 195 } FAT_ENTRY; 196 197 typedef struct { 198 int nfats; 199 off_t fat_start; 200 off_t fat_size; /* unit is bytes */ 201 unsigned int fat_bits; /* size of a FAT entry */ 202 unsigned int eff_fat_bits; /* # of used bits in a FAT entry */ 203 uint32_t root_cluster; /* 0 for old-style root dir */ 204 off_t root_start; 205 unsigned int root_entries; 206 off_t data_start; 207 unsigned int cluster_size; 208 uint32_t data_clusters; /* not including two reserved cluster numbers */ 209 off_t fsinfo_start; /* 0 if not present */ 210 long free_clusters; 211 off_t backupboot_start; /* 0 if not present */ 212 unsigned char *fat; 213 DOS_FILE **cluster_owner; 214 char *label; 215 } DOS_FS; 216 217 #ifndef __REACTOS__ 218 extern int interactive, rw, list, verbose, test, write_immed; 219 extern int atari_format; 220 extern unsigned n_files; 221 extern void *mem_queue; 222 #endif 223 224 /* value to use as end-of-file marker */ 225 #define FAT_EOF(fs) ((atari_format ? 0xfff : 0xff8) | FAT_EXTD(fs)) 226 #define FAT_IS_EOF(fs,v) ((uint32_t)(v) >= (0xff8|FAT_EXTD(fs))) 227 /* value to mark bad clusters */ 228 #define FAT_BAD(fs) (0xff7 | FAT_EXTD(fs)) 229 /* range of values used for bad clusters */ 230 #define FAT_MIN_BAD(fs) ((atari_format ? 0xff0 : 0xff7) | FAT_EXTD(fs)) 231 #define FAT_MAX_BAD(fs) ((atari_format ? 0xff7 : 0xff7) | FAT_EXTD(fs)) 232 #define FAT_IS_BAD(fs,v) ((v) >= FAT_MIN_BAD(fs) && (v) <= FAT_MAX_BAD(fs)) 233 234 /* return -16 as a number with fs->fat_bits bits */ 235 #define FAT_EXTD(fs) (((1 << fs->eff_fat_bits)-1) & ~0xf) 236 237 /* marker for files with no 8.3 name */ 238 #define FAT_NO_83NAME 32 239 240 #endif 241