added port of dosfsck. Does not work yet as I cannot figure how to open the device...
[reactos.git] / rosapps / sysutils / dosfsck / dosfsck.h
1 /* dosfsck.h - Common data structures and global variables */
2
3 /* Written 1993 by Werner Almesberger */
4
5 /* FAT32, VFAT, Atari format support, and various fixes additions May 1998
6 * by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> */
7
8
9 #ifndef _DOSFSCK_H
10 #define _DOSFSCK_H
11
12 //#include "types.h"
13
14 #ifdef _WIN32
15
16 typedef unsigned char __u8;
17 typedef unsigned short __u16;
18 typedef unsigned int __u32;
19 typedef unsigned __int64 __u64;
20 typedef unsigned short __le16;
21 typedef unsigned long __le32;
22 typedef __int64 loff_t;
23 typedef __int64 ll_t;
24
25 #endif
26
27 #define _LINUX_STAT_H /* hack to avoid inclusion of <linux/stat.h> */
28 #define _LINUX_STRING_H_ /* hack to avoid inclusion of <linux/string.h>*/
29 #define _LINUX_FS_H /* hack to avoid inclusion of <linux/fs.h> */
30
31 //#include <linux/version.h>
32 //# include "types.h"
33 # include "byteorder.h"
34
35 #include "msdos_fs.h"
36
37 #undef CF_LE_W
38 #undef CF_LE_L
39 #undef CT_LE_W
40 #undef CT_LE_L
41
42 #if __BYTE_ORDER == __BIG_ENDIAN
43 #include "byteswap.h"
44 #define CF_LE_W(v) bswap_16(v)
45 #define CF_LE_L(v) bswap_32(v)
46 #define CT_LE_W(v) CF_LE_W(v)
47 #define CT_LE_L(v) CF_LE_L(v)
48 #else
49 #define CF_LE_W(v) (v)
50 #define CF_LE_L(v) (v)
51 #define CT_LE_W(v) (v)
52 #define CT_LE_L(v) (v)
53 #endif /* __BIG_ENDIAN */
54
55 #define VFAT_LN_ATTR (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
56
57 /* ++roman: Use own definition of boot sector structure -- the kernel headers'
58 * name for it is msdos_boot_sector in 2.0 and fat_boot_sector in 2.1 ... */
59 struct boot_sector {
60 __u8 ignored[3]; /* Boot strap short or near jump */
61 __u8 system_id[8]; /* Name - can be used to special case
62 partition manager volumes */
63 __u8 sector_size[2]; /* bytes per logical sector */
64 __u8 cluster_size; /* sectors/cluster */
65 __u16 reserved; /* reserved sectors */
66 __u8 fats; /* number of FATs */
67 __u8 dir_entries[2]; /* root directory entries */
68 __u8 sectors[2]; /* number of sectors */
69 __u8 media; /* media code (unused) */
70 __u16 fat_length; /* sectors/FAT */
71 __u16 secs_track; /* sectors per track */
72 __u16 heads; /* number of heads */
73 __u32 hidden; /* hidden sectors (unused) */
74 __u32 total_sect; /* number of sectors (if sectors == 0) */
75
76 /* The following fields are only used by FAT32 */
77 __u32 fat32_length; /* sectors/FAT */
78 __u16 flags; /* bit 8: fat mirroring, low 4: active fat */
79 __u8 version[2]; /* major, minor filesystem version */
80 __u32 root_cluster; /* first cluster in root directory */
81 __u16 info_sector; /* filesystem info sector */
82 __u16 backup_boot; /* backup boot sector */
83 __u16 reserved2[6]; /* Unused */
84
85 /* fill up to 512 bytes */
86 __u8 junk[448];
87 } __attribute__ ((packed));
88
89 struct info_sector {
90 __u32 magic; /* Magic for info sector ('RRaA') */
91 __u8 junk[0x1dc];
92 __u32 reserved1; /* Nothing as far as I can tell */
93 __u32 signature; /* 0x61417272 ('rrAa') */
94 __u32 free_clusters; /* Free cluster count. -1 if unknown */
95 __u32 next_cluster; /* Most recently allocated cluster. */
96 __u32 reserved2[3];
97 __u16 reserved3;
98 __u16 boot_sign;
99 };
100
101 typedef struct {
102 __u8 name[8],ext[3]; /* name and extension */
103 __u8 attr; /* attribute bits */
104 __u8 lcase; /* Case for base and extension */
105 __u8 ctime_ms; /* Creation time, milliseconds */
106 __u16 ctime; /* Creation time */
107 __u16 cdate; /* Creation date */
108 __u16 adate; /* Last access date */
109 __u16 starthi; /* High 16 bits of cluster in FAT32 */
110 __u16 time,date,start;/* time, date and first cluster */
111 __u32 size; /* file size (in bytes) */
112 } DIR_ENT;
113
114 typedef struct _dos_file {
115 DIR_ENT dir_ent;
116 char *lfn;
117 loff_t offset;
118 struct _dos_file *parent; /* parent directory */
119 struct _dos_file *next; /* next entry */
120 struct _dos_file *first; /* first entry (directory only) */
121 } DOS_FILE;
122
123 typedef struct {
124 unsigned long value;
125 unsigned long reserved;
126 DOS_FILE *owner;
127 int prev; /* number of previous clusters */
128 } FAT_ENTRY;
129
130 typedef struct {
131 int nfats;
132 loff_t fat_start;
133 unsigned int fat_size; /* unit is bytes */
134 unsigned int fat_bits; /* size of a FAT entry */
135 unsigned int eff_fat_bits; /* # of used bits in a FAT entry */
136 unsigned long root_cluster; /* 0 for old-style root dir */
137 loff_t root_start;
138 unsigned int root_entries;
139 loff_t data_start;
140 unsigned int cluster_size;
141 unsigned long clusters;
142 loff_t fsinfo_start; /* 0 if not present */
143 long free_clusters;
144 loff_t backupboot_start; /* 0 if not present */
145 FAT_ENTRY *fat;
146 } DOS_FS;
147
148 #ifndef offsetof
149 #define offsetof(t,e) ((int)&(((t *)0)->e))
150 #endif
151
152 extern int interactive,list,verbose,test,write_immed;
153 extern int atari_format;
154 extern unsigned n_files;
155 extern void *mem_queue;
156
157 /* value to use as end-of-file marker */
158 #define FAT_EOF(fs) ((atari_format ? 0xfff : 0xff8) | FAT_EXTD(fs))
159 #define FAT_IS_EOF(fs,v) ((unsigned long)(v) >= (0xff8|FAT_EXTD(fs)))
160 /* value to mark bad clusters */
161 #define FAT_BAD(fs) (0xff7 | FAT_EXTD(fs))
162 /* range of values used for bad clusters */
163 #define FAT_MIN_BAD(fs) ((atari_format ? 0xff0 : 0xff7) | FAT_EXTD(fs))
164 #define FAT_MAX_BAD(fs) ((atari_format ? 0xff7 : 0xff7) | FAT_EXTD(fs))
165 #define FAT_IS_BAD(fs,v) ((v) >= FAT_MIN_BAD(fs) && (v) <= FAT_MAX_BAD(fs))
166
167 /* return -16 as a number with fs->fat_bits bits */
168 #define FAT_EXTD(fs) (((1 << fs->eff_fat_bits)-1) & ~0xf)
169
170 #endif
171
172 /* Local Variables: */
173 /* tab-width: 8 */
174 /* End: */