Add macro make_build in spec file
[platform/upstream/dosfstools.git] / src / fsck.fat.h
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
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) */
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 {
143     DIR_ENT dir_ent;
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) */
150 } DOS_FILE;
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 */
170     long free_clusters;
171     off_t backupboot_start;     /* 0 if not present */
172     unsigned char *fat;
173     DOS_FILE **cluster_owner;
174     uint32_t serial;
175     char label[11];
176 } DOS_FS;
177
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;
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