dosfstools  4.2
About: dosfstools are utilities to create, check and label (MS-DOS) FAT filesystems.
  Fossies Dox: dosfstools-4.2.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

fsck.fat.h
Go to the documentation of this file.
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 #include <sys/types.h>
32 #include <fcntl.h>
33 #include <stddef.h>
34 #include <stdint.h>
35 #include "endian_compat.h"
36 
37 #include "msdos_fs.h"
38 
39 #define VFAT_LN_ATTR (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
40 
41 #define FAT_STATE_DIRTY 0x01
42 #define FAT_NEED_SURFACE_TEST 0x02
43 
44 #define FAT16_FLAG_HARDDISK_ERROR 0x4000
45 #define FAT16_FLAG_CLEAN_SHUTDOWN 0x8000
46 
47 #define FAT32_FLAG_HARDDISK_ERROR 0x4000000
48 #define FAT32_FLAG_CLEAN_SHUTDOWN 0x8000000
49 
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 ... */
52 struct boot_sector {
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) */
68 
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 */
77 
78  uint8_t drive_number; /* Logical Drive Number */
79  uint8_t boot_flags; /* bit 0: dirty, bit 1: need surface test */
80 
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 */
85 
86  /* fill up to 512 bytes */
87  uint8_t junk[422];
88 } __attribute__ ((packed));
89 
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) */
106 
107  uint8_t drive_number; /* Logical Drive Number */
108  uint8_t boot_flags; /* bit 0: dirty, bit 1: need surface test */
109 
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 */
114 
115  /* fill up to 512 bytes */
116  uint8_t junk[450];
117 } __attribute__ ((packed));
118 
119 struct info_sector {
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];
126  uint32_t boot_sign;
127 };
128 
129 typedef struct {
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;
141 
142 typedef struct _dos_file {
144  char *lfn;
145  off_t offset;
146  off_t lfn_offset;
147  struct _dos_file *parent; /* parent directory */
148  struct _dos_file *next; /* next entry */
149  struct _dos_file *first; /* first entry (directory only) */
151 
152 typedef struct {
153  uint32_t value;
154  uint32_t reserved;
155 } FAT_ENTRY;
156 
157 typedef struct {
158  int nfats;
159  off_t fat_start;
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 */
164  off_t root_start;
165  unsigned int root_entries;
166  off_t data_start;
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 */
172  unsigned char *fat;
174  uint32_t serial;
175  char label[11];
176 } DOS_FS;
177 
179 extern long fat_table;
180 extern int only_uppercase_label;
181 extern unsigned n_files;
182 extern void *mem_queue;
183 
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))
193 
194 /* return -16 as a number with fs->fat_bits bits */
195 #define FAT_EXTD(fs) (((1 << fs->eff_fat_bits)-1) & ~0xf)
196 
197 /* marker for files with no 8.3 name */
198 #define FAT_NO_83NAME 32
199 
200 #endif
struct _dos_file DOS_FILE
int verbose
Definition: fsck.fat.h:178
int only_uppercase_label
Definition: fsck.fat.c:53
int test
Definition: fsck.fat.h:178
int rw
Definition: fatlabel.c:49
int list
Definition: fsck.fat.h:178
int no_spaces_in_sfns
Definition: fsck.fat.h:178
void * mem_queue
Definition: fatlabel.c:52
long fat_table
Definition: fatlabel.c:50
unsigned n_files
Definition: fatlabel.c:51
#define MSDOS_NAME
Definition: msdos_fs.h:44
uint16_t cdate
Definition: fsck.fat.h:135
uint16_t ctime
Definition: fsck.fat.h:134
uint16_t starthi
Definition: fsck.fat.h:137
uint32_t size
Definition: fsck.fat.h:139
uint8_t lcase
Definition: fsck.fat.h:132
uint8_t attr
Definition: fsck.fat.h:131
uint8_t ctime_ms
Definition: fsck.fat.h:133
uint16_t date
Definition: fsck.fat.h:138
uint16_t adate
Definition: fsck.fat.h:136
unsigned int fat_bits
Definition: fsck.fat.h:161
unsigned int cluster_size
Definition: fsck.fat.h:167
unsigned int fat_size
Definition: fsck.fat.h:160
off_t backupboot_start
Definition: fsck.fat.h:171
off_t fsinfo_start
Definition: fsck.fat.h:169
int nfats
Definition: fsck.fat.h:158
unsigned int eff_fat_bits
Definition: fsck.fat.h:162
DOS_FILE ** cluster_owner
Definition: fsck.fat.h:173
off_t fat_start
Definition: fsck.fat.h:159
uint32_t data_clusters
Definition: fsck.fat.h:168
unsigned int root_entries
Definition: fsck.fat.h:165
uint32_t root_cluster
Definition: fsck.fat.h:163
unsigned char * fat
Definition: fsck.fat.h:172
off_t root_start
Definition: fsck.fat.h:164
off_t data_start
Definition: fsck.fat.h:166
long free_clusters
Definition: fsck.fat.h:170
uint32_t serial
Definition: fsck.fat.h:174
Definition: fsck.fat.h:152
uint32_t value
Definition: fsck.fat.h:153
uint32_t reserved
Definition: fsck.fat.h:154
struct _dos_file * next
Definition: fsck.fat.h:148
struct _dos_file * parent
Definition: fsck.fat.h:147
DIR_ENT dir_ent
Definition: fsck.fat.h:143
off_t offset
Definition: fsck.fat.h:145
off_t lfn_offset
Definition: fsck.fat.h:146
char * lfn
Definition: fsck.fat.h:144
struct _dos_file * first
Definition: fsck.fat.h:149
uint8_t system_id[8]
Definition: fsck.fat.h:92
uint8_t drive_number
Definition: fsck.fat.h:107
uint8_t junk[450]
Definition: fsck.fat.h:116
uint16_t fat_length
Definition: fsck.fat.h:101
uint8_t fats
Definition: fsck.fat.h:97
uint8_t sector_size[2]
Definition: fsck.fat.h:94
uint8_t sectors[2]
Definition: fsck.fat.h:99
uint8_t media
Definition: fsck.fat.h:100
uint8_t boot_flags
Definition: fsck.fat.h:108
uint32_t hidden
Definition: fsck.fat.h:104
uint32_t total_sect
Definition: fsck.fat.h:105
uint8_t fs_type[8]
Definition: fsck.fat.h:113
uint8_t extended_sig
Definition: fsck.fat.h:110
uint8_t ignored[3]
Definition: fsck.fat.h:91
uint16_t heads
Definition: fsck.fat.h:103
uint8_t cluster_size
Definition: fsck.fat.h:95
uint16_t reserved
Definition: fsck.fat.h:96
uint8_t dir_entries[2]
Definition: fsck.fat.h:98
uint16_t secs_track
Definition: fsck.fat.h:102
uint8_t label[11]
Definition: fsck.fat.h:112
uint32_t serial
Definition: fsck.fat.h:111
uint16_t backup_boot
Definition: fsck.fat.h:75
uint8_t fs_type[8]
Definition: fsck.fat.h:84
uint8_t reserved2[12]
Definition: fsck.fat.h:76
uint8_t sector_size[2]
Definition: fsck.fat.h:56
uint32_t serial
Definition: fsck.fat.h:82
uint8_t dir_entries[2]
Definition: fsck.fat.h:60
uint32_t fat32_length
Definition: fsck.fat.h:70
uint32_t total_sect
Definition: fsck.fat.h:67
uint16_t secs_track
Definition: fsck.fat.h:64
uint16_t info_sector
Definition: fsck.fat.h:74
uint8_t extended_sig
Definition: fsck.fat.h:81
uint16_t reserved
Definition: fsck.fat.h:58
uint8_t version[2]
Definition: fsck.fat.h:72
uint8_t media
Definition: fsck.fat.h:62
uint8_t fats
Definition: fsck.fat.h:59
uint8_t drive_number
Definition: fsck.fat.h:78
uint16_t fat_length
Definition: fsck.fat.h:63
uint8_t label[11]
Definition: fsck.fat.h:83
uint8_t cluster_size
Definition: fsck.fat.h:57
uint32_t hidden
Definition: fsck.fat.h:66
uint8_t ignored[3]
Definition: fsck.fat.h:53
uint8_t junk[422]
Definition: fsck.fat.h:87
uint16_t flags
Definition: fsck.fat.h:71
uint8_t sectors[2]
Definition: fsck.fat.h:61
uint8_t system_id[8]
Definition: fsck.fat.h:54
uint16_t heads
Definition: fsck.fat.h:65
uint32_t root_cluster
Definition: fsck.fat.h:73
uint8_t boot_flags
Definition: fsck.fat.h:79
uint32_t boot_sign
Definition: fsck.fat.h:126
uint32_t magic
Definition: fsck.fat.h:120
uint32_t signature
Definition: fsck.fat.h:122
uint8_t reserved1[480]
Definition: fsck.fat.h:121
uint32_t next_cluster
Definition: fsck.fat.h:124
uint8_t reserved2[12]
Definition: fsck.fat.h:125
uint32_t free_clusters
Definition: fsck.fat.h:123