From 99b74393403aab847587d6c37cd1aaf1d935a81d Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Tue, 30 Oct 2012 07:35:00 +0900 Subject: [PATCH] Enhancement: add uuid "Usually, it is used 128-bits UUID for serial number. Why do you use __le32 as volume_serial_number?" >From Vyacheslav Dubeyko. I added an uuid facility for the serial number. And sync with kernel/include/linux/f2fs_fs.h. Signed-off-by: Jaegeuk Kim --- README | 6 ++++++ configure.ac | 4 ++++ mkfs/Makefile.am | 1 + mkfs/f2fs_format.c | 9 +++++---- mkfs/f2fs_format.h | 37 ++++++++++++++++++++++++++++++++----- 5 files changed, 48 insertions(+), 9 deletions(-) diff --git a/README b/README index c0be658..c7b4a31 100644 --- a/README +++ b/README @@ -4,6 +4,12 @@ F2FS format utilility To use f2fs filesystem, you should format the storage partition with this utilility. Otherwise, you cannot mount f2fs. +Before compilation +------------------ + +Your should install the following packages. + - libuuid-devel or uuid-dev + Initial compilation ------------------- diff --git a/configure.ac b/configure.ac index fd7272d..2a0c15f 100644 --- a/configure.ac +++ b/configure.ac @@ -11,6 +11,10 @@ AC_CONFIG_HEADERS([config.h]) AC_PROG_CC # Checks for libraries. +AC_CHECK_LIB([uuid], [uuid_generate], + [AC_DEFINE([HAVE_LIBUUID], 1, + [Define to 1 if you have the 'uuid' library (-luuid).])], + [AC_MSG_ERROR([UUID library not found])]) # Checks for header files. AC_CHECK_HEADERS([fcntl.h mntent.h stdlib.h string.h sys/ioctl.h sys/mount.h unistd.h]) diff --git a/mkfs/Makefile.am b/mkfs/Makefile.am index f47c1ec..b5a6cd2 100644 --- a/mkfs/Makefile.am +++ b/mkfs/Makefile.am @@ -1,5 +1,6 @@ ## Makefile.am AM_CFLAGS = -Wall +LDADD = -luuid bin_PROGRAMS = mkfs.f2fs mkfs_f2fs_SOURCES = f2fs_format.c f2fs_format.h diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c index 7d4dad2..84796c1 100644 --- a/mkfs/f2fs_format.c +++ b/mkfs/f2fs_format.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "f2fs_format.h" @@ -561,7 +562,7 @@ static int f2fs_prepare_super_block(void) / f2fs_params.segs_per_sec); super_block.segment_count_main = cpu_to_le32( - le32_to_cpu(super_block.section_count) * + le32_to_cpu(super_block.section_count) * f2fs_params.segs_per_sec); if ((le32_to_cpu(super_block.segment_count_main) - 2) < @@ -574,7 +575,7 @@ static int f2fs_prepare_super_block(void) } super_block.failure_safe_block_distance = 0; - super_block.volume_serial_number = 0; + uuid_generate(super_block.uuid); ASCIIToUNICODE(super_block.volume_name, f2fs_params.vol_label); @@ -582,7 +583,7 @@ static int f2fs_prepare_super_block(void) super_block.meta_ino = cpu_to_le32(2); super_block.root_ino = cpu_to_le32(3); - total_zones = ((le32_to_cpu(super_block.segment_count_main) - 1) / + total_zones = ((le32_to_cpu(super_block.segment_count_main) - 1) / f2fs_params.segs_per_sec) / f2fs_params.secs_per_zone; if (total_zones <= 6) { @@ -842,7 +843,7 @@ static int8_t f2fs_write_check_point_pack(void) SET_SUM_TYPE((&sum->footer), SUM_TYPE_DATA); sum->entries[0].nid = super_block.root_ino; - sum->entries[0].bidx = 0; + sum->entries[0].ofs_in_node = 0; cp_seg_blk_offset += blk_size_bytes; if (writetodisk(f2fs_params.fd, sum, cp_seg_blk_offset, diff --git a/mkfs/f2fs_format.h b/mkfs/f2fs_format.h index 31c075b..ec49d4d 100644 --- a/mkfs/f2fs_format.h +++ b/mkfs/f2fs_format.h @@ -56,6 +56,11 @@ #define F2FS_CP_BLOCK_SIZE (DEFAULT_SECTOR_SIZE * \ DEFAULT_SECTORS_PER_BLOCK) +/* + * For further optimization on multi-head logs, on-disk layout supports maximum + * 16 logs by default. The number, 16, is expected to cover all the cases + * enoughly. +*/ #define MAX_ACTIVE_LOGS 16 #define MAX_ACTIVE_NODE_LOGS 8 #define MAX_ACTIVE_DATA_LOGS 8 @@ -129,7 +134,7 @@ struct f2fs_super_block { __le32 root_ino; /* Root directory inode number */ __le32 node_ino; /* node inode number */ __le32 meta_ino; /* meta inode number */ - __le32 volume_serial_number; /* VSN is optional field */ + __u8 uuid[16]; /* 128-bit uuid for volume */ __le16 volume_name[512]; /* Volume Name */ __le32 extension_count; __u8 extension_list[F2FS_MAX_EXTENSION][8]; /* extension array */ @@ -273,6 +278,11 @@ enum { #define SIT_VBLOCK_MAP_SIZE 64 #define SIT_ENTRY_PER_BLOCK (PAGE_CACHE_SIZE / sizeof(struct f2fs_sit_entry)) +/* + * Note that f2fs_sit_entry->vblocks has the following bit-field information. + * [15:10] : allocation type such as CURSEG_XXXX_TYPE + * [9:0] : valid block count + */ struct f2fs_sit_entry { __le16 vblocks; __u8 valid_map[SIT_VBLOCK_MAP_SIZE]; @@ -283,13 +293,25 @@ struct f2fs_sit_block { struct f2fs_sit_entry entries[SIT_ENTRY_PER_BLOCK]; } __attribute__((packed)); +/** + * For segment summary + * + * NOTE : For initializing fields, you must use set_summary + * + * - If data page, nid represents dnode's nid + * - If node page, nid represents the node page's nid. + * + * The ofs_in_node is used by only data page. It represents offset + * from node's page's beginning to get a data block address. + * ex) data_blkaddr = (block_t)(nodepage_start_address + ofs_in_node) + */ struct f2fs_summary { __le32 nid; /* parent node id */ union { __u8 reserved[3]; struct { __u8 version; /* node version number */ - __le16 bidx; /* block index in parent node */ + __le16 ofs_in_node; /* block index in parent node */ } __attribute__((packed)); }; } __attribute__((packed)); @@ -360,9 +382,14 @@ struct f2fs_summary_block { /* * For directory operations */ -#define F2FS_NAME_LEN 8 /* 256 Unicode */ -#define NR_DENTRY_IN_BLOCK 214 /* the number of dentry in a block */ -#define MAX_DIR_HASH_DEPTH 63 /* MAX level for dir lookup */ +/* One directory entry slot covers 8bytes-long file name */ +#define F2FS_NAME_LEN 8 + +/* the number of dentry in a block */ +#define NR_DENTRY_IN_BLOCK 214 + +/* MAX level for dir lookup */ +#define MAX_DIR_HASH_DEPTH 63 #define SIZE_OF_DIR_ENTRY 11 /* by byte */ #define SIZE_OF_DENTRY_BITMAP ((NR_DENTRY_IN_BLOCK + BITS_PER_BYTE - 1) / \ -- 2.7.4