NEW API:ext:mke2fs

New api mke2fs for full configuration of filesystem.

Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>

RWMJ:
 - Update description.
 - Run and fix the tests.
 - Remove bogus filename from po/POTFILES.
This commit is contained in:
Wanlong Gao
2012-09-24 16:32:51 +08:00
committed by Richard W.M. Jones
parent a297a9348f
commit 0c2aab966a
5 changed files with 464 additions and 4 deletions

View File

@@ -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;
}

View File

@@ -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,90 @@ 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"; ""; "";
""; ""; ""];
["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; "";
""; ""; ""; ""; "";
""; ""; ""; ""; "/dev/sda1";
"NOARG"; "NOARG"; "NOARG"; "ext2"; "NOARG";
"NOARG"; ""; ""; ""; "";
""; ""; ""; ""; "";
""; ""; ""; ""; "";
""; ""; ""];
["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"; ""; "";
""; ""; ""];
["mke2fs"; "/dev/sda2"; ""; "4096"; ""; ""; "";
""; ""; ""; ""; "";
""; ""; ""; ""; "LABEL=JOURNAL";
"JOURNAL"; "NOARG"; "NOARG"; "ext2"; "NOARG";
"NOARG"; ""; ""; ""; "";
""; ""; ""; ""; "";
""; ""; ""; ""; "";
""; ""; ""];
["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
on C<device>. The optional C<blockscount> is the size of the
filesystem in blocks. If omitted it defaults to the size of
C<device>." (* XXX document optional args properly *) };
]
(* Non-API meta-commands available only in guestfish.

View File

@@ -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

View File

@@ -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

View File

@@ -1 +1 @@
367
368