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