ReactOS  0.4.14-dev-297-g23e575c
Mke2fs.h
Go to the documentation of this file.
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 {
121  char* bitmap;
123 
127 
138 
139 /*
140  * Badblocks list
141  */
143  int num;
144  int size;
147 };
148 
150 
151 typedef struct _ext2_filesys
152 {
153  int flags;
155  int fragsize;
157  unsigned long desc_blocks;
160  unsigned long inode_blocks_per_group;
163 
165 /*
166  ext2_dblist dblist;
167 */
168  __u32 stride; /* for mke2fs */
169 
171 
172  /*
173  * Reserved for future expansion
174  */
176 
177  /*
178  * Reserved for the use of the calling application.
179  */
180  void * priv_data;
181 
183 
185 
187 
189 
190 // Block Description List
191 typedef struct _EXT2_BDL {
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 
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 
226 
228  ULONG block);
229 
231  ULONG block, int num);
232 
234  ULONG inode);
235 
236 
241 
244 
246 
247 //bool read_bitmaps(PEXT2_FILESYS fs, int do_inode, int do_block);
251 
252 
253 /*
254  * Disk.c
255  */
256 
257 NTSTATUS
260 
261 NTSTATUS
263 
264 NTSTATUS
265 Ext2ReadDisk( PEXT2_FILESYS Ext2Sys,
267  ULONG Length,
268  PVOID Buffer );
269 
270 NTSTATUS
273  ULONG Length,
274  PVOID Buffer );
275 
276 NTSTATUS
278 
279 
280 NTSTATUS
281 Ext2LockVolume( PEXT2_FILESYS Ext2Sys );
282 
283 NTSTATUS
285 
286 NTSTATUS
288 
289 
290 /*
291  * Group.c
292  */
293 
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 
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);
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);
324 /*
325  * Memory.c
326  */
327 
328 //
329 // Return the group # of an inode number
330 //
332 
333 //
334 // Return the group # of a block
335 //
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);
346 
347 bool ext2_allocate_tables(PEXT2_FILESYS pExt2Sys);
353 
358  ULONG parent_ino, char **block);
361 
362 /*
363  * Mke2fs.c
364  */
365 
366 bool parase_cmd(int argc, char *argv[], PEXT2_FILESYS pExt2Sys);
367 
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_ */
bool ext2_allocate_group_desc(PEXT2_FILESYS pExt2Sys)
Definition: Group.c:43
static unsigned int block
Definition: xmlmemory.c:118
struct _GUID GUID
NTSTATUS Ext2ReadDisk(PEXT2_FILESYS Ext2Sys, ULONGLONG Offset, ULONG Length, PVOID Buffer)
Definition: Disk.c:964
void ext2_free_block_bitmap(PEXT2_FILESYS pExt2Sys)
Definition: Bitmap.c:205
bool ext2_mark_bitmap(PEXT2_BITMAP bitmap, ULONG bitno)
Definition: Bitmap.c:52
void ext2_free_group_desc(PEXT2_FILESYS pExt2Sys)
Definition: Group.c:61
NTSTATUS Ext2GetMediaInfo(PEXT2_FILESYS Ext2Sys)
Definition: Disk.c:1162
unsigned char __u8
Definition: compat.h:88
int blocksize
Definition: Mke2fs.h:154
static int argc
Definition: ServiceArgs.c:12
NTSTATUS Ext2WriteDisk(PEXT2_FILESYS Ext2Sys, ULONGLONG Offset, ULONG Length, PVOID Buffer)
Definition: Disk.c:1059
bool write_inode_tables(PEXT2_FILESYS fs)
Definition: Memory.c:221
bool ext2_allocate_inode_bitmap(PEXT2_FILESYS pExt2Sys)
Definition: Bitmap.c:140
Definition: scsiwmi.h:51
bool ext2_allocate_tables(PEXT2_FILESYS pExt2Sys)
Definition: Memory.c:75
bool ext2_write_block(PEXT2_FILESYS fs, ULONG block, void *inbuf)
Definition: Memory.c:394
ULONG nr
Definition: thread.c:7
Definition: ext3_fs.h:774
__u32 start
Definition: Mke2fs.h:119
struct ext2_dx_entry * PEXT2_DX_ENTRY
Definition: Mke2fs.h:133
ULONG group_desc_count
Definition: Mke2fs.h:156
bool ext2_add_entry(PEXT2_FILESYS pExt2Sys, ULONG parent, ULONG inode, int filetype, char *name)
Definition: Inode.c:619
bool ext2_alloc_block(PEXT2_FILESYS fs, ULONG goal, ULONG *ret)
Definition: Memory.c:293
LONG NTSTATUS
Definition: precomp.h:26
GLintptr offset
Definition: glext.h:5920
EXT2_BADBLK_LIST badblocks
Definition: Mke2fs.h:164
ULONG Ext2TotalBlocks(PEXT2_FILESYS Ext2Sys, ULONG DataBlocks)
Definition: Mke2fs.c:750
static int inbuf
Definition: adnsresfilter.c:73
int ext2_group_of_blk(PEXT2_FILESYS fs, ULONG blk)
Definition: Memory.c:31
bool ext2_read_block(PEXT2_FILESYS fs, ULONG block, void *inbuf)
Definition: Memory.c:406
bool ext2_write_bitmaps(PEXT2_FILESYS fs)
Definition: Bitmap.c:342
struct ext2_acl_header * PEXT2_ACL_HEADER
Definition: Mke2fs.h:129
bool ext2_expand_inode(PEXT2_FILESYS pExt2Sys, PEXT2_INODE, ULONG newBlk)
Definition: Inode.c:212
unsigned short Data2
Definition: scsiwmi.h:53
ULONG Ext2DataBlocks(PEXT2_FILESYS Ext2Sys, ULONG TotalBlocks)
Definition: Mke2fs.c:698
struct _ext2_filesys * PEXT2_FILESYS
NTSTATUS Ext2DisMountVolume(PEXT2_FILESYS Ext2Sys)
Definition: Disk.c:1260
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define argv
Definition: mplay32.c:18
bool ext2_test_inode_bitmap(PEXT2_BLOCK_BITMAP bitmap, ULONG inode)
Definition: Bitmap.c:93
Definition: fs.h:235
EXT2_BITMAP EXT2_BLOCK_BITMAP
Definition: Mke2fs.h:126
NTSTATUS Ext2OpenDevice(PEXT2_FILESYS Ext2Sys, PUNICODE_STRING DeviceName)
Definition: Disk.c:1282
NTSTATUS Ext2CloseDevice(PEXT2_FILESYS Ext2Sys)
Definition: Disk.c:1342
bool ext2_new_block(PEXT2_FILESYS fs, ULONG goal, PEXT2_BLOCK_BITMAP map, ULONG *ret)
Definition: Memory.c:254
Definition: fs.h:78
void ext2_print_super(PEXT2_SUPER_BLOCK pExt2Sb)
Definition: Super.c:20
bool ext2_read_inode(PEXT2_FILESYS pExt2Sys, ULONG ino, ULONG offset, PVOID Buffer, ULONG size, PULONG dwReturn)
Definition: Inode.c:494
bool ext2_read_inode_bitmap(PEXT2_FILESYS fs)
Definition: Bitmap.c:482
PEXT2_GROUP_DESC group_desc
Definition: Mke2fs.h:158
bool ext2_test_block_bitmap(PEXT2_BLOCK_BITMAP bitmap, ULONG block)
Definition: Bitmap.c:73
void ext2_free_inode_bitmap(PEXT2_FILESYS pExt2Sys)
Definition: Bitmap.c:194
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
struct ext2_super_block * PEXT2_SUPER_BLOCK
Definition: Mke2fs.h:137
struct _ext2_filesys EXT2_FILESYS
unsigned long Data1
Definition: scsiwmi.h:52
bool ext2_reserve_inodes(PEXT2_FILESYS fs)
Definition: Inode.c:681
bool ext2_test_block_bitmap_range(PEXT2_BLOCK_BITMAP bitmap, ULONG block, int num)
Definition: Bitmap.c:80
__u32 reserved[8]
Definition: Mke2fs.h:175
Definition: ext2_fs.h:492
bool ext2_new_dir_block(PEXT2_FILESYS fs, ULONG dir_ino, ULONG parent_ino, char **block)
Definition: Memory.c:349
ULONG Offset
Definition: Mke2fs.h:193
bool ext2_write_inode(PEXT2_FILESYS pExt2Sys, ULONG ino, ULONG offset, PVOID Buffer, ULONG size, PULONG dwReturn)
Definition: Inode.c:541
struct ext2_inode * PEXT2_INODE
Definition: Mke2fs.h:135
Definition: bufpool.h:45
bool ext2_initialize_sb(PEXT2_FILESYS pExt2Sys)
Definition: Super.c:74
unsigned int dir
Definition: maze.c:112
__u32 real_end
Definition: Mke2fs.h:120
NTSTATUS Ext2LockVolume(PEXT2_FILESYS Ext2Sys)
Definition: Disk.c:1212
bool ext2_new_inode(PEXT2_FILESYS fs, ULONG dir, int mode, PEXT2_INODE_BITMAP map, ULONG *ret)
Definition: Inode.c:84
GLboolean GLuint group
Definition: glext.h:11120
Definition: uimain.c:88
int64_t LONGLONG
Definition: typedefs.h:66
bool zero_blocks(PEXT2_FILESYS fs, ULONG blk, ULONG num, ULONG *ret_blk, ULONG *ret_count)
Definition: Mke2fs.c:122
bool ext2_load_inode(PEXT2_FILESYS pExt2Sys, ULONG no, PEXT2_INODE pInode)
Definition: Inode.c:41
ULONG Length
Definition: Mke2fs.h:194
static WCHAR no[MAX_STRING_RESOURCE_LEN]
Definition: object.c:2340
GLsizeiptr size
Definition: glext.h:5919
GUID UUID
Definition: Mke2fs.h:36
r parent
Definition: btrfs.c:2897
struct ext2_group_desc * PEXT2_GROUP_DESC
Definition: Mke2fs.h:136
unsigned long desc_blocks
Definition: Mke2fs.h:157
uint64_t ULONGLONG
Definition: typedefs.h:65
GLuint GLuint num
Definition: glext.h:9618
__u32 end
Definition: Mke2fs.h:119
PEXT2_INODE_BITMAP inode_map
Definition: Mke2fs.h:161
unsigned int __u32
Definition: compat.h:90
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
Definition: _map.h:44
int ret
char * bitmap
Definition: Mke2fs.h:121
GLenum const GLvoid * addr
Definition: glext.h:9621
ULONGLONG bmap(struct inode *i, ULONGLONG b)
Definition: linux.c:934
bool ext2_allocate_block_bitmap(PEXT2_FILESYS pExt2Sys)
Definition: Bitmap.c:100
void ext2_block_alloc_stats(PEXT2_FILESYS fs, ULONG blk, int inuse)
Definition: Memory.c:61
#define blk
Definition: linetest.c:70
unsigned long inode_blocks_per_group
Definition: Mke2fs.h:160
bool ext2_read_bitmaps(PEXT2_FILESYS fs)
Definition: Bitmap.c:492
Definition: ext2_fs.h:505
HANDLE MediaHandle
Definition: Mke2fs.h:182
struct _EXT2_BDL * PEXT2_BDL
GLenum mode
Definition: glext.h:6217
bool create_bad_block_inode(PEXT2_FILESYS fs, PEXT2_BADBLK_LIST bb_list)
Definition: Badblock.c:16
struct _ext2fs_bitmap * PEXT2_BITMAP
bool ext2_test_bit(int nr, void *addr)
Definition: Bitmap.c:41
EXT2_BITMAP * PEXT2_GENERIC_BITMAP
Definition: Mke2fs.h:124
bool ext2_save_inode(PEXT2_FILESYS pExt2Sys, ULONG no, PEXT2_INODE pInode)
Definition: Inode.c:59
__u32 stride
Definition: Mke2fs.h:168
NTSTATUS Ext2UnLockVolume(PEXT2_FILESYS Ext2Sys)
Definition: Disk.c:1237
__u32 umask
Definition: Mke2fs.h:170
ULONG ext2_unix_time(LONGLONG n_time)
bool parase_cmd(int argc, char *argv[], PEXT2_FILESYS pExt2Sys)
void uuid_generate(__u8 *uuid)
Definition: Uuid.c:17
struct ext2_struct_badblocks_list * PEXT2_BADBLK_LIST
Definition: Mke2fs.h:149
bool ext2_get_inode_lba(PEXT2_FILESYS pExt2Sys, ULONG no, LONGLONG *offset)
Definition: Inode.c:20
GLuint start
Definition: gl.h:1545
void ext2_inode_alloc_stats(PEXT2_FILESYS fs, ULONG ino, int inuse)
Definition: Memory.c:56
struct ext2_acl_entry * PEXT2_ACL_ENTRY
Definition: Mke2fs.h:128
PARTITION_INFORMATION PartInfo
Definition: Mke2fs.h:186
void ext2_inode_alloc_stats2(PEXT2_FILESYS fs, ULONG ino, int inuse, int isdir)
Definition: Memory.c:37
DISK_GEOMETRY DiskGeometry
Definition: Mke2fs.h:184
unsigned int * PULONG
Definition: retypes.h:1
EXT2_BITMAP * PEXT2_BLOCK_BITMAP
Definition: Mke2fs.h:126
Definition: ext2_fs.h:168
bool ext2_set_bit(int nr, void *addr)
Definition: Bitmap.c:18
struct ext2_dir_entry_2 * PEXT2_DIR_ENTRY2
Definition: Mke2fs.h:131
unsigned char Data4[8]
Definition: scsiwmi.h:55
struct ext2_dir_entry * PEXT2_DIR_ENTRY
Definition: Mke2fs.h:130
bool ext2_allocate_group_table(PEXT2_FILESYS fs, ULONG group, PEXT2_BLOCK_BITMAP bmap)
Definition: Memory.c:92
LONGLONG ext2_nt_time(ULONG i_time)
Definition: name.c:36
void * priv_data
Definition: Mke2fs.h:180
EXT2_BITMAP * PEXT2_INODE_BITMAP
Definition: Mke2fs.h:125
Definition: msctf.idl:510
unsigned int ULONG
Definition: retypes.h:1
LONGLONG Lba
Definition: Mke2fs.h:192
bool ext2_bg_has_super(PEXT2_SUPER_BLOCK pExt2Sb, int group_block)
Definition: Group.c:30
bool ext2_write_inode_bitmap(PEXT2_FILESYS fs)
Definition: Bitmap.c:216
LOCAL char * filetype(int t)
Definition: tree.c:114
unsigned short Data3
Definition: scsiwmi.h:54
EXT2_BITMAP EXT2_GENERIC_BITMAP
Definition: Mke2fs.h:124
bool ext2_get_free_blocks(PEXT2_FILESYS fs, ULONG start, ULONG finish, int num, PEXT2_BLOCK_BITMAP map, ULONG *ret)
Definition: Memory.c:182
bool ext2_write_block_bitmap(PEXT2_FILESYS fs)
Definition: Bitmap.c:270
struct _ext2fs_bitmap EXT2_BITMAP
bool ext2_read_block_bitmap(PEXT2_FILESYS fs)
Definition: Bitmap.c:487
bool ext2_clear_bit(int nr, void *addr)
Definition: Bitmap.c:30
EXT2_BITMAP EXT2_INODE_BITMAP
Definition: Mke2fs.h:125
PEXT2_SUPER_BLOCK ext2_sb
Definition: Mke2fs.h:159
struct ext2_dx_root_info * PEXT2_DX_RI
Definition: Mke2fs.h:134
Definition: ext2_fs.h:134
struct ext2_dx_countlimit * PEXT2_DX_CL
Definition: Mke2fs.h:132
int ext2_group_of_ino(PEXT2_FILESYS fs, ULONG ino)
Definition: Memory.c:23
PEXT2_BLOCK_BITMAP block_map
Definition: Mke2fs.h:162
bool ext2_unmark_bitmap(PEXT2_BITMAP bitmap, ULONG bitno)
Definition: Bitmap.c:62
int fragsize
Definition: Mke2fs.h:155
struct _EXT2_BDL EXT2_BDL