1 /* fsck.fat.h - Common data structures and global variables
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>
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.
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.
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/>.
21 The complete text of the GNU General Public License
22 can be found in /usr/share/common-licenses/GPL-3 file.
25 /* FAT32, VFAT, Atari format support, and various fixes additions May 1998
26 * by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> */
31 #include <sys/types.h>
35 #include "endian_compat.h"
39 #define VFAT_LN_ATTR (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
41 #define FAT_STATE_DIRTY 0x01
42 #define FAT_NEED_SURFACE_TEST 0x02
44 #define FAT16_FLAG_HARDDISK_ERROR 0x4000
45 #define FAT16_FLAG_CLEAN_SHUTDOWN 0x8000
47 #define FAT32_FLAG_HARDDISK_ERROR 0x4000000
48 #define FAT32_FLAG_CLEAN_SHUTDOWN 0x8000000
50 /* ++roman: Use own definition of boot sector structure -- the kernel headers'
51 * name for it is msdos_boot_sector in 2.0 and fat_boot_sector in 2.1 ... */
53 uint8_t ignored[3]; /* Boot strap short or near jump */
54 uint8_t system_id[8]; /* Name - can be used to special case
55 partition manager volumes */
56 uint8_t sector_size[2]; /* bytes per logical sector */
57 uint8_t cluster_size; /* sectors/cluster */
58 uint16_t reserved; /* reserved sectors */
59 uint8_t fats; /* number of FATs */
60 uint8_t dir_entries[2]; /* root directory entries */
61 uint8_t sectors[2]; /* number of sectors */
62 uint8_t media; /* media code (unused) */
63 uint16_t fat_length; /* sectors/FAT */
64 uint16_t secs_track; /* sectors per track */
65 uint16_t heads; /* number of heads */
66 uint32_t hidden; /* hidden sectors (unused) */
67 uint32_t total_sect; /* number of sectors (if sectors == 0) */
69 /* The following fields are only used by FAT32 */
70 uint32_t fat32_length; /* sectors/FAT */
71 uint16_t flags; /* bit 8: fat mirroring, low 4: active fat */
72 uint8_t version[2]; /* major, minor filesystem version */
73 uint32_t root_cluster; /* first cluster in root directory */
74 uint16_t info_sector; /* filesystem info sector */
75 uint16_t backup_boot; /* backup boot sector */
76 uint8_t reserved2[12]; /* Unused */
78 uint8_t drive_number; /* Logical Drive Number */
79 uint8_t boot_flags; /* bit 0: dirty, bit 1: need surface test */
81 uint8_t extended_sig; /* Extended Signature (0x29) */
82 uint32_t serial; /* Serial number */
83 uint8_t label[11]; /* FS label */
84 uint8_t fs_type[8]; /* FS Type */
86 /* fill up to 512 bytes */
88 } __attribute__ ((packed));
90 struct boot_sector_16 {
91 uint8_t ignored[3]; /* Boot strap short or near jump */
92 uint8_t system_id[8]; /* Name - can be used to special case
93 partition manager volumes */
94 uint8_t sector_size[2]; /* bytes per logical sector */
95 uint8_t cluster_size; /* sectors/cluster */
96 uint16_t reserved; /* reserved sectors */
97 uint8_t fats; /* number of FATs */
98 uint8_t dir_entries[2]; /* root directory entries */
99 uint8_t sectors[2]; /* number of sectors */
100 uint8_t media; /* media code (unused) */
101 uint16_t fat_length; /* sectors/FAT */
102 uint16_t secs_track; /* sectors per track */
103 uint16_t heads; /* number of heads */
104 uint32_t hidden; /* hidden sectors (unused) */
105 uint32_t total_sect; /* number of sectors (if sectors == 0) */
107 uint8_t drive_number; /* Logical Drive Number */
108 uint8_t boot_flags; /* bit 0: dirty, bit 1: need surface test */
110 uint8_t extended_sig; /* Extended Signature (0x29) */
111 uint32_t serial; /* Serial number */
112 uint8_t label[11]; /* FS label */
113 uint8_t fs_type[8]; /* FS Type */
115 /* fill up to 512 bytes */
117 } __attribute__ ((packed));
120 uint32_t magic; /* Magic for info sector ('RRaA') */
121 uint8_t reserved1[480];
122 uint32_t signature; /* 0x61417272 ('rrAa') */
123 uint32_t free_clusters; /* Free cluster count. -1 if unknown */
124 uint32_t next_cluster; /* Most recently allocated cluster. */
125 uint8_t reserved2[12];
130 uint8_t name[MSDOS_NAME]; /* name including extension */
131 uint8_t attr; /* attribute bits */
132 uint8_t lcase; /* Case for base and extension */
133 uint8_t ctime_ms; /* Creation time, milliseconds */
134 uint16_t ctime; /* Creation time */
135 uint16_t cdate; /* Creation date */
136 uint16_t adate; /* Last access date */
137 uint16_t starthi; /* High 16 bits of cluster in FAT32 */
138 uint16_t time, date, start; /* time, date and first cluster */
139 uint32_t size; /* file size (in bytes) */
140 } __attribute__ ((packed)) DIR_ENT;
142 typedef struct _dos_file {
147 struct _dos_file *parent; /* parent directory */
148 struct _dos_file *next; /* next entry */
149 struct _dos_file *first; /* first entry (directory only) */
160 unsigned int fat_size; /* unit is bytes */
161 unsigned int fat_bits; /* size of a FAT entry */
162 unsigned int eff_fat_bits; /* # of used bits in a FAT entry */
163 uint32_t root_cluster; /* 0 for old-style root dir */
165 unsigned int root_entries;
167 unsigned int cluster_size;
168 uint32_t data_clusters; /* not including two reserved cluster numbers */
169 off_t fsinfo_start; /* 0 if not present */
171 off_t backupboot_start; /* 0 if not present */
173 DOS_FILE **cluster_owner;
178 extern int rw, list, verbose, test, no_spaces_in_sfns;
179 extern long fat_table;
180 extern int only_uppercase_label;
181 extern unsigned n_files;
182 extern void *mem_queue;
184 /* value to use as end-of-file marker */
185 #define FAT_EOF(fs) ((atari_format ? 0xfff : 0xff8) | FAT_EXTD(fs))
186 #define FAT_IS_EOF(fs,v) ((uint32_t)(v) >= (0xff8|FAT_EXTD(fs)))
187 /* value to mark bad clusters */
188 #define FAT_BAD(fs) (0xff7 | FAT_EXTD(fs))
189 /* range of values used for bad clusters */
190 #define FAT_MIN_BAD(fs) ((atari_format ? 0xff0 : 0xff7) | FAT_EXTD(fs))
191 #define FAT_MAX_BAD(fs) ((atari_format ? 0xff7 : 0xff7) | FAT_EXTD(fs))
192 #define FAT_IS_BAD(fs,v) ((v) >= FAT_MIN_BAD(fs) && (v) <= FAT_MAX_BAD(fs))
194 /* return -16 as a number with fs->fat_bits bits */
195 #define FAT_EXTD(fs) (((1 << fs->eff_fat_bits)-1) & ~0xf)
197 /* marker for files with no 8.3 name */
198 #define FAT_NO_83NAME 32