From: Theodore Ts'o Date: Tue, 31 Dec 2013 04:03:09 +0000 (-0500) Subject: mke2fs: add support to create the file system at an offset X-Git-Tag: v1.42.9.wc1~148 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=88ee023be20b4ae1c795b6c4800947f7bf6c6c0c;p=tools%2Fe2fsprogs.git mke2fs: add support to create the file system at an offset This can be useful when creating a disk image for virtual machines. Addresses-Debian-Bug: #497984 Signed-off-by: "Theodore Ts'o" --- diff --git a/misc/mke2fs.8.in b/misc/mke2fs.8.in index fea50da..6e1121e 100644 --- a/misc/mke2fs.8.in +++ b/misc/mke2fs.8.in @@ -246,6 +246,10 @@ parity disk, so N will be the number of disks in the array minus 1). This allows the block allocator to prevent read-modify-write of the parity in a RAID stripe if possible when the data is written. .TP +.BI offset= offset +Create the filesystem at an offset from the beginning of the device or +file. This can be useful when creating disk images for virtual machines. +.TP .BI resize= max-online-resize Reserve enough space so that the block group descriptor table can grow to support a filesystem that has diff --git a/misc/mke2fs.c b/misc/mke2fs.c index 2e8ba60..10d3211 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -96,6 +96,7 @@ static int lazy_itable_init; static char *bad_blocks_filename = NULL; static __u32 fs_stride; static int quotatype = -1; /* Initialize both user and group quotas by default */ +static __u64 offset; static struct ext2_super_block fs_param; static char *fs_uuid = NULL; @@ -710,6 +711,19 @@ static void parse_extended_opts(struct ext2_super_block *param, continue; } param->s_desc_size = desc_size; + } else if (strcmp(token, "offset") == 0) { + if (!arg) { + r_usage++; + badopt = token; + continue; + } + offset = strtoull(arg, &p, 0); + if (*p) { + fprintf(stderr, _("Invalid offset: %s\n"), + arg); + r_usage++; + continue; + } } else if (strcmp(token, "mmp_update_interval") == 0) { if (!arg) { r_usage++; @@ -879,8 +893,10 @@ static void parse_extended_opts(struct ext2_super_block *param, "and may take an argument which\n" "\tis set off by an equals ('=') sign.\n\n" "Valid extended options are:\n" + "\tmmp_update_interval=\n" "\tstride=\n" "\tstripe-width=\n" + "\toffset=\n" "\tresize=\n" "\tlazy_itable_init=<0 to disable, 1 to enable>\n" "\tlazy_journal_init=<0 to disable, 1 to enable>\n" @@ -2368,7 +2384,7 @@ int main (int argc, char *argv[]) int flags; int old_bitmaps; io_manager io_ptr; - char tdb_string[40]; + char opt_string[40]; char *hash_alg_str; int itable_zeroed = 0; @@ -2438,9 +2454,13 @@ int main (int argc, char *argv[]) } } - sprintf(tdb_string, "tdb_data_size=%d", fs->blocksize <= 4096 ? + sprintf(opt_string, "tdb_data_size=%d", fs->blocksize <= 4096 ? 32768 : fs->blocksize * 8); - io_channel_set_options(fs->io, tdb_string); + io_channel_set_options(fs->io, opt_string); + if (offset) { + sprintf(opt_string, "offset=%llu", offset); + io_channel_set_options(fs->io, opt_string); + } if (fs_param.s_flags & EXT2_FLAGS_TEST_FILESYS) fs->super->s_flags |= EXT2_FLAGS_TEST_FILESYS;