ReactOS  0.4.13-dev-464-g6b95727
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 #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 
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') */
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. */
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;
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 {
195 } FAT_ENTRY;
196 
197 typedef struct {
198  int nfats;
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 */
205  unsigned int root_entries;
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 */
211  off_t backupboot_start; /* 0 if not present */
212  unsigned char *fat;
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
off_t offset
Definition: fsck.fat.h:185
uint8_t lcase
Definition: fsck.fat.h:168
uint8_t label[11]
Definition: fsck.fat.h:148
uint8_t dir_entries[2]
Definition: fsck.fat.h:96
uint8_t extended_sig
Definition: fsck.fat.h:117
struct _dos_file DOS_FILE
GLuint GLenum GLsizei GLsizei GLint GLint GLboolean packed
Definition: glext.h:9271
uint16_t ctime
Definition: fsck.fat.h:170
unsigned n_files
uint16_t fat_length
Definition: fsck.fat.h:99
unsigned char * fat
Definition: fsck.fat.h:212
uint8_t dir_entries[2]
Definition: fsck.fat.h:134
uint8_t label[11]
Definition: fsck.fat.h:119
__kernel_off_t off_t
Definition: linux.h:201
uint16_t adate
Definition: fsck.fat.h:172
uint32_t size
Definition: fsck.fat.h:175
uint16_t secs_track
Definition: fsck.fat.h:100
char * label
Definition: fsck.fat.h:214
uint32_t free_clusters
Definition: fsck.fat.h:159
off_t fat_size
Definition: fsck.fat.h:200
unsigned short int uint16_t
Definition: acefiex.h:54
struct _dos_file * first
Definition: fsck.fat.h:189
uint8_t sector_size[2]
Definition: fsck.fat.h:130
uint8_t junk[450]
Definition: fsck.fat.h:152
uint32_t magic
Definition: fsck.fat.h:156
uint16_t reserved
Definition: fsck.fat.h:94
DIR_ENT dir_ent
Definition: fsck.fat.h:183
int interactive
Definition: main.c:63
uint16_t heads
Definition: fsck.fat.h:101
unsigned int eff_fat_bits
Definition: fsck.fat.h:202
void * mem_queue
uint16_t fat_length
Definition: fsck.fat.h:137
DOS_FILE ** cluster_owner
Definition: fsck.fat.h:213
off_t data_start
Definition: fsck.fat.h:206
struct info_sector __attribute__
uint8_t reserved3
Definition: fsck.fat.h:115
uint8_t system_id[8]
Definition: fsck.fat.h:128
int atari_format
int list
Definition: glfuncs.h:298
uint32_t root_cluster
Definition: fsck.fat.h:203
uint8_t fs_type[8]
Definition: fsck.fat.h:120
uint8_t system_id[8]
Definition: fsck.fat.h:90
unsigned int root_entries
Definition: fsck.fat.h:205
off_t backupboot_start
Definition: fsck.fat.h:211
uint8_t fats
Definition: fsck.fat.h:133
uint32_t boot_sign
Definition: fsck.fat.h:162
uint8_t ignored[3]
Definition: fsck.fat.h:127
#define MSDOS_NAME
Definition: msdos_fs.h:46
struct _dos_file * next
Definition: fsck.fat.h:188
uint8_t media
Definition: fsck.fat.h:98
uint16_t starthi
Definition: fsck.fat.h:173
uint8_t reserved2[12]
Definition: fsck.fat.h:112
int write_immed
off_t fsinfo_start
Definition: fsck.fat.h:209
unsigned int __u32
Definition: compat.h:90
unsigned int fat_bits
Definition: fsck.fat.h:201
long free_clusters
Definition: fsck.fat.h:210
uint8_t media
Definition: fsck.fat.h:136
int rw
uint8_t junk[422]
Definition: fsck.fat.h:123
int verbose
Definition: main.c:60
BYTE uint8_t
Definition: msvideo1.c:66
uint8_t drive_number
Definition: fsck.fat.h:114
unsigned int cluster_size
Definition: fsck.fat.h:207
struct _dos_file * parent
Definition: fsck.fat.h:187
uint8_t cluster_size
Definition: fsck.fat.h:93
char * lfn
Definition: fsck.fat.h:184
uint8_t reserved1[480]
Definition: fsck.fat.h:157
uint16_t cdate
Definition: fsck.fat.h:171
uint8_t version[2]
Definition: fsck.fat.h:108
uint32_t reserved
Definition: fsck.fat.h:194
uint32_t hidden
Definition: fsck.fat.h:102
GLuint start
Definition: gl.h:1545
uint8_t ctime_ms
Definition: fsck.fat.h:169
int test
Definition: enumwnd.c:14
__u16 date
Definition: mkdosfs.c:366
off_t fat_start
Definition: fsck.fat.h:199
uint32_t value
Definition: fsck.fat.h:193
u64 __u64
Definition: btrfs.h:20
off_t lfn_offset
Definition: fsck.fat.h:186
uint32_t fat32_length
Definition: fsck.fat.h:106
UINT32 uint32_t
Definition: types.h:75
uint32_t hidden
Definition: fsck.fat.h:140
ULONG32 FAT_ENTRY
Definition: fat.h:225
uint8_t fats
Definition: fsck.fat.h:95
uint32_t data_clusters
Definition: fsck.fat.h:208
uint32_t total_sect
Definition: fsck.fat.h:141
Definition: name.c:36
uint16_t backup_boot
Definition: fsck.fat.h:111
int nfats
Definition: fsck.fat.h:198
uint32_t next_cluster
Definition: fsck.fat.h:160
uint8_t fs_type[8]
Definition: fsck.fat.h:149
uint16_t info_sector
Definition: fsck.fat.h:110
uint8_t drive_number
Definition: fsck.fat.h:143
uint32_t serial
Definition: fsck.fat.h:147
uint16_t time
Definition: fsck.fat.h:174
uint8_t cluster_size
Definition: fsck.fat.h:131
uint8_t extended_sig
Definition: fsck.fat.h:146
uint8_t reserved2
Definition: fsck.fat.h:144
uint16_t heads
Definition: fsck.fat.h:139
uint8_t sectors[2]
Definition: fsck.fat.h:97
uint8_t reserved2[12]
Definition: fsck.fat.h:161
uint8_t ignored[3]
Definition: fsck.fat.h:89
uint16_t secs_track
Definition: fsck.fat.h:138
uint32_t serial
Definition: fsck.fat.h:118
uint32_t total_sect
Definition: fsck.fat.h:103
uint8_t sector_size[2]
Definition: fsck.fat.h:92
uint16_t flags
Definition: fsck.fat.h:107
off_t root_start
Definition: fsck.fat.h:204
uint8_t sectors[2]
Definition: fsck.fat.h:135
#define __int64
Definition: basetyps.h:16
uint8_t attr
Definition: fsck.fat.h:167
uint32_t root_cluster
Definition: fsck.fat.h:109
uint16_t reserved
Definition: fsck.fat.h:132
uint32_t signature
Definition: fsck.fat.h:158