ref: e957027243c30367446a1a8963b7e86019f034fb
parent: b37b80f57b925327aa624a2b1f79e1db06368c9a
author: gkostka <kostka.grzegorz@gmail.com>
date: Tue Oct 21 14:32:16 EDT 2014
Add ext4_sb_is_super_in_bg
--- a/lwext4/ext4_super.c
+++ b/lwext4/ext4_super.c
@@ -126,6 +126,42 @@
return true;
}
+static inline int is_multiple(uint32_t a, uint32_t b)
+{
+ while (1) {
+ if (a < b)
+ return 0;
+ if (a == b)
+ return 1;
+ if ((a % b) != 0)
+ return 0;
+ a = a / b;
+ }
+}
+
+static int ext4_sb_sparse(uint32_t group)
+{
+ if (group <= 1)
+ return 1;
+
+ if (!(group & 1))
+ return 0;
+
+ return (is_multiple(group, 7) || is_multiple(group, 5) ||
+ is_multiple(group, 3));
+}
+
+
+bool ext4_sb_is_super_in_bg(struct ext4_sblock *s, uint32_t group)
+{
+ if (ext4_sb_check_read_only(s,
+ EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER) &&
+ !ext4_sb_sparse(group))
+ return false;
+ return true;
+}
+
+
/**
* @}
*/
--- a/lwext4/ext4_super.h
+++ b/lwext4/ext4_super.h
@@ -177,6 +177,11 @@
* @return true if OK*/
bool ext4_sb_check(struct ext4_sblock *s);
+/**@brief Superblock presence in block group.
+ * @param s superblock dsecriptor
+ * @param block_group block group id
+ * @return true if block group has superblock*/
+bool ext4_sb_is_super_in_bg(struct ext4_sblock *s, uint32_t block_group);
#endif /* EXT4_SUPER_H_ */