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