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