Skip to contentSkip to conversation

mkfs.f2fs: fix storing volume label correctly in utf16

PATCH New Jaegeuk Kim 1 participant 1 message Dec 15, 2015 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mkfs.f2fs: fix storing volume label correctly in utf16

This patch fixes to store volume label as utf16 correctly.

Many conversion codes are copied from exfat-tools.

---
 fsck/mount.c       |  11 ++++
 include/f2fs_fs.h  |   7 ++-
 lib/libf2fs.c      | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 mkfs/f2fs_format.c |   4 +-
 4 files changed, 186 insertions(+), 13 deletions(-)
fsck/mount.c +11 -0
index e773471..d34c704 100644
@@ -99,6 +99,14 @@ void print_node_info(struct f2fs_node *node_block)
 	}
 }
 
+static void DISP_label(u_int16_t *name)
+{
+	char buffer[MAX_VOLUME_NAME];
+
+	utf16_to_utf8(buffer, name, MAX_VOLUME_NAME, MAX_VOLUME_NAME);
+	printf("%-30s" "\t\t[%s]\n", "volum_name", buffer);
+}
+
 void print_raw_sb_info(struct f2fs_super_block *sb)
 {
 	if (!config.dbg_lv)
@@ -111,6 +119,9 @@ void print_raw_sb_info(struct f2fs_super_block *sb)
 
 	DISP_u32(sb, magic);
 	DISP_u32(sb, major_ver);
+
+	DISP_label(sb->volume_name);
+
 	DISP_u32(sb, minor_ver);
 	DISP_u32(sb, log_sectorsize);
 	DISP_u32(sb, log_sectors_per_block);
include/f2fs_fs.h +5 -2
index 29ff9fe..4927d24 100644
@@ -398,6 +398,8 @@ enum {
 
 #define F2FS_FEATURE_ENCRYPT	0x0001
 
+#define MAX_VOLUME_NAME		512
+
 /*
  * For superblock
  */
@@ -430,7 +432,7 @@ struct f2fs_super_block {
 	__le32 node_ino;		/* node inode number */
 	__le32 meta_ino;		/* meta inode number */
 	__u8 uuid[16];			/* 128-bit uuid for volume */
-	__le16 volume_name[512];	/* volume name */
+	__le16 volume_name[MAX_VOLUME_NAME];	/* volume name */
 	__le32 extension_count;		/* # of extensions below */
 	__u8 extension_list[F2FS_MAX_EXTENSION][8];	/* extension array */
 	__le32 cp_payload;
@@ -847,7 +849,8 @@ enum {
 	SSR
 };
 
-extern void ASCIIToUNICODE(u_int16_t *, u_int8_t *);
+extern int utf8_to_utf16(u_int16_t *, const char *, size_t, size_t);
+extern int utf16_to_utf8(char *, const u_int16_t *, size_t, size_t);
 extern int log_base_2(u_int32_t);
 extern unsigned int addrs_per_inode(struct f2fs_inode *);
 
lib/libf2fs.c +168 -9

186 lines not on this page · raw message

mkfs/f2fs_format.c +2 -2
index a2f33f9..fff74a9 100644
@@ -291,8 +291,8 @@ static int f2fs_prepare_super_block(void)
 
 	uuid_generate(sb->uuid);
 
-	ASCIIToUNICODE(sb->volume_name, (u_int8_t *)config.vol_label);
-
+	utf8_to_utf16(sb->volume_name, (const char *)config.vol_label,
+				MAX_VOLUME_NAME, strlen(config.vol_label));
 	set_sb(node_ino, 1);
 	set_sb(meta_ino, 2);
 	set_sb(root_ino, 3);
Signature · 4 lines
2.5.4 (Apple Git-61)


------------------------------------------------------------------------------