Skip to content
Snippets Groups Projects
Commit 6959fd5b authored by Brian Carrier's avatar Brian Carrier
Browse files

make new version of test_root that is not from other licensed code. Closes #1251

parent 8b15b4f5
No related branches found
No related tags found
No related merge requests found
...@@ -55,8 +55,6 @@ debug_print_buf(unsigned char *buf, int len) ...@@ -55,8 +55,6 @@ debug_print_buf(unsigned char *buf, int len)
/** \internal /** \internal
test_root - tests to see if a is power of b test_root - tests to see if a is power of b
Adapted from E2fsprogs sparse.c
Super blocks are only in block groups that are powers of 3,5, and 7
@param a the number being investigated @param a the number being investigated
@param b the root @param b the root
@return 1 if a is a power of b, otherwise 0 @return 1 if a is a power of b, otherwise 0
...@@ -64,15 +62,25 @@ debug_print_buf(unsigned char *buf, int len) ...@@ -64,15 +62,25 @@ debug_print_buf(unsigned char *buf, int len)
static uint8_t static uint8_t
test_root(uint32_t a, uint32_t b) test_root(uint32_t a, uint32_t b)
{ {
if (a == 0) if (a == 0) {
return 1; return (b == 0);
while (1) { }
if (a == 1) else if (b == 0) {
return 1; return 0;
if (a % b)
return 0;
a = a / b;
} }
else if (a == 1) {
return (b == 1);
}
else if (b == 1) {
return 0;
}
// keep on multiplying b by itself
uint32_t b2;
for (b2 = b; b2 < a; b2 *= b) {}
// was it an exact match?
return (b2 == a);
} }
/** \internal /** \internal
...@@ -86,6 +94,10 @@ ext2fs_bg_has_super(uint32_t feature_ro_compat, uint32_t group_block) ...@@ -86,6 +94,10 @@ ext2fs_bg_has_super(uint32_t feature_ro_compat, uint32_t group_block)
if (!(feature_ro_compat & EXT2FS_FEATURE_RO_COMPAT_SPARSE_SUPER)) if (!(feature_ro_compat & EXT2FS_FEATURE_RO_COMPAT_SPARSE_SUPER))
return 1; return 1;
if (group_block == 0)
return 1;
// Super blocks are only in block groups that are powers of 3,5, and 7
if (test_root(group_block, 3) || (test_root(group_block, 5)) || if (test_root(group_block, 3) || (test_root(group_block, 5)) ||
test_root(group_block, 7)) test_root(group_block, 7))
return 1; return 1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment