[USETUP][ROSAPPS][EXT2LIB] NtReadFile() calls: Remove unused 'ByteOffset = 0', Use...
[reactos.git] / sdk / lib / fslib / ext2lib / Mke2fs.h
1 /*
2 * PROJECT: Mke2fs
3 * FILE: Mke2fs.h
4 * PROGRAMMER: Matt Wu <mattwu@163.com>
5 * HOMEPAGE: http://ext2.yeah.net
6 */
7
8 #ifndef _MKE2FS_H_
9 #define _MKE2FS_H_
10
11 /* INCLUDES **************************************************************/
12
13 #define NTOS_MODE_USER
14 #include <ndk/kefuncs.h>
15 #include <ndk/rtlfuncs.h>
16
17 #include "ext2_fs.h"
18
19 /* DEFINITIONS ***********************************************************/
20
21 #define SECTOR_SIZE (Ext2Sys->DiskGeometry.BytesPerSector)
22
23 #ifndef GUID_DEFINED
24 #define GUID_DEFINED
25 typedef struct _GUID
26 {
27 unsigned long Data1;
28 unsigned short Data2;
29 unsigned short Data3;
30 unsigned char Data4[8];
31 } GUID;
32 #endif /* GUID_DEFINED */
33
34 #ifndef UUID_DEFINED
35 #define UUID_DEFINED
36 typedef GUID UUID;
37 #ifndef uuid_t
38 #define uuid_t UUID
39 #endif
40 #endif
41
42 #ifndef bool
43 #define bool BOOLEAN
44 #endif
45
46 #ifndef true
47 #define true TRUE
48 #endif
49
50 #ifndef false
51 #define false FALSE
52 #endif
53
54
55 #define EXT2_CHECK_MAGIC(struct, code) \
56 if ((struct)->magic != (code)) return (code)
57
58 /*
59 * ext2fs_scan flags
60 */
61 #define EXT2_SF_CHK_BADBLOCKS 0x0001
62 #define EXT2_SF_BAD_INODE_BLK 0x0002
63 #define EXT2_SF_BAD_EXTRA_BYTES 0x0004
64 #define EXT2_SF_SKIP_MISSING_ITABLE 0x0008
65
66 /*
67 * ext2fs_check_if_mounted flags
68 */
69 #define EXT2_MF_MOUNTED 1
70 #define EXT2_MF_ISROOT 2
71 #define EXT2_MF_READONLY 4
72 #define EXT2_MF_SWAP 8
73
74 /*
75 * Ext2/linux mode flags. We define them here so that we don't need
76 * to depend on the OS's sys/stat.h, since we may be compiling on a
77 * non-Linux system.
78 */
79
80 #define LINUX_S_IFMT 00170000
81 #define LINUX_S_IFSOCK 0140000
82 #define LINUX_S_IFLNK 0120000
83 #define LINUX_S_IFREG 0100000
84 #define LINUX_S_IFBLK 0060000
85 #define LINUX_S_IFDIR 0040000
86 #define LINUX_S_IFCHR 0020000
87 #define LINUX_S_IFIFO 0010000
88 #define LINUX_S_ISUID 0004000
89 #define LINUX_S_ISGID 0002000
90 #define LINUX_S_ISVTX 0001000
91
92 #define LINUX_S_IRWXU 00700
93 #define LINUX_S_IRUSR 00400
94 #define LINUX_S_IWUSR 00200
95 #define LINUX_S_IXUSR 00100
96
97 #define LINUX_S_IRWXG 00070
98 #define LINUX_S_IRGRP 00040
99 #define LINUX_S_IWGRP 00020
100 #define LINUX_S_IXGRP 00010
101
102 #define LINUX_S_IRWXO 00007
103 #define LINUX_S_IROTH 00004
104 #define LINUX_S_IWOTH 00002
105 #define LINUX_S_IXOTH 00001
106
107 #define LINUX_S_ISLNK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFLNK)
108 #define LINUX_S_ISREG(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFREG)
109 #define LINUX_S_ISDIR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFDIR)
110 #define LINUX_S_ISCHR(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFCHR)
111 #define LINUX_S_ISBLK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFBLK)
112 #define LINUX_S_ISFIFO(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFIFO)
113 #define LINUX_S_ISSOCK(m) (((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK)
114
115
116 #define EXT2_FIRST_INODE(s) EXT2_FIRST_INO(s)
117
118 typedef struct _ext2fs_bitmap {
119 __u32 start, end;
120 __u32 real_end;
121 char* bitmap;
122 } EXT2_BITMAP, *PEXT2_BITMAP;
123
124 typedef EXT2_BITMAP EXT2_GENERIC_BITMAP, *PEXT2_GENERIC_BITMAP;
125 typedef EXT2_BITMAP EXT2_INODE_BITMAP, *PEXT2_INODE_BITMAP;
126 typedef EXT2_BITMAP EXT2_BLOCK_BITMAP, *PEXT2_BLOCK_BITMAP;
127
128 typedef struct ext2_acl_entry EXT2_ACL_ENTRY, *PEXT2_ACL_ENTRY;
129 typedef struct ext2_acl_header EXT2_ACL_HEADER, *PEXT2_ACL_HEADER;
130 typedef struct ext2_dir_entry EXT2_DIR_ENTRY, *PEXT2_DIR_ENTRY;
131 typedef struct ext2_dir_entry_2 EXT2_DIR_ENTRY2, *PEXT2_DIR_ENTRY2;
132 typedef struct ext2_dx_countlimit EXT2_DX_CL, *PEXT2_DX_CL;
133 typedef struct ext2_dx_entry EXT2_DX_ENTRY, *PEXT2_DX_ENTRY;
134 typedef struct ext2_dx_root_info EXT2_DX_RI, *PEXT2_DX_RI;
135 typedef struct ext2_inode EXT2_INODE, *PEXT2_INODE;
136 typedef struct ext2_group_desc EXT2_GROUP_DESC, *PEXT2_GROUP_DESC;
137 typedef struct ext2_super_block EXT2_SUPER_BLOCK, *PEXT2_SUPER_BLOCK;
138
139 /*
140 * Badblocks list
141 */
142 struct ext2_struct_badblocks_list {
143 int num;
144 int size;
145 ULONG *list;
146 int badblocks_flags;
147 };
148
149 typedef struct ext2_struct_badblocks_list EXT2_BADBLK_LIST, *PEXT2_BADBLK_LIST;
150
151 typedef struct _ext2_filesys
152 {
153 int flags;
154 int blocksize;
155 int fragsize;
156 ULONG group_desc_count;
157 unsigned long desc_blocks;
158 PEXT2_GROUP_DESC group_desc;
159 PEXT2_SUPER_BLOCK ext2_sb;
160 unsigned long inode_blocks_per_group;
161 PEXT2_INODE_BITMAP inode_map;
162 PEXT2_BLOCK_BITMAP block_map;
163
164 EXT2_BADBLK_LIST badblocks;
165 /*
166 ext2_dblist dblist;
167 */
168 __u32 stride; /* for mke2fs */
169
170 __u32 umask;
171
172 /*
173 * Reserved for future expansion
174 */
175 __u32 reserved[8];
176
177 /*
178 * Reserved for the use of the calling application.
179 */
180 void * priv_data;
181
182 HANDLE MediaHandle;
183
184 DISK_GEOMETRY DiskGeometry;
185
186 PARTITION_INFORMATION PartInfo;
187
188 } EXT2_FILESYS, *PEXT2_FILESYS;
189
190 // Block Description List
191 typedef struct _EXT2_BDL {
192 LONGLONG Lba;
193 ULONG Offset;
194 ULONG Length;
195 } EXT2_BDL, *PEXT2_BDL;
196
197 /*
198 * Where the master copy of the superblock is located, and how big
199 * superblocks are supposed to be. We define SUPERBLOCK_SIZE because
200 * the size of the superblock structure is not necessarily trustworthy
201 * (some versions have the padding set up so that the superblock is
202 * 1032 bytes long).
203 */
204 #define SUPERBLOCK_OFFSET 1024
205 #define SUPERBLOCK_SIZE 1024
206
207
208 bool create_bad_block_inode(PEXT2_FILESYS fs, PEXT2_BADBLK_LIST bb_list);
209
210
211 /*
212 * Bitmap.c
213 */
214
215 #define ext2_mark_block_bitmap ext2_mark_bitmap
216 #define ext2_mark_inode_bitmap ext2_mark_bitmap
217 #define ext2_unmark_block_bitmap ext2_unmark_bitmap
218 #define ext2_unmark_inode_bitmap ext2_unmark_bitmap
219
220 bool ext2_set_bit(int nr, void * addr);
221 bool ext2_clear_bit(int nr, void * addr);
222 bool ext2_test_bit(int nr, void * addr);
223
224 bool ext2_mark_bitmap(PEXT2_BITMAP bitmap, ULONG bitno);
225 bool ext2_unmark_bitmap(PEXT2_BITMAP bitmap, ULONG bitno);
226
227 bool ext2_test_block_bitmap(PEXT2_BLOCK_BITMAP bitmap,
228 ULONG block);
229
230 bool ext2_test_block_bitmap_range(PEXT2_BLOCK_BITMAP bitmap,
231 ULONG block, int num);
232
233 bool ext2_test_inode_bitmap(PEXT2_BLOCK_BITMAP bitmap,
234 ULONG inode);
235
236
237 bool ext2_allocate_block_bitmap(PEXT2_FILESYS pExt2Sys);
238 bool ext2_allocate_inode_bitmap(PEXT2_FILESYS pExt2Sys);
239 void ext2_free_inode_bitmap(PEXT2_FILESYS pExt2Sys);
240 void ext2_free_block_bitmap(PEXT2_FILESYS pExt2Sys);
241
242 bool ext2_write_block_bitmap (PEXT2_FILESYS fs);
243 bool ext2_write_inode_bitmap (PEXT2_FILESYS fs);
244
245 bool ext2_write_bitmaps(PEXT2_FILESYS fs);
246
247 //bool read_bitmaps(PEXT2_FILESYS fs, int do_inode, int do_block);
248 bool ext2_read_inode_bitmap (PEXT2_FILESYS fs);
249 bool ext2_read_block_bitmap(PEXT2_FILESYS fs);
250 bool ext2_read_bitmaps(PEXT2_FILESYS fs);
251
252
253 /*
254 * Disk.c
255 */
256
257 NTSTATUS
258 Ext2OpenDevice( PEXT2_FILESYS Ext2Sys,
259 PUNICODE_STRING DeviceName );
260
261 NTSTATUS
262 Ext2CloseDevice( PEXT2_FILESYS Ext2Sys);
263
264 NTSTATUS
265 Ext2ReadDisk( PEXT2_FILESYS Ext2Sys,
266 ULONGLONG Offset,
267 ULONG Length,
268 PVOID Buffer );
269
270 NTSTATUS
271 Ext2WriteDisk( PEXT2_FILESYS Ext2Sys,
272 ULONGLONG Offset,
273 ULONG Length,
274 PVOID Buffer );
275
276 NTSTATUS
277 Ext2GetMediaInfo( PEXT2_FILESYS Ext2Sys );
278
279
280 NTSTATUS
281 Ext2LockVolume( PEXT2_FILESYS Ext2Sys );
282
283 NTSTATUS
284 Ext2UnLockVolume( PEXT2_FILESYS Ext2Sys );
285
286 NTSTATUS
287 Ext2DisMountVolume( PEXT2_FILESYS Ext2Sys );
288
289
290 /*
291 * Group.c
292 */
293
294 bool ext2_allocate_group_desc(PEXT2_FILESYS pExt2Sys);
295 void ext2_free_group_desc(PEXT2_FILESYS pExt2Sys);
296 bool ext2_bg_has_super(PEXT2_SUPER_BLOCK pExt2Sb, int group_block);
297
298 /*
299 * Inode.c
300 */
301
302 bool ext2_get_inode_lba(PEXT2_FILESYS pExt2Sys, ULONG no, LONGLONG *offset);
303 bool ext2_load_inode(PEXT2_FILESYS pExt2Sys, ULONG no, PEXT2_INODE pInode);
304 bool ext2_save_inode(PEXT2_FILESYS pExt2Sys, ULONG no, PEXT2_INODE pInode);
305 bool ext2_new_inode(PEXT2_FILESYS fs, ULONG dir, int mode,
306 PEXT2_INODE_BITMAP map, ULONG *ret);
307 bool ext2_expand_inode(PEXT2_FILESYS pExt2Sys, PEXT2_INODE, ULONG newBlk);
308
309 bool ext2_read_inode (PEXT2_FILESYS pExt2Sys,
310 ULONG ino,
311 ULONG offset,
312 PVOID Buffer,
313 ULONG size,
314 PULONG dwReturn );
315 bool ext2_write_inode (PEXT2_FILESYS pExt2Sys,
316 ULONG ino,
317 ULONG offset,
318 PVOID Buffer,
319 ULONG size,
320 PULONG dwReturn );
321
322 bool ext2_add_entry(PEXT2_FILESYS pExt2Sys, ULONG parent, ULONG inode, int filetype, char *name);
323 bool ext2_reserve_inodes(PEXT2_FILESYS fs);
324 /*
325 * Memory.c
326 */
327
328 //
329 // Return the group # of an inode number
330 //
331 int ext2_group_of_ino(PEXT2_FILESYS fs, ULONG ino);
332
333 //
334 // Return the group # of a block
335 //
336 int ext2_group_of_blk(PEXT2_FILESYS fs, ULONG blk);
337
338 /*
339 * Badblock.c
340 */
341
342
343 void ext2_inode_alloc_stats2(PEXT2_FILESYS fs, ULONG ino, int inuse, int isdir);
344 void ext2_inode_alloc_stats(PEXT2_FILESYS fs, ULONG ino, int inuse);
345 void ext2_block_alloc_stats(PEXT2_FILESYS fs, ULONG blk, int inuse);
346
347 bool ext2_allocate_tables(PEXT2_FILESYS pExt2Sys);
348 bool ext2_allocate_group_table(PEXT2_FILESYS fs, ULONG group,
349 PEXT2_BLOCK_BITMAP bmap);
350 bool ext2_get_free_blocks(PEXT2_FILESYS fs, ULONG start, ULONG finish,
351 int num, PEXT2_BLOCK_BITMAP map, ULONG *ret);
352 bool write_inode_tables(PEXT2_FILESYS fs);
353
354 bool ext2_new_block(PEXT2_FILESYS fs, ULONG goal,
355 PEXT2_BLOCK_BITMAP map, ULONG *ret);
356 bool ext2_alloc_block(PEXT2_FILESYS fs, ULONG goal, ULONG *ret);
357 bool ext2_new_dir_block(PEXT2_FILESYS fs, ULONG dir_ino,
358 ULONG parent_ino, char **block);
359 bool ext2_write_block(PEXT2_FILESYS fs, ULONG block, void *inbuf);
360 bool ext2_read_block(PEXT2_FILESYS fs, ULONG block, void *inbuf);
361
362 /*
363 * Mke2fs.c
364 */
365
366 bool parase_cmd(int argc, char *argv[], PEXT2_FILESYS pExt2Sys);
367
368 bool zero_blocks(PEXT2_FILESYS fs, ULONG blk, ULONG num,
369 ULONG *ret_blk, ULONG *ret_count);
370
371 ULONG
372 Ext2DataBlocks(PEXT2_FILESYS Ext2Sys, ULONG TotalBlocks);
373
374 ULONG
375 Ext2TotalBlocks(PEXT2_FILESYS Ext2Sys, ULONG DataBlocks);
376
377
378
379 /*
380 * Super.c
381 */
382
383 void ext2_print_super(PEXT2_SUPER_BLOCK pExt2Sb);
384 bool ext2_initialize_sb(PEXT2_FILESYS pExt2Sys);
385
386
387 /*
388 * Super.c
389 */
390
391 LONGLONG ext2_nt_time (ULONG i_time);
392 ULONG ext2_unix_time (LONGLONG n_time);
393
394 /*
395 * Uuid.c
396 */
397
398 void uuid_generate(__u8 * uuid);
399
400 #endif /* _MKE2FS_H_ */