New api mke2fs for full configuration of filesystem. Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/ext2.c | 452 +++++++++++++++++++++++++++++++++++++++++ generator/generator_actions.ml | 18 ++ gobject/Makefile.inc | 6 +- src/MAX_PROC_NR | 2 +- 4 files changed, 475 insertions(+), 3 deletions(-) diff --git a/daemon/ext2.c b/daemon/ext2.c index 40b36d2..ee87d05 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -811,3 +811,455 @@ do_set_e2generation (const char *filename, int64_t generation) return 0; } + +int +do_mke2fs (const char *device, + int checkbadblock, const char *badblockfile, + int64_t blocksize, int directwrite, + int64_t fragsize, int forcecreate, + int64_t blockspergroup, int64_t numberofgroups, + int64_t bytesperinode, int64_t inodesize, + int withjournal, int64_t journalsize, + const char *journaldevice, const char *newvolumelabel, + int reservedblockspercentage, const char *lastmounteddir, + int64_t numberofinodes, const char *creatoros, + int writesbandgrouponly, + const char *fstype, const char *usagetype, + const char *fsuuid, int mmpupdateinterval, + int64_t stridesize, int64_t stripewidth, + int64_t maxonlineresize, int lazyitableinit, + int lazyjournalinit, int testfs, + int discard, int quotatype, + int dirindex, int extent, int filetype, + int flexbg, int hasjournal, int journaldev, + int largefile, int quota, int resizeinode, + int sparsesuper, int uninitbg, + int64_t blockscount) +{ + int r; + char *err = NULL; + const char *argv[MAX_ARGS]; + char blocksize_s[64]; + char fragsize_s[64]; + char blockspergroup_s[64]; + char numberofgroups_s[64]; + char bytesperinode_s[64]; + char inodesize_s[64]; + char journalsize_s[64]; + char journaldevice_s[256]; + char reservedblockspercentage_s[64]; + char numberofinodes_s[64]; + char mmpupdateinterval_s[84]; + char stridesize_s[74]; + char stripewidth_s[84]; + char maxonlineresize_s[74]; + char blockscount_s[64]; + size_t i = 0; + int feature = 0; + char features[256]; + + ADD_ARG (argv, i, str_mke2fs); + + if (optargs_bitmask & GUESTFS_MKE2FS_CHECKBADBLOCK_BITMASK) { + if (checkbadblock) + ADD_ARG (argv, i, "-c"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_BADBLOCKFILE_BITMASK) { + if (badblockfile) { + ADD_ARG (argv, i, "-l"); + ADD_ARG (argv, i, badblockfile); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSIZE_BITMASK) { + if (blocksize < 0) { + reply_with_error ("blocksize must be >= 0"); + goto error; + } + snprintf (blocksize_s, sizeof blocksize_s, "%" PRIi64, blocksize); + ADD_ARG (argv, i, "-b"); + ADD_ARG (argv, i, blocksize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_DIRECTWRITE_BITMASK) { + if (directwrite) + ADD_ARG (argv, i, "-D"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FRAGSIZE_BITMASK) { + if (fragsize < 0) { + reply_with_error ("fragsize must be >= 0"); + goto error; + } + snprintf (fragsize_s, sizeof fragsize_s, "%" PRIi64, fragsize); + ADD_ARG (argv, i, "-f"); + ADD_ARG (argv, i, fragsize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FORCECREATE_BITMASK) { + if (forcecreate) + ADD_ARG (argv, i, "-F"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSPERGROUP_BITMASK) { + if (blockspergroup < 0) { + reply_with_error ("blockspergroup must be >= 0"); + goto error; + } + snprintf (blockspergroup_s, sizeof blockspergroup_s, + "%" PRIi64, blockspergroup); + ADD_ARG (argv, i, "-g"); + ADD_ARG (argv, i, blockspergroup_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_NUMBEROFGROUPS_BITMASK) { + if (numberofgroups < 0) { + reply_with_error ("numberofgroups must be >= 0"); + goto error; + } + snprintf (numberofgroups_s, sizeof numberofgroups_s, + "%" PRIi64, numberofgroups); + ADD_ARG (argv, i, "-G"); + ADD_ARG (argv, i, numberofgroups_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_BYTESPERINODE_BITMASK) { + if (bytesperinode < 0) { + reply_with_error ("bytesperinode must be >= 0"); + goto error; + } + snprintf (bytesperinode_s, sizeof bytesperinode_s, "%" PRIi64, bytesperinode); + ADD_ARG (argv, i, "-i"); + ADD_ARG (argv, i, bytesperinode_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_INODESIZE_BITMASK) { + if (inodesize < 0) { + reply_with_error ("inodesize must be >= 0"); + goto error; + } + snprintf (inodesize_s, sizeof inodesize_s, "%" PRIi64, inodesize); + ADD_ARG (argv, i, "-I"); + ADD_ARG (argv, i, inodesize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_WITHJOURNAL_BITMASK) { + if (withjournal) + ADD_ARG (argv, i, "-j"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALSIZE_BITMASK) { + if (journalsize < 0) { + reply_with_error ("journalsize must be >= 0"); + goto error; + } + snprintf (journalsize_s, sizeof journalsize_s, + "size=" "%" PRIi64, journalsize); + ADD_ARG (argv, i, "-J"); + ADD_ARG (argv, i, journalsize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALDEVICE_BITMASK) { + if (journaldevice) { + snprintf (journaldevice_s, sizeof journaldevice_s, + "device=%s", journaldevice); + ADD_ARG (argv, i, "-J"); + ADD_ARG (argv, i, journaldevice_s); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_NEWVOLUMELABEL_BITMASK) { + if (newvolumelabel) { + ADD_ARG (argv, i, "-L"); + ADD_ARG (argv, i, newvolumelabel); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_RESERVEDBLOCKSPERCENTAGE_BITMASK) { + if (reservedblockspercentage < 0) { + reply_with_error ("reservedblockspercentage must be >= 0"); + goto error; + } + snprintf (reservedblockspercentage_s, sizeof reservedblockspercentage_s, + "%" PRIi32, reservedblockspercentage); + ADD_ARG (argv, i, "-m"); + ADD_ARG (argv, i, reservedblockspercentage_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LASTMOUNTEDDIR_BITMASK) { + if (lastmounteddir) { + ADD_ARG (argv, i, "-M"); + ADD_ARG (argv, i, lastmounteddir); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_NUMBEROFINODES_BITMASK) { + if (numberofinodes < 0) { + reply_with_error ("numberofinodes must be >= 0"); + goto error; + } + snprintf (numberofinodes_s, sizeof numberofinodes_s, + "%" PRIi64, numberofinodes); + ADD_ARG (argv, i, "-N"); + ADD_ARG (argv, i, numberofinodes_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_CREATOROS_BITMASK) { + if (creatoros) { + ADD_ARG (argv, i, "-o"); + ADD_ARG (argv, i, creatoros); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_WRITESBANDGROUPONLY_BITMASK) { + if (writesbandgrouponly) + ADD_ARG (argv, i, "-S"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FSTYPE_BITMASK) { + if (fstype) { + ADD_ARG (argv, i, "-t"); + ADD_ARG (argv, i, fstype); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_USAGETYPE_BITMASK) { + if (usagetype) { + ADD_ARG (argv, i, "-T"); + ADD_ARG (argv, i, usagetype); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_FSUUID_BITMASK) { + if (fsuuid) { + ADD_ARG (argv, i, "-U"); + ADD_ARG (argv, i, fsuuid); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_MMPUPDATEINTERVAL_BITMASK) { + if (mmpupdateinterval < 0) { + reply_with_error ("mmpupdateinterval must be >= 0"); + goto error; + } + snprintf (mmpupdateinterval_s, sizeof mmpupdateinterval_s, + "mmp_update_interval=" "%" PRIi32, mmpupdateinterval); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, mmpupdateinterval_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_STRIDESIZE_BITMASK) { + if (stridesize < 0) { + reply_with_error ("stridesize must be >= 0"); + goto error; + } + snprintf (stridesize_s, sizeof stridesize_s, + "stride=" "%" PRIi64, stridesize); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, stridesize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_STRIPEWIDTH_BITMASK) { + if (stripewidth< 0) { + reply_with_error ("stripewidth must be >= 0"); + goto error; + } + snprintf (stripewidth_s, sizeof stripewidth_s, + "stripe_width=" "%" PRIi64, stripewidth); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, stripewidth_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_MAXONLINERESIZE_BITMASK) { + if (maxonlineresize < 0) { + reply_with_error ("maxonlineresize must be >= 0"); + goto error; + } + snprintf (maxonlineresize_s, sizeof maxonlineresize_s, + "resize=" "%" PRIi64, maxonlineresize); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, maxonlineresize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LAZYITABLEINIT_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (lazyitableinit) + ADD_ARG (argv, i, "lazy_itable_init=1"); + else + ADD_ARG (argv, i, "lazy_itable_init=0"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LAZYJOURNALINIT_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (lazyjournalinit) + ADD_ARG (argv, i, "lazy_journal_init=1"); + else + ADD_ARG (argv, i, "lazy_journal_init=0"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_TESTFS_BITMASK) { + if (testfs) { + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, "test_fs"); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_DISCARD_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (discard) + ADD_ARG (argv, i, "discard"); + else + ADD_ARG (argv, i, "nodiscard"); + } + + if (optargs_bitmask & GUESTFS_MKE2FS_DIRINDEX_BITMASK) { + if (dirindex) + strncat (features, "dir_index", 9); + else + strncat (features, "^dir_index", 10); + feature++; + } + if (optargs_bitmask & GUESTFS_MKE2FS_EXTENT_BITMASK) { + if (feature == 0) { + if (extent) + strncat (features, "extent", 6); + else + strncat (features, "^extent", 7); + feature++; + } else { + if (extent) + strncat (features, ",extent", 7); + else + strncat (features, ",^extent", 8); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_FILETYPE_BITMASK) { + if (feature == 0) { + if (filetype) + strncat (features, "filetype", 8); + else + strncat (features, "^filetype", 9); + feature++; + } else { + if (filetype) + strncat (features, ",filetype", 9); + else + strncat (features, ",^filetype", 10); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_FLEXBG_BITMASK) { + if (feature == 0) { + if (flexbg) + strncat (features, "flex_bg", 7); + else + strncat (features, "^flex_bg", 8); + feature++; + } else { + if (flexbg) + strncat (features, ",flex_bg", 8); + else + strncat (features, ",^flex_bg", 9); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_HASJOURNAL_BITMASK) { + if (feature == 0) { + if (hasjournal) + strncat (features, "has_journal", 11); + else + strncat (features, "^has_journal", 12); + feature++; + } else { + if (hasjournal) + strncat (features, ",has_journal", 12); + else + strncat (features, ",^has_journal", 13); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALDEV_BITMASK) { + if (feature == 0) { + if (journaldev) + strncat (features, "journal_dev", 11); + else + strncat (features, "^journal_dev", 12); + feature++; + } else { + if (journaldev) + strncat (features, ",journal_dev", 12); + else + strncat (features, ",^journal_dev", 13); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_LARGEFILE_BITMASK) { + if (feature == 0) { + if (largefile) + strncat (features, "large_file", 10); + else + strncat (features, "^large_file", 11); + feature++; + } else { + if (largefile) + strncat (features, ",large_file", 11); + else + strncat (features, ",^large_file", 12); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_QUOTA_BITMASK) { + if (feature == 0) { + if (quota) + strncat (features, "quota", 5); + else + strncat (features, "^quota", 6); + feature++; + } else { + if (quota) + strncat (features, ",quota", 6); + else + strncat (features, ",^quota", 7); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_RESIZEINODE_BITMASK) { + if (feature == 0) { + if (resizeinode) + strncat (features, "resize_inode", 12); + else + strncat (features, "^resize_inode", 13); + feature++; + } else { + if (resizeinode) + strncat (features, ",resize_inode", 13); + else + strncat (features, ",^resize_inode", 14); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_SPARSESUPER_BITMASK) { + if (feature == 0) { + if (sparsesuper) + strncat (features, "sparse_super", 12); + else + strncat (features, "^sparse_super", 13); + feature++; + } else { + if (sparsesuper) + strncat (features, ",sparse_super", 13); + else + strncat (features, ",^sparse_super", 14); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_UNINITBG_BITMASK) { + if (feature == 0) { + if (uninitbg) + strncat (features, "uninit_bg", 9); + else + strncat (features, "^uninit_bg", 10); + feature++; + } else { + if (uninitbg) + strncat (features, ",uninit_bg", 10); + else + strncat (features, ",^uninit_bg", 11); + } + } + + if (feature != 0) { + ADD_ARG (argv, i, "-O"); + ADD_ARG (argv, i, features); + } + + ADD_ARG (argv, i, device); + + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSCOUNT_BITMASK) { + if (blockscount < 0) { + reply_with_error ("blockscount must be >= 0"); + goto error; + } + snprintf (blockscount_s, sizeof blockscount_s, "%" PRIi64, blockscount); + ADD_ARG (argv, i, blockscount_s); + } + + ADD_ARG (argv, i, NULL); + + r = commandv (NULL, &err, argv); + if (r == -1) { + reply_with_error ("%s: %s", device, err); + goto error; + } + + free (err); + return 0; + +error: + if (err) free (err); + return -1; +} diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index 0033e3a..2c71263 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -9710,6 +9710,24 @@ the resulting filesystem may be inconsistent or corrupt. The returned status indicates whether filesystem corruption was detected (returns C<1>) or was not detected (returns C<0>)." }; + { defaults with + name = "mke2fs"; + style = RErr, [Device "device"], [OBool "checkbadblock"; OString "badblockfile"; OInt64 "blocksize"; OBool "directwrite"; OInt64 "fragsize"; OBool "forcecreate"; OInt64 "blockspergroup"; OInt64 "numberofgroups"; OInt64 "bytesperinode"; OInt64 "inodesize"; OBool "withjournal"; OInt64 "journalsize"; OString "journaldevice"; OString "newvolumelabel"; OInt "reservedblockspercentage"; OString "lastmounteddir"; OInt64 "numberofinodes"; OString "creatoros"; OBool "writesbandgrouponly"; OString "fstype"; OString "usagetype"; OString "fsuuid"; OInt "mmpupdateinterval"; OInt64 "stridesize"; OInt64 "stripewidth"; OInt64 "maxonlineresize"; OBool "lazyitableinit"; OBool "lazyjournalinit"; OBool "testfs"; OBool "discard"; OBool "quotatype"; OBool "dirindex"; OBool "extent"; OBool "filetype"; OBool "flexbg"; OBool "hasjournal"; OBool "journaldev"; OBool "largefile"; OBool "quota"; OBool "resizeinode"; OBool "sparsesuper"; OBool "uninitbg"; OInt64 "blockscount"]; + proc_nr = Some 367; + tests = [ + InitEmpty, IfAvailable "ext2", TestRun ( + [["part_disk"; "/dev/sda"; "mbr"]; + ["mke2fs"; "/dev/sda1"; ""; "NOARG"; ""; ""; ""; ""; ""; ""; ""; ""; "true"; ""; "NOARG"; "NOARG"; ""; "NOARG"; ""; "NOARG"; ""; "ext4"; "NOARG"; "NOARG"; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""]; + ]) + ]; + shortdesc = "create an ext2/ext3/ext4 filesystem on C<device>"; + longdesc = "\ +C<mke2fs> is used to create an ext2, ext3, or ext4 filesystem, +usually in a disk partition. C<device> is the special file corresponding +to the device (e.g /dev/sdXX). C<blockscount> is the number of blocks +on C<device>. If omitted, C<mke2fs> automagically figures the file system +size." }; + ] (* Non-API meta-commands available only in guestfish. diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc index ba41b48..de8e1e7 100644 --- a/gobject/Makefile.inc +++ b/gobject/Makefile.inc @@ -78,7 +78,8 @@ guestfs_gobject_headers= \ include/guestfs-gobject/optargs-rsync_out.h \ include/guestfs-gobject/optargs-xfs_admin.h \ include/guestfs-gobject/optargs-hivex_open.h \ - include/guestfs-gobject/optargs-xfs_repair.h + include/guestfs-gobject/optargs-xfs_repair.h \ + include/guestfs-gobject/optargs-mke2fs.h guestfs_gobject_sources= \ src/session.c \ @@ -138,4 +139,5 @@ guestfs_gobject_sources= \ src/optargs-rsync_out.c \ src/optargs-xfs_admin.c \ src/optargs-hivex_open.c \ - src/optargs-xfs_repair.c + src/optargs-xfs_repair.c \ + src/optargs-mke2fs.c diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 4203007..526204c 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -366 +367 -- 1.7.12
On 08/31/2012 06:00 PM, Wanlong Gao wrote:
New api mke2fs for full configuration of filesystem.
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/ext2.c | 452 +++++++++++++++++++++++++++++++++++++++++ generator/generator_actions.ml | 18 ++ gobject/Makefile.inc | 6 +- src/MAX_PROC_NR | 2 +- 4 files changed, 475 insertions(+), 3 deletions(-)
Hi Rich, I got the following error when compiling with this patch, it seems that the long typed optargs_bitmask can't accept more than 31 optional arguments, it's odd ? This mke2fs api has about 43 optional arguments, so 64bit typed optargs_bitmask is enough, but why does long type limit the arguments to 31? ./com/redhat/et/libguestfs/GuestFS.java:14731: error: integer number too large: 2147483648 _optargs_bitmask |= 2147483648; ^ Thanks, Wanlong Gao
New api mke2fs for full configuration of filesystem. Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/ext2.c | 452 +++++++++++++++++++++++++++++++++++++++++++++++++++ generator/actions.ml | 18 ++ gobject/Makefile.inc | 6 +- src/MAX_PROC_NR | 2 +- 4 files changed, 475 insertions(+), 3 deletions(-) diff --git a/daemon/ext2.c b/daemon/ext2.c index 40b36d2..7108547 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -811,3 +811,455 @@ do_set_e2generation (const char *filename, int64_t generation) return 0; } + +int +do_mke2fs (const char *device, + int checkbadblock, const char *badblockfile, + int64_t blocksize, int directwrite, + int64_t fragsize, int forcecreate, + int64_t blockspergroup, int64_t numberofgroups, + int64_t bytesperinode, int64_t inodesize, + int withjournal, int64_t journalsize, + const char *journaldevice, const char *newvolumelabel, + int reservedblockspercentage, const char *lastmounteddir, + int64_t numberofinodes, const char *creatoros, + int writesbandgrouponly, + const char *fstype, const char *usagetype, + const char *fsuuid, int mmpupdateinterval, + int64_t stridesize, int64_t stripewidth, + int64_t maxonlineresize, int lazyitableinit, + int lazyjournalinit, int testfs, + int discard, int quotatype, + int dirindex, int extent, int filetype, + int flexbg, int hasjournal, int journaldev, + int largefile, int quota, int resizeinode, + int sparsesuper, int uninitbg, + int64_t blockscount) +{ + int r; + char *err = NULL; + const char *argv[MAX_ARGS]; + char blocksize_s[64]; + char fragsize_s[64]; + char blockspergroup_s[64]; + char numberofgroups_s[64]; + char bytesperinode_s[64]; + char inodesize_s[64]; + char journalsize_s[64]; + char journaldevice_s[256]; + char reservedblockspercentage_s[64]; + char numberofinodes_s[64]; + char mmpupdateinterval_s[84]; + char stridesize_s[74]; + char stripewidth_s[84]; + char maxonlineresize_s[74]; + char blockscount_s[64]; + size_t i = 0; + int feature = 0; + char features[256]; + + ADD_ARG (argv, i, str_mke2fs); + + if (optargs_bitmask & GUESTFS_MKE2FS_CHECKBADBLOCK_BITMASK) { + if (checkbadblock) + ADD_ARG (argv, i, "-c"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_BADBLOCKFILE_BITMASK) { + if (badblockfile) { + ADD_ARG (argv, i, "-l"); + ADD_ARG (argv, i, badblockfile); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSIZE_BITMASK) { + if (blocksize < 0) { + reply_with_error ("blocksize must be >= 0"); + goto error; + } + snprintf (blocksize_s, sizeof blocksize_s, "%" PRIi64, blocksize); + ADD_ARG (argv, i, "-b"); + ADD_ARG (argv, i, blocksize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_DIRECTWRITE_BITMASK) { + if (directwrite) + ADD_ARG (argv, i, "-D"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FRAGSIZE_BITMASK) { + if (fragsize < 0) { + reply_with_error ("fragsize must be >= 0"); + goto error; + } + snprintf (fragsize_s, sizeof fragsize_s, "%" PRIi64, fragsize); + ADD_ARG (argv, i, "-f"); + ADD_ARG (argv, i, fragsize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FORCECREATE_BITMASK) { + if (forcecreate) + ADD_ARG (argv, i, "-F"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSPERGROUP_BITMASK) { + if (blockspergroup < 0) { + reply_with_error ("blockspergroup must be >= 0"); + goto error; + } + snprintf (blockspergroup_s, sizeof blockspergroup_s, + "%" PRIi64, blockspergroup); + ADD_ARG (argv, i, "-g"); + ADD_ARG (argv, i, blockspergroup_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_NUMBEROFGROUPS_BITMASK) { + if (numberofgroups < 0) { + reply_with_error ("numberofgroups must be >= 0"); + goto error; + } + snprintf (numberofgroups_s, sizeof numberofgroups_s, + "%" PRIi64, numberofgroups); + ADD_ARG (argv, i, "-G"); + ADD_ARG (argv, i, numberofgroups_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_BYTESPERINODE_BITMASK) { + if (bytesperinode < 0) { + reply_with_error ("bytesperinode must be >= 0"); + goto error; + } + snprintf (bytesperinode_s, sizeof bytesperinode_s, "%" PRIi64, bytesperinode); + ADD_ARG (argv, i, "-i"); + ADD_ARG (argv, i, bytesperinode_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_INODESIZE_BITMASK) { + if (inodesize < 0) { + reply_with_error ("inodesize must be >= 0"); + goto error; + } + snprintf (inodesize_s, sizeof inodesize_s, "%" PRIi64, inodesize); + ADD_ARG (argv, i, "-I"); + ADD_ARG (argv, i, inodesize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_WITHJOURNAL_BITMASK) { + if (withjournal) + ADD_ARG (argv, i, "-j"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALSIZE_BITMASK) { + if (journalsize < 0) { + reply_with_error ("journalsize must be >= 0"); + goto error; + } + snprintf (journalsize_s, sizeof journalsize_s, + "size=" "%" PRIi64, journalsize); + ADD_ARG (argv, i, "-J"); + ADD_ARG (argv, i, journalsize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALDEVICE_BITMASK) { + if (journaldevice) { + snprintf (journaldevice_s, sizeof journaldevice_s, + "device=%s", journaldevice); + ADD_ARG (argv, i, "-J"); + ADD_ARG (argv, i, journaldevice_s); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_NEWVOLUMELABEL_BITMASK) { + if (newvolumelabel) { + ADD_ARG (argv, i, "-L"); + ADD_ARG (argv, i, newvolumelabel); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_RESERVEDBLOCKSPERCENTAGE_BITMASK) { + if (reservedblockspercentage < 0) { + reply_with_error ("reservedblockspercentage must be >= 0"); + goto error; + } + snprintf (reservedblockspercentage_s, sizeof reservedblockspercentage_s, + "%" PRIi32, reservedblockspercentage); + ADD_ARG (argv, i, "-m"); + ADD_ARG (argv, i, reservedblockspercentage_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LASTMOUNTEDDIR_BITMASK) { + if (lastmounteddir) { + ADD_ARG (argv, i, "-M"); + ADD_ARG (argv, i, lastmounteddir); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_NUMBEROFINODES_BITMASK) { + if (numberofinodes < 0) { + reply_with_error ("numberofinodes must be >= 0"); + goto error; + } + snprintf (numberofinodes_s, sizeof numberofinodes_s, + "%" PRIi64, numberofinodes); + ADD_ARG (argv, i, "-N"); + ADD_ARG (argv, i, numberofinodes_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_CREATOROS_BITMASK) { + if (creatoros) { + ADD_ARG (argv, i, "-o"); + ADD_ARG (argv, i, creatoros); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_WRITESBANDGROUPONLY_BITMASK) { + if (writesbandgrouponly) + ADD_ARG (argv, i, "-S"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FSTYPE_BITMASK) { + if (fstype) { + ADD_ARG (argv, i, "-t"); + ADD_ARG (argv, i, fstype); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_USAGETYPE_BITMASK) { + if (usagetype) { + ADD_ARG (argv, i, "-T"); + ADD_ARG (argv, i, usagetype); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_FSUUID_BITMASK) { + if (fsuuid) { + ADD_ARG (argv, i, "-U"); + ADD_ARG (argv, i, fsuuid); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_MMPUPDATEINTERVAL_BITMASK) { + if (mmpupdateinterval < 0) { + reply_with_error ("mmpupdateinterval must be >= 0"); + goto error; + } + snprintf (mmpupdateinterval_s, sizeof mmpupdateinterval_s, + "mmp_update_interval=" "%" PRIi32, mmpupdateinterval); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, mmpupdateinterval_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_STRIDESIZE_BITMASK) { + if (stridesize < 0) { + reply_with_error ("stridesize must be >= 0"); + goto error; + } + snprintf (stridesize_s, sizeof stridesize_s, + "stride=" "%" PRIi64, stridesize); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, stridesize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_STRIPEWIDTH_BITMASK) { + if (stripewidth< 0) { + reply_with_error ("stripewidth must be >= 0"); + goto error; + } + snprintf (stripewidth_s, sizeof stripewidth_s, + "stripe_width=" "%" PRIi64, stripewidth); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, stripewidth_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_MAXONLINERESIZE_BITMASK) { + if (maxonlineresize < 0) { + reply_with_error ("maxonlineresize must be >= 0"); + goto error; + } + snprintf (maxonlineresize_s, sizeof maxonlineresize_s, + "resize=" "%" PRIi64, maxonlineresize); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, maxonlineresize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LAZYITABLEINIT_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (lazyitableinit) + ADD_ARG (argv, i, "lazy_itable_init=1"); + else + ADD_ARG (argv, i, "lazy_itable_init=0"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LAZYJOURNALINIT_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (lazyjournalinit) + ADD_ARG (argv, i, "lazy_journal_init=1"); + else + ADD_ARG (argv, i, "lazy_journal_init=0"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_TESTFS_BITMASK) { + if (testfs) { + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, "test_fs"); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_DISCARD_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (discard) + ADD_ARG (argv, i, "discard"); + else + ADD_ARG (argv, i, "nodiscard"); + } + + if (optargs_bitmask & GUESTFS_MKE2FS_DIRINDEX_BITMASK) { + if (dirindex) + strncat (features, "dir_index", 9); + else + strncat (features, "^dir_index", 10); + feature++; + } + if (optargs_bitmask & GUESTFS_MKE2FS_EXTENT_BITMASK) { + if (feature == 0) { + if (extent) + strncat (features, "extent", 6); + else + strncat (features, "^extent", 7); + feature++; + } else { + if (extent) + strncat (features, ",extent", 7); + else + strncat (features, ",^extent", 8); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_FILETYPE_BITMASK) { + if (feature == 0) { + if (filetype) + strncat (features, "filetype", 8); + else + strncat (features, "^filetype", 9); + feature++; + } else { + if (filetype) + strncat (features, ",filetype", 9); + else + strncat (features, ",^filetype", 10); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_FLEXBG_BITMASK) { + if (feature == 0) { + if (flexbg) + strncat (features, "flex_bg", 7); + else + strncat (features, "^flex_bg", 8); + feature++; + } else { + if (flexbg) + strncat (features, ",flex_bg", 8); + else + strncat (features, ",^flex_bg", 9); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_HASJOURNAL_BITMASK) { + if (feature == 0) { + if (hasjournal) + strncat (features, "has_journal", 11); + else + strncat (features, "^has_journal", 12); + feature++; + } else { + if (hasjournal) + strncat (features, ",has_journal", 12); + else + strncat (features, ",^has_journal", 13); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALDEV_BITMASK) { + if (feature == 0) { + if (journaldev) + strncat (features, "journal_dev", 11); + else + strncat (features, "^journal_dev", 12); + feature++; + } else { + if (journaldev) + strncat (features, ",journal_dev", 12); + else + strncat (features, ",^journal_dev", 13); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_LARGEFILE_BITMASK) { + if (feature == 0) { + if (largefile) + strncat (features, "large_file", 10); + else + strncat (features, "^large_file", 11); + feature++; + } else { + if (largefile) + strncat (features, ",large_file", 11); + else + strncat (features, ",^large_file", 12); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_QUOTA_BITMASK) { + if (feature == 0) { + if (quota) + strncat (features, "quota", 5); + else + strncat (features, "^quota", 6); + feature++; + } else { + if (quota) + strncat (features, ",quota", 6); + else + strncat (features, ",^quota", 7); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_RESIZEINODE_BITMASK) { + if (feature == 0) { + if (resizeinode) + strncat (features, "resize_inode", 12); + else + strncat (features, "^resize_inode", 13); + feature++; + } else { + if (resizeinode) + strncat (features, ",resize_inode", 13); + else + strncat (features, ",^resize_inode", 14); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_SPARSESUPER_BITMASK) { + if (feature == 0) { + if (sparsesuper) + strncat (features, "sparse_super", 12); + else + strncat (features, "^sparse_super", 13); + feature++; + } else { + if (sparsesuper) + strncat (features, ",sparse_super", 13); + else + strncat (features, ",^sparse_super", 14); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_UNINITBG_BITMASK) { + if (feature == 0) { + if (uninitbg) + strncat (features, "uninit_bg", 9); + else + strncat (features, "^uninit_bg", 10); + feature++; + } else { + if (uninitbg) + strncat (features, ",uninit_bg", 10); + else + strncat (features, ",^uninit_bg", 11); + } + } + + if (feature != 0) { + ADD_ARG (argv, i, "-O"); + ADD_ARG (argv, i, features); + } + + ADD_ARG (argv, i, device); + + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSCOUNT_BITMASK) { + if (blockscount < 0) { + reply_with_error ("blockscount must be >= 0"); + goto error; + } + snprintf (blockscount_s, sizeof blockscount_s, "%" PRIi64, blockscount); + ADD_ARG (argv, i, blockscount_s); + } + + ADD_ARG (argv, i, NULL); + + r = commandv (NULL, &err, argv); + if (r == -1) { + reply_with_error ("%s: %s", device, err); + goto error; + } + + free (err); + return 0; + +error: + if (err) free (err); + return -1; +} diff --git a/generator/actions.ml b/generator/actions.ml index 65012ad..cfd5198 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -9710,6 +9710,24 @@ the resulting filesystem may be inconsistent or corrupt. The returned status indicates whether filesystem corruption was detected (returns C<1>) or was not detected (returns C<0>)." }; + { defaults with + name = "mke2fs"; + style = RErr, [Device "device"], [OBool "checkbadblock"; OString "badblockfile"; OInt64 "blocksize"; OBool "directwrite"; OInt64 "fragsize"; OBool "forcecreate"; OInt64 "blockspergroup"; OInt64 "numberofgroups"; OInt64 "bytesperinode"; OInt64 "inodesize"; OBool "withjournal"; OInt64 "journalsize"; OString "journaldevice"; OString "newvolumelabel"; OInt "reservedblockspercentage"; OString "lastmounteddir"; OInt64 "numberofinodes"; OString "creatoros"; OBool "writesbandgrouponly"; OString "fstype"; OString "usagetype"; OString "fsuuid"; OInt "mmpupdateinterval"; OInt64 "stridesize"; OInt64 "stripewidth"; OInt64 "maxonlineresize"; OBool "lazyitableinit"; OBool "lazyjournalinit"; OBool "testfs"; OBool "discard"; OBool "quotatype"; OBool "dirindex"; OBool "extent"; OBool "filetype"; OBool "flexbg"; OBool "hasjournal"; OBool "journaldev"; OBool "largefile"; OBool "quota"; OBool "resizeinode"; OBool "sparsesuper"; OBool "uninitbg"; OInt64 "blockscount"]; + proc_nr = Some 367; + tests = [ + InitEmpty, IfAvailable "ext2", TestRun ( + [["part_disk"; "/dev/sda"; "mbr"]; + ["mke2fs"; "/dev/sda1"; ""; "NOARG"; ""; ""; ""; ""; ""; ""; ""; ""; "true"; ""; "NOARG"; "NOARG"; ""; "NOARG"; ""; "NOARG"; ""; "ext4"; "NOARG"; "NOARG"; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""]; + ]) + ]; + shortdesc = "create an ext2/ext3/ext4 filesystem on C<device>"; + longdesc = "\ +C<mke2fs> is used to create an ext2, ext3, or ext4 filesystem, +usually in a disk partition. C<device> is the special file corresponding +to the device (e.g /dev/sdXX). C<blockscount> is the number of blocks +on C<device>. If omitted, C<mke2fs> automagically figures the file system +size." }; + ] (* Non-API meta-commands available only in guestfish. diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc index ba41b48..de8e1e7 100644 --- a/gobject/Makefile.inc +++ b/gobject/Makefile.inc @@ -78,7 +78,8 @@ guestfs_gobject_headers= \ include/guestfs-gobject/optargs-rsync_out.h \ include/guestfs-gobject/optargs-xfs_admin.h \ include/guestfs-gobject/optargs-hivex_open.h \ - include/guestfs-gobject/optargs-xfs_repair.h + include/guestfs-gobject/optargs-xfs_repair.h \ + include/guestfs-gobject/optargs-mke2fs.h guestfs_gobject_sources= \ src/session.c \ @@ -138,4 +139,5 @@ guestfs_gobject_sources= \ src/optargs-rsync_out.c \ src/optargs-xfs_admin.c \ src/optargs-hivex_open.c \ - src/optargs-xfs_repair.c + src/optargs-xfs_repair.c \ + src/optargs-mke2fs.c diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 4203007..526204c 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -366 +367 -- 1.7.12
If we don't add a "L" at the end of a number, its type will be int but not long. This bug is found when compiling JAVA binding with the following error: ./com/redhat/et/libguestfs/GuestFS.java:14731: error: integer number too large: 2147483648 _optargs_bitmask |= 2147483648; ^ Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- generator/java.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generator/java.ml b/generator/java.ml index 4f549dc..5cf8c3a 100644 --- a/generator/java.ml +++ b/generator/java.ml @@ -136,7 +136,7 @@ public class GuestFS { pr "\n"; pr " /* Unpack optional args. */\n"; pr " Object _optobj;\n"; - pr " long _optargs_bitmask = 0;\n"; + pr " long _optargs_bitmask = 0L;\n"; iteri ( fun i argt -> let t, boxed_t, convert, n, default = @@ -152,7 +152,7 @@ public class GuestFS { pr " _optobj = optargs.get (\"%s\");\n" n; pr " if (_optobj != null) {\n"; pr " %s = ((%s) _optobj)%s;\n" n boxed_t convert; - pr " _optargs_bitmask |= %Ld;\n" + pr " _optargs_bitmask |= %LdL;\n" (Int64.shift_left Int64.one i); pr " }\n"; ) optargs -- 1.7.12
On Mon, Sep 03, 2012 at 01:50:59PM +0800, Wanlong Gao wrote:
If we don't add a "L" at the end of a number, its type will be int but not long.
This bug is found when compiling JAVA binding with the following error:
./com/redhat/et/libguestfs/GuestFS.java:14731: error: integer number too large: 2147483648 _optargs_bitmask |= 2147483648; ^
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- generator/java.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/generator/java.ml b/generator/java.ml index 4f549dc..5cf8c3a 100644 --- a/generator/java.ml +++ b/generator/java.ml @@ -136,7 +136,7 @@ public class GuestFS { pr "\n"; pr " /* Unpack optional args. */\n"; pr " Object _optobj;\n"; - pr " long _optargs_bitmask = 0;\n"; + pr " long _optargs_bitmask = 0L;\n"; iteri ( fun i argt -> let t, boxed_t, convert, n, default = @@ -152,7 +152,7 @@ public class GuestFS { pr " _optobj = optargs.get (\"%s\");\n" n; pr " if (_optobj != null) {\n"; pr " %s = ((%s) _optobj)%s;\n" n boxed_t convert; - pr " _optargs_bitmask |= %Ld;\n" + pr " _optargs_bitmask |= %LdL;\n" (Int64.shift_left Int64.one i); pr " }\n"; ) optargs -- 1.7.12
Sorry, I missed this patch. However the fix I pushed is equivalent and includes your credit. Thanks, Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
On 09/03/2012 01:50 PM, Wanlong Gao wrote:
New api mke2fs for full configuration of filesystem.
Missed this? Thanks, Wanlong Gao
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/ext2.c | 452 +++++++++++++++++++++++++++++++++++++++++++++++++++ generator/actions.ml | 18 ++ gobject/Makefile.inc | 6 +- src/MAX_PROC_NR | 2 +- 4 files changed, 475 insertions(+), 3 deletions(-)
diff --git a/daemon/ext2.c b/daemon/ext2.c index 40b36d2..7108547 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -811,3 +811,455 @@ do_set_e2generation (const char *filename, int64_t generation)
return 0; } + +int +do_mke2fs (const char *device, + int checkbadblock, const char *badblockfile, + int64_t blocksize, int directwrite, + int64_t fragsize, int forcecreate, + int64_t blockspergroup, int64_t numberofgroups, + int64_t bytesperinode, int64_t inodesize, + int withjournal, int64_t journalsize, + const char *journaldevice, const char *newvolumelabel, + int reservedblockspercentage, const char *lastmounteddir, + int64_t numberofinodes, const char *creatoros, + int writesbandgrouponly, + const char *fstype, const char *usagetype, + const char *fsuuid, int mmpupdateinterval, + int64_t stridesize, int64_t stripewidth, + int64_t maxonlineresize, int lazyitableinit, + int lazyjournalinit, int testfs, + int discard, int quotatype, + int dirindex, int extent, int filetype, + int flexbg, int hasjournal, int journaldev, + int largefile, int quota, int resizeinode, + int sparsesuper, int uninitbg, + int64_t blockscount) +{ + int r; + char *err = NULL; + const char *argv[MAX_ARGS]; + char blocksize_s[64]; + char fragsize_s[64]; + char blockspergroup_s[64]; + char numberofgroups_s[64]; + char bytesperinode_s[64]; + char inodesize_s[64]; + char journalsize_s[64]; + char journaldevice_s[256]; + char reservedblockspercentage_s[64]; + char numberofinodes_s[64]; + char mmpupdateinterval_s[84]; + char stridesize_s[74]; + char stripewidth_s[84]; + char maxonlineresize_s[74]; + char blockscount_s[64]; + size_t i = 0; + int feature = 0; + char features[256]; + + ADD_ARG (argv, i, str_mke2fs); + + if (optargs_bitmask & GUESTFS_MKE2FS_CHECKBADBLOCK_BITMASK) { + if (checkbadblock) + ADD_ARG (argv, i, "-c"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_BADBLOCKFILE_BITMASK) { + if (badblockfile) { + ADD_ARG (argv, i, "-l"); + ADD_ARG (argv, i, badblockfile); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSIZE_BITMASK) { + if (blocksize < 0) { + reply_with_error ("blocksize must be >= 0"); + goto error; + } + snprintf (blocksize_s, sizeof blocksize_s, "%" PRIi64, blocksize); + ADD_ARG (argv, i, "-b"); + ADD_ARG (argv, i, blocksize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_DIRECTWRITE_BITMASK) { + if (directwrite) + ADD_ARG (argv, i, "-D"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FRAGSIZE_BITMASK) { + if (fragsize < 0) { + reply_with_error ("fragsize must be >= 0"); + goto error; + } + snprintf (fragsize_s, sizeof fragsize_s, "%" PRIi64, fragsize); + ADD_ARG (argv, i, "-f"); + ADD_ARG (argv, i, fragsize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FORCECREATE_BITMASK) { + if (forcecreate) + ADD_ARG (argv, i, "-F"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSPERGROUP_BITMASK) { + if (blockspergroup < 0) { + reply_with_error ("blockspergroup must be >= 0"); + goto error; + } + snprintf (blockspergroup_s, sizeof blockspergroup_s, + "%" PRIi64, blockspergroup); + ADD_ARG (argv, i, "-g"); + ADD_ARG (argv, i, blockspergroup_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_NUMBEROFGROUPS_BITMASK) { + if (numberofgroups < 0) { + reply_with_error ("numberofgroups must be >= 0"); + goto error; + } + snprintf (numberofgroups_s, sizeof numberofgroups_s, + "%" PRIi64, numberofgroups); + ADD_ARG (argv, i, "-G"); + ADD_ARG (argv, i, numberofgroups_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_BYTESPERINODE_BITMASK) { + if (bytesperinode < 0) { + reply_with_error ("bytesperinode must be >= 0"); + goto error; + } + snprintf (bytesperinode_s, sizeof bytesperinode_s, "%" PRIi64, bytesperinode); + ADD_ARG (argv, i, "-i"); + ADD_ARG (argv, i, bytesperinode_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_INODESIZE_BITMASK) { + if (inodesize < 0) { + reply_with_error ("inodesize must be >= 0"); + goto error; + } + snprintf (inodesize_s, sizeof inodesize_s, "%" PRIi64, inodesize); + ADD_ARG (argv, i, "-I"); + ADD_ARG (argv, i, inodesize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_WITHJOURNAL_BITMASK) { + if (withjournal) + ADD_ARG (argv, i, "-j"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALSIZE_BITMASK) { + if (journalsize < 0) { + reply_with_error ("journalsize must be >= 0"); + goto error; + } + snprintf (journalsize_s, sizeof journalsize_s, + "size=" "%" PRIi64, journalsize); + ADD_ARG (argv, i, "-J"); + ADD_ARG (argv, i, journalsize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALDEVICE_BITMASK) { + if (journaldevice) { + snprintf (journaldevice_s, sizeof journaldevice_s, + "device=%s", journaldevice); + ADD_ARG (argv, i, "-J"); + ADD_ARG (argv, i, journaldevice_s); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_NEWVOLUMELABEL_BITMASK) { + if (newvolumelabel) { + ADD_ARG (argv, i, "-L"); + ADD_ARG (argv, i, newvolumelabel); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_RESERVEDBLOCKSPERCENTAGE_BITMASK) { + if (reservedblockspercentage < 0) { + reply_with_error ("reservedblockspercentage must be >= 0"); + goto error; + } + snprintf (reservedblockspercentage_s, sizeof reservedblockspercentage_s, + "%" PRIi32, reservedblockspercentage); + ADD_ARG (argv, i, "-m"); + ADD_ARG (argv, i, reservedblockspercentage_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LASTMOUNTEDDIR_BITMASK) { + if (lastmounteddir) { + ADD_ARG (argv, i, "-M"); + ADD_ARG (argv, i, lastmounteddir); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_NUMBEROFINODES_BITMASK) { + if (numberofinodes < 0) { + reply_with_error ("numberofinodes must be >= 0"); + goto error; + } + snprintf (numberofinodes_s, sizeof numberofinodes_s, + "%" PRIi64, numberofinodes); + ADD_ARG (argv, i, "-N"); + ADD_ARG (argv, i, numberofinodes_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_CREATOROS_BITMASK) { + if (creatoros) { + ADD_ARG (argv, i, "-o"); + ADD_ARG (argv, i, creatoros); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_WRITESBANDGROUPONLY_BITMASK) { + if (writesbandgrouponly) + ADD_ARG (argv, i, "-S"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FSTYPE_BITMASK) { + if (fstype) { + ADD_ARG (argv, i, "-t"); + ADD_ARG (argv, i, fstype); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_USAGETYPE_BITMASK) { + if (usagetype) { + ADD_ARG (argv, i, "-T"); + ADD_ARG (argv, i, usagetype); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_FSUUID_BITMASK) { + if (fsuuid) { + ADD_ARG (argv, i, "-U"); + ADD_ARG (argv, i, fsuuid); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_MMPUPDATEINTERVAL_BITMASK) { + if (mmpupdateinterval < 0) { + reply_with_error ("mmpupdateinterval must be >= 0"); + goto error; + } + snprintf (mmpupdateinterval_s, sizeof mmpupdateinterval_s, + "mmp_update_interval=" "%" PRIi32, mmpupdateinterval); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, mmpupdateinterval_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_STRIDESIZE_BITMASK) { + if (stridesize < 0) { + reply_with_error ("stridesize must be >= 0"); + goto error; + } + snprintf (stridesize_s, sizeof stridesize_s, + "stride=" "%" PRIi64, stridesize); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, stridesize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_STRIPEWIDTH_BITMASK) { + if (stripewidth< 0) { + reply_with_error ("stripewidth must be >= 0"); + goto error; + } + snprintf (stripewidth_s, sizeof stripewidth_s, + "stripe_width=" "%" PRIi64, stripewidth); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, stripewidth_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_MAXONLINERESIZE_BITMASK) { + if (maxonlineresize < 0) { + reply_with_error ("maxonlineresize must be >= 0"); + goto error; + } + snprintf (maxonlineresize_s, sizeof maxonlineresize_s, + "resize=" "%" PRIi64, maxonlineresize); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, maxonlineresize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LAZYITABLEINIT_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (lazyitableinit) + ADD_ARG (argv, i, "lazy_itable_init=1"); + else + ADD_ARG (argv, i, "lazy_itable_init=0"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LAZYJOURNALINIT_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (lazyjournalinit) + ADD_ARG (argv, i, "lazy_journal_init=1"); + else + ADD_ARG (argv, i, "lazy_journal_init=0"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_TESTFS_BITMASK) { + if (testfs) { + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, "test_fs"); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_DISCARD_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (discard) + ADD_ARG (argv, i, "discard"); + else + ADD_ARG (argv, i, "nodiscard"); + } + + if (optargs_bitmask & GUESTFS_MKE2FS_DIRINDEX_BITMASK) { + if (dirindex) + strncat (features, "dir_index", 9); + else + strncat (features, "^dir_index", 10); + feature++; + } + if (optargs_bitmask & GUESTFS_MKE2FS_EXTENT_BITMASK) { + if (feature == 0) { + if (extent) + strncat (features, "extent", 6); + else + strncat (features, "^extent", 7); + feature++; + } else { + if (extent) + strncat (features, ",extent", 7); + else + strncat (features, ",^extent", 8); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_FILETYPE_BITMASK) { + if (feature == 0) { + if (filetype) + strncat (features, "filetype", 8); + else + strncat (features, "^filetype", 9); + feature++; + } else { + if (filetype) + strncat (features, ",filetype", 9); + else + strncat (features, ",^filetype", 10); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_FLEXBG_BITMASK) { + if (feature == 0) { + if (flexbg) + strncat (features, "flex_bg", 7); + else + strncat (features, "^flex_bg", 8); + feature++; + } else { + if (flexbg) + strncat (features, ",flex_bg", 8); + else + strncat (features, ",^flex_bg", 9); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_HASJOURNAL_BITMASK) { + if (feature == 0) { + if (hasjournal) + strncat (features, "has_journal", 11); + else + strncat (features, "^has_journal", 12); + feature++; + } else { + if (hasjournal) + strncat (features, ",has_journal", 12); + else + strncat (features, ",^has_journal", 13); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALDEV_BITMASK) { + if (feature == 0) { + if (journaldev) + strncat (features, "journal_dev", 11); + else + strncat (features, "^journal_dev", 12); + feature++; + } else { + if (journaldev) + strncat (features, ",journal_dev", 12); + else + strncat (features, ",^journal_dev", 13); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_LARGEFILE_BITMASK) { + if (feature == 0) { + if (largefile) + strncat (features, "large_file", 10); + else + strncat (features, "^large_file", 11); + feature++; + } else { + if (largefile) + strncat (features, ",large_file", 11); + else + strncat (features, ",^large_file", 12); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_QUOTA_BITMASK) { + if (feature == 0) { + if (quota) + strncat (features, "quota", 5); + else + strncat (features, "^quota", 6); + feature++; + } else { + if (quota) + strncat (features, ",quota", 6); + else + strncat (features, ",^quota", 7); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_RESIZEINODE_BITMASK) { + if (feature == 0) { + if (resizeinode) + strncat (features, "resize_inode", 12); + else + strncat (features, "^resize_inode", 13); + feature++; + } else { + if (resizeinode) + strncat (features, ",resize_inode", 13); + else + strncat (features, ",^resize_inode", 14); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_SPARSESUPER_BITMASK) { + if (feature == 0) { + if (sparsesuper) + strncat (features, "sparse_super", 12); + else + strncat (features, "^sparse_super", 13); + feature++; + } else { + if (sparsesuper) + strncat (features, ",sparse_super", 13); + else + strncat (features, ",^sparse_super", 14); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_UNINITBG_BITMASK) { + if (feature == 0) { + if (uninitbg) + strncat (features, "uninit_bg", 9); + else + strncat (features, "^uninit_bg", 10); + feature++; + } else { + if (uninitbg) + strncat (features, ",uninit_bg", 10); + else + strncat (features, ",^uninit_bg", 11); + } + } + + if (feature != 0) { + ADD_ARG (argv, i, "-O"); + ADD_ARG (argv, i, features); + } + + ADD_ARG (argv, i, device); + + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSCOUNT_BITMASK) { + if (blockscount < 0) { + reply_with_error ("blockscount must be >= 0"); + goto error; + } + snprintf (blockscount_s, sizeof blockscount_s, "%" PRIi64, blockscount); + ADD_ARG (argv, i, blockscount_s); + } + + ADD_ARG (argv, i, NULL); + + r = commandv (NULL, &err, argv); + if (r == -1) { + reply_with_error ("%s: %s", device, err); + goto error; + } + + free (err); + return 0; + +error: + if (err) free (err); + return -1; +} diff --git a/generator/actions.ml b/generator/actions.ml index 65012ad..cfd5198 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -9710,6 +9710,24 @@ the resulting filesystem may be inconsistent or corrupt. The returned status indicates whether filesystem corruption was detected (returns C<1>) or was not detected (returns C<0>)." };
+ { defaults with + name = "mke2fs"; + style = RErr, [Device "device"], [OBool "checkbadblock"; OString "badblockfile"; OInt64 "blocksize"; OBool "directwrite"; OInt64 "fragsize"; OBool "forcecreate"; OInt64 "blockspergroup"; OInt64 "numberofgroups"; OInt64 "bytesperinode"; OInt64 "inodesize"; OBool "withjournal"; OInt64 "journalsize"; OString "journaldevice"; OString "newvolumelabel"; OInt "reservedblockspercentage"; OString "lastmounteddir"; OInt64 "numberofinodes"; OString "creatoros"; OBool "writesbandgrouponly"; OString "fstype"; OString "usagetype"; OString "fsuuid"; OInt "mmpupdateinterval"; OInt64 "stridesize"; OInt64 "stripewidth"; OInt64 "maxonlineresize"; OBool "lazyitableinit"; OBool "lazyjournalinit"; OBool "testfs"; OBool "discard"; OBool "quotatype"; OBool "dirindex"; OBool "extent"; OBool "filetype"; OBool "flexbg"; OBool "hasjournal"; OBool "journaldev"; OBool "largefile"; OBool "quota"; OBool "resizeinode"; OBool "sparsesuper"; OBool "uninitbg"; OInt64 "blockscount"]; + proc_nr = Some 367; + tests = [ + InitEmpty, IfAvailable "ext2", TestRun ( + [["part_disk"; "/dev/sda"; "mbr"]; + ["mke2fs"; "/dev/sda1"; ""; "NOARG"; ""; ""; ""; ""; ""; ""; ""; ""; "true"; ""; "NOARG"; "NOARG"; ""; "NOARG"; ""; "NOARG"; ""; "ext4"; "NOARG"; "NOARG"; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""]; + ]) + ]; + shortdesc = "create an ext2/ext3/ext4 filesystem on C<device>"; + longdesc = "\ +C<mke2fs> is used to create an ext2, ext3, or ext4 filesystem, +usually in a disk partition. C<device> is the special file corresponding +to the device (e.g /dev/sdXX). C<blockscount> is the number of blocks +on C<device>. If omitted, C<mke2fs> automagically figures the file system +size." }; + ]
(* Non-API meta-commands available only in guestfish. diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc index ba41b48..de8e1e7 100644 --- a/gobject/Makefile.inc +++ b/gobject/Makefile.inc @@ -78,7 +78,8 @@ guestfs_gobject_headers= \ include/guestfs-gobject/optargs-rsync_out.h \ include/guestfs-gobject/optargs-xfs_admin.h \ include/guestfs-gobject/optargs-hivex_open.h \ - include/guestfs-gobject/optargs-xfs_repair.h + include/guestfs-gobject/optargs-xfs_repair.h \ + include/guestfs-gobject/optargs-mke2fs.h
guestfs_gobject_sources= \ src/session.c \ @@ -138,4 +139,5 @@ guestfs_gobject_sources= \ src/optargs-rsync_out.c \ src/optargs-xfs_admin.c \ src/optargs-hivex_open.c \ - src/optargs-xfs_repair.c + src/optargs-xfs_repair.c \ + src/optargs-mke2fs.c diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 4203007..526204c 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -366 +367
On Mon, Sep 03, 2012 at 01:50:58PM +0800, Wanlong Gao wrote:
New api mke2fs for full configuration of filesystem.
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/ext2.c | 452 +++++++++++++++++++++++++++++++++++++++++++++++++++ generator/actions.ml | 18 ++ gobject/Makefile.inc | 6 +- src/MAX_PROC_NR | 2 +- 4 files changed, 475 insertions(+), 3 deletions(-)
diff --git a/daemon/ext2.c b/daemon/ext2.c index 40b36d2..7108547 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -811,3 +811,455 @@ do_set_e2generation (const char *filename, int64_t generation)
return 0; } + +int +do_mke2fs (const char *device, + int checkbadblock, const char *badblockfile, + int64_t blocksize, int directwrite, + int64_t fragsize, int forcecreate, + int64_t blockspergroup, int64_t numberofgroups, + int64_t bytesperinode, int64_t inodesize, + int withjournal, int64_t journalsize, + const char *journaldevice, const char *newvolumelabel, + int reservedblockspercentage, const char *lastmounteddir, + int64_t numberofinodes, const char *creatoros, + int writesbandgrouponly, + const char *fstype, const char *usagetype, + const char *fsuuid, int mmpupdateinterval, + int64_t stridesize, int64_t stripewidth, + int64_t maxonlineresize, int lazyitableinit, + int lazyjournalinit, int testfs, + int discard, int quotatype, + int dirindex, int extent, int filetype, + int flexbg, int hasjournal, int journaldev, + int largefile, int quota, int resizeinode, + int sparsesuper, int uninitbg, + int64_t blockscount) +{ + int r; + char *err = NULL; + const char *argv[MAX_ARGS];
I bet there is a scenario where we exceed MAX_ARGS (64?) ...
+ char blocksize_s[64]; + char fragsize_s[64]; + char blockspergroup_s[64]; + char numberofgroups_s[64]; + char bytesperinode_s[64]; + char inodesize_s[64]; + char journalsize_s[64]; + char journaldevice_s[256]; + char reservedblockspercentage_s[64]; + char numberofinodes_s[64]; + char mmpupdateinterval_s[84]; + char stridesize_s[74]; + char stripewidth_s[84]; + char maxonlineresize_s[74]; + char blockscount_s[64]; + size_t i = 0; + int feature = 0; + char features[256];
Does mke2fs let you use multiple -O options? If so, we don't need this fixed size "features" array, or the horrible and possibly unsafe use of strncat later on.
+ ADD_ARG (argv, i, str_mke2fs); + + if (optargs_bitmask & GUESTFS_MKE2FS_CHECKBADBLOCK_BITMASK) { + if (checkbadblock) + ADD_ARG (argv, i, "-c"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_BADBLOCKFILE_BITMASK) { + if (badblockfile) { + ADD_ARG (argv, i, "-l"); + ADD_ARG (argv, i, badblockfile); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSIZE_BITMASK) { + if (blocksize < 0) { + reply_with_error ("blocksize must be >= 0"); + goto error; + } + snprintf (blocksize_s, sizeof blocksize_s, "%" PRIi64, blocksize); + ADD_ARG (argv, i, "-b"); + ADD_ARG (argv, i, blocksize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_DIRECTWRITE_BITMASK) { + if (directwrite) + ADD_ARG (argv, i, "-D"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FRAGSIZE_BITMASK) { + if (fragsize < 0) { + reply_with_error ("fragsize must be >= 0"); + goto error; + } + snprintf (fragsize_s, sizeof fragsize_s, "%" PRIi64, fragsize); + ADD_ARG (argv, i, "-f"); + ADD_ARG (argv, i, fragsize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FORCECREATE_BITMASK) { + if (forcecreate) + ADD_ARG (argv, i, "-F"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSPERGROUP_BITMASK) { + if (blockspergroup < 0) { + reply_with_error ("blockspergroup must be >= 0"); + goto error; + } + snprintf (blockspergroup_s, sizeof blockspergroup_s, + "%" PRIi64, blockspergroup); + ADD_ARG (argv, i, "-g"); + ADD_ARG (argv, i, blockspergroup_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_NUMBEROFGROUPS_BITMASK) { + if (numberofgroups < 0) { + reply_with_error ("numberofgroups must be >= 0"); + goto error; + } + snprintf (numberofgroups_s, sizeof numberofgroups_s, + "%" PRIi64, numberofgroups); + ADD_ARG (argv, i, "-G"); + ADD_ARG (argv, i, numberofgroups_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_BYTESPERINODE_BITMASK) { + if (bytesperinode < 0) { + reply_with_error ("bytesperinode must be >= 0"); + goto error; + } + snprintf (bytesperinode_s, sizeof bytesperinode_s, "%" PRIi64, bytesperinode); + ADD_ARG (argv, i, "-i"); + ADD_ARG (argv, i, bytesperinode_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_INODESIZE_BITMASK) { + if (inodesize < 0) { + reply_with_error ("inodesize must be >= 0"); + goto error; + } + snprintf (inodesize_s, sizeof inodesize_s, "%" PRIi64, inodesize); + ADD_ARG (argv, i, "-I"); + ADD_ARG (argv, i, inodesize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_WITHJOURNAL_BITMASK) { + if (withjournal) + ADD_ARG (argv, i, "-j"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALSIZE_BITMASK) { + if (journalsize < 0) { + reply_with_error ("journalsize must be >= 0"); + goto error; + } + snprintf (journalsize_s, sizeof journalsize_s, + "size=" "%" PRIi64, journalsize); + ADD_ARG (argv, i, "-J"); + ADD_ARG (argv, i, journalsize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALDEVICE_BITMASK) { + if (journaldevice) { + snprintf (journaldevice_s, sizeof journaldevice_s, + "device=%s", journaldevice); + ADD_ARG (argv, i, "-J"); + ADD_ARG (argv, i, journaldevice_s); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_NEWVOLUMELABEL_BITMASK) { + if (newvolumelabel) { + ADD_ARG (argv, i, "-L"); + ADD_ARG (argv, i, newvolumelabel); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_RESERVEDBLOCKSPERCENTAGE_BITMASK) { + if (reservedblockspercentage < 0) { + reply_with_error ("reservedblockspercentage must be >= 0"); + goto error; + } + snprintf (reservedblockspercentage_s, sizeof reservedblockspercentage_s, + "%" PRIi32, reservedblockspercentage); + ADD_ARG (argv, i, "-m"); + ADD_ARG (argv, i, reservedblockspercentage_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LASTMOUNTEDDIR_BITMASK) { + if (lastmounteddir) { + ADD_ARG (argv, i, "-M"); + ADD_ARG (argv, i, lastmounteddir); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_NUMBEROFINODES_BITMASK) { + if (numberofinodes < 0) { + reply_with_error ("numberofinodes must be >= 0"); + goto error; + } + snprintf (numberofinodes_s, sizeof numberofinodes_s, + "%" PRIi64, numberofinodes); + ADD_ARG (argv, i, "-N"); + ADD_ARG (argv, i, numberofinodes_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_CREATOROS_BITMASK) { + if (creatoros) { + ADD_ARG (argv, i, "-o"); + ADD_ARG (argv, i, creatoros); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_WRITESBANDGROUPONLY_BITMASK) { + if (writesbandgrouponly) + ADD_ARG (argv, i, "-S"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FSTYPE_BITMASK) { + if (fstype) { + ADD_ARG (argv, i, "-t"); + ADD_ARG (argv, i, fstype); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_USAGETYPE_BITMASK) { + if (usagetype) { + ADD_ARG (argv, i, "-T"); + ADD_ARG (argv, i, usagetype); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_FSUUID_BITMASK) { + if (fsuuid) { + ADD_ARG (argv, i, "-U"); + ADD_ARG (argv, i, fsuuid); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_MMPUPDATEINTERVAL_BITMASK) { + if (mmpupdateinterval < 0) { + reply_with_error ("mmpupdateinterval must be >= 0"); + goto error; + } + snprintf (mmpupdateinterval_s, sizeof mmpupdateinterval_s, + "mmp_update_interval=" "%" PRIi32, mmpupdateinterval); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, mmpupdateinterval_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_STRIDESIZE_BITMASK) { + if (stridesize < 0) { + reply_with_error ("stridesize must be >= 0"); + goto error; + } + snprintf (stridesize_s, sizeof stridesize_s, + "stride=" "%" PRIi64, stridesize); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, stridesize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_STRIPEWIDTH_BITMASK) { + if (stripewidth< 0) { + reply_with_error ("stripewidth must be >= 0"); + goto error; + } + snprintf (stripewidth_s, sizeof stripewidth_s, + "stripe_width=" "%" PRIi64, stripewidth); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, stripewidth_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_MAXONLINERESIZE_BITMASK) { + if (maxonlineresize < 0) { + reply_with_error ("maxonlineresize must be >= 0"); + goto error; + } + snprintf (maxonlineresize_s, sizeof maxonlineresize_s, + "resize=" "%" PRIi64, maxonlineresize); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, maxonlineresize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LAZYITABLEINIT_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (lazyitableinit) + ADD_ARG (argv, i, "lazy_itable_init=1"); + else + ADD_ARG (argv, i, "lazy_itable_init=0"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LAZYJOURNALINIT_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (lazyjournalinit) + ADD_ARG (argv, i, "lazy_journal_init=1"); + else + ADD_ARG (argv, i, "lazy_journal_init=0"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_TESTFS_BITMASK) { + if (testfs) { + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, "test_fs"); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_DISCARD_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (discard) + ADD_ARG (argv, i, "discard"); + else + ADD_ARG (argv, i, "nodiscard"); + } + + if (optargs_bitmask & GUESTFS_MKE2FS_DIRINDEX_BITMASK) { + if (dirindex) + strncat (features, "dir_index", 9); + else + strncat (features, "^dir_index", 10); + feature++;
Is there a reason to use ^dir_index? Surely it can just be omitted?
+ } + if (optargs_bitmask & GUESTFS_MKE2FS_EXTENT_BITMASK) { + if (feature == 0) { + if (extent) + strncat (features, "extent", 6); + else + strncat (features, "^extent", 7); + feature++; + } else { + if (extent) + strncat (features, ",extent", 7); + else + strncat (features, ",^extent", 8); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_FILETYPE_BITMASK) { + if (feature == 0) { + if (filetype) + strncat (features, "filetype", 8); + else + strncat (features, "^filetype", 9); + feature++; + } else { + if (filetype) + strncat (features, ",filetype", 9); + else + strncat (features, ",^filetype", 10); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_FLEXBG_BITMASK) { + if (feature == 0) { + if (flexbg) + strncat (features, "flex_bg", 7); + else + strncat (features, "^flex_bg", 8); + feature++; + } else { + if (flexbg) + strncat (features, ",flex_bg", 8); + else + strncat (features, ",^flex_bg", 9); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_HASJOURNAL_BITMASK) { + if (feature == 0) { + if (hasjournal) + strncat (features, "has_journal", 11); + else + strncat (features, "^has_journal", 12); + feature++; + } else { + if (hasjournal) + strncat (features, ",has_journal", 12); + else + strncat (features, ",^has_journal", 13); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALDEV_BITMASK) { + if (feature == 0) { + if (journaldev) + strncat (features, "journal_dev", 11); + else + strncat (features, "^journal_dev", 12); + feature++; + } else { + if (journaldev) + strncat (features, ",journal_dev", 12); + else + strncat (features, ",^journal_dev", 13); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_LARGEFILE_BITMASK) { + if (feature == 0) { + if (largefile) + strncat (features, "large_file", 10); + else + strncat (features, "^large_file", 11); + feature++; + } else { + if (largefile) + strncat (features, ",large_file", 11); + else + strncat (features, ",^large_file", 12); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_QUOTA_BITMASK) { + if (feature == 0) { + if (quota) + strncat (features, "quota", 5); + else + strncat (features, "^quota", 6); + feature++; + } else { + if (quota) + strncat (features, ",quota", 6); + else + strncat (features, ",^quota", 7); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_RESIZEINODE_BITMASK) { + if (feature == 0) { + if (resizeinode) + strncat (features, "resize_inode", 12); + else + strncat (features, "^resize_inode", 13); + feature++; + } else { + if (resizeinode) + strncat (features, ",resize_inode", 13); + else + strncat (features, ",^resize_inode", 14); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_SPARSESUPER_BITMASK) { + if (feature == 0) { + if (sparsesuper) + strncat (features, "sparse_super", 12); + else + strncat (features, "^sparse_super", 13); + feature++; + } else { + if (sparsesuper) + strncat (features, ",sparse_super", 13); + else + strncat (features, ",^sparse_super", 14); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_UNINITBG_BITMASK) { + if (feature == 0) { + if (uninitbg) + strncat (features, "uninit_bg", 9); + else + strncat (features, "^uninit_bg", 10); + feature++; + } else { + if (uninitbg) + strncat (features, ",uninit_bg", 10); + else + strncat (features, ",^uninit_bg", 11); + } + } + + if (feature != 0) { + ADD_ARG (argv, i, "-O"); + ADD_ARG (argv, i, features); + } + + ADD_ARG (argv, i, device); + + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSCOUNT_BITMASK) { + if (blockscount < 0) { + reply_with_error ("blockscount must be >= 0"); + goto error; + } + snprintf (blockscount_s, sizeof blockscount_s, "%" PRIi64, blockscount); + ADD_ARG (argv, i, blockscount_s); + } + + ADD_ARG (argv, i, NULL); + + r = commandv (NULL, &err, argv); + if (r == -1) { + reply_with_error ("%s: %s", device, err); + goto error; + } + + free (err); + return 0; + +error: + if (err) free (err); + return -1; +} diff --git a/generator/actions.ml b/generator/actions.ml index 65012ad..cfd5198 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -9710,6 +9710,24 @@ the resulting filesystem may be inconsistent or corrupt. The returned status indicates whether filesystem corruption was detected (returns C<1>) or was not detected (returns C<0>)." };
+ { defaults with + name = "mke2fs";
+ style = RErr, [Device "device"],
[OBool "checkbadblock"; OString "badblockfile";
Bad blocks aren't relevant on virtual disks. I would omit anything related to bad blocks unless someone comes up with a compelling reason for them.
OInt64 "blocksize"; OBool "directwrite";
I would omit "directwrite". It appears to be a very specialized corner-case, and if not it should probably be enabled by default.
OInt64 "fragsize"; OBool "forcecreate"; OInt64 "blockspergroup"; OInt64 "numberofgroups"; OInt64 "bytesperinode"; OInt64 "inodesize"; OBool "withjournal"; OInt64 "journalsize"; OString "journaldevice"; OString "newvolumelabel";
Elsewhere (eg. mkswap) we have called this just "label".
OInt "reservedblockspercentage"; OString "lastmounteddir"; OInt64 "numberofinodes"; OString "creatoros"; OBool "writesbandgrouponly"; OString "fstype"; OString "usagetype"; OString "fsuuid";
Elsewhere we have called this just "uuid".
OInt "mmpupdateinterval"; OInt64 "stridesize"; OInt64 "stripewidth"; OInt64 "maxonlineresize"; OBool "lazyitableinit"; OBool "lazyjournalinit"; OBool "testfs"; OBool "discard"; OBool "quotatype"; OBool "dirindex"; OBool "extent"; OBool "filetype"; OBool "flexbg"; OBool "hasjournal";
I think -O has-journal is the same as the -j option, so probably this one can be omitted.
OBool "journaldev"; OBool "largefile"; OBool "quota"; OBool "resizeinode"; OBool "sparsesuper"; OBool "uninitbg";
I was waiting for ...
OInt64 "blockscount"];
I think blockscount should be the first in the optional argument list.
+ proc_nr = Some 367; + tests = [ + InitEmpty, IfAvailable "ext2", TestRun ( + [["part_disk"; "/dev/sda"; "mbr"]; + ["mke2fs"; "/dev/sda1"; ""; "NOARG"; ""; ""; ""; ""; ""; ""; ""; ""; "true"; ""; "NOARG"; "NOARG"; ""; "NOARG"; ""; "NOARG"; ""; "ext4"; "NOARG"; "NOARG"; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""; ""]; + ]) + ];
This needs to add deprecated_by for any existing API which can now be done using this call. There are several of them. AND it needs to add the tests for all those other APIs too (while leaving the tests of the other APIs intact). See mkswap (f23a5c468e959f86df89e2a4e8aa9160eca532f8) for an example of what I mean.
+ shortdesc = "create an ext2/ext3/ext4 filesystem on C<device>";
You can't use POD (C<> etc) in shortdesc.
+ longdesc = "\ +C<mke2fs> is used to create an ext2, ext3, or ext4 filesystem, +usually in a disk partition. C<device> is the special file corresponding +to the device (e.g /dev/sdXX). C<blockscount> is the number of blocks +on C<device>. If omitted, C<mke2fs> automagically figures the file system +size." }; + ]
Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
New api mke2fs for full configuration of filesystem. Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/ext2.c | 369 +++++++++++++++++++++++++++++++++++++++++++++- generator/actions.ml | 85 ++++++++++- gobject/Makefile.inc | 6 +- guestfs-release-notes.txt | 5 + po/POTFILES | 1 + src/MAX_PROC_NR | 2 +- 6 files changed, 458 insertions(+), 10 deletions(-) diff --git a/daemon/ext2.c b/daemon/ext2.c index 40b36d2..7fc1172 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -29,7 +29,7 @@ #include "c-ctype.h" #include "actions.h" -#define MAX_ARGS 64 +#define MAX_ARGS 128 GUESTFSD_EXT_CMD(str_tune2fs, tune2fs); GUESTFSD_EXT_CMD(str_e2fsck, e2fsck); @@ -811,3 +811,370 @@ do_set_e2generation (const char *filename, int64_t generation) return 0; } + +int +do_mke2fs (const char *device, /* 0 */ + int64_t blockscount, + int64_t blocksize, + int64_t fragsize, + int64_t blockspergroup, + int64_t numberofgroups, /* 5 */ + int64_t bytesperinode, + int64_t inodesize, + int64_t journalsize, + int64_t numberofinodes, + int64_t stridesize, /* 10 */ + int64_t stripewidth, + int64_t maxonlineresize, + int reservedblockspercentage, + int mmpupdateinterval, + const char *journaldevice, /* 15 */ + const char *label, + const char *lastmounteddir, + const char *creatoros, + const char *fstype, + const char *usagetype, /* 20 */ + const char *uuid, + int forcecreate, + int writesbandgrouponly, + int lazyitableinit, + int lazyjournalinit, /* 25 */ + int testfs, + int discard, + int quotatype, + int extent, + int filetype, /* 30 */ + int flexbg, + int hasjournal, + int journaldev, + int largefile, + int quota, /* 35 */ + int resizeinode, + int sparsesuper, + int uninitbg) +{ + int r; + char *err = NULL; + const char *argv[MAX_ARGS]; + char blockscount_s[64]; + char blocksize_s[64]; + char fragsize_s[64]; + char blockspergroup_s[64]; + char numberofgroups_s[64]; + char bytesperinode_s[64]; + char inodesize_s[64]; + char journalsize_s[64]; + char journaldevice_s[256]; + char reservedblockspercentage_s[64]; + char numberofinodes_s[64]; + char mmpupdateinterval_s[84]; + char stridesize_s[74]; + char stripewidth_s[84]; + char maxonlineresize_s[74]; + size_t i = 0; + + ADD_ARG (argv, i, str_mke2fs); + + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSIZE_BITMASK) { + if (blocksize < 0) { + reply_with_error ("blocksize must be >= 0"); + goto error; + } + snprintf (blocksize_s, sizeof blocksize_s, "%" PRIi64, blocksize); + ADD_ARG (argv, i, "-b"); + ADD_ARG (argv, i, blocksize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FRAGSIZE_BITMASK) { + if (fragsize < 0) { + reply_with_error ("fragsize must be >= 0"); + goto error; + } + snprintf (fragsize_s, sizeof fragsize_s, "%" PRIi64, fragsize); + ADD_ARG (argv, i, "-f"); + ADD_ARG (argv, i, fragsize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FORCECREATE_BITMASK) { + if (forcecreate) + ADD_ARG (argv, i, "-F"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSPERGROUP_BITMASK) { + if (blockspergroup < 0) { + reply_with_error ("blockspergroup must be >= 0"); + goto error; + } + snprintf (blockspergroup_s, sizeof blockspergroup_s, + "%" PRIi64, blockspergroup); + ADD_ARG (argv, i, "-g"); + ADD_ARG (argv, i, blockspergroup_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_NUMBEROFGROUPS_BITMASK) { + if (numberofgroups < 0) { + reply_with_error ("numberofgroups must be >= 0"); + goto error; + } + snprintf (numberofgroups_s, sizeof numberofgroups_s, + "%" PRIi64, numberofgroups); + ADD_ARG (argv, i, "-G"); + ADD_ARG (argv, i, numberofgroups_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_BYTESPERINODE_BITMASK) { + if (bytesperinode < 0) { + reply_with_error ("bytesperinode must be >= 0"); + goto error; + } + snprintf (bytesperinode_s, sizeof bytesperinode_s, "%" PRIi64, bytesperinode); + ADD_ARG (argv, i, "-i"); + ADD_ARG (argv, i, bytesperinode_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_INODESIZE_BITMASK) { + if (inodesize < 0) { + reply_with_error ("inodesize must be >= 0"); + goto error; + } + snprintf (inodesize_s, sizeof inodesize_s, "%" PRIi64, inodesize); + ADD_ARG (argv, i, "-I"); + ADD_ARG (argv, i, inodesize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALSIZE_BITMASK) { + if (journalsize < 0) { + reply_with_error ("journalsize must be >= 0"); + goto error; + } + snprintf (journalsize_s, sizeof journalsize_s, + "size=" "%" PRIi64, journalsize); + ADD_ARG (argv, i, "-J"); + ADD_ARG (argv, i, journalsize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALDEVICE_BITMASK) { + if (journaldevice) { + snprintf (journaldevice_s, sizeof journaldevice_s, + "device=%s", journaldevice); + ADD_ARG (argv, i, "-J"); + ADD_ARG (argv, i, journaldevice_s); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_LABEL_BITMASK) { + if (label) { + ADD_ARG (argv, i, "-L"); + ADD_ARG (argv, i, label); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_RESERVEDBLOCKSPERCENTAGE_BITMASK) { + if (reservedblockspercentage < 0) { + reply_with_error ("reservedblockspercentage must be >= 0"); + goto error; + } + snprintf (reservedblockspercentage_s, sizeof reservedblockspercentage_s, + "%" PRIi32, reservedblockspercentage); + ADD_ARG (argv, i, "-m"); + ADD_ARG (argv, i, reservedblockspercentage_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LASTMOUNTEDDIR_BITMASK) { + if (lastmounteddir) { + ADD_ARG (argv, i, "-M"); + ADD_ARG (argv, i, lastmounteddir); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_NUMBEROFINODES_BITMASK) { + if (numberofinodes < 0) { + reply_with_error ("numberofinodes must be >= 0"); + goto error; + } + snprintf (numberofinodes_s, sizeof numberofinodes_s, + "%" PRIi64, numberofinodes); + ADD_ARG (argv, i, "-N"); + ADD_ARG (argv, i, numberofinodes_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_CREATOROS_BITMASK) { + if (creatoros) { + ADD_ARG (argv, i, "-o"); + ADD_ARG (argv, i, creatoros); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_WRITESBANDGROUPONLY_BITMASK) { + if (writesbandgrouponly) + ADD_ARG (argv, i, "-S"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FSTYPE_BITMASK) { + if (fstype) { + ADD_ARG (argv, i, "-t"); + ADD_ARG (argv, i, fstype); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_USAGETYPE_BITMASK) { + if (usagetype) { + ADD_ARG (argv, i, "-T"); + ADD_ARG (argv, i, usagetype); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_UUID_BITMASK) { + if (uuid) { + ADD_ARG (argv, i, "-U"); + ADD_ARG (argv, i, uuid); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_MMPUPDATEINTERVAL_BITMASK) { + if (mmpupdateinterval < 0) { + reply_with_error ("mmpupdateinterval must be >= 0"); + goto error; + } + snprintf (mmpupdateinterval_s, sizeof mmpupdateinterval_s, + "mmp_update_interval=" "%" PRIi32, mmpupdateinterval); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, mmpupdateinterval_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_STRIDESIZE_BITMASK) { + if (stridesize < 0) { + reply_with_error ("stridesize must be >= 0"); + goto error; + } + snprintf (stridesize_s, sizeof stridesize_s, + "stride=" "%" PRIi64, stridesize); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, stridesize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_STRIPEWIDTH_BITMASK) { + if (stripewidth< 0) { + reply_with_error ("stripewidth must be >= 0"); + goto error; + } + snprintf (stripewidth_s, sizeof stripewidth_s, + "stripe_width=" "%" PRIi64, stripewidth); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, stripewidth_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_MAXONLINERESIZE_BITMASK) { + if (maxonlineresize < 0) { + reply_with_error ("maxonlineresize must be >= 0"); + goto error; + } + snprintf (maxonlineresize_s, sizeof maxonlineresize_s, + "resize=" "%" PRIi64, maxonlineresize); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, maxonlineresize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LAZYITABLEINIT_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (lazyitableinit) + ADD_ARG (argv, i, "lazy_itable_init=1"); + else + ADD_ARG (argv, i, "lazy_itable_init=0"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LAZYJOURNALINIT_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (lazyjournalinit) + ADD_ARG (argv, i, "lazy_journal_init=1"); + else + ADD_ARG (argv, i, "lazy_journal_init=0"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_TESTFS_BITMASK) { + if (testfs) { + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, "test_fs"); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_DISCARD_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (discard) + ADD_ARG (argv, i, "discard"); + else + ADD_ARG (argv, i, "nodiscard"); + } + + if (optargs_bitmask & GUESTFS_MKE2FS_EXTENT_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (extent) + ADD_ARG (argv, i, "extent"); + else + ADD_ARG (argv, i, "^extent"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FILETYPE_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (filetype) + ADD_ARG (argv, i, "filetype"); + else + ADD_ARG (argv, i, "^filetype"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FLEXBG_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (flexbg) + ADD_ARG (argv, i, "flexbg"); + else + ADD_ARG (argv, i, "^flexbg"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_HASJOURNAL_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (hasjournal) + ADD_ARG (argv, i, "has_journal"); + else + ADD_ARG (argv, i, "^has_journal"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALDEV_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (journaldev) + ADD_ARG (argv, i, "journal_dev"); + else + ADD_ARG (argv, i, "^journal_dev"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LARGEFILE_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (largefile) + ADD_ARG (argv, i, "large_file"); + else + ADD_ARG (argv, i, "^large_file"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_QUOTA_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (quota) + ADD_ARG (argv, i, "quota"); + else + ADD_ARG (argv, i, "^quota"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_RESIZEINODE_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (resizeinode) + ADD_ARG (argv, i, "resize_inode"); + else + ADD_ARG (argv, i, "^resize_inode"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_SPARSESUPER_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (sparsesuper) + ADD_ARG (argv, i, "sparse_super"); + else + ADD_ARG (argv, i, "^sparse_super"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_UNINITBG_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (uninitbg) + ADD_ARG (argv, i, "uninit_bg"); + else + ADD_ARG (argv, i, "^uninit_bg"); + } + + ADD_ARG (argv, i, device); + + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSCOUNT_BITMASK) { + if (blockscount < 0) { + reply_with_error ("blockscount must be >= 0"); + goto error; + } + snprintf (blockscount_s, sizeof blockscount_s, "%" PRIi64, blockscount); + ADD_ARG (argv, i, blockscount_s); + } + + ADD_ARG (argv, i, NULL); + + r = commandv (NULL, &err, argv); + if (r == -1) { + reply_with_error ("%s: %s", device, err); + goto error; + } + + free (err); + return 0; + +error: + if (err) free (err); + return -1; +} diff --git a/generator/actions.ml b/generator/actions.ml index a3ff9ad..43f4837 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -6091,13 +6091,28 @@ the requested cluster size." }; name = "mke2journal"; style = RErr, [Int "blocksize"; Device "device"], []; proc_nr = Some 188; + deprecated_by = Some "mke2fs"; tests = [ InitEmpty, Always, TestOutput ( [["part_init"; "/dev/sda"; "mbr"]; ["part_add"; "/dev/sda"; "p"; "64"; "204799"]; ["part_add"; "/dev/sda"; "p"; "204800"; "-64"]; - ["mke2journal"; "4096"; "/dev/sda1"]; - ["mke2fs_J"; "ext2"; "4096"; "/dev/sda2"; "/dev/sda1"]; + ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "NOARG"; + "NOARG"; "NOARG"; "NOARG"; "NOARG"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; "true"; ""; ""; + ""; ""; ""]; + ["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "/dev/sda1"; + "NOARG"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; ["mount"; "/dev/sda2"; "/"]; ["write"; "/new"; "new file contents"]; ["cat"; "/new"]], "new file contents") @@ -6113,13 +6128,28 @@ to the command: name = "mke2journal_L"; style = RErr, [Int "blocksize"; String "label"; Device "device"], []; proc_nr = Some 189; + deprecated_by = Some "mke2fs"; tests = [ InitEmpty, Always, TestOutput ( [["part_init"; "/dev/sda"; "mbr"]; ["part_add"; "/dev/sda"; "p"; "64"; "204799"]; ["part_add"; "/dev/sda"; "p"; "204800"; "-64"]; - ["mke2journal_L"; "4096"; "JOURNAL"; "/dev/sda1"]; - ["mke2fs_JL"; "ext2"; "4096"; "/dev/sda2"; "JOURNAL"]; + ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "/dev/sda1"; + "JOURNAL"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; "true"; ""; ""; + ""; ""; ""]; + ["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "LABEL=JOURNAL"; + "JOURNAL"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; ["mount"; "/dev/sda2"; "/"]; ["write"; "/new"; "new file contents"]; ["cat"; "/new"]], "new file contents") @@ -6132,6 +6162,7 @@ This creates an ext2 external journal on C<device> with label C<label>." }; name = "mke2journal_U"; style = RErr, [Int "blocksize"; String "uuid"; Device "device"], []; proc_nr = Some 190; + deprecated_by = Some "mke2fs"; optional = Some "linuxfsuuid"; tests = (let uuid = uuidgen () in [ @@ -6139,8 +6170,22 @@ This creates an ext2 external journal on C<device> with label C<label>." }; [["part_init"; "/dev/sda"; "mbr"]; ["part_add"; "/dev/sda"; "p"; "64"; "204799"]; ["part_add"; "/dev/sda"; "p"; "204800"; "-64"]; - ["mke2journal_U"; "4096"; uuid; "/dev/sda1"]; - ["mke2fs_JU"; "ext2"; "4096"; "/dev/sda2"; uuid]; + ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "NOARG"; + "NOARG"; "NOARG"; "NOARG"; "NOARG"; "NOARG"; + uuid; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; + ["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "UUID=uuid"; + "JOURNAL"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; ["mount"; "/dev/sda2"; "/"]; ["write"; "/new"; "new file contents"]; ["cat"; "/new"]], "new file contents") @@ -6153,6 +6198,7 @@ This creates an ext2 external journal on C<device> with UUID C<uuid>." }; name = "mke2fs_J"; style = RErr, [String "fstype"; Int "blocksize"; Device "device"; Device "journal"], []; proc_nr = Some 191; + deprecated_by = Some "mke2fs"; shortdesc = "make ext2/3/4 filesystem with external journal"; longdesc = "\ This creates an ext2/3/4 filesystem on C<device> with @@ -6167,6 +6213,7 @@ See also C<guestfs_mke2journal>." }; name = "mke2fs_JL"; style = RErr, [String "fstype"; Int "blocksize"; Device "device"; String "label"], []; proc_nr = Some 192; + deprecated_by = Some "mke2fs"; shortdesc = "make ext2/3/4 filesystem with external journal"; longdesc = "\ This creates an ext2/3/4 filesystem on C<device> with @@ -6178,6 +6225,7 @@ See also C<guestfs_mke2journal_L>." }; name = "mke2fs_JU"; style = RErr, [String "fstype"; Int "blocksize"; Device "device"; String "uuid"], []; proc_nr = Some 193; + deprecated_by = Some "mke2fs"; optional = Some "linuxfsuuid"; shortdesc = "make ext2/3/4 filesystem with external journal"; longdesc = "\ @@ -9802,6 +9850,31 @@ the resulting filesystem may be inconsistent or corrupt. The returned status indicates whether filesystem corruption was detected (returns C<1>) or was not detected (returns C<0>)." }; + { defaults with + name = "mke2fs"; + style = RErr, [Device "device"], [OInt64 "blockscount"; OInt64 "blocksize"; OInt64 "fragsize"; OInt64 "blockspergroup"; OInt64 "numberofgroups"; OInt64 "bytesperinode"; OInt64 "inodesize"; OInt64 "journalsize"; OInt64 "numberofinodes"; OInt64 "stridesize"; OInt64 "stripewidth"; OInt64 "maxonlineresize"; OInt "reservedblockspercentage"; OInt "mmpupdateinterval"; OString "journaldevice"; OString "label"; OString "lastmounteddir"; OString "creatoros"; OString "fstype"; OString "usagetype"; OString "uuid"; OBool "forcecreate"; OBool "writesbandgrouponly"; OBool "lazyitableinit"; OBool "lazyjournalinit"; OBool "testfs"; OBool "discard"; OBool "quotatype"; OBool "extent"; OBool "filetype"; OBool "flexbg"; OBool "hasjournal"; OBool "journaldev"; OBool "largefile"; OBool "quota"; OBool "resizeinode"; OBool "sparsesuper"; OBool "uninitbg"]; + proc_nr = Some 367; + tests = [ + InitEmpty, IfAvailable "ext2", TestRun ( + [["part_disk"; "/dev/sda"; "mbr"]; + ["mke2fs"; "/dev/sda1"; ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "NOARG"; + "NOARG"; "NOARG"; "NOARG"; "ext4"; "NOARG"; + "NOARG"; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; "false"; ""; ""; ""; + ""; ""; ""]; + ]) + ]; + shortdesc = "create an ext2/ext3/ext4 filesystem on device"; + longdesc = "\ +C<mke2fs> is used to create an ext2, ext3, or ext4 filesystem, +usually in a disk partition. C<device> is the special file corresponding +to the device (e.g /dev/sdXX). C<blockscount> is the number of blocks +on C<device>. If omitted, C<mke2fs> automagically figures the file system +size." }; + ] (* Non-API meta-commands available only in guestfish. diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc index e0d00d5..c4532c9 100644 --- a/gobject/Makefile.inc +++ b/gobject/Makefile.inc @@ -80,7 +80,8 @@ guestfs_gobject_headers= \ include/guestfs-gobject/optargs-rsync_out.h \ include/guestfs-gobject/optargs-xfs_admin.h \ include/guestfs-gobject/optargs-hivex_open.h \ - include/guestfs-gobject/optargs-xfs_repair.h + include/guestfs-gobject/optargs-xfs_repair.h \ + include/guestfs-gobject/optargs-mke2fs.h guestfs_gobject_sources= \ src/session.c \ @@ -142,4 +143,5 @@ guestfs_gobject_sources= \ src/optargs-rsync_out.c \ src/optargs-xfs_admin.c \ src/optargs-hivex_open.c \ - src/optargs-xfs_repair.c + src/optargs-xfs_repair.c \ + src/optargs-mke2fs.c diff --git a/guestfs-release-notes.txt b/guestfs-release-notes.txt index e4ddefd..4f3860d 100644 --- a/guestfs-release-notes.txt +++ b/guestfs-release-notes.txt @@ -120,6 +120,7 @@ RELEASE NOTES FOR LIBGUESTFS 1.20 For further information, see https://bugzilla.redhat.com/show_bug.cgi?id=788642 + <https://bugzilla.redhat.com/show_bug.cgi?id=788642> New APIs @@ -1659,10 +1660,14 @@ BUGS To get a list of bugs against libguestfs, use this link: https://bugzilla.redhat.com/buglist.cgi?component=libguestfs&product=Vi rtualization+Tools + <https://bugzilla.redhat.com/buglist.cgi?component=libguestfs&product=V + irtualization+Tools> To report a new bug against libguestfs, use this link: https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product= Virtualization+Tools + <https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product + =Virtualization+Tools> When reporting a bug, please supply: diff --git a/po/POTFILES b/po/POTFILES index 129c80f..548156c 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -155,6 +155,7 @@ gobject/src/optargs-internal_test.c gobject/src/optargs-internal_test_63_optargs.c gobject/src/optargs-internal_test_only_optargs.c gobject/src/optargs-md_create.c +gobject/src/optargs-mke2fs.c gobject/src/optargs-mkfs.c gobject/src/optargs-mkfs_btrfs.c gobject/src/optargs-mkswap.c diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 4203007..526204c 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -366 +367 -- 1.7.12
On 09/11/2012 08:53 PM, Wanlong Gao wrote:
New api mke2fs for full configuration of filesystem.
Hi Rich, I fixed as your comments, but see this error, "Fatal error: exception Failure("function mke2journal has tests but does not test itself") " How should I fix this problem ? And can you review the other parts? Thanks, Wanlong Gao
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/ext2.c | 369 +++++++++++++++++++++++++++++++++++++++++++++- generator/actions.ml | 85 ++++++++++- gobject/Makefile.inc | 6 +- guestfs-release-notes.txt | 5 + po/POTFILES | 1 + src/MAX_PROC_NR | 2 +- 6 files changed, 458 insertions(+), 10 deletions(-)
diff --git a/daemon/ext2.c b/daemon/ext2.c index 40b36d2..7fc1172 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -29,7 +29,7 @@ #include "c-ctype.h" #include "actions.h"
-#define MAX_ARGS 64 +#define MAX_ARGS 128
GUESTFSD_EXT_CMD(str_tune2fs, tune2fs); GUESTFSD_EXT_CMD(str_e2fsck, e2fsck); @@ -811,3 +811,370 @@ do_set_e2generation (const char *filename, int64_t generation)
return 0; } + +int +do_mke2fs (const char *device, /* 0 */ + int64_t blockscount, + int64_t blocksize, + int64_t fragsize, + int64_t blockspergroup, + int64_t numberofgroups, /* 5 */ + int64_t bytesperinode, + int64_t inodesize, + int64_t journalsize, + int64_t numberofinodes, + int64_t stridesize, /* 10 */ + int64_t stripewidth, + int64_t maxonlineresize, + int reservedblockspercentage, + int mmpupdateinterval, + const char *journaldevice, /* 15 */ + const char *label, + const char *lastmounteddir, + const char *creatoros, + const char *fstype, + const char *usagetype, /* 20 */ + const char *uuid, + int forcecreate, + int writesbandgrouponly, + int lazyitableinit, + int lazyjournalinit, /* 25 */ + int testfs, + int discard, + int quotatype, + int extent, + int filetype, /* 30 */ + int flexbg, + int hasjournal, + int journaldev, + int largefile, + int quota, /* 35 */ + int resizeinode, + int sparsesuper, + int uninitbg) +{ + int r; + char *err = NULL; + const char *argv[MAX_ARGS]; + char blockscount_s[64]; + char blocksize_s[64]; + char fragsize_s[64]; + char blockspergroup_s[64]; + char numberofgroups_s[64]; + char bytesperinode_s[64]; + char inodesize_s[64]; + char journalsize_s[64]; + char journaldevice_s[256]; + char reservedblockspercentage_s[64]; + char numberofinodes_s[64]; + char mmpupdateinterval_s[84]; + char stridesize_s[74]; + char stripewidth_s[84]; + char maxonlineresize_s[74]; + size_t i = 0; + + ADD_ARG (argv, i, str_mke2fs); + + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSIZE_BITMASK) { + if (blocksize < 0) { + reply_with_error ("blocksize must be >= 0"); + goto error; + } + snprintf (blocksize_s, sizeof blocksize_s, "%" PRIi64, blocksize); + ADD_ARG (argv, i, "-b"); + ADD_ARG (argv, i, blocksize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FRAGSIZE_BITMASK) { + if (fragsize < 0) { + reply_with_error ("fragsize must be >= 0"); + goto error; + } + snprintf (fragsize_s, sizeof fragsize_s, "%" PRIi64, fragsize); + ADD_ARG (argv, i, "-f"); + ADD_ARG (argv, i, fragsize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FORCECREATE_BITMASK) { + if (forcecreate) + ADD_ARG (argv, i, "-F"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSPERGROUP_BITMASK) { + if (blockspergroup < 0) { + reply_with_error ("blockspergroup must be >= 0"); + goto error; + } + snprintf (blockspergroup_s, sizeof blockspergroup_s, + "%" PRIi64, blockspergroup); + ADD_ARG (argv, i, "-g"); + ADD_ARG (argv, i, blockspergroup_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_NUMBEROFGROUPS_BITMASK) { + if (numberofgroups < 0) { + reply_with_error ("numberofgroups must be >= 0"); + goto error; + } + snprintf (numberofgroups_s, sizeof numberofgroups_s, + "%" PRIi64, numberofgroups); + ADD_ARG (argv, i, "-G"); + ADD_ARG (argv, i, numberofgroups_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_BYTESPERINODE_BITMASK) { + if (bytesperinode < 0) { + reply_with_error ("bytesperinode must be >= 0"); + goto error; + } + snprintf (bytesperinode_s, sizeof bytesperinode_s, "%" PRIi64, bytesperinode); + ADD_ARG (argv, i, "-i"); + ADD_ARG (argv, i, bytesperinode_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_INODESIZE_BITMASK) { + if (inodesize < 0) { + reply_with_error ("inodesize must be >= 0"); + goto error; + } + snprintf (inodesize_s, sizeof inodesize_s, "%" PRIi64, inodesize); + ADD_ARG (argv, i, "-I"); + ADD_ARG (argv, i, inodesize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALSIZE_BITMASK) { + if (journalsize < 0) { + reply_with_error ("journalsize must be >= 0"); + goto error; + } + snprintf (journalsize_s, sizeof journalsize_s, + "size=" "%" PRIi64, journalsize); + ADD_ARG (argv, i, "-J"); + ADD_ARG (argv, i, journalsize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALDEVICE_BITMASK) { + if (journaldevice) { + snprintf (journaldevice_s, sizeof journaldevice_s, + "device=%s", journaldevice); + ADD_ARG (argv, i, "-J"); + ADD_ARG (argv, i, journaldevice_s); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_LABEL_BITMASK) { + if (label) { + ADD_ARG (argv, i, "-L"); + ADD_ARG (argv, i, label); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_RESERVEDBLOCKSPERCENTAGE_BITMASK) { + if (reservedblockspercentage < 0) { + reply_with_error ("reservedblockspercentage must be >= 0"); + goto error; + } + snprintf (reservedblockspercentage_s, sizeof reservedblockspercentage_s, + "%" PRIi32, reservedblockspercentage); + ADD_ARG (argv, i, "-m"); + ADD_ARG (argv, i, reservedblockspercentage_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LASTMOUNTEDDIR_BITMASK) { + if (lastmounteddir) { + ADD_ARG (argv, i, "-M"); + ADD_ARG (argv, i, lastmounteddir); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_NUMBEROFINODES_BITMASK) { + if (numberofinodes < 0) { + reply_with_error ("numberofinodes must be >= 0"); + goto error; + } + snprintf (numberofinodes_s, sizeof numberofinodes_s, + "%" PRIi64, numberofinodes); + ADD_ARG (argv, i, "-N"); + ADD_ARG (argv, i, numberofinodes_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_CREATOROS_BITMASK) { + if (creatoros) { + ADD_ARG (argv, i, "-o"); + ADD_ARG (argv, i, creatoros); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_WRITESBANDGROUPONLY_BITMASK) { + if (writesbandgrouponly) + ADD_ARG (argv, i, "-S"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FSTYPE_BITMASK) { + if (fstype) { + ADD_ARG (argv, i, "-t"); + ADD_ARG (argv, i, fstype); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_USAGETYPE_BITMASK) { + if (usagetype) { + ADD_ARG (argv, i, "-T"); + ADD_ARG (argv, i, usagetype); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_UUID_BITMASK) { + if (uuid) { + ADD_ARG (argv, i, "-U"); + ADD_ARG (argv, i, uuid); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_MMPUPDATEINTERVAL_BITMASK) { + if (mmpupdateinterval < 0) { + reply_with_error ("mmpupdateinterval must be >= 0"); + goto error; + } + snprintf (mmpupdateinterval_s, sizeof mmpupdateinterval_s, + "mmp_update_interval=" "%" PRIi32, mmpupdateinterval); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, mmpupdateinterval_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_STRIDESIZE_BITMASK) { + if (stridesize < 0) { + reply_with_error ("stridesize must be >= 0"); + goto error; + } + snprintf (stridesize_s, sizeof stridesize_s, + "stride=" "%" PRIi64, stridesize); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, stridesize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_STRIPEWIDTH_BITMASK) { + if (stripewidth< 0) { + reply_with_error ("stripewidth must be >= 0"); + goto error; + } + snprintf (stripewidth_s, sizeof stripewidth_s, + "stripe_width=" "%" PRIi64, stripewidth); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, stripewidth_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_MAXONLINERESIZE_BITMASK) { + if (maxonlineresize < 0) { + reply_with_error ("maxonlineresize must be >= 0"); + goto error; + } + snprintf (maxonlineresize_s, sizeof maxonlineresize_s, + "resize=" "%" PRIi64, maxonlineresize); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, maxonlineresize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LAZYITABLEINIT_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (lazyitableinit) + ADD_ARG (argv, i, "lazy_itable_init=1"); + else + ADD_ARG (argv, i, "lazy_itable_init=0"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LAZYJOURNALINIT_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (lazyjournalinit) + ADD_ARG (argv, i, "lazy_journal_init=1"); + else + ADD_ARG (argv, i, "lazy_journal_init=0"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_TESTFS_BITMASK) { + if (testfs) { + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, "test_fs"); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_DISCARD_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (discard) + ADD_ARG (argv, i, "discard"); + else + ADD_ARG (argv, i, "nodiscard"); + } + + if (optargs_bitmask & GUESTFS_MKE2FS_EXTENT_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (extent) + ADD_ARG (argv, i, "extent"); + else + ADD_ARG (argv, i, "^extent"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FILETYPE_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (filetype) + ADD_ARG (argv, i, "filetype"); + else + ADD_ARG (argv, i, "^filetype"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FLEXBG_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (flexbg) + ADD_ARG (argv, i, "flexbg"); + else + ADD_ARG (argv, i, "^flexbg"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_HASJOURNAL_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (hasjournal) + ADD_ARG (argv, i, "has_journal"); + else + ADD_ARG (argv, i, "^has_journal"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALDEV_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (journaldev) + ADD_ARG (argv, i, "journal_dev"); + else + ADD_ARG (argv, i, "^journal_dev"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LARGEFILE_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (largefile) + ADD_ARG (argv, i, "large_file"); + else + ADD_ARG (argv, i, "^large_file"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_QUOTA_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (quota) + ADD_ARG (argv, i, "quota"); + else + ADD_ARG (argv, i, "^quota"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_RESIZEINODE_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (resizeinode) + ADD_ARG (argv, i, "resize_inode"); + else + ADD_ARG (argv, i, "^resize_inode"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_SPARSESUPER_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (sparsesuper) + ADD_ARG (argv, i, "sparse_super"); + else + ADD_ARG (argv, i, "^sparse_super"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_UNINITBG_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (uninitbg) + ADD_ARG (argv, i, "uninit_bg"); + else + ADD_ARG (argv, i, "^uninit_bg"); + } + + ADD_ARG (argv, i, device); + + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSCOUNT_BITMASK) { + if (blockscount < 0) { + reply_with_error ("blockscount must be >= 0"); + goto error; + } + snprintf (blockscount_s, sizeof blockscount_s, "%" PRIi64, blockscount); + ADD_ARG (argv, i, blockscount_s); + } + + ADD_ARG (argv, i, NULL); + + r = commandv (NULL, &err, argv); + if (r == -1) { + reply_with_error ("%s: %s", device, err); + goto error; + } + + free (err); + return 0; + +error: + if (err) free (err); + return -1; +} diff --git a/generator/actions.ml b/generator/actions.ml index a3ff9ad..43f4837 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -6091,13 +6091,28 @@ the requested cluster size." }; name = "mke2journal"; style = RErr, [Int "blocksize"; Device "device"], []; proc_nr = Some 188; + deprecated_by = Some "mke2fs"; tests = [ InitEmpty, Always, TestOutput ( [["part_init"; "/dev/sda"; "mbr"]; ["part_add"; "/dev/sda"; "p"; "64"; "204799"]; ["part_add"; "/dev/sda"; "p"; "204800"; "-64"]; - ["mke2journal"; "4096"; "/dev/sda1"]; - ["mke2fs_J"; "ext2"; "4096"; "/dev/sda2"; "/dev/sda1"]; + ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "NOARG"; + "NOARG"; "NOARG"; "NOARG"; "NOARG"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; "true"; ""; ""; + ""; ""; ""]; + ["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "/dev/sda1"; + "NOARG"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; ["mount"; "/dev/sda2"; "/"]; ["write"; "/new"; "new file contents"]; ["cat"; "/new"]], "new file contents") @@ -6113,13 +6128,28 @@ to the command: name = "mke2journal_L"; style = RErr, [Int "blocksize"; String "label"; Device "device"], []; proc_nr = Some 189; + deprecated_by = Some "mke2fs"; tests = [ InitEmpty, Always, TestOutput ( [["part_init"; "/dev/sda"; "mbr"]; ["part_add"; "/dev/sda"; "p"; "64"; "204799"]; ["part_add"; "/dev/sda"; "p"; "204800"; "-64"]; - ["mke2journal_L"; "4096"; "JOURNAL"; "/dev/sda1"]; - ["mke2fs_JL"; "ext2"; "4096"; "/dev/sda2"; "JOURNAL"]; + ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "/dev/sda1"; + "JOURNAL"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; "true"; ""; ""; + ""; ""; ""]; + ["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "LABEL=JOURNAL"; + "JOURNAL"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; ["mount"; "/dev/sda2"; "/"]; ["write"; "/new"; "new file contents"]; ["cat"; "/new"]], "new file contents") @@ -6132,6 +6162,7 @@ This creates an ext2 external journal on C<device> with label C<label>." }; name = "mke2journal_U"; style = RErr, [Int "blocksize"; String "uuid"; Device "device"], []; proc_nr = Some 190; + deprecated_by = Some "mke2fs"; optional = Some "linuxfsuuid"; tests = (let uuid = uuidgen () in [ @@ -6139,8 +6170,22 @@ This creates an ext2 external journal on C<device> with label C<label>." }; [["part_init"; "/dev/sda"; "mbr"]; ["part_add"; "/dev/sda"; "p"; "64"; "204799"]; ["part_add"; "/dev/sda"; "p"; "204800"; "-64"]; - ["mke2journal_U"; "4096"; uuid; "/dev/sda1"]; - ["mke2fs_JU"; "ext2"; "4096"; "/dev/sda2"; uuid]; + ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "NOARG"; + "NOARG"; "NOARG"; "NOARG"; "NOARG"; "NOARG"; + uuid; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; + ["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "UUID=uuid"; + "JOURNAL"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; ["mount"; "/dev/sda2"; "/"]; ["write"; "/new"; "new file contents"]; ["cat"; "/new"]], "new file contents") @@ -6153,6 +6198,7 @@ This creates an ext2 external journal on C<device> with UUID C<uuid>." }; name = "mke2fs_J"; style = RErr, [String "fstype"; Int "blocksize"; Device "device"; Device "journal"], []; proc_nr = Some 191; + deprecated_by = Some "mke2fs"; shortdesc = "make ext2/3/4 filesystem with external journal"; longdesc = "\ This creates an ext2/3/4 filesystem on C<device> with @@ -6167,6 +6213,7 @@ See also C<guestfs_mke2journal>." }; name = "mke2fs_JL"; style = RErr, [String "fstype"; Int "blocksize"; Device "device"; String "label"], []; proc_nr = Some 192; + deprecated_by = Some "mke2fs"; shortdesc = "make ext2/3/4 filesystem with external journal"; longdesc = "\ This creates an ext2/3/4 filesystem on C<device> with @@ -6178,6 +6225,7 @@ See also C<guestfs_mke2journal_L>." }; name = "mke2fs_JU"; style = RErr, [String "fstype"; Int "blocksize"; Device "device"; String "uuid"], []; proc_nr = Some 193; + deprecated_by = Some "mke2fs"; optional = Some "linuxfsuuid"; shortdesc = "make ext2/3/4 filesystem with external journal"; longdesc = "\ @@ -9802,6 +9850,31 @@ the resulting filesystem may be inconsistent or corrupt. The returned status indicates whether filesystem corruption was detected (returns C<1>) or was not detected (returns C<0>)." };
+ { defaults with + name = "mke2fs"; + style = RErr, [Device "device"], [OInt64 "blockscount"; OInt64 "blocksize"; OInt64 "fragsize"; OInt64 "blockspergroup"; OInt64 "numberofgroups"; OInt64 "bytesperinode"; OInt64 "inodesize"; OInt64 "journalsize"; OInt64 "numberofinodes"; OInt64 "stridesize"; OInt64 "stripewidth"; OInt64 "maxonlineresize"; OInt "reservedblockspercentage"; OInt "mmpupdateinterval"; OString "journaldevice"; OString "label"; OString "lastmounteddir"; OString "creatoros"; OString "fstype"; OString "usagetype"; OString "uuid"; OBool "forcecreate"; OBool "writesbandgrouponly"; OBool "lazyitableinit"; OBool "lazyjournalinit"; OBool "testfs"; OBool "discard"; OBool "quotatype"; OBool "extent"; OBool "filetype"; OBool "flexbg"; OBool "hasjournal"; OBool "journaldev"; OBool "largefile"; OBool "quota"; OBool "resizeinode"; OBool "sparsesuper"; OBool "uninitbg"]; + proc_nr = Some 367; + tests = [ + InitEmpty, IfAvailable "ext2", TestRun ( + [["part_disk"; "/dev/sda"; "mbr"]; + ["mke2fs"; "/dev/sda1"; ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "NOARG"; + "NOARG"; "NOARG"; "NOARG"; "ext4"; "NOARG"; + "NOARG"; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; "false"; ""; ""; ""; + ""; ""; ""]; + ]) + ]; + shortdesc = "create an ext2/ext3/ext4 filesystem on device"; + longdesc = "\ +C<mke2fs> is used to create an ext2, ext3, or ext4 filesystem, +usually in a disk partition. C<device> is the special file corresponding +to the device (e.g /dev/sdXX). C<blockscount> is the number of blocks +on C<device>. If omitted, C<mke2fs> automagically figures the file system +size." }; + ]
(* Non-API meta-commands available only in guestfish. diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc index e0d00d5..c4532c9 100644 --- a/gobject/Makefile.inc +++ b/gobject/Makefile.inc @@ -80,7 +80,8 @@ guestfs_gobject_headers= \ include/guestfs-gobject/optargs-rsync_out.h \ include/guestfs-gobject/optargs-xfs_admin.h \ include/guestfs-gobject/optargs-hivex_open.h \ - include/guestfs-gobject/optargs-xfs_repair.h + include/guestfs-gobject/optargs-xfs_repair.h \ + include/guestfs-gobject/optargs-mke2fs.h
guestfs_gobject_sources= \ src/session.c \ @@ -142,4 +143,5 @@ guestfs_gobject_sources= \ src/optargs-rsync_out.c \ src/optargs-xfs_admin.c \ src/optargs-hivex_open.c \ - src/optargs-xfs_repair.c + src/optargs-xfs_repair.c \ + src/optargs-mke2fs.c diff --git a/guestfs-release-notes.txt b/guestfs-release-notes.txt index e4ddefd..4f3860d 100644 --- a/guestfs-release-notes.txt +++ b/guestfs-release-notes.txt @@ -120,6 +120,7 @@ RELEASE NOTES FOR LIBGUESTFS 1.20
For further information, see https://bugzilla.redhat.com/show_bug.cgi?id=788642 + <https://bugzilla.redhat.com/show_bug.cgi?id=788642>
New APIs
@@ -1659,10 +1660,14 @@ BUGS To get a list of bugs against libguestfs, use this link: https://bugzilla.redhat.com/buglist.cgi?component=libguestfs&product=Vi rtualization+Tools + <https://bugzilla.redhat.com/buglist.cgi?component=libguestfs&product=V + irtualization+Tools>
To report a new bug against libguestfs, use this link: https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product= Virtualization+Tools + <https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product + =Virtualization+Tools>
When reporting a bug, please supply:
diff --git a/po/POTFILES b/po/POTFILES index 129c80f..548156c 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -155,6 +155,7 @@ gobject/src/optargs-internal_test.c gobject/src/optargs-internal_test_63_optargs.c gobject/src/optargs-internal_test_only_optargs.c gobject/src/optargs-md_create.c +gobject/src/optargs-mke2fs.c gobject/src/optargs-mkfs.c gobject/src/optargs-mkfs_btrfs.c gobject/src/optargs-mkswap.c diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 4203007..526204c 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -366 +367
On Mon, Sep 17, 2012 at 02:39:17PM +0800, Wanlong Gao wrote:
On 09/11/2012 08:53 PM, Wanlong Gao wrote:
New api mke2fs for full configuration of filesystem.
Hi Rich,
I fixed as your comments, but see this error, "Fatal error: exception Failure("function mke2journal has tests but does not test itself") "
How should I fix this problem ?
This means that the mke2journal test doesn't test the mke2journal function. That's because you shouldn't change the tests of the deprecated functions (mke2journal etc). Leave them alone. But you should copy those tests into mke2fs, changing them to use mke2fs (which you did, but only partially).
And can you review the other parts?
Sure, later (today hopefully).
Thanks, Wanlong Gao
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/ext2.c | 369 +++++++++++++++++++++++++++++++++++++++++++++- generator/actions.ml | 85 ++++++++++- gobject/Makefile.inc | 6 +- guestfs-release-notes.txt | 5 + po/POTFILES | 1 + src/MAX_PROC_NR | 2 +- 6 files changed, 458 insertions(+), 10 deletions(-)
diff --git a/daemon/ext2.c b/daemon/ext2.c index 40b36d2..7fc1172 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -29,7 +29,7 @@ #include "c-ctype.h" #include "actions.h"
-#define MAX_ARGS 64 +#define MAX_ARGS 128
GUESTFSD_EXT_CMD(str_tune2fs, tune2fs); GUESTFSD_EXT_CMD(str_e2fsck, e2fsck); @@ -811,3 +811,370 @@ do_set_e2generation (const char *filename, int64_t generation)
return 0; } + +int +do_mke2fs (const char *device, /* 0 */ + int64_t blockscount, + int64_t blocksize, + int64_t fragsize, + int64_t blockspergroup, + int64_t numberofgroups, /* 5 */ + int64_t bytesperinode, + int64_t inodesize, + int64_t journalsize, + int64_t numberofinodes, + int64_t stridesize, /* 10 */ + int64_t stripewidth, + int64_t maxonlineresize, + int reservedblockspercentage, + int mmpupdateinterval, + const char *journaldevice, /* 15 */ + const char *label, + const char *lastmounteddir, + const char *creatoros, + const char *fstype, + const char *usagetype, /* 20 */ + const char *uuid, + int forcecreate, + int writesbandgrouponly, + int lazyitableinit, + int lazyjournalinit, /* 25 */ + int testfs, + int discard, + int quotatype, + int extent, + int filetype, /* 30 */ + int flexbg, + int hasjournal, + int journaldev, + int largefile, + int quota, /* 35 */ + int resizeinode, + int sparsesuper, + int uninitbg) +{ + int r; + char *err = NULL; + const char *argv[MAX_ARGS]; + char blockscount_s[64]; + char blocksize_s[64]; + char fragsize_s[64]; + char blockspergroup_s[64]; + char numberofgroups_s[64]; + char bytesperinode_s[64]; + char inodesize_s[64]; + char journalsize_s[64]; + char journaldevice_s[256]; + char reservedblockspercentage_s[64]; + char numberofinodes_s[64]; + char mmpupdateinterval_s[84]; + char stridesize_s[74]; + char stripewidth_s[84]; + char maxonlineresize_s[74]; + size_t i = 0; + + ADD_ARG (argv, i, str_mke2fs); + + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSIZE_BITMASK) { + if (blocksize < 0) { + reply_with_error ("blocksize must be >= 0"); + goto error; + } + snprintf (blocksize_s, sizeof blocksize_s, "%" PRIi64, blocksize); + ADD_ARG (argv, i, "-b"); + ADD_ARG (argv, i, blocksize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FRAGSIZE_BITMASK) { + if (fragsize < 0) { + reply_with_error ("fragsize must be >= 0"); + goto error; + } + snprintf (fragsize_s, sizeof fragsize_s, "%" PRIi64, fragsize); + ADD_ARG (argv, i, "-f"); + ADD_ARG (argv, i, fragsize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FORCECREATE_BITMASK) { + if (forcecreate) + ADD_ARG (argv, i, "-F"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSPERGROUP_BITMASK) { + if (blockspergroup < 0) { + reply_with_error ("blockspergroup must be >= 0"); + goto error; + } + snprintf (blockspergroup_s, sizeof blockspergroup_s, + "%" PRIi64, blockspergroup); + ADD_ARG (argv, i, "-g"); + ADD_ARG (argv, i, blockspergroup_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_NUMBEROFGROUPS_BITMASK) { + if (numberofgroups < 0) { + reply_with_error ("numberofgroups must be >= 0"); + goto error; + } + snprintf (numberofgroups_s, sizeof numberofgroups_s, + "%" PRIi64, numberofgroups); + ADD_ARG (argv, i, "-G"); + ADD_ARG (argv, i, numberofgroups_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_BYTESPERINODE_BITMASK) { + if (bytesperinode < 0) { + reply_with_error ("bytesperinode must be >= 0"); + goto error; + } + snprintf (bytesperinode_s, sizeof bytesperinode_s, "%" PRIi64, bytesperinode); + ADD_ARG (argv, i, "-i"); + ADD_ARG (argv, i, bytesperinode_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_INODESIZE_BITMASK) { + if (inodesize < 0) { + reply_with_error ("inodesize must be >= 0"); + goto error; + } + snprintf (inodesize_s, sizeof inodesize_s, "%" PRIi64, inodesize); + ADD_ARG (argv, i, "-I"); + ADD_ARG (argv, i, inodesize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALSIZE_BITMASK) { + if (journalsize < 0) { + reply_with_error ("journalsize must be >= 0"); + goto error; + } + snprintf (journalsize_s, sizeof journalsize_s, + "size=" "%" PRIi64, journalsize); + ADD_ARG (argv, i, "-J"); + ADD_ARG (argv, i, journalsize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALDEVICE_BITMASK) { + if (journaldevice) { + snprintf (journaldevice_s, sizeof journaldevice_s, + "device=%s", journaldevice); + ADD_ARG (argv, i, "-J"); + ADD_ARG (argv, i, journaldevice_s); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_LABEL_BITMASK) { + if (label) { + ADD_ARG (argv, i, "-L"); + ADD_ARG (argv, i, label); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_RESERVEDBLOCKSPERCENTAGE_BITMASK) { + if (reservedblockspercentage < 0) { + reply_with_error ("reservedblockspercentage must be >= 0"); + goto error; + } + snprintf (reservedblockspercentage_s, sizeof reservedblockspercentage_s, + "%" PRIi32, reservedblockspercentage); + ADD_ARG (argv, i, "-m"); + ADD_ARG (argv, i, reservedblockspercentage_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LASTMOUNTEDDIR_BITMASK) { + if (lastmounteddir) { + ADD_ARG (argv, i, "-M"); + ADD_ARG (argv, i, lastmounteddir); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_NUMBEROFINODES_BITMASK) { + if (numberofinodes < 0) { + reply_with_error ("numberofinodes must be >= 0"); + goto error; + } + snprintf (numberofinodes_s, sizeof numberofinodes_s, + "%" PRIi64, numberofinodes); + ADD_ARG (argv, i, "-N"); + ADD_ARG (argv, i, numberofinodes_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_CREATOROS_BITMASK) { + if (creatoros) { + ADD_ARG (argv, i, "-o"); + ADD_ARG (argv, i, creatoros); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_WRITESBANDGROUPONLY_BITMASK) { + if (writesbandgrouponly) + ADD_ARG (argv, i, "-S"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FSTYPE_BITMASK) { + if (fstype) { + ADD_ARG (argv, i, "-t"); + ADD_ARG (argv, i, fstype); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_USAGETYPE_BITMASK) { + if (usagetype) { + ADD_ARG (argv, i, "-T"); + ADD_ARG (argv, i, usagetype); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_UUID_BITMASK) { + if (uuid) { + ADD_ARG (argv, i, "-U"); + ADD_ARG (argv, i, uuid); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_MMPUPDATEINTERVAL_BITMASK) { + if (mmpupdateinterval < 0) { + reply_with_error ("mmpupdateinterval must be >= 0"); + goto error; + } + snprintf (mmpupdateinterval_s, sizeof mmpupdateinterval_s, + "mmp_update_interval=" "%" PRIi32, mmpupdateinterval); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, mmpupdateinterval_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_STRIDESIZE_BITMASK) { + if (stridesize < 0) { + reply_with_error ("stridesize must be >= 0"); + goto error; + } + snprintf (stridesize_s, sizeof stridesize_s, + "stride=" "%" PRIi64, stridesize); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, stridesize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_STRIPEWIDTH_BITMASK) { + if (stripewidth< 0) { + reply_with_error ("stripewidth must be >= 0"); + goto error; + } + snprintf (stripewidth_s, sizeof stripewidth_s, + "stripe_width=" "%" PRIi64, stripewidth); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, stripewidth_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_MAXONLINERESIZE_BITMASK) { + if (maxonlineresize < 0) { + reply_with_error ("maxonlineresize must be >= 0"); + goto error; + } + snprintf (maxonlineresize_s, sizeof maxonlineresize_s, + "resize=" "%" PRIi64, maxonlineresize); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, maxonlineresize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LAZYITABLEINIT_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (lazyitableinit) + ADD_ARG (argv, i, "lazy_itable_init=1"); + else + ADD_ARG (argv, i, "lazy_itable_init=0"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LAZYJOURNALINIT_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (lazyjournalinit) + ADD_ARG (argv, i, "lazy_journal_init=1"); + else + ADD_ARG (argv, i, "lazy_journal_init=0"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_TESTFS_BITMASK) { + if (testfs) { + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, "test_fs"); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_DISCARD_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (discard) + ADD_ARG (argv, i, "discard"); + else + ADD_ARG (argv, i, "nodiscard"); + } + + if (optargs_bitmask & GUESTFS_MKE2FS_EXTENT_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (extent) + ADD_ARG (argv, i, "extent"); + else + ADD_ARG (argv, i, "^extent"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FILETYPE_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (filetype) + ADD_ARG (argv, i, "filetype"); + else + ADD_ARG (argv, i, "^filetype"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FLEXBG_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (flexbg) + ADD_ARG (argv, i, "flexbg"); + else + ADD_ARG (argv, i, "^flexbg"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_HASJOURNAL_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (hasjournal) + ADD_ARG (argv, i, "has_journal"); + else + ADD_ARG (argv, i, "^has_journal"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALDEV_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (journaldev) + ADD_ARG (argv, i, "journal_dev"); + else + ADD_ARG (argv, i, "^journal_dev"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LARGEFILE_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (largefile) + ADD_ARG (argv, i, "large_file"); + else + ADD_ARG (argv, i, "^large_file"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_QUOTA_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (quota) + ADD_ARG (argv, i, "quota"); + else + ADD_ARG (argv, i, "^quota"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_RESIZEINODE_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (resizeinode) + ADD_ARG (argv, i, "resize_inode"); + else + ADD_ARG (argv, i, "^resize_inode"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_SPARSESUPER_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (sparsesuper) + ADD_ARG (argv, i, "sparse_super"); + else + ADD_ARG (argv, i, "^sparse_super"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_UNINITBG_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (uninitbg) + ADD_ARG (argv, i, "uninit_bg"); + else + ADD_ARG (argv, i, "^uninit_bg"); + } + + ADD_ARG (argv, i, device); + + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSCOUNT_BITMASK) { + if (blockscount < 0) { + reply_with_error ("blockscount must be >= 0"); + goto error; + } + snprintf (blockscount_s, sizeof blockscount_s, "%" PRIi64, blockscount); + ADD_ARG (argv, i, blockscount_s); + } + + ADD_ARG (argv, i, NULL); + + r = commandv (NULL, &err, argv); + if (r == -1) { + reply_with_error ("%s: %s", device, err); + goto error; + } + + free (err); + return 0; + +error: + if (err) free (err); + return -1; +} diff --git a/generator/actions.ml b/generator/actions.ml index a3ff9ad..43f4837 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -6091,13 +6091,28 @@ the requested cluster size." }; name = "mke2journal"; style = RErr, [Int "blocksize"; Device "device"], []; proc_nr = Some 188; + deprecated_by = Some "mke2fs"; tests = [ InitEmpty, Always, TestOutput ( [["part_init"; "/dev/sda"; "mbr"]; ["part_add"; "/dev/sda"; "p"; "64"; "204799"]; ["part_add"; "/dev/sda"; "p"; "204800"; "-64"]; - ["mke2journal"; "4096"; "/dev/sda1"]; - ["mke2fs_J"; "ext2"; "4096"; "/dev/sda2"; "/dev/sda1"]; + ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "NOARG"; + "NOARG"; "NOARG"; "NOARG"; "NOARG"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; "true"; ""; ""; + ""; ""; ""]; + ["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "/dev/sda1"; + "NOARG"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; ["mount"; "/dev/sda2"; "/"]; ["write"; "/new"; "new file contents"]; ["cat"; "/new"]], "new file contents") @@ -6113,13 +6128,28 @@ to the command: name = "mke2journal_L"; style = RErr, [Int "blocksize"; String "label"; Device "device"], []; proc_nr = Some 189; + deprecated_by = Some "mke2fs"; tests = [ InitEmpty, Always, TestOutput ( [["part_init"; "/dev/sda"; "mbr"]; ["part_add"; "/dev/sda"; "p"; "64"; "204799"]; ["part_add"; "/dev/sda"; "p"; "204800"; "-64"]; - ["mke2journal_L"; "4096"; "JOURNAL"; "/dev/sda1"]; - ["mke2fs_JL"; "ext2"; "4096"; "/dev/sda2"; "JOURNAL"]; + ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "/dev/sda1"; + "JOURNAL"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; "true"; ""; ""; + ""; ""; ""]; + ["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "LABEL=JOURNAL"; + "JOURNAL"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; ["mount"; "/dev/sda2"; "/"]; ["write"; "/new"; "new file contents"]; ["cat"; "/new"]], "new file contents") @@ -6132,6 +6162,7 @@ This creates an ext2 external journal on C<device> with label C<label>." }; name = "mke2journal_U"; style = RErr, [Int "blocksize"; String "uuid"; Device "device"], []; proc_nr = Some 190; + deprecated_by = Some "mke2fs"; optional = Some "linuxfsuuid"; tests = (let uuid = uuidgen () in [ @@ -6139,8 +6170,22 @@ This creates an ext2 external journal on C<device> with label C<label>." }; [["part_init"; "/dev/sda"; "mbr"]; ["part_add"; "/dev/sda"; "p"; "64"; "204799"]; ["part_add"; "/dev/sda"; "p"; "204800"; "-64"]; - ["mke2journal_U"; "4096"; uuid; "/dev/sda1"]; - ["mke2fs_JU"; "ext2"; "4096"; "/dev/sda2"; uuid]; + ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "NOARG"; + "NOARG"; "NOARG"; "NOARG"; "NOARG"; "NOARG"; + uuid; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; + ["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "UUID=uuid"; + "JOURNAL"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; ["mount"; "/dev/sda2"; "/"]; ["write"; "/new"; "new file contents"]; ["cat"; "/new"]], "new file contents") @@ -6153,6 +6198,7 @@ This creates an ext2 external journal on C<device> with UUID C<uuid>." }; name = "mke2fs_J"; style = RErr, [String "fstype"; Int "blocksize"; Device "device"; Device "journal"], []; proc_nr = Some 191; + deprecated_by = Some "mke2fs"; shortdesc = "make ext2/3/4 filesystem with external journal"; longdesc = "\ This creates an ext2/3/4 filesystem on C<device> with @@ -6167,6 +6213,7 @@ See also C<guestfs_mke2journal>." }; name = "mke2fs_JL"; style = RErr, [String "fstype"; Int "blocksize"; Device "device"; String "label"], []; proc_nr = Some 192; + deprecated_by = Some "mke2fs"; shortdesc = "make ext2/3/4 filesystem with external journal"; longdesc = "\ This creates an ext2/3/4 filesystem on C<device> with @@ -6178,6 +6225,7 @@ See also C<guestfs_mke2journal_L>." }; name = "mke2fs_JU"; style = RErr, [String "fstype"; Int "blocksize"; Device "device"; String "uuid"], []; proc_nr = Some 193; + deprecated_by = Some "mke2fs"; optional = Some "linuxfsuuid"; shortdesc = "make ext2/3/4 filesystem with external journal"; longdesc = "\ @@ -9802,6 +9850,31 @@ the resulting filesystem may be inconsistent or corrupt. The returned status indicates whether filesystem corruption was detected (returns C<1>) or was not detected (returns C<0>)." };
+ { defaults with + name = "mke2fs"; + style = RErr, [Device "device"], [OInt64 "blockscount"; OInt64 "blocksize"; OInt64 "fragsize"; OInt64 "blockspergroup"; OInt64 "numberofgroups"; OInt64 "bytesperinode"; OInt64 "inodesize"; OInt64 "journalsize"; OInt64 "numberofinodes"; OInt64 "stridesize"; OInt64 "stripewidth"; OInt64 "maxonlineresize"; OInt "reservedblockspercentage"; OInt "mmpupdateinterval"; OString "journaldevice"; OString "label"; OString "lastmounteddir"; OString "creatoros"; OString "fstype"; OString "usagetype"; OString "uuid"; OBool "forcecreate"; OBool "writesbandgrouponly"; OBool "lazyitableinit"; OBool "lazyjournalinit"; OBool "testfs"; OBool "discard"; OBool "quotatype"; OBool "extent"; OBool "filetype"; OBool "flexbg"; OBool "hasjournal"; OBool "journaldev"; OBool "largefile"; OBool "quota"; OBool "resizeinode"; OBool "sparsesuper"; OBool "uninitbg"]; + proc_nr = Some 367; + tests = [ + InitEmpty, IfAvailable "ext2", TestRun ( + [["part_disk"; "/dev/sda"; "mbr"]; + ["mke2fs"; "/dev/sda1"; ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "NOARG"; + "NOARG"; "NOARG"; "NOARG"; "ext4"; "NOARG"; + "NOARG"; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; "false"; ""; ""; ""; + ""; ""; ""]; + ]) + ]; + shortdesc = "create an ext2/ext3/ext4 filesystem on device"; + longdesc = "\ +C<mke2fs> is used to create an ext2, ext3, or ext4 filesystem, +usually in a disk partition. C<device> is the special file corresponding +to the device (e.g /dev/sdXX). C<blockscount> is the number of blocks +on C<device>. If omitted, C<mke2fs> automagically figures the file system +size." }; + ]
(* Non-API meta-commands available only in guestfish. diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc index e0d00d5..c4532c9 100644 --- a/gobject/Makefile.inc +++ b/gobject/Makefile.inc @@ -80,7 +80,8 @@ guestfs_gobject_headers= \ include/guestfs-gobject/optargs-rsync_out.h \ include/guestfs-gobject/optargs-xfs_admin.h \ include/guestfs-gobject/optargs-hivex_open.h \ - include/guestfs-gobject/optargs-xfs_repair.h + include/guestfs-gobject/optargs-xfs_repair.h \ + include/guestfs-gobject/optargs-mke2fs.h
guestfs_gobject_sources= \ src/session.c \ @@ -142,4 +143,5 @@ guestfs_gobject_sources= \ src/optargs-rsync_out.c \ src/optargs-xfs_admin.c \ src/optargs-hivex_open.c \ - src/optargs-xfs_repair.c + src/optargs-xfs_repair.c \ + src/optargs-mke2fs.c diff --git a/guestfs-release-notes.txt b/guestfs-release-notes.txt index e4ddefd..4f3860d 100644 --- a/guestfs-release-notes.txt +++ b/guestfs-release-notes.txt @@ -120,6 +120,7 @@ RELEASE NOTES FOR LIBGUESTFS 1.20
For further information, see https://bugzilla.redhat.com/show_bug.cgi?id=788642 + <https://bugzilla.redhat.com/show_bug.cgi?id=788642>
New APIs
@@ -1659,10 +1660,14 @@ BUGS To get a list of bugs against libguestfs, use this link: https://bugzilla.redhat.com/buglist.cgi?component=libguestfs&product=Vi rtualization+Tools + <https://bugzilla.redhat.com/buglist.cgi?component=libguestfs&product=V + irtualization+Tools>
To report a new bug against libguestfs, use this link: https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product= Virtualization+Tools + <https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product + =Virtualization+Tools>
When reporting a bug, please supply:
diff --git a/po/POTFILES b/po/POTFILES index 129c80f..548156c 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -155,6 +155,7 @@ gobject/src/optargs-internal_test.c gobject/src/optargs-internal_test_63_optargs.c gobject/src/optargs-internal_test_only_optargs.c gobject/src/optargs-md_create.c +gobject/src/optargs-mke2fs.c gobject/src/optargs-mkfs.c gobject/src/optargs-mkfs_btrfs.c gobject/src/optargs-mkswap.c diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 4203007..526204c 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -366 +367
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
On 09/17/2012 03:12 PM, Richard W.M. Jones wrote:
On Mon, Sep 17, 2012 at 02:39:17PM +0800, Wanlong Gao wrote:
On 09/11/2012 08:53 PM, Wanlong Gao wrote:
New api mke2fs for full configuration of filesystem.
Hi Rich,
I fixed as your comments, but see this error, "Fatal error: exception Failure("function mke2journal has tests but does not test itself") "
How should I fix this problem ? This means that the mke2journal test doesn't test the mke2journal function. That's because you shouldn't change the tests of the deprecated functions (mke2journal etc). Leave them alone. But you should copy those tests into mke2fs, changing them to use mke2fs (which you did, but only partially).
OK, got it. Thank you.
And can you review the other parts? Sure, later (today hopefully).
OK. Thanks, Wanlong Gao
New api mke2fs for full configuration of filesystem. Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- Hi Rich, I made this new version by rebasing against the lastest tree, there is something wrong with the test of "mke2journal_U", please review and teach me, thank you. Regards, Wanlong Gao daemon/ext2.c | 369 +++++++++++++++++++++++++++++++++++++++++++++- generator/actions.ml | 139 +++++++++++++++++ gobject/Makefile.inc | 6 +- guestfs-release-notes.txt | 5 + po/POTFILES | 2 + src/MAX_PROC_NR | 2 +- 6 files changed, 519 insertions(+), 4 deletions(-) diff --git a/daemon/ext2.c b/daemon/ext2.c index 40b36d2..7fc1172 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -29,7 +29,7 @@ #include "c-ctype.h" #include "actions.h" -#define MAX_ARGS 64 +#define MAX_ARGS 128 GUESTFSD_EXT_CMD(str_tune2fs, tune2fs); GUESTFSD_EXT_CMD(str_e2fsck, e2fsck); @@ -811,3 +811,370 @@ do_set_e2generation (const char *filename, int64_t generation) return 0; } + +int +do_mke2fs (const char *device, /* 0 */ + int64_t blockscount, + int64_t blocksize, + int64_t fragsize, + int64_t blockspergroup, + int64_t numberofgroups, /* 5 */ + int64_t bytesperinode, + int64_t inodesize, + int64_t journalsize, + int64_t numberofinodes, + int64_t stridesize, /* 10 */ + int64_t stripewidth, + int64_t maxonlineresize, + int reservedblockspercentage, + int mmpupdateinterval, + const char *journaldevice, /* 15 */ + const char *label, + const char *lastmounteddir, + const char *creatoros, + const char *fstype, + const char *usagetype, /* 20 */ + const char *uuid, + int forcecreate, + int writesbandgrouponly, + int lazyitableinit, + int lazyjournalinit, /* 25 */ + int testfs, + int discard, + int quotatype, + int extent, + int filetype, /* 30 */ + int flexbg, + int hasjournal, + int journaldev, + int largefile, + int quota, /* 35 */ + int resizeinode, + int sparsesuper, + int uninitbg) +{ + int r; + char *err = NULL; + const char *argv[MAX_ARGS]; + char blockscount_s[64]; + char blocksize_s[64]; + char fragsize_s[64]; + char blockspergroup_s[64]; + char numberofgroups_s[64]; + char bytesperinode_s[64]; + char inodesize_s[64]; + char journalsize_s[64]; + char journaldevice_s[256]; + char reservedblockspercentage_s[64]; + char numberofinodes_s[64]; + char mmpupdateinterval_s[84]; + char stridesize_s[74]; + char stripewidth_s[84]; + char maxonlineresize_s[74]; + size_t i = 0; + + ADD_ARG (argv, i, str_mke2fs); + + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSIZE_BITMASK) { + if (blocksize < 0) { + reply_with_error ("blocksize must be >= 0"); + goto error; + } + snprintf (blocksize_s, sizeof blocksize_s, "%" PRIi64, blocksize); + ADD_ARG (argv, i, "-b"); + ADD_ARG (argv, i, blocksize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FRAGSIZE_BITMASK) { + if (fragsize < 0) { + reply_with_error ("fragsize must be >= 0"); + goto error; + } + snprintf (fragsize_s, sizeof fragsize_s, "%" PRIi64, fragsize); + ADD_ARG (argv, i, "-f"); + ADD_ARG (argv, i, fragsize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FORCECREATE_BITMASK) { + if (forcecreate) + ADD_ARG (argv, i, "-F"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSPERGROUP_BITMASK) { + if (blockspergroup < 0) { + reply_with_error ("blockspergroup must be >= 0"); + goto error; + } + snprintf (blockspergroup_s, sizeof blockspergroup_s, + "%" PRIi64, blockspergroup); + ADD_ARG (argv, i, "-g"); + ADD_ARG (argv, i, blockspergroup_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_NUMBEROFGROUPS_BITMASK) { + if (numberofgroups < 0) { + reply_with_error ("numberofgroups must be >= 0"); + goto error; + } + snprintf (numberofgroups_s, sizeof numberofgroups_s, + "%" PRIi64, numberofgroups); + ADD_ARG (argv, i, "-G"); + ADD_ARG (argv, i, numberofgroups_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_BYTESPERINODE_BITMASK) { + if (bytesperinode < 0) { + reply_with_error ("bytesperinode must be >= 0"); + goto error; + } + snprintf (bytesperinode_s, sizeof bytesperinode_s, "%" PRIi64, bytesperinode); + ADD_ARG (argv, i, "-i"); + ADD_ARG (argv, i, bytesperinode_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_INODESIZE_BITMASK) { + if (inodesize < 0) { + reply_with_error ("inodesize must be >= 0"); + goto error; + } + snprintf (inodesize_s, sizeof inodesize_s, "%" PRIi64, inodesize); + ADD_ARG (argv, i, "-I"); + ADD_ARG (argv, i, inodesize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALSIZE_BITMASK) { + if (journalsize < 0) { + reply_with_error ("journalsize must be >= 0"); + goto error; + } + snprintf (journalsize_s, sizeof journalsize_s, + "size=" "%" PRIi64, journalsize); + ADD_ARG (argv, i, "-J"); + ADD_ARG (argv, i, journalsize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALDEVICE_BITMASK) { + if (journaldevice) { + snprintf (journaldevice_s, sizeof journaldevice_s, + "device=%s", journaldevice); + ADD_ARG (argv, i, "-J"); + ADD_ARG (argv, i, journaldevice_s); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_LABEL_BITMASK) { + if (label) { + ADD_ARG (argv, i, "-L"); + ADD_ARG (argv, i, label); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_RESERVEDBLOCKSPERCENTAGE_BITMASK) { + if (reservedblockspercentage < 0) { + reply_with_error ("reservedblockspercentage must be >= 0"); + goto error; + } + snprintf (reservedblockspercentage_s, sizeof reservedblockspercentage_s, + "%" PRIi32, reservedblockspercentage); + ADD_ARG (argv, i, "-m"); + ADD_ARG (argv, i, reservedblockspercentage_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LASTMOUNTEDDIR_BITMASK) { + if (lastmounteddir) { + ADD_ARG (argv, i, "-M"); + ADD_ARG (argv, i, lastmounteddir); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_NUMBEROFINODES_BITMASK) { + if (numberofinodes < 0) { + reply_with_error ("numberofinodes must be >= 0"); + goto error; + } + snprintf (numberofinodes_s, sizeof numberofinodes_s, + "%" PRIi64, numberofinodes); + ADD_ARG (argv, i, "-N"); + ADD_ARG (argv, i, numberofinodes_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_CREATOROS_BITMASK) { + if (creatoros) { + ADD_ARG (argv, i, "-o"); + ADD_ARG (argv, i, creatoros); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_WRITESBANDGROUPONLY_BITMASK) { + if (writesbandgrouponly) + ADD_ARG (argv, i, "-S"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FSTYPE_BITMASK) { + if (fstype) { + ADD_ARG (argv, i, "-t"); + ADD_ARG (argv, i, fstype); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_USAGETYPE_BITMASK) { + if (usagetype) { + ADD_ARG (argv, i, "-T"); + ADD_ARG (argv, i, usagetype); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_UUID_BITMASK) { + if (uuid) { + ADD_ARG (argv, i, "-U"); + ADD_ARG (argv, i, uuid); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_MMPUPDATEINTERVAL_BITMASK) { + if (mmpupdateinterval < 0) { + reply_with_error ("mmpupdateinterval must be >= 0"); + goto error; + } + snprintf (mmpupdateinterval_s, sizeof mmpupdateinterval_s, + "mmp_update_interval=" "%" PRIi32, mmpupdateinterval); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, mmpupdateinterval_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_STRIDESIZE_BITMASK) { + if (stridesize < 0) { + reply_with_error ("stridesize must be >= 0"); + goto error; + } + snprintf (stridesize_s, sizeof stridesize_s, + "stride=" "%" PRIi64, stridesize); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, stridesize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_STRIPEWIDTH_BITMASK) { + if (stripewidth< 0) { + reply_with_error ("stripewidth must be >= 0"); + goto error; + } + snprintf (stripewidth_s, sizeof stripewidth_s, + "stripe_width=" "%" PRIi64, stripewidth); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, stripewidth_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_MAXONLINERESIZE_BITMASK) { + if (maxonlineresize < 0) { + reply_with_error ("maxonlineresize must be >= 0"); + goto error; + } + snprintf (maxonlineresize_s, sizeof maxonlineresize_s, + "resize=" "%" PRIi64, maxonlineresize); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, maxonlineresize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LAZYITABLEINIT_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (lazyitableinit) + ADD_ARG (argv, i, "lazy_itable_init=1"); + else + ADD_ARG (argv, i, "lazy_itable_init=0"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LAZYJOURNALINIT_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (lazyjournalinit) + ADD_ARG (argv, i, "lazy_journal_init=1"); + else + ADD_ARG (argv, i, "lazy_journal_init=0"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_TESTFS_BITMASK) { + if (testfs) { + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, "test_fs"); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_DISCARD_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (discard) + ADD_ARG (argv, i, "discard"); + else + ADD_ARG (argv, i, "nodiscard"); + } + + if (optargs_bitmask & GUESTFS_MKE2FS_EXTENT_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (extent) + ADD_ARG (argv, i, "extent"); + else + ADD_ARG (argv, i, "^extent"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FILETYPE_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (filetype) + ADD_ARG (argv, i, "filetype"); + else + ADD_ARG (argv, i, "^filetype"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FLEXBG_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (flexbg) + ADD_ARG (argv, i, "flexbg"); + else + ADD_ARG (argv, i, "^flexbg"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_HASJOURNAL_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (hasjournal) + ADD_ARG (argv, i, "has_journal"); + else + ADD_ARG (argv, i, "^has_journal"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALDEV_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (journaldev) + ADD_ARG (argv, i, "journal_dev"); + else + ADD_ARG (argv, i, "^journal_dev"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LARGEFILE_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (largefile) + ADD_ARG (argv, i, "large_file"); + else + ADD_ARG (argv, i, "^large_file"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_QUOTA_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (quota) + ADD_ARG (argv, i, "quota"); + else + ADD_ARG (argv, i, "^quota"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_RESIZEINODE_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (resizeinode) + ADD_ARG (argv, i, "resize_inode"); + else + ADD_ARG (argv, i, "^resize_inode"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_SPARSESUPER_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (sparsesuper) + ADD_ARG (argv, i, "sparse_super"); + else + ADD_ARG (argv, i, "^sparse_super"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_UNINITBG_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (uninitbg) + ADD_ARG (argv, i, "uninit_bg"); + else + ADD_ARG (argv, i, "^uninit_bg"); + } + + ADD_ARG (argv, i, device); + + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSCOUNT_BITMASK) { + if (blockscount < 0) { + reply_with_error ("blockscount must be >= 0"); + goto error; + } + snprintf (blockscount_s, sizeof blockscount_s, "%" PRIi64, blockscount); + ADD_ARG (argv, i, blockscount_s); + } + + ADD_ARG (argv, i, NULL); + + r = commandv (NULL, &err, argv); + if (r == -1) { + reply_with_error ("%s: %s", device, err); + goto error; + } + + free (err); + return 0; + +error: + if (err) free (err); + return -1; +} diff --git a/generator/actions.ml b/generator/actions.ml index a17fed0..32f91df 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -6091,6 +6091,7 @@ the requested cluster size." }; name = "mke2journal"; style = RErr, [Int "blocksize"; Device "device"], []; proc_nr = Some 188; + deprecated_by = Some "mke2fs"; tests = [ InitEmpty, Always, TestOutput ( [["part_init"; "/dev/sda"; "mbr"]; @@ -6098,6 +6099,22 @@ the requested cluster size." }; ["part_add"; "/dev/sda"; "p"; "204800"; "-64"]; ["mke2journal"; "4096"; "/dev/sda1"]; ["mke2fs_J"; "ext2"; "4096"; "/dev/sda2"; "/dev/sda1"]; + ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "NOARG"; + "NOARG"; "NOARG"; "NOARG"; "NOARG"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; "true"; ""; ""; + ""; ""; ""]; + ["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "/dev/sda1"; + "NOARG"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; ["mount"; "/dev/sda2"; "/"]; ["write"; "/new"; "new file contents"]; ["cat"; "/new"]], "new file contents") @@ -6113,6 +6130,7 @@ to the command: name = "mke2journal_L"; style = RErr, [Int "blocksize"; String "label"; Device "device"], []; proc_nr = Some 189; + deprecated_by = Some "mke2fs"; tests = [ InitEmpty, Always, TestOutput ( [["part_init"; "/dev/sda"; "mbr"]; @@ -6120,6 +6138,22 @@ to the command: ["part_add"; "/dev/sda"; "p"; "204800"; "-64"]; ["mke2journal_L"; "4096"; "JOURNAL"; "/dev/sda1"]; ["mke2fs_JL"; "ext2"; "4096"; "/dev/sda2"; "JOURNAL"]; + ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "/dev/sda1"; + "JOURNAL"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; "true"; ""; ""; + ""; ""; ""]; + ["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "LABEL=JOURNAL"; + "JOURNAL"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; ["mount"; "/dev/sda2"; "/"]; ["write"; "/new"; "new file contents"]; ["cat"; "/new"]], "new file contents") @@ -6132,6 +6166,7 @@ This creates an ext2 external journal on C<device> with label C<label>." }; name = "mke2journal_U"; style = RErr, [Int "blocksize"; String "uuid"; Device "device"], []; proc_nr = Some 190; + deprecated_by = Some "mke2fs"; optional = Some "linuxfsuuid"; tests = (let uuid = uuidgen () in [ @@ -6141,6 +6176,22 @@ This creates an ext2 external journal on C<device> with label C<label>." }; ["part_add"; "/dev/sda"; "p"; "204800"; "-64"]; ["mke2journal_U"; "4096"; uuid; "/dev/sda1"]; ["mke2fs_JU"; "ext2"; "4096"; "/dev/sda2"; uuid]; + ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "NOARG"; + "NOARG"; "NOARG"; "NOARG"; "NOARG"; "NOARG"; + uuid; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; + ["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "UUID=uuid"; + "JOURNAL"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; ["mount"; "/dev/sda2"; "/"]; ["write"; "/new"; "new file contents"]; ["cat"; "/new"]], "new file contents") @@ -6153,6 +6204,7 @@ This creates an ext2 external journal on C<device> with UUID C<uuid>." }; name = "mke2fs_J"; style = RErr, [String "fstype"; Int "blocksize"; Device "device"; Device "journal"], []; proc_nr = Some 191; + deprecated_by = Some "mke2fs"; shortdesc = "make ext2/3/4 filesystem with external journal"; longdesc = "\ This creates an ext2/3/4 filesystem on C<device> with @@ -6167,6 +6219,7 @@ See also C<guestfs_mke2journal>." }; name = "mke2fs_JL"; style = RErr, [String "fstype"; Int "blocksize"; Device "device"; String "label"], []; proc_nr = Some 192; + deprecated_by = Some "mke2fs"; shortdesc = "make ext2/3/4 filesystem with external journal"; longdesc = "\ This creates an ext2/3/4 filesystem on C<device> with @@ -6178,6 +6231,7 @@ See also C<guestfs_mke2journal_L>." }; name = "mke2fs_JU"; style = RErr, [String "fstype"; Int "blocksize"; Device "device"; String "uuid"], []; proc_nr = Some 193; + deprecated_by = Some "mke2fs"; optional = Some "linuxfsuuid"; shortdesc = "make ext2/3/4 filesystem with external journal"; longdesc = "\ @@ -9829,6 +9883,91 @@ This call cannot remove directories. Use C<guestfs_rmdir> to remove an empty directory, or C<guestfs_rm_rf> to remove directories recursively." }; + { defaults with + name = "mke2fs"; + style = RErr, [Device "device"], [OInt64 "blockscount"; OInt64 "blocksize"; OInt64 "fragsize"; OInt64 "blockspergroup"; OInt64 "numberofgroups"; OInt64 "bytesperinode"; OInt64 "inodesize"; OInt64 "journalsize"; OInt64 "numberofinodes"; OInt64 "stridesize"; OInt64 "stripewidth"; OInt64 "maxonlineresize"; OInt "reservedblockspercentage"; OInt "mmpupdateinterval"; OString "journaldevice"; OString "label"; OString "lastmounteddir"; OString "creatoros"; OString "fstype"; OString "usagetype"; OString "uuid"; OBool "forcecreate"; OBool "writesbandgrouponly"; OBool "lazyitableinit"; OBool "lazyjournalinit"; OBool "testfs"; OBool "discard"; OBool "quotatype"; OBool "extent"; OBool "filetype"; OBool "flexbg"; OBool "hasjournal"; OBool "journaldev"; OBool "largefile"; OBool "quota"; OBool "resizeinode"; OBool "sparsesuper"; OBool "uninitbg"]; + proc_nr = Some 368; + tests = [ + InitEmpty, Always, TestOutput ( + [["part_init"; "/dev/sda"; "mbr"]; + ["part_add"; "/dev/sda"; "p"; "64"; "204799"]; + ["part_add"; "/dev/sda"; "p"; "204800"; "-64"]; + ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "NOARG"; + "NOARG"; "NOARG"; "NOARG"; "NOARG"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; "true"; ""; ""; + ""; ""; ""]; + ["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "/dev/sda1"; + "NOARG"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; + ["mount"; "/dev/sda2"; "/"]; + ["write"; "/new"; "new file contents"]; + ["cat"; "/new"]], "new file contents"); + InitEmpty, Always, TestOutput ( + [["part_init"; "/dev/sda"; "mbr"]; + ["part_add"; "/dev/sda"; "p"; "64"; "204799"]; + ["part_add"; "/dev/sda"; "p"; "204800"; "-64"]; + ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "/dev/sda1"; + "JOURNAL"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; "true"; ""; ""; + ""; ""; ""]; + ["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "LABEL=JOURNAL"; + "JOURNAL"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; + ["mount"; "/dev/sda2"; "/"]; + ["write"; "/new"; "new file contents"]; + ["cat"; "/new"]], "new file contents"); + InitEmpty, Always, TestOutput ( + [["part_init"; "/dev/sda"; "mbr"]; + ["part_add"; "/dev/sda"; "p"; "64"; "204799"]; + ["part_add"; "/dev/sda"; "p"; "204800"; "-64"]; + ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "NOARG"; + "NOARG"; "NOARG"; "NOARG"; "NOARG"; "NOARG"; +(* there is something wrong with uuid *) + "uuid"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; + ["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "UUID=uuid"; + "JOURNAL"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; + ["mount"; "/dev/sda2"; "/"]; + ["write"; "/new"; "new file contents"]; + ["cat"; "/new"]], "new file contents") + + ]; + shortdesc = "create an ext2/ext3/ext4 filesystem on device"; + longdesc = "\ +C<mke2fs> is used to create an ext2, ext3, or ext4 filesystem, +usually in a disk partition. C<device> is the special file corresponding +to the device (e.g /dev/sdXX). C<blockscount> is the number of blocks +on C<device>. If omitted, C<mke2fs> automagically figures the file system +size." }; + ] (* Non-API meta-commands available only in guestfish. diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc index e0d00d5..c4532c9 100644 --- a/gobject/Makefile.inc +++ b/gobject/Makefile.inc @@ -80,7 +80,8 @@ guestfs_gobject_headers= \ include/guestfs-gobject/optargs-rsync_out.h \ include/guestfs-gobject/optargs-xfs_admin.h \ include/guestfs-gobject/optargs-hivex_open.h \ - include/guestfs-gobject/optargs-xfs_repair.h + include/guestfs-gobject/optargs-xfs_repair.h \ + include/guestfs-gobject/optargs-mke2fs.h guestfs_gobject_sources= \ src/session.c \ @@ -142,4 +143,5 @@ guestfs_gobject_sources= \ src/optargs-rsync_out.c \ src/optargs-xfs_admin.c \ src/optargs-hivex_open.c \ - src/optargs-xfs_repair.c + src/optargs-xfs_repair.c \ + src/optargs-mke2fs.c diff --git a/guestfs-release-notes.txt b/guestfs-release-notes.txt index e4ddefd..4f3860d 100644 --- a/guestfs-release-notes.txt +++ b/guestfs-release-notes.txt @@ -120,6 +120,7 @@ RELEASE NOTES FOR LIBGUESTFS 1.20 For further information, see https://bugzilla.redhat.com/show_bug.cgi?id=788642 + <https://bugzilla.redhat.com/show_bug.cgi?id=788642> New APIs @@ -1659,10 +1660,14 @@ BUGS To get a list of bugs against libguestfs, use this link: https://bugzilla.redhat.com/buglist.cgi?component=libguestfs&product=Vi rtualization+Tools + <https://bugzilla.redhat.com/buglist.cgi?component=libguestfs&product=V + irtualization+Tools> To report a new bug against libguestfs, use this link: https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product= Virtualization+Tools + <https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product + =Virtualization+Tools> When reporting a bug, please supply: diff --git a/po/POTFILES b/po/POTFILES index 129c80f..4bd8509 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -136,6 +136,7 @@ fish/tilde.c fish/time.c format/format.c fuse/guestmount.c +gobject/docs/guestfs-scan.c gobject/src/optargs-add_domain.c gobject/src/optargs-add_drive.c gobject/src/optargs-btrfs_filesystem_resize.c @@ -155,6 +156,7 @@ gobject/src/optargs-internal_test.c gobject/src/optargs-internal_test_63_optargs.c gobject/src/optargs-internal_test_only_optargs.c gobject/src/optargs-md_create.c +gobject/src/optargs-mke2fs.c gobject/src/optargs-mkfs.c gobject/src/optargs-mkfs_btrfs.c gobject/src/optargs-mkswap.c diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 526204c..cb35cf9 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -367 +368 -- 1.7.12
On 09/18/2012 04:22 PM, Wanlong Gao wrote:
New api mke2fs for full configuration of filesystem.
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> ---
Hi Rich,
I made this new version by rebasing against the lastest tree, there is something wrong with the test of "mke2journal_U", please review and teach me, thank you.
Regards, Wanlong Gao
daemon/ext2.c | 369 +++++++++++++++++++++++++++++++++++++++++++++- generator/actions.ml | 139 +++++++++++++++++ gobject/Makefile.inc | 6 +- guestfs-release-notes.txt | 5 + po/POTFILES | 2 + src/MAX_PROC_NR | 2 +- 6 files changed, 519 insertions(+), 4 deletions(-)
diff --git a/daemon/ext2.c b/daemon/ext2.c index 40b36d2..7fc1172 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -29,7 +29,7 @@ #include "c-ctype.h" #include "actions.h"
-#define MAX_ARGS 64 +#define MAX_ARGS 128
[..]
+ { defaults with + name = "mke2fs"; + style = RErr, [Device "device"], [OInt64 "blockscount"; OInt64 "blocksize"; OInt64 "fragsize"; OInt64 "blockspergroup"; OInt64 "numberofgroups"; OInt64 "bytesperinode"; OInt64 "inodesize"; OInt64 "journalsize"; OInt64 "numberofinodes"; OInt64 "stridesize"; OInt64 "stripewidth"; OInt64 "maxonlineresize"; OInt "reservedblockspercentage"; OInt "mmpupdateinterval"; OString "journaldevice"; OString "label"; OString "lastmounteddir"; OString "creatoros"; OString "fstype"; OString "usagetype"; OString "uuid"; OBool "forcecreate"; OBool "writesbandgrouponly"; OBool "lazyitableinit"; OBool "lazyjournalinit"; OBool "testfs"; OBool "discard"; OBool "quotatype"; OBool "extent"; OBool "filetype"; OBool "flexbg"; OBool "hasjournal"; OBool "journaldev"; OBool "largefile"; OBool "quota"; OBool "resizeinode"; OBool "sparsesuper"; OBool "uninitbg"]; + proc_nr = Some 368; + tests = [ + InitEmpty, Always, TestOutput ( + [["part_init"; "/dev/sda"; "mbr"]; + ["part_add"; "/dev/sda"; "p"; "64"; "204799"]; + ["part_add"; "/dev/sda"; "p"; "204800"; "-64"]; + ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "NOARG"; + "NOARG"; "NOARG"; "NOARG"; "NOARG"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; "true"; ""; ""; + ""; ""; ""]; + ["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "/dev/sda1"; + "NOARG"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; + ["mount"; "/dev/sda2"; "/"]; + ["write"; "/new"; "new file contents"]; + ["cat"; "/new"]], "new file contents"); + InitEmpty, Always, TestOutput ( + [["part_init"; "/dev/sda"; "mbr"]; + ["part_add"; "/dev/sda"; "p"; "64"; "204799"]; + ["part_add"; "/dev/sda"; "p"; "204800"; "-64"]; + ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "/dev/sda1"; + "JOURNAL"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; "true"; ""; ""; + ""; ""; ""]; + ["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "LABEL=JOURNAL"; + "JOURNAL"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; + ["mount"; "/dev/sda2"; "/"]; + ["write"; "/new"; "new file contents"]; + ["cat"; "/new"]], "new file contents"); + InitEmpty, Always, TestOutput ( + [["part_init"; "/dev/sda"; "mbr"]; + ["part_add"; "/dev/sda"; "p"; "64"; "204799"]; + ["part_add"; "/dev/sda"; "p"; "204800"; "-64"]; + ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "NOARG"; + "NOARG"; "NOARG"; "NOARG"; "NOARG"; "NOARG"; +(* there is something wrong with uuid *)
Can you teach me how to test the "uuid" here? Thanks, Wanlong Gao
On Wed, Sep 19, 2012 at 04:54:28PM +0800, Wanlong Gao wrote:
+ { defaults with + name = "mke2fs"; + style = RErr, [Device "device"], [OInt64 "blockscount"; OInt64 "blocksize"; OInt64 "fragsize"; OInt64 "blockspergroup"; OInt64 "numberofgroups"; OInt64 "bytesperinode"; OInt64 "inodesize"; OInt64 "journalsize"; OInt64 "numberofinodes"; OInt64 "stridesize"; OInt64 "stripewidth"; OInt64 "maxonlineresize"; OInt "reservedblockspercentage"; OInt "mmpupdateinterval"; OString "journaldevice"; OString "label"; OString "lastmounteddir"; OString "creatoros"; OString "fstype"; OString "usagetype"; OString "uuid"; OBool "forcecreate"; OBool "writesbandgrouponly"; OBool "lazyitableinit"; OBool "lazyjournalinit"; OBool "testfs"; OBool "discard"; OBool "quotatype"; OBool "extent"; OBool "filetype"; OBool "flexbg"; OBool "hasjournal"; OBool "journaldev"; OBool "largefile"; OBool "quota"; OBool "resizeinode"; OBool "sparsesuper"; OBool "uninitbg"]; + proc_nr = Some 368; + tests = [ + InitEmpty, Always, TestOutput ( + [["part_init"; "/dev/sda"; "mbr"]; + ["part_add"; "/dev/sda"; "p"; "64"; "204799"]; + ["part_add"; "/dev/sda"; "p"; "204800"; "-64"]; + ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "NOARG"; + "NOARG"; "NOARG"; "NOARG"; "NOARG"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; "true"; ""; ""; + ""; ""; ""]; + ["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "/dev/sda1"; + "NOARG"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; + ["mount"; "/dev/sda2"; "/"]; + ["write"; "/new"; "new file contents"]; + ["cat"; "/new"]], "new file contents"); + InitEmpty, Always, TestOutput ( + [["part_init"; "/dev/sda"; "mbr"]; + ["part_add"; "/dev/sda"; "p"; "64"; "204799"]; + ["part_add"; "/dev/sda"; "p"; "204800"; "-64"]; + ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "/dev/sda1"; + "JOURNAL"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; "true"; ""; ""; + ""; ""; ""]; + ["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "LABEL=JOURNAL"; + "JOURNAL"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; + ["mount"; "/dev/sda2"; "/"]; + ["write"; "/new"; "new file contents"]; + ["cat"; "/new"]], "new file contents"); + InitEmpty, Always, TestOutput ( + [["part_init"; "/dev/sda"; "mbr"]; + ["part_add"; "/dev/sda"; "p"; "64"; "204799"]; + ["part_add"; "/dev/sda"; "p"; "204800"; "-64"]; + ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "NOARG"; + "NOARG"; "NOARG"; "NOARG"; "NOARG"; "NOARG"; +(* there is something wrong with uuid *)
Can you teach me how to test the "uuid" here?
Probably the best thing is to look at the tests for set_e2uuid: tests = (let uuid = uuidgen () in [ InitBasicFS, Always, TestOutput ( [["set_e2uuid"; "/dev/sda1"; uuid]; ["get_e2uuid"; "/dev/sda1"]], uuid); 'tests = (let uuid = uuidgen () in [...])' causes a fresh uuid to be generated (by 'uuidgen ()') and returned in 'uuid', and then substituted in the list of tests. In this case, 'uuid' is used as a parameter to 'set_e2uuid', and to test the return value from 'get_e2uuid'. Note that the random UUID changes each time the generator runs. The actual C code generated by the above test (ie. in tests/c-api/tests.c) is below. In this case, the value of the 'uuid' variable in the OCaml code was "d62333[..]". /* TestOutput for set_e2uuid (0) */ const char *expected = "d623335b-b2c7-461c-46a8-05a4f2af7bee"; { const char *device = "/dev/sda1"; const char *uuid = "d623335b-b2c7-461c-46a8-05a4f2af7bee"; int r; suppress_error = 0; r = guestfs_set_e2uuid (g, device, uuid); if (r == -1) return -1; } { const char *device = "/dev/sda1"; char *r; suppress_error = 0; r = guestfs_get_e2uuid (g, device); if (r == NULL) return -1; if (STRNEQ (r, expected)) { fprintf (stderr, "test_set_e2uuid_0: expected \"%s\" but got \"%s\"\n", expected, r); return -1; } free (r); } Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
New api mke2fs for full configuration of filesystem. Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/ext2.c | 369 +++++++++++++++++++++++++++++++++++++++++++++- generator/actions.ml | 91 ++++++++++++ gobject/Makefile.inc | 6 +- po/POTFILES | 2 + src/MAX_PROC_NR | 2 +- 6 files changed, 471 insertions(+), 4 deletions(-) diff --git a/daemon/ext2.c b/daemon/ext2.c index 40b36d2..7fc1172 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -29,7 +29,7 @@ #include "c-ctype.h" #include "actions.h" -#define MAX_ARGS 64 +#define MAX_ARGS 128 GUESTFSD_EXT_CMD(str_tune2fs, tune2fs); GUESTFSD_EXT_CMD(str_e2fsck, e2fsck); @@ -811,3 +811,370 @@ do_set_e2generation (const char *filename, int64_t generation) return 0; } + +int +do_mke2fs (const char *device, /* 0 */ + int64_t blockscount, + int64_t blocksize, + int64_t fragsize, + int64_t blockspergroup, + int64_t numberofgroups, /* 5 */ + int64_t bytesperinode, + int64_t inodesize, + int64_t journalsize, + int64_t numberofinodes, + int64_t stridesize, /* 10 */ + int64_t stripewidth, + int64_t maxonlineresize, + int reservedblockspercentage, + int mmpupdateinterval, + const char *journaldevice, /* 15 */ + const char *label, + const char *lastmounteddir, + const char *creatoros, + const char *fstype, + const char *usagetype, /* 20 */ + const char *uuid, + int forcecreate, + int writesbandgrouponly, + int lazyitableinit, + int lazyjournalinit, /* 25 */ + int testfs, + int discard, + int quotatype, + int extent, + int filetype, /* 30 */ + int flexbg, + int hasjournal, + int journaldev, + int largefile, + int quota, /* 35 */ + int resizeinode, + int sparsesuper, + int uninitbg) +{ + int r; + char *err = NULL; + const char *argv[MAX_ARGS]; + char blockscount_s[64]; + char blocksize_s[64]; + char fragsize_s[64]; + char blockspergroup_s[64]; + char numberofgroups_s[64]; + char bytesperinode_s[64]; + char inodesize_s[64]; + char journalsize_s[64]; + char journaldevice_s[256]; + char reservedblockspercentage_s[64]; + char numberofinodes_s[64]; + char mmpupdateinterval_s[84]; + char stridesize_s[74]; + char stripewidth_s[84]; + char maxonlineresize_s[74]; + size_t i = 0; + + ADD_ARG (argv, i, str_mke2fs); + + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSIZE_BITMASK) { + if (blocksize < 0) { + reply_with_error ("blocksize must be >= 0"); + goto error; + } + snprintf (blocksize_s, sizeof blocksize_s, "%" PRIi64, blocksize); + ADD_ARG (argv, i, "-b"); + ADD_ARG (argv, i, blocksize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FRAGSIZE_BITMASK) { + if (fragsize < 0) { + reply_with_error ("fragsize must be >= 0"); + goto error; + } + snprintf (fragsize_s, sizeof fragsize_s, "%" PRIi64, fragsize); + ADD_ARG (argv, i, "-f"); + ADD_ARG (argv, i, fragsize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FORCECREATE_BITMASK) { + if (forcecreate) + ADD_ARG (argv, i, "-F"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSPERGROUP_BITMASK) { + if (blockspergroup < 0) { + reply_with_error ("blockspergroup must be >= 0"); + goto error; + } + snprintf (blockspergroup_s, sizeof blockspergroup_s, + "%" PRIi64, blockspergroup); + ADD_ARG (argv, i, "-g"); + ADD_ARG (argv, i, blockspergroup_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_NUMBEROFGROUPS_BITMASK) { + if (numberofgroups < 0) { + reply_with_error ("numberofgroups must be >= 0"); + goto error; + } + snprintf (numberofgroups_s, sizeof numberofgroups_s, + "%" PRIi64, numberofgroups); + ADD_ARG (argv, i, "-G"); + ADD_ARG (argv, i, numberofgroups_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_BYTESPERINODE_BITMASK) { + if (bytesperinode < 0) { + reply_with_error ("bytesperinode must be >= 0"); + goto error; + } + snprintf (bytesperinode_s, sizeof bytesperinode_s, "%" PRIi64, bytesperinode); + ADD_ARG (argv, i, "-i"); + ADD_ARG (argv, i, bytesperinode_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_INODESIZE_BITMASK) { + if (inodesize < 0) { + reply_with_error ("inodesize must be >= 0"); + goto error; + } + snprintf (inodesize_s, sizeof inodesize_s, "%" PRIi64, inodesize); + ADD_ARG (argv, i, "-I"); + ADD_ARG (argv, i, inodesize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALSIZE_BITMASK) { + if (journalsize < 0) { + reply_with_error ("journalsize must be >= 0"); + goto error; + } + snprintf (journalsize_s, sizeof journalsize_s, + "size=" "%" PRIi64, journalsize); + ADD_ARG (argv, i, "-J"); + ADD_ARG (argv, i, journalsize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALDEVICE_BITMASK) { + if (journaldevice) { + snprintf (journaldevice_s, sizeof journaldevice_s, + "device=%s", journaldevice); + ADD_ARG (argv, i, "-J"); + ADD_ARG (argv, i, journaldevice_s); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_LABEL_BITMASK) { + if (label) { + ADD_ARG (argv, i, "-L"); + ADD_ARG (argv, i, label); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_RESERVEDBLOCKSPERCENTAGE_BITMASK) { + if (reservedblockspercentage < 0) { + reply_with_error ("reservedblockspercentage must be >= 0"); + goto error; + } + snprintf (reservedblockspercentage_s, sizeof reservedblockspercentage_s, + "%" PRIi32, reservedblockspercentage); + ADD_ARG (argv, i, "-m"); + ADD_ARG (argv, i, reservedblockspercentage_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LASTMOUNTEDDIR_BITMASK) { + if (lastmounteddir) { + ADD_ARG (argv, i, "-M"); + ADD_ARG (argv, i, lastmounteddir); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_NUMBEROFINODES_BITMASK) { + if (numberofinodes < 0) { + reply_with_error ("numberofinodes must be >= 0"); + goto error; + } + snprintf (numberofinodes_s, sizeof numberofinodes_s, + "%" PRIi64, numberofinodes); + ADD_ARG (argv, i, "-N"); + ADD_ARG (argv, i, numberofinodes_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_CREATOROS_BITMASK) { + if (creatoros) { + ADD_ARG (argv, i, "-o"); + ADD_ARG (argv, i, creatoros); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_WRITESBANDGROUPONLY_BITMASK) { + if (writesbandgrouponly) + ADD_ARG (argv, i, "-S"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FSTYPE_BITMASK) { + if (fstype) { + ADD_ARG (argv, i, "-t"); + ADD_ARG (argv, i, fstype); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_USAGETYPE_BITMASK) { + if (usagetype) { + ADD_ARG (argv, i, "-T"); + ADD_ARG (argv, i, usagetype); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_UUID_BITMASK) { + if (uuid) { + ADD_ARG (argv, i, "-U"); + ADD_ARG (argv, i, uuid); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_MMPUPDATEINTERVAL_BITMASK) { + if (mmpupdateinterval < 0) { + reply_with_error ("mmpupdateinterval must be >= 0"); + goto error; + } + snprintf (mmpupdateinterval_s, sizeof mmpupdateinterval_s, + "mmp_update_interval=" "%" PRIi32, mmpupdateinterval); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, mmpupdateinterval_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_STRIDESIZE_BITMASK) { + if (stridesize < 0) { + reply_with_error ("stridesize must be >= 0"); + goto error; + } + snprintf (stridesize_s, sizeof stridesize_s, + "stride=" "%" PRIi64, stridesize); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, stridesize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_STRIPEWIDTH_BITMASK) { + if (stripewidth< 0) { + reply_with_error ("stripewidth must be >= 0"); + goto error; + } + snprintf (stripewidth_s, sizeof stripewidth_s, + "stripe_width=" "%" PRIi64, stripewidth); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, stripewidth_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_MAXONLINERESIZE_BITMASK) { + if (maxonlineresize < 0) { + reply_with_error ("maxonlineresize must be >= 0"); + goto error; + } + snprintf (maxonlineresize_s, sizeof maxonlineresize_s, + "resize=" "%" PRIi64, maxonlineresize); + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, maxonlineresize_s); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LAZYITABLEINIT_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (lazyitableinit) + ADD_ARG (argv, i, "lazy_itable_init=1"); + else + ADD_ARG (argv, i, "lazy_itable_init=0"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LAZYJOURNALINIT_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (lazyjournalinit) + ADD_ARG (argv, i, "lazy_journal_init=1"); + else + ADD_ARG (argv, i, "lazy_journal_init=0"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_TESTFS_BITMASK) { + if (testfs) { + ADD_ARG (argv, i, "-E"); + ADD_ARG (argv, i, "test_fs"); + } + } + if (optargs_bitmask & GUESTFS_MKE2FS_DISCARD_BITMASK) { + ADD_ARG (argv, i, "-E"); + if (discard) + ADD_ARG (argv, i, "discard"); + else + ADD_ARG (argv, i, "nodiscard"); + } + + if (optargs_bitmask & GUESTFS_MKE2FS_EXTENT_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (extent) + ADD_ARG (argv, i, "extent"); + else + ADD_ARG (argv, i, "^extent"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FILETYPE_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (filetype) + ADD_ARG (argv, i, "filetype"); + else + ADD_ARG (argv, i, "^filetype"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_FLEXBG_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (flexbg) + ADD_ARG (argv, i, "flexbg"); + else + ADD_ARG (argv, i, "^flexbg"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_HASJOURNAL_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (hasjournal) + ADD_ARG (argv, i, "has_journal"); + else + ADD_ARG (argv, i, "^has_journal"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_JOURNALDEV_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (journaldev) + ADD_ARG (argv, i, "journal_dev"); + else + ADD_ARG (argv, i, "^journal_dev"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_LARGEFILE_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (largefile) + ADD_ARG (argv, i, "large_file"); + else + ADD_ARG (argv, i, "^large_file"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_QUOTA_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (quota) + ADD_ARG (argv, i, "quota"); + else + ADD_ARG (argv, i, "^quota"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_RESIZEINODE_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (resizeinode) + ADD_ARG (argv, i, "resize_inode"); + else + ADD_ARG (argv, i, "^resize_inode"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_SPARSESUPER_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (sparsesuper) + ADD_ARG (argv, i, "sparse_super"); + else + ADD_ARG (argv, i, "^sparse_super"); + } + if (optargs_bitmask & GUESTFS_MKE2FS_UNINITBG_BITMASK) { + ADD_ARG (argv, i, "-O"); + if (uninitbg) + ADD_ARG (argv, i, "uninit_bg"); + else + ADD_ARG (argv, i, "^uninit_bg"); + } + + ADD_ARG (argv, i, device); + + if (optargs_bitmask & GUESTFS_MKE2FS_BLOCKSCOUNT_BITMASK) { + if (blockscount < 0) { + reply_with_error ("blockscount must be >= 0"); + goto error; + } + snprintf (blockscount_s, sizeof blockscount_s, "%" PRIi64, blockscount); + ADD_ARG (argv, i, blockscount_s); + } + + ADD_ARG (argv, i, NULL); + + r = commandv (NULL, &err, argv); + if (r == -1) { + reply_with_error ("%s: %s", device, err); + goto error; + } + + free (err); + return 0; + +error: + if (err) free (err); + return -1; +} diff --git a/generator/actions.ml b/generator/actions.ml index 438b316..d21864e 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -6099,6 +6099,7 @@ the requested cluster size." }; name = "mke2journal"; style = RErr, [Int "blocksize"; Device "device"], []; proc_nr = Some 188; + deprecated_by = Some "mke2fs"; tests = [ InitEmpty, Always, TestOutput ( [["part_init"; "/dev/sda"; "mbr"]; @@ -6121,6 +6122,7 @@ to the command: name = "mke2journal_L"; style = RErr, [Int "blocksize"; String "label"; Device "device"], []; proc_nr = Some 189; + deprecated_by = Some "mke2fs"; tests = [ InitEmpty, Always, TestOutput ( [["part_init"; "/dev/sda"; "mbr"]; @@ -6140,6 +6142,7 @@ This creates an ext2 external journal on C<device> with label C<label>." }; name = "mke2journal_U"; style = RErr, [Int "blocksize"; String "uuid"; Device "device"], []; proc_nr = Some 190; + deprecated_by = Some "mke2fs"; optional = Some "linuxfsuuid"; tests = (let uuid = uuidgen () in [ @@ -6161,6 +6164,7 @@ This creates an ext2 external journal on C<device> with UUID C<uuid>." }; name = "mke2fs_J"; style = RErr, [String "fstype"; Int "blocksize"; Device "device"; Device "journal"], []; proc_nr = Some 191; + deprecated_by = Some "mke2fs"; shortdesc = "make ext2/3/4 filesystem with external journal"; longdesc = "\ This creates an ext2/3/4 filesystem on C<device> with @@ -6175,6 +6179,7 @@ See also C<guestfs_mke2journal>." }; name = "mke2fs_JL"; style = RErr, [String "fstype"; Int "blocksize"; Device "device"; String "label"], []; proc_nr = Some 192; + deprecated_by = Some "mke2fs"; shortdesc = "make ext2/3/4 filesystem with external journal"; longdesc = "\ This creates an ext2/3/4 filesystem on C<device> with @@ -6186,6 +6191,7 @@ See also C<guestfs_mke2journal_L>." }; name = "mke2fs_JU"; style = RErr, [String "fstype"; Int "blocksize"; Device "device"; String "uuid"], []; proc_nr = Some 193; + deprecated_by = Some "mke2fs"; optional = Some "linuxfsuuid"; shortdesc = "make ext2/3/4 filesystem with external journal"; longdesc = "\ @@ -9837,6 +9843,91 @@ This call cannot remove directories. Use C<guestfs_rmdir> to remove an empty directory, or C<guestfs_rm_rf> to remove directories recursively." }; + { defaults with + name = "mke2fs"; + style = RErr, [Device "device"], [OInt64 "blockscount"; OInt64 "blocksize"; OInt64 "fragsize"; OInt64 "blockspergroup"; OInt64 "numberofgroups"; OInt64 "bytesperinode"; OInt64 "inodesize"; OInt64 "journalsize"; OInt64 "numberofinodes"; OInt64 "stridesize"; OInt64 "stripewidth"; OInt64 "maxonlineresize"; OInt "reservedblockspercentage"; OInt "mmpupdateinterval"; OString "journaldevice"; OString "label"; OString "lastmounteddir"; OString "creatoros"; OString "fstype"; OString "usagetype"; OString "uuid"; OBool "forcecreate"; OBool "writesbandgrouponly"; OBool "lazyitableinit"; OBool "lazyjournalinit"; OBool "testfs"; OBool "discard"; OBool "quotatype"; OBool "extent"; OBool "filetype"; OBool "flexbg"; OBool "hasjournal"; OBool "journaldev"; OBool "largefile"; OBool "quota"; OBool "resizeinode"; OBool "sparsesuper"; OBool "uninitbg"]; + proc_nr = Some 368; + tests = + (let uuid = uuidgen () in + let uuid_s = "UUID=" ^ uuid in [ + InitEmpty, Always, TestOutput ( + [["part_init"; "/dev/sda"; "mbr"]; + ["part_add"; "/dev/sda"; "p"; "64"; "204799"]; + ["part_add"; "/dev/sda"; "p"; "204800"; "-64"]; + ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "NOARG"; + "NOARG"; "NOARG"; "NOARG"; "NOARG"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; "true"; ""; ""; + ""; ""; ""]; + ["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "/dev/sda1"; + "NOARG"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; + ["mount"; "/dev/sda2"; "/"]; + ["write"; "/new"; "new file contents"]; + ["cat"; "/new"]], "new file contents"); + InitEmpty, Always, TestOutput ( + [["part_init"; "/dev/sda"; "mbr"]; + ["part_add"; "/dev/sda"; "p"; "64"; "204799"]; + ["part_add"; "/dev/sda"; "p"; "204800"; "-64"]; + ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "/dev/sda1"; + "JOURNAL"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; "true"; ""; ""; + ""; ""; ""]; + ["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "LABEL=JOURNAL"; + "JOURNAL"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; + ["mount"; "/dev/sda2"; "/"]; + ["write"; "/new"; "new file contents"]; + ["cat"; "/new"]], "new file contents"); + InitEmpty, Always, TestOutput ( + [["part_init"; "/dev/sda"; "mbr"]; + ["part_add"; "/dev/sda"; "p"; "64"; "204799"]; + ["part_add"; "/dev/sda"; "p"; "204800"; "-64"]; + ["mke2fs"; "/dev/sda1"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; "NOARG"; + "NOARG"; "NOARG"; "NOARG"; "NOARG"; "NOARG"; + uuid; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; + ["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; uuid_s; + "JOURNAL"; "NOARG"; "NOARG"; "ext2"; "NOARG"; + "NOARG"; "true"; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""; ""; ""; + ""; ""; ""]; + ["mount"; "/dev/sda2"; "/"]; + ["write"; "/new"; "new file contents"]; + ["cat"; "/new"]], "new file contents") + ]); + shortdesc = "create an ext2/ext3/ext4 filesystem on device"; + longdesc = "\ +C<mke2fs> is used to create an ext2, ext3, or ext4 filesystem, +usually in a disk partition. C<device> is the special file corresponding +to the device (e.g /dev/sdXX). C<blockscount> is the number of blocks +on C<device>. If omitted, C<mke2fs> automagically figures the file system +size." }; + ] (* Non-API meta-commands available only in guestfish. diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc index e0d00d5..c4532c9 100644 --- a/gobject/Makefile.inc +++ b/gobject/Makefile.inc @@ -80,7 +80,8 @@ guestfs_gobject_headers= \ include/guestfs-gobject/optargs-rsync_out.h \ include/guestfs-gobject/optargs-xfs_admin.h \ include/guestfs-gobject/optargs-hivex_open.h \ - include/guestfs-gobject/optargs-xfs_repair.h + include/guestfs-gobject/optargs-xfs_repair.h \ + include/guestfs-gobject/optargs-mke2fs.h guestfs_gobject_sources= \ src/session.c \ @@ -142,4 +143,5 @@ guestfs_gobject_sources= \ src/optargs-rsync_out.c \ src/optargs-xfs_admin.c \ src/optargs-hivex_open.c \ - src/optargs-xfs_repair.c + src/optargs-xfs_repair.c \ + src/optargs-mke2fs.c diff --git a/po/POTFILES b/po/POTFILES index 129c80f..4bd8509 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -136,6 +136,7 @@ fish/tilde.c fish/time.c format/format.c fuse/guestmount.c +gobject/docs/guestfs-scan.c gobject/src/optargs-add_domain.c gobject/src/optargs-add_drive.c gobject/src/optargs-btrfs_filesystem_resize.c @@ -155,6 +156,7 @@ gobject/src/optargs-internal_test.c gobject/src/optargs-internal_test_63_optargs.c gobject/src/optargs-internal_test_only_optargs.c gobject/src/optargs-md_create.c +gobject/src/optargs-mke2fs.c gobject/src/optargs-mkfs.c gobject/src/optargs-mkfs_btrfs.c gobject/src/optargs-mkswap.c diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 526204c..cb35cf9 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -367 +368 -- 1.7.12
On Mon, Sep 24, 2012 at 04:32:51PM +0800, Wanlong Gao wrote:
New api mke2fs for full configuration of filesystem.
Thanks - this was much easier to review. ACK to both of these patches. I'm just running the tests and then I'll push it later today. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
On Mon, Sep 03, 2012 at 11:44:15AM +0800, Wanlong Gao wrote:
On 08/31/2012 06:00 PM, Wanlong Gao wrote:
New api mke2fs for full configuration of filesystem.
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/ext2.c | 452 +++++++++++++++++++++++++++++++++++++++++ generator/generator_actions.ml | 18 ++ gobject/Makefile.inc | 6 +- src/MAX_PROC_NR | 2 +- 4 files changed, 475 insertions(+), 3 deletions(-)
Hi Rich,
I got the following error when compiling with this patch, it seems that the long typed optargs_bitmask can't accept more than 31 optional arguments, it's odd ? This mke2fs api has about 43 optional arguments, so 64bit typed optargs_bitmask is enough, but why does long type limit the arguments to 31?
No, this is a bug. The limit should be *63* optional arguments. (Actually we could do more than this in future, but we'd have to change the XDR protocol to support that).
./com/redhat/et/libguestfs/GuestFS.java:14731: error: integer number too large: 2147483648 _optargs_bitmask |= 2147483648;
This is a bug in the generator: I'll post a fix soon. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
On 09/03/2012 03:44 PM, Richard W.M. Jones wrote:
On Mon, Sep 03, 2012 at 11:44:15AM +0800, Wanlong Gao wrote:
On 08/31/2012 06:00 PM, Wanlong Gao wrote:
New api mke2fs for full configuration of filesystem.
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/ext2.c | 452 +++++++++++++++++++++++++++++++++++++++++ generator/generator_actions.ml | 18 ++ gobject/Makefile.inc | 6 +- src/MAX_PROC_NR | 2 +- 4 files changed, 475 insertions(+), 3 deletions(-)
Hi Rich,
I got the following error when compiling with this patch, it seems that the long typed optargs_bitmask can't accept more than 31 optional arguments, it's odd ? This mke2fs api has about 43 optional arguments, so 64bit typed optargs_bitmask is enough, but why does long type limit the arguments to 31?
No, this is a bug.
The limit should be *63* optional arguments. (Actually we could do more than this in future, but we'd have to change the XDR protocol to support that).
./com/redhat/et/libguestfs/GuestFS.java:14731: error: integer number too large: 2147483648 _optargs_bitmask |= 2147483648;
This is a bug in the generator: I'll post a fix soon.
I sent a patch already. Thanks, Wanlong Gao
Rich.
On Mon, Sep 03, 2012 at 11:44:15AM +0800, Wanlong Gao wrote:
On 08/31/2012 06:00 PM, Wanlong Gao wrote:
New api mke2fs for full configuration of filesystem.
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/ext2.c | 452 +++++++++++++++++++++++++++++++++++++++++ generator/generator_actions.ml | 18 ++ gobject/Makefile.inc | 6 +- src/MAX_PROC_NR | 2 +- 4 files changed, 475 insertions(+), 3 deletions(-)
Hi Rich,
I got the following error when compiling with this patch, it seems that the long typed optargs_bitmask can't accept more than 31 optional arguments, it's odd ? This mke2fs api has about 43 optional arguments, so 64bit typed optargs_bitmask is enough, but why does long type limit the arguments to 31?
./com/redhat/et/libguestfs/GuestFS.java:14731: error: integer number too large: 2147483648 _optargs_bitmask |= 2147483648;
I fixed this and added a test, thanks: https://github.com/libguestfs/libguestfs/commit/f65dee769d1fc53c5963c381bf8a... https://github.com/libguestfs/libguestfs/commit/3820a2578c120056683a4b152b72... Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
participants (2)
-
Richard W.M. Jones -
Wanlong Gao