aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorChangman Lee <cm224.lee@samsung.com>2013-07-30 16:39:06 +0900
committerJaegeuk Kim <jaegeuk.kim@samsung.com>2013-07-30 17:06:44 +0900
commit57baa23a3279a4b9e9df0ab92ee20a2c79b839d8 (patch)
treea00d6f9294ee7915a1f57139180f14fbc7ff42f2 /lib
parent932f9845f6d6ab79815d80a1eb03b1b3509a4463 (diff)
downloadandroid_external_f2fs-tools-57baa23a3279a4b9e9df0ab92ee20a2c79b839d8.tar.gz
android_external_f2fs-tools-57baa23a3279a4b9e9df0ab92ee20a2c79b839d8.tar.bz2
android_external_f2fs-tools-57baa23a3279a4b9e9df0ab92ee20a2c79b839d8.zip
f2fs-tools: add option to display directory tree
This option shows directory tree of f2fs. Usage: fsck.f2fs -t /dev/sdx `-- p0 |-- f4 `-- d6 |-- f5e |-- cb6 |-- fdb |-- fe8 `-- l9a Signed-off-by: Changman Lee <cm224.lee@samsung.com> Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/libf2fs.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index 3f00871..b02072f 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -146,6 +146,76 @@ int f2fs_clear_bit(unsigned int nr, char *addr)
return ret;
}
+static inline unsigned long __ffs(unsigned long word)
+{
+ int num = 0;
+
+#if BITS_PER_LONG == 64
+ if ((word & 0xffffffff) == 0) {
+ num += 32;
+ word >>= 32;
+ }
+#endif
+ if ((word & 0xffff) == 0) {
+ num += 16;
+ word >>= 16;
+ }
+ if ((word & 0xff) == 0) {
+ num += 8;
+ word >>= 8;
+ }
+ if ((word & 0xf) == 0) {
+ num += 4;
+ word >>= 4;
+ }
+ if ((word & 0x3) == 0) {
+ num += 2;
+ word >>= 2;
+ }
+ if ((word & 0x1) == 0)
+ num += 1;
+ return num;
+}
+
+unsigned long find_next_bit(const unsigned long *addr, unsigned long size,
+ unsigned long offset)
+{
+ const unsigned long *p = addr + BIT_WORD(offset);
+ unsigned long result = offset & ~(BITS_PER_LONG-1);
+ unsigned long tmp;
+
+ if (offset >= size)
+ return size;
+ size -= result;
+ offset %= BITS_PER_LONG;
+ if (offset) {
+ tmp = *(p++);
+ tmp &= (~0UL << offset);
+ if (size < BITS_PER_LONG)
+ goto found_first;
+ if (tmp)
+ goto found_middle;
+ size -= BITS_PER_LONG;
+ result += BITS_PER_LONG;
+ }
+ while (size & ~(BITS_PER_LONG-1)) {
+ if ((tmp = *(p++)))
+ goto found_middle;
+ result += BITS_PER_LONG;
+ size -= BITS_PER_LONG;
+ }
+ if (!size)
+ return result;
+ tmp = *p;
+
+found_first:
+ tmp &= (~0UL >> (BITS_PER_LONG - size));
+ if (tmp == 0UL) /* Are any bits set? */
+ return result + size; /* Nope. */
+found_middle:
+ return result + __ffs(tmp);
+}
+
/*
* Hashing code adapted from ext3
*/