[USETUP][ROSAPPS][EXT2LIB] NtReadFile() calls: Remove unused 'ByteOffset = 0', Use...
[reactos.git] / sdk / lib / fslib / ext2lib / Group.c
1 /*
2 * PROJECT: Mke2fs
3 * FILE: Group.c
4 * PROGRAMMER: Matt Wu <mattwu@163.com>
5 * HOMEPAGE: http://ext2.yeah.net
6 */
7
8 /* INCLUDES **************************************************************/
9
10 #include "Mke2fs.h"
11
12 /* DEFINITIONS ***********************************************************/
13
14 /* FUNCTIONS *************************************************************/
15
16 int test_root(int a, int b)
17 {
18 if (a == 0)
19 return 1;
20 while (1)
21 {
22 if (a == 1)
23 return 1;
24 if (a % b)
25 return 0;
26 a = a / b;
27 }
28 }
29
30 bool ext2_bg_has_super(PEXT2_SUPER_BLOCK pExt2Sb, int group_block)
31 {
32 if (!(pExt2Sb->s_feature_ro_compat & EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER))
33 return true;
34
35 if (test_root(group_block, 3) || (test_root(group_block, 5)) ||
36 test_root(group_block, 7))
37 return true;
38
39 return false;
40 }
41
42
43 bool ext2_allocate_group_desc(PEXT2_FILESYS Ext2Sys)
44 {
45 ULONG size;
46
47 size = Ext2Sys->desc_blocks * Ext2Sys->blocksize;
48
49 Ext2Sys->group_desc =
50 (PEXT2_GROUP_DESC)RtlAllocateHeap(RtlGetProcessHeap(), 0, size);
51
52 if (Ext2Sys->group_desc)
53 {
54 memset(Ext2Sys->group_desc, 0, size);
55 return true;
56 }
57
58 return false;
59 }
60
61 void ext2_free_group_desc(PEXT2_FILESYS Ext2Sys)
62 {
63 if (Ext2Sys->group_desc)
64 {
65 RtlFreeHeap(RtlGetProcessHeap(), 0, Ext2Sys->group_desc);
66 Ext2Sys->group_desc = NULL;
67 }
68 }