aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaegeuk Kim <jaegeuk@kernel.org>2016-02-10 13:20:25 -0800
committerluca020400 <luca.stefani.ge1@gmail.com>2016-04-04 17:16:18 +0200
commite88571e2c56a6e55fdb34450195b40a1d99467b1 (patch)
treeff424edeada206e072d9a2d017892ee56597328c
parent936247546216eee702f9e5b63163f7d819f58c9a (diff)
downloadandroid_external_f2fs-tools-e88571e2c56a6e55fdb34450195b40a1d99467b1.tar.gz
android_external_f2fs-tools-e88571e2c56a6e55fdb34450195b40a1d99467b1.tar.bz2
android_external_f2fs-tools-e88571e2c56a6e55fdb34450195b40a1d99467b1.zip
fsck.f2fs: show encrypted filenames matched with kernel
This patch follows the kernel's encrypted name resolution. Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--fsck/fsck.c41
1 files changed, 32 insertions, 9 deletions
diff --git a/fsck/fsck.c b/fsck/fsck.c
index 99dfe1f..6451595 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -874,6 +874,36 @@ int fsck_chk_didnode_blk(struct f2fs_sb_info *sbi, struct f2fs_inode *inode,
return 0;
}
+static const char *lookup_table =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
+
+/**
+ * digest_encode() -
+ *
+ * Encodes the input digest using characters from the set [a-zA-Z0-9_+].
+ * The encoded string is roughly 4/3 times the size of the input string.
+ */
+static int digest_encode(const char *src, int len, char *dst)
+{
+ int i = 0, bits = 0, ac = 0;
+ char *cp = dst;
+
+ while (i < len) {
+ ac += (((unsigned char) src[i]) << bits);
+ bits += 8;
+ do {
+ *cp++ = lookup_table[ac & 0x3f];
+ ac >>= 6;
+ bits -= 6;
+ } while (bits >= 6);
+ i++;
+ }
+ if (bits)
+ *cp++ = lookup_table[ac & 0x3f];
+ *cp = 0;
+ return cp - dst;
+}
+
static void convert_encrypted_name(unsigned char *name, int len,
unsigned char *new, int encrypted)
{
@@ -883,15 +913,8 @@ static void convert_encrypted_name(unsigned char *name, int len,
return;
}
- while (len--) {
- *new = *name++;
- if (*new > 128)
- *new -= 128;
- if (*new < 32 || *new == 0x7f)
- *new ^= 0x40; /* ^@, ^A, ^B; ^? for DEL */
- new++;
- }
- *new = 0;
+ *new = '_';
+ digest_encode((const char *)name, 24, (char *)new + 1);
}
static void print_dentry(__u32 depth, __u8 *name,