From e6c1489c80067f2aa8aa46a767e65dc025bbf1a6 Mon Sep 17 00:00:00 2001 From: Mark Fasheh Date: Fri, 5 Mar 2010 15:56:22 +0800 Subject: [PATCH 03/15] dx_dirs: mkfs.ocfs2 support This adds only basic support to mkfs.ocfs2 to write the seed fields used in directory indexing. The feature string 'indexed-dirs' is already there from a previous patch, so it is possible to create a new file system with the directory indexing feature turned on. Future improvements that are needed: - mkfs.ocfs2 should create the root directory and orphan dirs as indexed. - possibly also we want to do this for the system dir, but that might require some discussion. Signed-off-by: Mark Fasheh Signed-off-by: Coly Li --- mkfs.ocfs2/mkfs.c | 17 ++++++++++++++--- 1 files changed, 14 insertions(+), 3 deletions(-) Index: ocfs2-tools/mkfs.ocfs2/mkfs.c =================================================================== --- ocfs2-tools.orig/mkfs.ocfs2/mkfs.c +++ ocfs2-tools/mkfs.ocfs2/mkfs.c @@ -1004,6 +1004,8 @@ get_state(int argc, char **argv) if ((optind == argc) && !show_version) usage(progname); + srand48(time(NULL)); + device_name = argv[optind]; optind++; @@ -2240,11 +2242,9 @@ format_superblock(State *s, SystemFileDi */ s->feature_flags.opt_compat &= ~OCFS2_FEATURE_COMPAT_BACKUP_SB; - if (s->feature_flags.opt_incompat & OCFS2_FEATURE_INCOMPAT_XATTR) { + if (s->feature_flags.opt_incompat & OCFS2_FEATURE_INCOMPAT_XATTR) di->id2.i_super.s_xattr_inline_size = OCFS2_MIN_XATTR_INLINE_SIZE; - di->id2.i_super.s_uuid_hash = ocfs2_xattr_uuid_hash(s->uuid); - } di->id2.i_super.s_feature_incompat = s->feature_flags.opt_incompat; di->id2.i_super.s_feature_compat = s->feature_flags.opt_compat; @@ -2253,6 +2253,17 @@ format_superblock(State *s, SystemFileDi strcpy((char *)di->id2.i_super.s_label, s->vol_label); memcpy(di->id2.i_super.s_uuid, s->uuid, 16); + /* s_uuid_hash is also used by Indexed Dirs */ + if (s->feature_flags.opt_incompat & OCFS2_FEATURE_INCOMPAT_XATTR || + s->feature_flags.opt_incompat & OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS) + di->id2.i_super.s_uuid_hash = ocfs2_xattr_uuid_hash(s->uuid); + + if (s->feature_flags.opt_incompat & OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS) { + di->id2.i_super.s_dx_seed[0] = mrand48(); + di->id2.i_super.s_dx_seed[1] = mrand48(); + di->id2.i_super.s_dx_seed[2] = mrand48(); + } + mkfs_swap_inode_from_cpu(s, di); mkfs_compute_meta_ecc(s, di, &di->i_check); do_pwrite(s, di, s->blocksize, super_off);