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