From b348eacbc4d84337856cf7cca518d61c63e92631 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Wed, 15 Apr 2009 17:48:54 +0100 Subject: [PATCH] Generated code for blockdev_* calls, RInt64, enhanced tests. --- daemon/actions.h | 10 + daemon/stubs.c | 282 +++++ fish/cmds.c | 226 +++- fish/completion.c | 10 + guestfish-actions.pod | 99 ++ guestfs-actions.pod | 130 ++ ocaml/guestfs.ml | 10 + ocaml/guestfs.mli | 30 + ocaml/guestfs_c_actions.c | 231 ++++ perl/Guestfs.xs | 126 ++ perl/lib/Sys/Guestfs.pm | 79 ++ python/guestfs-py.c | 256 ++++ python/guestfs.py | 30 + src/guestfs-actions.c | 717 +++++++++++ src/guestfs-actions.h | 10 + src/guestfs_protocol.c | 152 +++ src/guestfs_protocol.h | 118 +- src/guestfs_protocol.x | 71 ++ tests.c | 2930 ++++++++++++++++++++++++++------------------- 19 files changed, 4253 insertions(+), 1264 deletions(-) diff --git a/daemon/actions.h b/daemon/actions.h index 53f3b79..76ce8fc 100644 --- a/daemon/actions.h +++ b/daemon/actions.h @@ -76,3 +76,13 @@ extern guestfs_int_stat *do_stat (const char *path); extern guestfs_int_stat *do_lstat (const char *path); extern guestfs_int_statvfs *do_statvfs (const char *path); extern char **do_tune2fs_l (const char *device); +extern int do_blockdev_setro (const char *device); +extern int do_blockdev_setrw (const char *device); +extern int do_blockdev_getro (const char *device); +extern int do_blockdev_getss (const char *device); +extern int do_blockdev_getbsz (const char *device); +extern int do_blockdev_setbsz (const char *device, int blocksize); +extern int64_t do_blockdev_getsz (const char *device); +extern int64_t do_blockdev_getsize64 (const char *device); +extern int do_blockdev_flushbufs (const char *device); +extern int do_blockdev_rereadpt (const char *device); diff --git a/daemon/stubs.c b/daemon/stubs.c index a6175cb..2711000 100644 --- a/daemon/stubs.c +++ b/daemon/stubs.c @@ -1332,6 +1332,258 @@ done: xdr_free ((xdrproc_t) xdr_guestfs_tune2fs_l_args, (char *) &args); } +static void blockdev_setro_stub (XDR *xdr_in) +{ + int r; + struct guestfs_blockdev_setro_args args; + const char *device; + + memset (&args, 0, sizeof args); + + if (!xdr_guestfs_blockdev_setro_args (xdr_in, &args)) { + reply_with_error ("%s: daemon failed to decode procedure arguments", "blockdev_setro"); + return; + } + device = args.device; + + r = do_blockdev_setro (device); + if (r == -1) + /* do_blockdev_setro has already called reply_with_error */ + goto done; + + reply (NULL, NULL); +done: + xdr_free ((xdrproc_t) xdr_guestfs_blockdev_setro_args, (char *) &args); +} + +static void blockdev_setrw_stub (XDR *xdr_in) +{ + int r; + struct guestfs_blockdev_setrw_args args; + const char *device; + + memset (&args, 0, sizeof args); + + if (!xdr_guestfs_blockdev_setrw_args (xdr_in, &args)) { + reply_with_error ("%s: daemon failed to decode procedure arguments", "blockdev_setrw"); + return; + } + device = args.device; + + r = do_blockdev_setrw (device); + if (r == -1) + /* do_blockdev_setrw has already called reply_with_error */ + goto done; + + reply (NULL, NULL); +done: + xdr_free ((xdrproc_t) xdr_guestfs_blockdev_setrw_args, (char *) &args); +} + +static void blockdev_getro_stub (XDR *xdr_in) +{ + int r; + struct guestfs_blockdev_getro_args args; + const char *device; + + memset (&args, 0, sizeof args); + + if (!xdr_guestfs_blockdev_getro_args (xdr_in, &args)) { + reply_with_error ("%s: daemon failed to decode procedure arguments", "blockdev_getro"); + return; + } + device = args.device; + + r = do_blockdev_getro (device); + if (r == -1) + /* do_blockdev_getro has already called reply_with_error */ + goto done; + + struct guestfs_blockdev_getro_ret ret; + ret.ro = r; + reply ((xdrproc_t) &xdr_guestfs_blockdev_getro_ret, (char *) &ret); +done: + xdr_free ((xdrproc_t) xdr_guestfs_blockdev_getro_args, (char *) &args); +} + +static void blockdev_getss_stub (XDR *xdr_in) +{ + int r; + struct guestfs_blockdev_getss_args args; + const char *device; + + memset (&args, 0, sizeof args); + + if (!xdr_guestfs_blockdev_getss_args (xdr_in, &args)) { + reply_with_error ("%s: daemon failed to decode procedure arguments", "blockdev_getss"); + return; + } + device = args.device; + + r = do_blockdev_getss (device); + if (r == -1) + /* do_blockdev_getss has already called reply_with_error */ + goto done; + + struct guestfs_blockdev_getss_ret ret; + ret.sectorsize = r; + reply ((xdrproc_t) &xdr_guestfs_blockdev_getss_ret, (char *) &ret); +done: + xdr_free ((xdrproc_t) xdr_guestfs_blockdev_getss_args, (char *) &args); +} + +static void blockdev_getbsz_stub (XDR *xdr_in) +{ + int r; + struct guestfs_blockdev_getbsz_args args; + const char *device; + + memset (&args, 0, sizeof args); + + if (!xdr_guestfs_blockdev_getbsz_args (xdr_in, &args)) { + reply_with_error ("%s: daemon failed to decode procedure arguments", "blockdev_getbsz"); + return; + } + device = args.device; + + r = do_blockdev_getbsz (device); + if (r == -1) + /* do_blockdev_getbsz has already called reply_with_error */ + goto done; + + struct guestfs_blockdev_getbsz_ret ret; + ret.blocksize = r; + reply ((xdrproc_t) &xdr_guestfs_blockdev_getbsz_ret, (char *) &ret); +done: + xdr_free ((xdrproc_t) xdr_guestfs_blockdev_getbsz_args, (char *) &args); +} + +static void blockdev_setbsz_stub (XDR *xdr_in) +{ + int r; + struct guestfs_blockdev_setbsz_args args; + const char *device; + int blocksize; + + memset (&args, 0, sizeof args); + + if (!xdr_guestfs_blockdev_setbsz_args (xdr_in, &args)) { + reply_with_error ("%s: daemon failed to decode procedure arguments", "blockdev_setbsz"); + return; + } + device = args.device; + blocksize = args.blocksize; + + r = do_blockdev_setbsz (device, blocksize); + if (r == -1) + /* do_blockdev_setbsz has already called reply_with_error */ + goto done; + + reply (NULL, NULL); +done: + xdr_free ((xdrproc_t) xdr_guestfs_blockdev_setbsz_args, (char *) &args); +} + +static void blockdev_getsz_stub (XDR *xdr_in) +{ + int64_t r; + struct guestfs_blockdev_getsz_args args; + const char *device; + + memset (&args, 0, sizeof args); + + if (!xdr_guestfs_blockdev_getsz_args (xdr_in, &args)) { + reply_with_error ("%s: daemon failed to decode procedure arguments", "blockdev_getsz"); + return; + } + device = args.device; + + r = do_blockdev_getsz (device); + if (r == -1) + /* do_blockdev_getsz has already called reply_with_error */ + goto done; + + struct guestfs_blockdev_getsz_ret ret; + ret.sizeinsectors = r; + reply ((xdrproc_t) &xdr_guestfs_blockdev_getsz_ret, (char *) &ret); +done: + xdr_free ((xdrproc_t) xdr_guestfs_blockdev_getsz_args, (char *) &args); +} + +static void blockdev_getsize64_stub (XDR *xdr_in) +{ + int64_t r; + struct guestfs_blockdev_getsize64_args args; + const char *device; + + memset (&args, 0, sizeof args); + + if (!xdr_guestfs_blockdev_getsize64_args (xdr_in, &args)) { + reply_with_error ("%s: daemon failed to decode procedure arguments", "blockdev_getsize64"); + return; + } + device = args.device; + + r = do_blockdev_getsize64 (device); + if (r == -1) + /* do_blockdev_getsize64 has already called reply_with_error */ + goto done; + + struct guestfs_blockdev_getsize64_ret ret; + ret.sizeinbytes = r; + reply ((xdrproc_t) &xdr_guestfs_blockdev_getsize64_ret, (char *) &ret); +done: + xdr_free ((xdrproc_t) xdr_guestfs_blockdev_getsize64_args, (char *) &args); +} + +static void blockdev_flushbufs_stub (XDR *xdr_in) +{ + int r; + struct guestfs_blockdev_flushbufs_args args; + const char *device; + + memset (&args, 0, sizeof args); + + if (!xdr_guestfs_blockdev_flushbufs_args (xdr_in, &args)) { + reply_with_error ("%s: daemon failed to decode procedure arguments", "blockdev_flushbufs"); + return; + } + device = args.device; + + r = do_blockdev_flushbufs (device); + if (r == -1) + /* do_blockdev_flushbufs has already called reply_with_error */ + goto done; + + reply (NULL, NULL); +done: + xdr_free ((xdrproc_t) xdr_guestfs_blockdev_flushbufs_args, (char *) &args); +} + +static void blockdev_rereadpt_stub (XDR *xdr_in) +{ + int r; + struct guestfs_blockdev_rereadpt_args args; + const char *device; + + memset (&args, 0, sizeof args); + + if (!xdr_guestfs_blockdev_rereadpt_args (xdr_in, &args)) { + reply_with_error ("%s: daemon failed to decode procedure arguments", "blockdev_rereadpt"); + return; + } + device = args.device; + + r = do_blockdev_rereadpt (device); + if (r == -1) + /* do_blockdev_rereadpt has already called reply_with_error */ + goto done; + + reply (NULL, NULL); +done: + xdr_free ((xdrproc_t) xdr_guestfs_blockdev_rereadpt_args, (char *) &args); +} + void dispatch_incoming_message (XDR *xdr_in) { switch (proc_nr) { @@ -1500,6 +1752,36 @@ void dispatch_incoming_message (XDR *xdr_in) case GUESTFS_PROC_TUNE2FS_L: tune2fs_l_stub (xdr_in); break; + case GUESTFS_PROC_BLOCKDEV_SETRO: + blockdev_setro_stub (xdr_in); + break; + case GUESTFS_PROC_BLOCKDEV_SETRW: + blockdev_setrw_stub (xdr_in); + break; + case GUESTFS_PROC_BLOCKDEV_GETRO: + blockdev_getro_stub (xdr_in); + break; + case GUESTFS_PROC_BLOCKDEV_GETSS: + blockdev_getss_stub (xdr_in); + break; + case GUESTFS_PROC_BLOCKDEV_GETBSZ: + blockdev_getbsz_stub (xdr_in); + break; + case GUESTFS_PROC_BLOCKDEV_SETBSZ: + blockdev_setbsz_stub (xdr_in); + break; + case GUESTFS_PROC_BLOCKDEV_GETSZ: + blockdev_getsz_stub (xdr_in); + break; + case GUESTFS_PROC_BLOCKDEV_GETSIZE64: + blockdev_getsize64_stub (xdr_in); + break; + case GUESTFS_PROC_BLOCKDEV_FLUSHBUFS: + blockdev_flushbufs_stub (xdr_in); + break; + case GUESTFS_PROC_BLOCKDEV_REREADPT: + blockdev_rereadpt_stub (xdr_in); + break; default: reply_with_error ("dispatch_incoming_message: unknown procedure number %d", proc_nr); } diff --git a/fish/cmds.c b/fish/cmds.c index c68924a..8ee72d2 100644 --- a/fish/cmds.c +++ b/fish/cmds.c @@ -46,6 +46,16 @@ void list_commands (void) printf ("%-20s %s\n", "aug-rm", "remove an Augeas path"); printf ("%-20s %s\n", "aug-save", "write all pending Augeas changes to disk"); printf ("%-20s %s\n", "aug-set", "set Augeas path to value"); + printf ("%-20s %s\n", "blockdev-flushbufs", "flush device buffers"); + printf ("%-20s %s\n", "blockdev-getbsz", "get blocksize of block device"); + printf ("%-20s %s\n", "blockdev-getro", "is block device set to read-only"); + printf ("%-20s %s\n", "blockdev-getsize64", "get total size of device in bytes"); + printf ("%-20s %s\n", "blockdev-getss", "get sectorsize of block device"); + printf ("%-20s %s\n", "blockdev-getsz", "get total size of device in 512-byte sectors"); + printf ("%-20s %s\n", "blockdev-rereadpt", "reread partition table"); + printf ("%-20s %s\n", "blockdev-setbsz", "set blocksize of block device"); + printf ("%-20s %s\n", "blockdev-setro", "set block device to read-only"); + printf ("%-20s %s\n", "blockdev-setrw", "set block device to read-write"); printf ("%-20s %s\n", "cat", "list the contents of a file"); printf ("%-20s %s\n", "chmod", "change file mode"); printf ("%-20s %s\n", "chown", "change file owner and group"); @@ -300,6 +310,36 @@ void display_command (const char *cmd) if (strcasecmp (cmd, "tune2fs_l") == 0 || strcasecmp (cmd, "tune2fs-l") == 0) pod2text ("tune2fs-l - get ext2/ext3 superblock details", " tune2fs-l \n\nThis returns the contents of the ext2 or ext3 filesystem superblock\non C.\n\nIt is the same as running C. See L\nmanpage for more details. The list of fields returned isn't\nclearly defined, and depends on both the version of C\nthat libguestfs was built against, and the filesystem itself."); else + if (strcasecmp (cmd, "blockdev_setro") == 0 || strcasecmp (cmd, "blockdev-setro") == 0) + pod2text ("blockdev-setro - set block device to read-only", " blockdev-setro \n\nSets the block device named C to read-only.\n\nThis uses the L command."); + else + if (strcasecmp (cmd, "blockdev_setrw") == 0 || strcasecmp (cmd, "blockdev-setrw") == 0) + pod2text ("blockdev-setrw - set block device to read-write", " blockdev-setrw \n\nSets the block device named C to read-write.\n\nThis uses the L command."); + else + if (strcasecmp (cmd, "blockdev_getro") == 0 || strcasecmp (cmd, "blockdev-getro") == 0) + pod2text ("blockdev-getro - is block device set to read-only", " blockdev-getro \n\nReturns a boolean indicating if the block device is read-only\n(true if read-only, false if not).\n\nThis uses the L command."); + else + if (strcasecmp (cmd, "blockdev_getss") == 0 || strcasecmp (cmd, "blockdev-getss") == 0) + pod2text ("blockdev-getss - get sectorsize of block device", " blockdev-getss \n\nThis returns the size of sectors on a block device.\nUsually 512, but can be larger for modern devices.\n\n(Note, this is not the size in sectors, use C\nfor that).\n\nThis uses the L command."); + else + if (strcasecmp (cmd, "blockdev_getbsz") == 0 || strcasecmp (cmd, "blockdev-getbsz") == 0) + pod2text ("blockdev-getbsz - get blocksize of block device", " blockdev-getbsz \n\nThis returns the block size of a device.\n\n(Note this is different from both I and\nI).\n\nThis uses the L command."); + else + if (strcasecmp (cmd, "blockdev_setbsz") == 0 || strcasecmp (cmd, "blockdev-setbsz") == 0) + pod2text ("blockdev-setbsz - set blocksize of block device", " blockdev-setbsz \n\nThis sets the block size of a device.\n\n(Note this is different from both I and\nI).\n\nThis uses the L command."); + else + if (strcasecmp (cmd, "blockdev_getsz") == 0 || strcasecmp (cmd, "blockdev-getsz") == 0) + pod2text ("blockdev-getsz - get total size of device in 512-byte sectors", " blockdev-getsz \n\nThis returns the size of the device in units of 512-byte sectors\n(even if the sectorsize isn't 512 bytes ... weird).\n\nSee also C for the real sector size of\nthe device, and C for the more\nuseful I.\n\nThis uses the L command."); + else + if (strcasecmp (cmd, "blockdev_getsize64") == 0 || strcasecmp (cmd, "blockdev-getsize64") == 0) + pod2text ("blockdev-getsize64 - get total size of device in bytes", " blockdev-getsize64 \n\nThis returns the size of the device in bytes.\n\nSee also C.\n\nThis uses the L command."); + else + if (strcasecmp (cmd, "blockdev_flushbufs") == 0 || strcasecmp (cmd, "blockdev-flushbufs") == 0) + pod2text ("blockdev-flushbufs - flush device buffers", " blockdev-flushbufs \n\nThis tells the kernel to flush internal buffers associated\nwith C.\n\nThis uses the L command."); + else + if (strcasecmp (cmd, "blockdev_rereadpt") == 0 || strcasecmp (cmd, "blockdev-rereadpt") == 0) + pod2text ("blockdev-rereadpt - reread partition table", " blockdev-rereadpt \n\nReread the partition table on C.\n\nThis uses the L command."); + else display_builtin_command (cmd); } @@ -861,7 +901,7 @@ static int run_aug_defvar (const char *cmd, int argc, char *argv[]) expr = strcmp (argv[1], "") != 0 ? argv[1] : NULL; r = guestfs_aug_defvar (g, name, expr); if (r == -1) return -1; - if (r) printf ("%d\n", r); + printf ("%d\n", r); return 0; } @@ -950,7 +990,7 @@ static int run_aug_rm (const char *cmd, int argc, char *argv[]) path = argv[0]; r = guestfs_aug_rm (g, path); if (r == -1) return -1; - if (r) printf ("%d\n", r); + printf ("%d\n", r); return 0; } @@ -1456,6 +1496,158 @@ static int run_tune2fs_l (const char *cmd, int argc, char *argv[]) return 0; } +static int run_blockdev_setro (const char *cmd, int argc, char *argv[]) +{ + int r; + const char *device; + if (argc != 1) { + fprintf (stderr, "%s should have 1 parameter(s)\n", cmd); + fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd); + return -1; + } + device = argv[0]; + r = guestfs_blockdev_setro (g, device); + return r; +} + +static int run_blockdev_setrw (const char *cmd, int argc, char *argv[]) +{ + int r; + const char *device; + if (argc != 1) { + fprintf (stderr, "%s should have 1 parameter(s)\n", cmd); + fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd); + return -1; + } + device = argv[0]; + r = guestfs_blockdev_setrw (g, device); + return r; +} + +static int run_blockdev_getro (const char *cmd, int argc, char *argv[]) +{ + int r; + const char *device; + if (argc != 1) { + fprintf (stderr, "%s should have 1 parameter(s)\n", cmd); + fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd); + return -1; + } + device = argv[0]; + r = guestfs_blockdev_getro (g, device); + if (r == -1) return -1; + if (r) printf ("true\n"); else printf ("false\n"); + return 0; +} + +static int run_blockdev_getss (const char *cmd, int argc, char *argv[]) +{ + int r; + const char *device; + if (argc != 1) { + fprintf (stderr, "%s should have 1 parameter(s)\n", cmd); + fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd); + return -1; + } + device = argv[0]; + r = guestfs_blockdev_getss (g, device); + if (r == -1) return -1; + printf ("%d\n", r); + return 0; +} + +static int run_blockdev_getbsz (const char *cmd, int argc, char *argv[]) +{ + int r; + const char *device; + if (argc != 1) { + fprintf (stderr, "%s should have 1 parameter(s)\n", cmd); + fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd); + return -1; + } + device = argv[0]; + r = guestfs_blockdev_getbsz (g, device); + if (r == -1) return -1; + printf ("%d\n", r); + return 0; +} + +static int run_blockdev_setbsz (const char *cmd, int argc, char *argv[]) +{ + int r; + const char *device; + int blocksize; + if (argc != 2) { + fprintf (stderr, "%s should have 2 parameter(s)\n", cmd); + fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd); + return -1; + } + device = argv[0]; + blocksize = atoi (argv[1]); + r = guestfs_blockdev_setbsz (g, device, blocksize); + return r; +} + +static int run_blockdev_getsz (const char *cmd, int argc, char *argv[]) +{ + int64_t r; + const char *device; + if (argc != 1) { + fprintf (stderr, "%s should have 1 parameter(s)\n", cmd); + fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd); + return -1; + } + device = argv[0]; + r = guestfs_blockdev_getsz (g, device); + if (r == -1) return -1; + printf ("%" PRIi64 "\n", r); + return 0; +} + +static int run_blockdev_getsize64 (const char *cmd, int argc, char *argv[]) +{ + int64_t r; + const char *device; + if (argc != 1) { + fprintf (stderr, "%s should have 1 parameter(s)\n", cmd); + fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd); + return -1; + } + device = argv[0]; + r = guestfs_blockdev_getsize64 (g, device); + if (r == -1) return -1; + printf ("%" PRIi64 "\n", r); + return 0; +} + +static int run_blockdev_flushbufs (const char *cmd, int argc, char *argv[]) +{ + int r; + const char *device; + if (argc != 1) { + fprintf (stderr, "%s should have 1 parameter(s)\n", cmd); + fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd); + return -1; + } + device = argv[0]; + r = guestfs_blockdev_flushbufs (g, device); + return r; +} + +static int run_blockdev_rereadpt (const char *cmd, int argc, char *argv[]) +{ + int r; + const char *device; + if (argc != 1) { + fprintf (stderr, "%s should have 1 parameter(s)\n", cmd); + fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd); + return -1; + } + device = argv[0]; + r = guestfs_blockdev_rereadpt (g, device); + return r; +} + int run_action (const char *cmd, int argc, char *argv[]) { if (strcasecmp (cmd, "launch") == 0 || strcasecmp (cmd, "run") == 0) @@ -1656,6 +1848,36 @@ int run_action (const char *cmd, int argc, char *argv[]) if (strcasecmp (cmd, "tune2fs_l") == 0 || strcasecmp (cmd, "tune2fs-l") == 0) return run_tune2fs_l (cmd, argc, argv); else + if (strcasecmp (cmd, "blockdev_setro") == 0 || strcasecmp (cmd, "blockdev-setro") == 0) + return run_blockdev_setro (cmd, argc, argv); + else + if (strcasecmp (cmd, "blockdev_setrw") == 0 || strcasecmp (cmd, "blockdev-setrw") == 0) + return run_blockdev_setrw (cmd, argc, argv); + else + if (strcasecmp (cmd, "blockdev_getro") == 0 || strcasecmp (cmd, "blockdev-getro") == 0) + return run_blockdev_getro (cmd, argc, argv); + else + if (strcasecmp (cmd, "blockdev_getss") == 0 || strcasecmp (cmd, "blockdev-getss") == 0) + return run_blockdev_getss (cmd, argc, argv); + else + if (strcasecmp (cmd, "blockdev_getbsz") == 0 || strcasecmp (cmd, "blockdev-getbsz") == 0) + return run_blockdev_getbsz (cmd, argc, argv); + else + if (strcasecmp (cmd, "blockdev_setbsz") == 0 || strcasecmp (cmd, "blockdev-setbsz") == 0) + return run_blockdev_setbsz (cmd, argc, argv); + else + if (strcasecmp (cmd, "blockdev_getsz") == 0 || strcasecmp (cmd, "blockdev-getsz") == 0) + return run_blockdev_getsz (cmd, argc, argv); + else + if (strcasecmp (cmd, "blockdev_getsize64") == 0 || strcasecmp (cmd, "blockdev-getsize64") == 0) + return run_blockdev_getsize64 (cmd, argc, argv); + else + if (strcasecmp (cmd, "blockdev_flushbufs") == 0 || strcasecmp (cmd, "blockdev-flushbufs") == 0) + return run_blockdev_flushbufs (cmd, argc, argv); + else + if (strcasecmp (cmd, "blockdev_rereadpt") == 0 || strcasecmp (cmd, "blockdev-rereadpt") == 0) + return run_blockdev_rereadpt (cmd, argc, argv); + else { fprintf (stderr, "%s: unknown command\n", cmd); return -1; diff --git a/fish/completion.c b/fish/completion.c index cee2b39..f7ba61f 100644 --- a/fish/completion.c +++ b/fish/completion.c @@ -51,6 +51,16 @@ static const char *commands[] = { "aug-save", "aug-set", "autosync", + "blockdev-flushbufs", + "blockdev-getbsz", + "blockdev-getro", + "blockdev-getsize64", + "blockdev-getss", + "blockdev-getsz", + "blockdev-rereadpt", + "blockdev-setbsz", + "blockdev-setro", + "blockdev-setrw", "cat", "cdrom", "chmod", diff --git a/guestfish-actions.pod b/guestfish-actions.pod index 28f9559..d4c0401 100644 --- a/guestfish-actions.pod +++ b/guestfish-actions.pod @@ -182,6 +182,105 @@ how files are saved. Set the value associated with C to C. +=head2 blockdev-flushbufs + + blockdev-flushbufs device + +This tells the kernel to flush internal buffers associated +with C. + +This uses the L command. + +=head2 blockdev-getbsz + + blockdev-getbsz device + +This returns the block size of a device. + +(Note this is different from both I and +I). + +This uses the L command. + +=head2 blockdev-getro + + blockdev-getro device + +Returns a boolean indicating if the block device is read-only +(true if read-only, false if not). + +This uses the L command. + +=head2 blockdev-getsize64 + + blockdev-getsize64 device + +This returns the size of the device in bytes. + +See also C. + +This uses the L command. + +=head2 blockdev-getss + + blockdev-getss device + +This returns the size of sectors on a block device. +Usually 512, but can be larger for modern devices. + +(Note, this is not the size in sectors, use C +for that). + +This uses the L command. + +=head2 blockdev-getsz + + blockdev-getsz device + +This returns the size of the device in units of 512-byte sectors +(even if the sectorsize isn't 512 bytes ... weird). + +See also C for the real sector size of +the device, and C for the more +useful I. + +This uses the L command. + +=head2 blockdev-rereadpt + + blockdev-rereadpt device + +Reread the partition table on C. + +This uses the L command. + +=head2 blockdev-setbsz + + blockdev-setbsz device blocksize + +This sets the block size of a device. + +(Note this is different from both I and +I). + +This uses the L command. + +=head2 blockdev-setro + + blockdev-setro device + +Sets the block device named C to read-only. + +This uses the L command. + +=head2 blockdev-setrw + + blockdev-setrw device + +Sets the block device named C to read-write. + +This uses the L command. + =head2 cat cat path diff --git a/guestfs-actions.pod b/guestfs-actions.pod index 889363a..cb2415c 100644 --- a/guestfs-actions.pod +++ b/guestfs-actions.pod @@ -239,6 +239,136 @@ Set the value associated with C to C. This function returns 0 on success or -1 on error. +=head2 guestfs_blockdev_flushbufs + + int guestfs_blockdev_flushbufs (guestfs_h *handle, + const char *device); + +This tells the kernel to flush internal buffers associated +with C. + +This uses the L command. + +This function returns 0 on success or -1 on error. + +=head2 guestfs_blockdev_getbsz + + int guestfs_blockdev_getbsz (guestfs_h *handle, + const char *device); + +This returns the block size of a device. + +(Note this is different from both I and +I). + +This uses the L command. + +On error this function returns -1. + +=head2 guestfs_blockdev_getro + + int guestfs_blockdev_getro (guestfs_h *handle, + const char *device); + +Returns a boolean indicating if the block device is read-only +(true if read-only, false if not). + +This uses the L command. + +This function returns a C truth value on success or -1 on error. + +=head2 guestfs_blockdev_getsize64 + + int64_t guestfs_blockdev_getsize64 (guestfs_h *handle, + const char *device); + +This returns the size of the device in bytes. + +See also C. + +This uses the L command. + +On error this function returns -1. + +=head2 guestfs_blockdev_getss + + int guestfs_blockdev_getss (guestfs_h *handle, + const char *device); + +This returns the size of sectors on a block device. +Usually 512, but can be larger for modern devices. + +(Note, this is not the size in sectors, use C +for that). + +This uses the L command. + +On error this function returns -1. + +=head2 guestfs_blockdev_getsz + + int64_t guestfs_blockdev_getsz (guestfs_h *handle, + const char *device); + +This returns the size of the device in units of 512-byte sectors +(even if the sectorsize isn't 512 bytes ... weird). + +See also C for the real sector size of +the device, and C for the more +useful I. + +This uses the L command. + +On error this function returns -1. + +=head2 guestfs_blockdev_rereadpt + + int guestfs_blockdev_rereadpt (guestfs_h *handle, + const char *device); + +Reread the partition table on C. + +This uses the L command. + +This function returns 0 on success or -1 on error. + +=head2 guestfs_blockdev_setbsz + + int guestfs_blockdev_setbsz (guestfs_h *handle, + const char *device, + int blocksize); + +This sets the block size of a device. + +(Note this is different from both I and +I). + +This uses the L command. + +This function returns 0 on success or -1 on error. + +=head2 guestfs_blockdev_setro + + int guestfs_blockdev_setro (guestfs_h *handle, + const char *device); + +Sets the block device named C to read-only. + +This uses the L command. + +This function returns 0 on success or -1 on error. + +=head2 guestfs_blockdev_setrw + + int guestfs_blockdev_setrw (guestfs_h *handle, + const char *device); + +Sets the block device named C to read-write. + +This uses the L command. + +This function returns 0 on success or -1 on error. + =head2 guestfs_cat char *guestfs_cat (guestfs_h *handle, diff --git a/ocaml/guestfs.ml b/ocaml/guestfs.ml index e29daea..6477e95 100644 --- a/ocaml/guestfs.ml +++ b/ocaml/guestfs.ml @@ -182,3 +182,13 @@ external stat : t -> string -> stat = "ocaml_guestfs_stat" external lstat : t -> string -> stat = "ocaml_guestfs_lstat" external statvfs : t -> string -> statvfs = "ocaml_guestfs_statvfs" external tune2fs_l : t -> string -> (string * string) list = "ocaml_guestfs_tune2fs_l" +external blockdev_setro : t -> string -> unit = "ocaml_guestfs_blockdev_setro" +external blockdev_setrw : t -> string -> unit = "ocaml_guestfs_blockdev_setrw" +external blockdev_getro : t -> string -> bool = "ocaml_guestfs_blockdev_getro" +external blockdev_getss : t -> string -> int = "ocaml_guestfs_blockdev_getss" +external blockdev_getbsz : t -> string -> int = "ocaml_guestfs_blockdev_getbsz" +external blockdev_setbsz : t -> string -> int -> unit = "ocaml_guestfs_blockdev_setbsz" +external blockdev_getsz : t -> string -> int64 = "ocaml_guestfs_blockdev_getsz" +external blockdev_getsize64 : t -> string -> int64 = "ocaml_guestfs_blockdev_getsize64" +external blockdev_flushbufs : t -> string -> unit = "ocaml_guestfs_blockdev_flushbufs" +external blockdev_rereadpt : t -> string -> unit = "ocaml_guestfs_blockdev_rereadpt" diff --git a/ocaml/guestfs.mli b/ocaml/guestfs.mli index e6f5231..b9b9f52 100644 --- a/ocaml/guestfs.mli +++ b/ocaml/guestfs.mli @@ -325,3 +325,33 @@ val statvfs : t -> string -> statvfs val tune2fs_l : t -> string -> (string * string) list (** get ext2/ext3 superblock details *) +val blockdev_setro : t -> string -> unit +(** set block device to read-only *) + +val blockdev_setrw : t -> string -> unit +(** set block device to read-write *) + +val blockdev_getro : t -> string -> bool +(** is block device set to read-only *) + +val blockdev_getss : t -> string -> int +(** get sectorsize of block device *) + +val blockdev_getbsz : t -> string -> int +(** get blocksize of block device *) + +val blockdev_setbsz : t -> string -> int -> unit +(** set blocksize of block device *) + +val blockdev_getsz : t -> string -> int64 +(** get total size of device in 512-byte sectors *) + +val blockdev_getsize64 : t -> string -> int64 +(** get total size of device in bytes *) + +val blockdev_flushbufs : t -> string -> unit +(** flush device buffers *) + +val blockdev_rereadpt : t -> string -> unit +(** reread partition table *) + diff --git a/ocaml/guestfs_c_actions.c b/ocaml/guestfs_c_actions.c index a3186d1..c0618b2 100644 --- a/ocaml/guestfs_c_actions.c +++ b/ocaml/guestfs_c_actions.c @@ -1934,3 +1934,234 @@ ocaml_guestfs_tune2fs_l (value gv, value devicev) CAMLreturn (rv); } +CAMLprim value +ocaml_guestfs_blockdev_setro (value gv, value devicev) +{ + CAMLparam2 (gv, devicev); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("blockdev_setro: used handle after closing it"); + + const char *device = String_val (devicev); + int r; + + caml_enter_blocking_section (); + r = guestfs_blockdev_setro (g, device); + caml_leave_blocking_section (); + if (r == -1) + ocaml_guestfs_raise_error (g, "blockdev_setro"); + + rv = Val_unit; + CAMLreturn (rv); +} + +CAMLprim value +ocaml_guestfs_blockdev_setrw (value gv, value devicev) +{ + CAMLparam2 (gv, devicev); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("blockdev_setrw: used handle after closing it"); + + const char *device = String_val (devicev); + int r; + + caml_enter_blocking_section (); + r = guestfs_blockdev_setrw (g, device); + caml_leave_blocking_section (); + if (r == -1) + ocaml_guestfs_raise_error (g, "blockdev_setrw"); + + rv = Val_unit; + CAMLreturn (rv); +} + +CAMLprim value +ocaml_guestfs_blockdev_getro (value gv, value devicev) +{ + CAMLparam2 (gv, devicev); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("blockdev_getro: used handle after closing it"); + + const char *device = String_val (devicev); + int r; + + caml_enter_blocking_section (); + r = guestfs_blockdev_getro (g, device); + caml_leave_blocking_section (); + if (r == -1) + ocaml_guestfs_raise_error (g, "blockdev_getro"); + + rv = Val_bool (r); + CAMLreturn (rv); +} + +CAMLprim value +ocaml_guestfs_blockdev_getss (value gv, value devicev) +{ + CAMLparam2 (gv, devicev); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("blockdev_getss: used handle after closing it"); + + const char *device = String_val (devicev); + int r; + + caml_enter_blocking_section (); + r = guestfs_blockdev_getss (g, device); + caml_leave_blocking_section (); + if (r == -1) + ocaml_guestfs_raise_error (g, "blockdev_getss"); + + rv = Val_int (r); + CAMLreturn (rv); +} + +CAMLprim value +ocaml_guestfs_blockdev_getbsz (value gv, value devicev) +{ + CAMLparam2 (gv, devicev); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("blockdev_getbsz: used handle after closing it"); + + const char *device = String_val (devicev); + int r; + + caml_enter_blocking_section (); + r = guestfs_blockdev_getbsz (g, device); + caml_leave_blocking_section (); + if (r == -1) + ocaml_guestfs_raise_error (g, "blockdev_getbsz"); + + rv = Val_int (r); + CAMLreturn (rv); +} + +CAMLprim value +ocaml_guestfs_blockdev_setbsz (value gv, value devicev, value blocksizev) +{ + CAMLparam3 (gv, devicev, blocksizev); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("blockdev_setbsz: used handle after closing it"); + + const char *device = String_val (devicev); + int blocksize = Int_val (blocksizev); + int r; + + caml_enter_blocking_section (); + r = guestfs_blockdev_setbsz (g, device, blocksize); + caml_leave_blocking_section (); + if (r == -1) + ocaml_guestfs_raise_error (g, "blockdev_setbsz"); + + rv = Val_unit; + CAMLreturn (rv); +} + +CAMLprim value +ocaml_guestfs_blockdev_getsz (value gv, value devicev) +{ + CAMLparam2 (gv, devicev); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("blockdev_getsz: used handle after closing it"); + + const char *device = String_val (devicev); + int64_t r; + + caml_enter_blocking_section (); + r = guestfs_blockdev_getsz (g, device); + caml_leave_blocking_section (); + if (r == -1) + ocaml_guestfs_raise_error (g, "blockdev_getsz"); + + rv = caml_copy_int64 (r); + CAMLreturn (rv); +} + +CAMLprim value +ocaml_guestfs_blockdev_getsize64 (value gv, value devicev) +{ + CAMLparam2 (gv, devicev); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("blockdev_getsize64: used handle after closing it"); + + const char *device = String_val (devicev); + int64_t r; + + caml_enter_blocking_section (); + r = guestfs_blockdev_getsize64 (g, device); + caml_leave_blocking_section (); + if (r == -1) + ocaml_guestfs_raise_error (g, "blockdev_getsize64"); + + rv = caml_copy_int64 (r); + CAMLreturn (rv); +} + +CAMLprim value +ocaml_guestfs_blockdev_flushbufs (value gv, value devicev) +{ + CAMLparam2 (gv, devicev); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("blockdev_flushbufs: used handle after closing it"); + + const char *device = String_val (devicev); + int r; + + caml_enter_blocking_section (); + r = guestfs_blockdev_flushbufs (g, device); + caml_leave_blocking_section (); + if (r == -1) + ocaml_guestfs_raise_error (g, "blockdev_flushbufs"); + + rv = Val_unit; + CAMLreturn (rv); +} + +CAMLprim value +ocaml_guestfs_blockdev_rereadpt (value gv, value devicev) +{ + CAMLparam2 (gv, devicev); + CAMLlocal1 (rv); + + guestfs_h *g = Guestfs_val (gv); + if (g == NULL) + caml_failwith ("blockdev_rereadpt: used handle after closing it"); + + const char *device = String_val (devicev); + int r; + + caml_enter_blocking_section (); + r = guestfs_blockdev_rereadpt (g, device); + caml_leave_blocking_section (); + if (r == -1) + ocaml_guestfs_raise_error (g, "blockdev_rereadpt"); + + rv = Val_unit; + CAMLreturn (rv); +} + diff --git a/perl/Guestfs.xs b/perl/Guestfs.xs index 93abd9e..beb1c99 100644 --- a/perl/Guestfs.xs +++ b/perl/Guestfs.xs @@ -1106,3 +1106,129 @@ PREINIT: } free (superblock); +void +blockdev_setro (g, device) + guestfs_h *g; + char *device; +PREINIT: + int r; + PPCODE: + r = guestfs_blockdev_setro (g, device); + if (r == -1) + croak ("blockdev_setro: %s", guestfs_last_error (g)); + +void +blockdev_setrw (g, device) + guestfs_h *g; + char *device; +PREINIT: + int r; + PPCODE: + r = guestfs_blockdev_setrw (g, device); + if (r == -1) + croak ("blockdev_setrw: %s", guestfs_last_error (g)); + +SV * +blockdev_getro (g, device) + guestfs_h *g; + char *device; +PREINIT: + int ro; + CODE: + ro = guestfs_blockdev_getro (g, device); + if (ro == -1) + croak ("blockdev_getro: %s", guestfs_last_error (g)); + RETVAL = newSViv (ro); + OUTPUT: + RETVAL + +SV * +blockdev_getss (g, device) + guestfs_h *g; + char *device; +PREINIT: + int sectorsize; + CODE: + sectorsize = guestfs_blockdev_getss (g, device); + if (sectorsize == -1) + croak ("blockdev_getss: %s", guestfs_last_error (g)); + RETVAL = newSViv (sectorsize); + OUTPUT: + RETVAL + +SV * +blockdev_getbsz (g, device) + guestfs_h *g; + char *device; +PREINIT: + int blocksize; + CODE: + blocksize = guestfs_blockdev_getbsz (g, device); + if (blocksize == -1) + croak ("blockdev_getbsz: %s", guestfs_last_error (g)); + RETVAL = newSViv (blocksize); + OUTPUT: + RETVAL + +void +blockdev_setbsz (g, device, blocksize) + guestfs_h *g; + char *device; + int blocksize; +PREINIT: + int r; + PPCODE: + r = guestfs_blockdev_setbsz (g, device, blocksize); + if (r == -1) + croak ("blockdev_setbsz: %s", guestfs_last_error (g)); + +SV * +blockdev_getsz (g, device) + guestfs_h *g; + char *device; +PREINIT: + int64_t sizeinsectors; + CODE: + sizeinsectors = guestfs_blockdev_getsz (g, device); + if (sizeinsectors == -1) + croak ("blockdev_getsz: %s", guestfs_last_error (g)); + RETVAL = my_newSVll (sizeinsectors); + OUTPUT: + RETVAL + +SV * +blockdev_getsize64 (g, device) + guestfs_h *g; + char *device; +PREINIT: + int64_t sizeinbytes; + CODE: + sizeinbytes = guestfs_blockdev_getsize64 (g, device); + if (sizeinbytes == -1) + croak ("blockdev_getsize64: %s", guestfs_last_error (g)); + RETVAL = my_newSVll (sizeinbytes); + OUTPUT: + RETVAL + +void +blockdev_flushbufs (g, device) + guestfs_h *g; + char *device; +PREINIT: + int r; + PPCODE: + r = guestfs_blockdev_flushbufs (g, device); + if (r == -1) + croak ("blockdev_flushbufs: %s", guestfs_last_error (g)); + +void +blockdev_rereadpt (g, device) + guestfs_h *g; + char *device; +PREINIT: + int r; + PPCODE: + r = guestfs_blockdev_rereadpt (g, device); + if (r == -1) + croak ("blockdev_rereadpt: %s", guestfs_last_error (g)); + diff --git a/perl/lib/Sys/Guestfs.pm b/perl/lib/Sys/Guestfs.pm index 36bedd5..a351d57 100644 --- a/perl/lib/Sys/Guestfs.pm +++ b/perl/lib/Sys/Guestfs.pm @@ -245,6 +245,85 @@ how files are saved. Set the value associated with C to C. +=item $h->blockdev_flushbufs ($device); + +This tells the kernel to flush internal buffers associated +with C. + +This uses the L command. + +=item $blocksize = $h->blockdev_getbsz ($device); + +This returns the block size of a device. + +(Note this is different from both I and +I). + +This uses the L command. + +=item $ro = $h->blockdev_getro ($device); + +Returns a boolean indicating if the block device is read-only +(true if read-only, false if not). + +This uses the L command. + +=item $sizeinbytes = $h->blockdev_getsize64 ($device); + +This returns the size of the device in bytes. + +See also C<$h-Eblockdev_getsz>. + +This uses the L command. + +=item $sectorsize = $h->blockdev_getss ($device); + +This returns the size of sectors on a block device. +Usually 512, but can be larger for modern devices. + +(Note, this is not the size in sectors, use C<$h-Eblockdev_getsz> +for that). + +This uses the L command. + +=item $sizeinsectors = $h->blockdev_getsz ($device); + +This returns the size of the device in units of 512-byte sectors +(even if the sectorsize isn't 512 bytes ... weird). + +See also C<$h-Eblockdev_getss> for the real sector size of +the device, and C<$h-Eblockdev_getsize64> for the more +useful I. + +This uses the L command. + +=item $h->blockdev_rereadpt ($device); + +Reread the partition table on C. + +This uses the L command. + +=item $h->blockdev_setbsz ($device, $blocksize); + +This sets the block size of a device. + +(Note this is different from both I and +I). + +This uses the L command. + +=item $h->blockdev_setro ($device); + +Sets the block device named C to read-only. + +This uses the L command. + +=item $h->blockdev_setrw ($device); + +Sets the block device named C to read-write. + +This uses the L command. + =item $content = $h->cat ($path); Return the contents of the file named C. diff --git a/python/guestfs-py.c b/python/guestfs-py.c index 21ecd54..c8df178 100644 --- a/python/guestfs-py.c +++ b/python/guestfs-py.c @@ -2076,6 +2076,252 @@ py_guestfs_tune2fs_l (PyObject *self, PyObject *args) return py_r; } +static PyObject * +py_guestfs_blockdev_setro (PyObject *self, PyObject *args) +{ + PyObject *py_g; + guestfs_h *g; + PyObject *py_r; + int r; + const char *device; + + if (!PyArg_ParseTuple (args, (char *) "Os:guestfs_blockdev_setro", + &py_g, &device)) + return NULL; + g = get_handle (py_g); + + r = guestfs_blockdev_setro (g, device); + if (r == -1) { + PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g)); + return NULL; + } + + Py_INCREF (Py_None); + py_r = Py_None; + return py_r; +} + +static PyObject * +py_guestfs_blockdev_setrw (PyObject *self, PyObject *args) +{ + PyObject *py_g; + guestfs_h *g; + PyObject *py_r; + int r; + const char *device; + + if (!PyArg_ParseTuple (args, (char *) "Os:guestfs_blockdev_setrw", + &py_g, &device)) + return NULL; + g = get_handle (py_g); + + r = guestfs_blockdev_setrw (g, device); + if (r == -1) { + PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g)); + return NULL; + } + + Py_INCREF (Py_None); + py_r = Py_None; + return py_r; +} + +static PyObject * +py_guestfs_blockdev_getro (PyObject *self, PyObject *args) +{ + PyObject *py_g; + guestfs_h *g; + PyObject *py_r; + int r; + const char *device; + + if (!PyArg_ParseTuple (args, (char *) "Os:guestfs_blockdev_getro", + &py_g, &device)) + return NULL; + g = get_handle (py_g); + + r = guestfs_blockdev_getro (g, device); + if (r == -1) { + PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g)); + return NULL; + } + + py_r = PyInt_FromLong ((long) r); + return py_r; +} + +static PyObject * +py_guestfs_blockdev_getss (PyObject *self, PyObject *args) +{ + PyObject *py_g; + guestfs_h *g; + PyObject *py_r; + int r; + const char *device; + + if (!PyArg_ParseTuple (args, (char *) "Os:guestfs_blockdev_getss", + &py_g, &device)) + return NULL; + g = get_handle (py_g); + + r = guestfs_blockdev_getss (g, device); + if (r == -1) { + PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g)); + return NULL; + } + + py_r = PyInt_FromLong ((long) r); + return py_r; +} + +static PyObject * +py_guestfs_blockdev_getbsz (PyObject *self, PyObject *args) +{ + PyObject *py_g; + guestfs_h *g; + PyObject *py_r; + int r; + const char *device; + + if (!PyArg_ParseTuple (args, (char *) "Os:guestfs_blockdev_getbsz", + &py_g, &device)) + return NULL; + g = get_handle (py_g); + + r = guestfs_blockdev_getbsz (g, device); + if (r == -1) { + PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g)); + return NULL; + } + + py_r = PyInt_FromLong ((long) r); + return py_r; +} + +static PyObject * +py_guestfs_blockdev_setbsz (PyObject *self, PyObject *args) +{ + PyObject *py_g; + guestfs_h *g; + PyObject *py_r; + int r; + const char *device; + int blocksize; + + if (!PyArg_ParseTuple (args, (char *) "Osi:guestfs_blockdev_setbsz", + &py_g, &device, &blocksize)) + return NULL; + g = get_handle (py_g); + + r = guestfs_blockdev_setbsz (g, device, blocksize); + if (r == -1) { + PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g)); + return NULL; + } + + Py_INCREF (Py_None); + py_r = Py_None; + return py_r; +} + +static PyObject * +py_guestfs_blockdev_getsz (PyObject *self, PyObject *args) +{ + PyObject *py_g; + guestfs_h *g; + PyObject *py_r; + int64_t r; + const char *device; + + if (!PyArg_ParseTuple (args, (char *) "Os:guestfs_blockdev_getsz", + &py_g, &device)) + return NULL; + g = get_handle (py_g); + + r = guestfs_blockdev_getsz (g, device); + if (r == -1) { + PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g)); + return NULL; + } + + py_r = PyLong_FromLongLong (r); + return py_r; +} + +static PyObject * +py_guestfs_blockdev_getsize64 (PyObject *self, PyObject *args) +{ + PyObject *py_g; + guestfs_h *g; + PyObject *py_r; + int64_t r; + const char *device; + + if (!PyArg_ParseTuple (args, (char *) "Os:guestfs_blockdev_getsize64", + &py_g, &device)) + return NULL; + g = get_handle (py_g); + + r = guestfs_blockdev_getsize64 (g, device); + if (r == -1) { + PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g)); + return NULL; + } + + py_r = PyLong_FromLongLong (r); + return py_r; +} + +static PyObject * +py_guestfs_blockdev_flushbufs (PyObject *self, PyObject *args) +{ + PyObject *py_g; + guestfs_h *g; + PyObject *py_r; + int r; + const char *device; + + if (!PyArg_ParseTuple (args, (char *) "Os:guestfs_blockdev_flushbufs", + &py_g, &device)) + return NULL; + g = get_handle (py_g); + + r = guestfs_blockdev_flushbufs (g, device); + if (r == -1) { + PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g)); + return NULL; + } + + Py_INCREF (Py_None); + py_r = Py_None; + return py_r; +} + +static PyObject * +py_guestfs_blockdev_rereadpt (PyObject *self, PyObject *args) +{ + PyObject *py_g; + guestfs_h *g; + PyObject *py_r; + int r; + const char *device; + + if (!PyArg_ParseTuple (args, (char *) "Os:guestfs_blockdev_rereadpt", + &py_g, &device)) + return NULL; + g = get_handle (py_g); + + r = guestfs_blockdev_rereadpt (g, device); + if (r == -1) { + PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g)); + return NULL; + } + + Py_INCREF (Py_None); + py_r = Py_None; + return py_r; +} + static PyMethodDef methods[] = { { (char *) "create", py_guestfs_create, METH_VARARGS, NULL }, { (char *) "close", py_guestfs_close, METH_VARARGS, NULL }, @@ -2146,6 +2392,16 @@ static PyMethodDef methods[] = { { (char *) "lstat", py_guestfs_lstat, METH_VARARGS, NULL }, { (char *) "statvfs", py_guestfs_statvfs, METH_VARARGS, NULL }, { (char *) "tune2fs_l", py_guestfs_tune2fs_l, METH_VARARGS, NULL }, + { (char *) "blockdev_setro", py_guestfs_blockdev_setro, METH_VARARGS, NULL }, + { (char *) "blockdev_setrw", py_guestfs_blockdev_setrw, METH_VARARGS, NULL }, + { (char *) "blockdev_getro", py_guestfs_blockdev_getro, METH_VARARGS, NULL }, + { (char *) "blockdev_getss", py_guestfs_blockdev_getss, METH_VARARGS, NULL }, + { (char *) "blockdev_getbsz", py_guestfs_blockdev_getbsz, METH_VARARGS, NULL }, + { (char *) "blockdev_setbsz", py_guestfs_blockdev_setbsz, METH_VARARGS, NULL }, + { (char *) "blockdev_getsz", py_guestfs_blockdev_getsz, METH_VARARGS, NULL }, + { (char *) "blockdev_getsize64", py_guestfs_blockdev_getsize64, METH_VARARGS, NULL }, + { (char *) "blockdev_flushbufs", py_guestfs_blockdev_flushbufs, METH_VARARGS, NULL }, + { (char *) "blockdev_rereadpt", py_guestfs_blockdev_rereadpt, METH_VARARGS, NULL }, { NULL, NULL, 0, NULL } }; diff --git a/python/guestfs.py b/python/guestfs.py index 95156fc..9bd1edf 100644 --- a/python/guestfs.py +++ b/python/guestfs.py @@ -228,3 +228,33 @@ class GuestFS: def tune2fs_l (self, device): return libguestfsmod.tune2fs_l (self._o, device) + def blockdev_setro (self, device): + return libguestfsmod.blockdev_setro (self._o, device) + + def blockdev_setrw (self, device): + return libguestfsmod.blockdev_setrw (self._o, device) + + def blockdev_getro (self, device): + return libguestfsmod.blockdev_getro (self._o, device) + + def blockdev_getss (self, device): + return libguestfsmod.blockdev_getss (self._o, device) + + def blockdev_getbsz (self, device): + return libguestfsmod.blockdev_getbsz (self._o, device) + + def blockdev_setbsz (self, device, blocksize): + return libguestfsmod.blockdev_setbsz (self._o, device, blocksize) + + def blockdev_getsz (self, device): + return libguestfsmod.blockdev_getsz (self._o, device) + + def blockdev_getsize64 (self, device): + return libguestfsmod.blockdev_getsize64 (self._o, device) + + def blockdev_flushbufs (self, device): + return libguestfsmod.blockdev_flushbufs (self._o, device) + + def blockdev_rereadpt (self, device): + return libguestfsmod.blockdev_rereadpt (self._o, device) + diff --git a/src/guestfs-actions.c b/src/guestfs-actions.c index 0961df6..f516979 100644 --- a/src/guestfs-actions.c +++ b/src/guestfs-actions.c @@ -4002,3 +4002,720 @@ char **guestfs_tune2fs_l (guestfs_h *g, return rv.ret.superblock.superblock_val; } +struct blockdev_setro_rv { + int cb_done; /* flag to indicate callback was called */ + struct guestfs_message_header hdr; + struct guestfs_message_error err; +}; + +static void blockdev_setro_cb (guestfs_h *g, void *data, XDR *xdr) +{ + struct blockdev_setro_rv *rv = (struct blockdev_setro_rv *) data; + + if (!xdr_guestfs_message_header (xdr, &rv->hdr)) { + error (g, "guestfs_blockdev_setro: failed to parse reply header"); + return; + } + if (rv->hdr.status == GUESTFS_STATUS_ERROR) { + if (!xdr_guestfs_message_error (xdr, &rv->err)) { + error (g, "guestfs_blockdev_setro: failed to parse reply error"); + return; + } + goto done; + } + done: + rv->cb_done = 1; + main_loop.main_loop_quit (g); +} + +int guestfs_blockdev_setro (guestfs_h *g, + const char *device) +{ + struct guestfs_blockdev_setro_args args; + struct blockdev_setro_rv rv; + int serial; + + if (g->state != READY) { + error (g, "guestfs_blockdev_setro called from the wrong state, %d != READY", + g->state); + return -1; + } + + memset (&rv, 0, sizeof rv); + + args.device = (char *) device; + serial = dispatch (g, GUESTFS_PROC_BLOCKDEV_SETRO, + (xdrproc_t) xdr_guestfs_blockdev_setro_args, (char *) &args); + if (serial == -1) + return -1; + + rv.cb_done = 0; + g->reply_cb_internal = blockdev_setro_cb; + g->reply_cb_internal_data = &rv; + main_loop.main_loop_run (g); + g->reply_cb_internal = NULL; + g->reply_cb_internal_data = NULL; + if (!rv.cb_done) { + error (g, "guestfs_blockdev_setro failed, see earlier error messages"); + return -1; + } + + if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_BLOCKDEV_SETRO, serial) == -1) + return -1; + + if (rv.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", rv.err.error); + return -1; + } + + return 0; +} + +struct blockdev_setrw_rv { + int cb_done; /* flag to indicate callback was called */ + struct guestfs_message_header hdr; + struct guestfs_message_error err; +}; + +static void blockdev_setrw_cb (guestfs_h *g, void *data, XDR *xdr) +{ + struct blockdev_setrw_rv *rv = (struct blockdev_setrw_rv *) data; + + if (!xdr_guestfs_message_header (xdr, &rv->hdr)) { + error (g, "guestfs_blockdev_setrw: failed to parse reply header"); + return; + } + if (rv->hdr.status == GUESTFS_STATUS_ERROR) { + if (!xdr_guestfs_message_error (xdr, &rv->err)) { + error (g, "guestfs_blockdev_setrw: failed to parse reply error"); + return; + } + goto done; + } + done: + rv->cb_done = 1; + main_loop.main_loop_quit (g); +} + +int guestfs_blockdev_setrw (guestfs_h *g, + const char *device) +{ + struct guestfs_blockdev_setrw_args args; + struct blockdev_setrw_rv rv; + int serial; + + if (g->state != READY) { + error (g, "guestfs_blockdev_setrw called from the wrong state, %d != READY", + g->state); + return -1; + } + + memset (&rv, 0, sizeof rv); + + args.device = (char *) device; + serial = dispatch (g, GUESTFS_PROC_BLOCKDEV_SETRW, + (xdrproc_t) xdr_guestfs_blockdev_setrw_args, (char *) &args); + if (serial == -1) + return -1; + + rv.cb_done = 0; + g->reply_cb_internal = blockdev_setrw_cb; + g->reply_cb_internal_data = &rv; + main_loop.main_loop_run (g); + g->reply_cb_internal = NULL; + g->reply_cb_internal_data = NULL; + if (!rv.cb_done) { + error (g, "guestfs_blockdev_setrw failed, see earlier error messages"); + return -1; + } + + if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_BLOCKDEV_SETRW, serial) == -1) + return -1; + + if (rv.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", rv.err.error); + return -1; + } + + return 0; +} + +struct blockdev_getro_rv { + int cb_done; /* flag to indicate callback was called */ + struct guestfs_message_header hdr; + struct guestfs_message_error err; + struct guestfs_blockdev_getro_ret ret; +}; + +static void blockdev_getro_cb (guestfs_h *g, void *data, XDR *xdr) +{ + struct blockdev_getro_rv *rv = (struct blockdev_getro_rv *) data; + + if (!xdr_guestfs_message_header (xdr, &rv->hdr)) { + error (g, "guestfs_blockdev_getro: failed to parse reply header"); + return; + } + if (rv->hdr.status == GUESTFS_STATUS_ERROR) { + if (!xdr_guestfs_message_error (xdr, &rv->err)) { + error (g, "guestfs_blockdev_getro: failed to parse reply error"); + return; + } + goto done; + } + if (!xdr_guestfs_blockdev_getro_ret (xdr, &rv->ret)) { + error (g, "guestfs_blockdev_getro: failed to parse reply"); + return; + } + done: + rv->cb_done = 1; + main_loop.main_loop_quit (g); +} + +int guestfs_blockdev_getro (guestfs_h *g, + const char *device) +{ + struct guestfs_blockdev_getro_args args; + struct blockdev_getro_rv rv; + int serial; + + if (g->state != READY) { + error (g, "guestfs_blockdev_getro called from the wrong state, %d != READY", + g->state); + return -1; + } + + memset (&rv, 0, sizeof rv); + + args.device = (char *) device; + serial = dispatch (g, GUESTFS_PROC_BLOCKDEV_GETRO, + (xdrproc_t) xdr_guestfs_blockdev_getro_args, (char *) &args); + if (serial == -1) + return -1; + + rv.cb_done = 0; + g->reply_cb_internal = blockdev_getro_cb; + g->reply_cb_internal_data = &rv; + main_loop.main_loop_run (g); + g->reply_cb_internal = NULL; + g->reply_cb_internal_data = NULL; + if (!rv.cb_done) { + error (g, "guestfs_blockdev_getro failed, see earlier error messages"); + return -1; + } + + if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_BLOCKDEV_GETRO, serial) == -1) + return -1; + + if (rv.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", rv.err.error); + return -1; + } + + return rv.ret.ro; +} + +struct blockdev_getss_rv { + int cb_done; /* flag to indicate callback was called */ + struct guestfs_message_header hdr; + struct guestfs_message_error err; + struct guestfs_blockdev_getss_ret ret; +}; + +static void blockdev_getss_cb (guestfs_h *g, void *data, XDR *xdr) +{ + struct blockdev_getss_rv *rv = (struct blockdev_getss_rv *) data; + + if (!xdr_guestfs_message_header (xdr, &rv->hdr)) { + error (g, "guestfs_blockdev_getss: failed to parse reply header"); + return; + } + if (rv->hdr.status == GUESTFS_STATUS_ERROR) { + if (!xdr_guestfs_message_error (xdr, &rv->err)) { + error (g, "guestfs_blockdev_getss: failed to parse reply error"); + return; + } + goto done; + } + if (!xdr_guestfs_blockdev_getss_ret (xdr, &rv->ret)) { + error (g, "guestfs_blockdev_getss: failed to parse reply"); + return; + } + done: + rv->cb_done = 1; + main_loop.main_loop_quit (g); +} + +int guestfs_blockdev_getss (guestfs_h *g, + const char *device) +{ + struct guestfs_blockdev_getss_args args; + struct blockdev_getss_rv rv; + int serial; + + if (g->state != READY) { + error (g, "guestfs_blockdev_getss called from the wrong state, %d != READY", + g->state); + return -1; + } + + memset (&rv, 0, sizeof rv); + + args.device = (char *) device; + serial = dispatch (g, GUESTFS_PROC_BLOCKDEV_GETSS, + (xdrproc_t) xdr_guestfs_blockdev_getss_args, (char *) &args); + if (serial == -1) + return -1; + + rv.cb_done = 0; + g->reply_cb_internal = blockdev_getss_cb; + g->reply_cb_internal_data = &rv; + main_loop.main_loop_run (g); + g->reply_cb_internal = NULL; + g->reply_cb_internal_data = NULL; + if (!rv.cb_done) { + error (g, "guestfs_blockdev_getss failed, see earlier error messages"); + return -1; + } + + if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_BLOCKDEV_GETSS, serial) == -1) + return -1; + + if (rv.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", rv.err.error); + return -1; + } + + return rv.ret.sectorsize; +} + +struct blockdev_getbsz_rv { + int cb_done; /* flag to indicate callback was called */ + struct guestfs_message_header hdr; + struct guestfs_message_error err; + struct guestfs_blockdev_getbsz_ret ret; +}; + +static void blockdev_getbsz_cb (guestfs_h *g, void *data, XDR *xdr) +{ + struct blockdev_getbsz_rv *rv = (struct blockdev_getbsz_rv *) data; + + if (!xdr_guestfs_message_header (xdr, &rv->hdr)) { + error (g, "guestfs_blockdev_getbsz: failed to parse reply header"); + return; + } + if (rv->hdr.status == GUESTFS_STATUS_ERROR) { + if (!xdr_guestfs_message_error (xdr, &rv->err)) { + error (g, "guestfs_blockdev_getbsz: failed to parse reply error"); + return; + } + goto done; + } + if (!xdr_guestfs_blockdev_getbsz_ret (xdr, &rv->ret)) { + error (g, "guestfs_blockdev_getbsz: failed to parse reply"); + return; + } + done: + rv->cb_done = 1; + main_loop.main_loop_quit (g); +} + +int guestfs_blockdev_getbsz (guestfs_h *g, + const char *device) +{ + struct guestfs_blockdev_getbsz_args args; + struct blockdev_getbsz_rv rv; + int serial; + + if (g->state != READY) { + error (g, "guestfs_blockdev_getbsz called from the wrong state, %d != READY", + g->state); + return -1; + } + + memset (&rv, 0, sizeof rv); + + args.device = (char *) device; + serial = dispatch (g, GUESTFS_PROC_BLOCKDEV_GETBSZ, + (xdrproc_t) xdr_guestfs_blockdev_getbsz_args, (char *) &args); + if (serial == -1) + return -1; + + rv.cb_done = 0; + g->reply_cb_internal = blockdev_getbsz_cb; + g->reply_cb_internal_data = &rv; + main_loop.main_loop_run (g); + g->reply_cb_internal = NULL; + g->reply_cb_internal_data = NULL; + if (!rv.cb_done) { + error (g, "guestfs_blockdev_getbsz failed, see earlier error messages"); + return -1; + } + + if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_BLOCKDEV_GETBSZ, serial) == -1) + return -1; + + if (rv.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", rv.err.error); + return -1; + } + + return rv.ret.blocksize; +} + +struct blockdev_setbsz_rv { + int cb_done; /* flag to indicate callback was called */ + struct guestfs_message_header hdr; + struct guestfs_message_error err; +}; + +static void blockdev_setbsz_cb (guestfs_h *g, void *data, XDR *xdr) +{ + struct blockdev_setbsz_rv *rv = (struct blockdev_setbsz_rv *) data; + + if (!xdr_guestfs_message_header (xdr, &rv->hdr)) { + error (g, "guestfs_blockdev_setbsz: failed to parse reply header"); + return; + } + if (rv->hdr.status == GUESTFS_STATUS_ERROR) { + if (!xdr_guestfs_message_error (xdr, &rv->err)) { + error (g, "guestfs_blockdev_setbsz: failed to parse reply error"); + return; + } + goto done; + } + done: + rv->cb_done = 1; + main_loop.main_loop_quit (g); +} + +int guestfs_blockdev_setbsz (guestfs_h *g, + const char *device, + int blocksize) +{ + struct guestfs_blockdev_setbsz_args args; + struct blockdev_setbsz_rv rv; + int serial; + + if (g->state != READY) { + error (g, "guestfs_blockdev_setbsz called from the wrong state, %d != READY", + g->state); + return -1; + } + + memset (&rv, 0, sizeof rv); + + args.device = (char *) device; + args.blocksize = blocksize; + serial = dispatch (g, GUESTFS_PROC_BLOCKDEV_SETBSZ, + (xdrproc_t) xdr_guestfs_blockdev_setbsz_args, (char *) &args); + if (serial == -1) + return -1; + + rv.cb_done = 0; + g->reply_cb_internal = blockdev_setbsz_cb; + g->reply_cb_internal_data = &rv; + main_loop.main_loop_run (g); + g->reply_cb_internal = NULL; + g->reply_cb_internal_data = NULL; + if (!rv.cb_done) { + error (g, "guestfs_blockdev_setbsz failed, see earlier error messages"); + return -1; + } + + if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_BLOCKDEV_SETBSZ, serial) == -1) + return -1; + + if (rv.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", rv.err.error); + return -1; + } + + return 0; +} + +struct blockdev_getsz_rv { + int cb_done; /* flag to indicate callback was called */ + struct guestfs_message_header hdr; + struct guestfs_message_error err; + struct guestfs_blockdev_getsz_ret ret; +}; + +static void blockdev_getsz_cb (guestfs_h *g, void *data, XDR *xdr) +{ + struct blockdev_getsz_rv *rv = (struct blockdev_getsz_rv *) data; + + if (!xdr_guestfs_message_header (xdr, &rv->hdr)) { + error (g, "guestfs_blockdev_getsz: failed to parse reply header"); + return; + } + if (rv->hdr.status == GUESTFS_STATUS_ERROR) { + if (!xdr_guestfs_message_error (xdr, &rv->err)) { + error (g, "guestfs_blockdev_getsz: failed to parse reply error"); + return; + } + goto done; + } + if (!xdr_guestfs_blockdev_getsz_ret (xdr, &rv->ret)) { + error (g, "guestfs_blockdev_getsz: failed to parse reply"); + return; + } + done: + rv->cb_done = 1; + main_loop.main_loop_quit (g); +} + +int64_t guestfs_blockdev_getsz (guestfs_h *g, + const char *device) +{ + struct guestfs_blockdev_getsz_args args; + struct blockdev_getsz_rv rv; + int serial; + + if (g->state != READY) { + error (g, "guestfs_blockdev_getsz called from the wrong state, %d != READY", + g->state); + return -1; + } + + memset (&rv, 0, sizeof rv); + + args.device = (char *) device; + serial = dispatch (g, GUESTFS_PROC_BLOCKDEV_GETSZ, + (xdrproc_t) xdr_guestfs_blockdev_getsz_args, (char *) &args); + if (serial == -1) + return -1; + + rv.cb_done = 0; + g->reply_cb_internal = blockdev_getsz_cb; + g->reply_cb_internal_data = &rv; + main_loop.main_loop_run (g); + g->reply_cb_internal = NULL; + g->reply_cb_internal_data = NULL; + if (!rv.cb_done) { + error (g, "guestfs_blockdev_getsz failed, see earlier error messages"); + return -1; + } + + if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_BLOCKDEV_GETSZ, serial) == -1) + return -1; + + if (rv.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", rv.err.error); + return -1; + } + + return rv.ret.sizeinsectors; +} + +struct blockdev_getsize64_rv { + int cb_done; /* flag to indicate callback was called */ + struct guestfs_message_header hdr; + struct guestfs_message_error err; + struct guestfs_blockdev_getsize64_ret ret; +}; + +static void blockdev_getsize64_cb (guestfs_h *g, void *data, XDR *xdr) +{ + struct blockdev_getsize64_rv *rv = (struct blockdev_getsize64_rv *) data; + + if (!xdr_guestfs_message_header (xdr, &rv->hdr)) { + error (g, "guestfs_blockdev_getsize64: failed to parse reply header"); + return; + } + if (rv->hdr.status == GUESTFS_STATUS_ERROR) { + if (!xdr_guestfs_message_error (xdr, &rv->err)) { + error (g, "guestfs_blockdev_getsize64: failed to parse reply error"); + return; + } + goto done; + } + if (!xdr_guestfs_blockdev_getsize64_ret (xdr, &rv->ret)) { + error (g, "guestfs_blockdev_getsize64: failed to parse reply"); + return; + } + done: + rv->cb_done = 1; + main_loop.main_loop_quit (g); +} + +int64_t guestfs_blockdev_getsize64 (guestfs_h *g, + const char *device) +{ + struct guestfs_blockdev_getsize64_args args; + struct blockdev_getsize64_rv rv; + int serial; + + if (g->state != READY) { + error (g, "guestfs_blockdev_getsize64 called from the wrong state, %d != READY", + g->state); + return -1; + } + + memset (&rv, 0, sizeof rv); + + args.device = (char *) device; + serial = dispatch (g, GUESTFS_PROC_BLOCKDEV_GETSIZE64, + (xdrproc_t) xdr_guestfs_blockdev_getsize64_args, (char *) &args); + if (serial == -1) + return -1; + + rv.cb_done = 0; + g->reply_cb_internal = blockdev_getsize64_cb; + g->reply_cb_internal_data = &rv; + main_loop.main_loop_run (g); + g->reply_cb_internal = NULL; + g->reply_cb_internal_data = NULL; + if (!rv.cb_done) { + error (g, "guestfs_blockdev_getsize64 failed, see earlier error messages"); + return -1; + } + + if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_BLOCKDEV_GETSIZE64, serial) == -1) + return -1; + + if (rv.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", rv.err.error); + return -1; + } + + return rv.ret.sizeinbytes; +} + +struct blockdev_flushbufs_rv { + int cb_done; /* flag to indicate callback was called */ + struct guestfs_message_header hdr; + struct guestfs_message_error err; +}; + +static void blockdev_flushbufs_cb (guestfs_h *g, void *data, XDR *xdr) +{ + struct blockdev_flushbufs_rv *rv = (struct blockdev_flushbufs_rv *) data; + + if (!xdr_guestfs_message_header (xdr, &rv->hdr)) { + error (g, "guestfs_blockdev_flushbufs: failed to parse reply header"); + return; + } + if (rv->hdr.status == GUESTFS_STATUS_ERROR) { + if (!xdr_guestfs_message_error (xdr, &rv->err)) { + error (g, "guestfs_blockdev_flushbufs: failed to parse reply error"); + return; + } + goto done; + } + done: + rv->cb_done = 1; + main_loop.main_loop_quit (g); +} + +int guestfs_blockdev_flushbufs (guestfs_h *g, + const char *device) +{ + struct guestfs_blockdev_flushbufs_args args; + struct blockdev_flushbufs_rv rv; + int serial; + + if (g->state != READY) { + error (g, "guestfs_blockdev_flushbufs called from the wrong state, %d != READY", + g->state); + return -1; + } + + memset (&rv, 0, sizeof rv); + + args.device = (char *) device; + serial = dispatch (g, GUESTFS_PROC_BLOCKDEV_FLUSHBUFS, + (xdrproc_t) xdr_guestfs_blockdev_flushbufs_args, (char *) &args); + if (serial == -1) + return -1; + + rv.cb_done = 0; + g->reply_cb_internal = blockdev_flushbufs_cb; + g->reply_cb_internal_data = &rv; + main_loop.main_loop_run (g); + g->reply_cb_internal = NULL; + g->reply_cb_internal_data = NULL; + if (!rv.cb_done) { + error (g, "guestfs_blockdev_flushbufs failed, see earlier error messages"); + return -1; + } + + if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_BLOCKDEV_FLUSHBUFS, serial) == -1) + return -1; + + if (rv.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", rv.err.error); + return -1; + } + + return 0; +} + +struct blockdev_rereadpt_rv { + int cb_done; /* flag to indicate callback was called */ + struct guestfs_message_header hdr; + struct guestfs_message_error err; +}; + +static void blockdev_rereadpt_cb (guestfs_h *g, void *data, XDR *xdr) +{ + struct blockdev_rereadpt_rv *rv = (struct blockdev_rereadpt_rv *) data; + + if (!xdr_guestfs_message_header (xdr, &rv->hdr)) { + error (g, "guestfs_blockdev_rereadpt: failed to parse reply header"); + return; + } + if (rv->hdr.status == GUESTFS_STATUS_ERROR) { + if (!xdr_guestfs_message_error (xdr, &rv->err)) { + error (g, "guestfs_blockdev_rereadpt: failed to parse reply error"); + return; + } + goto done; + } + done: + rv->cb_done = 1; + main_loop.main_loop_quit (g); +} + +int guestfs_blockdev_rereadpt (guestfs_h *g, + const char *device) +{ + struct guestfs_blockdev_rereadpt_args args; + struct blockdev_rereadpt_rv rv; + int serial; + + if (g->state != READY) { + error (g, "guestfs_blockdev_rereadpt called from the wrong state, %d != READY", + g->state); + return -1; + } + + memset (&rv, 0, sizeof rv); + + args.device = (char *) device; + serial = dispatch (g, GUESTFS_PROC_BLOCKDEV_REREADPT, + (xdrproc_t) xdr_guestfs_blockdev_rereadpt_args, (char *) &args); + if (serial == -1) + return -1; + + rv.cb_done = 0; + g->reply_cb_internal = blockdev_rereadpt_cb; + g->reply_cb_internal_data = &rv; + main_loop.main_loop_run (g); + g->reply_cb_internal = NULL; + g->reply_cb_internal_data = NULL; + if (!rv.cb_done) { + error (g, "guestfs_blockdev_rereadpt failed, see earlier error messages"); + return -1; + } + + if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_BLOCKDEV_REREADPT, serial) == -1) + return -1; + + if (rv.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", rv.err.error); + return -1; + } + + return 0; +} + diff --git a/src/guestfs-actions.h b/src/guestfs-actions.h index 5f523c3..14ca54f 100644 --- a/src/guestfs-actions.h +++ b/src/guestfs-actions.h @@ -86,3 +86,13 @@ extern struct guestfs_stat *guestfs_stat (guestfs_h *handle, const char *path); extern struct guestfs_stat *guestfs_lstat (guestfs_h *handle, const char *path); extern struct guestfs_statvfs *guestfs_statvfs (guestfs_h *handle, const char *path); extern char **guestfs_tune2fs_l (guestfs_h *handle, const char *device); +extern int guestfs_blockdev_setro (guestfs_h *handle, const char *device); +extern int guestfs_blockdev_setrw (guestfs_h *handle, const char *device); +extern int guestfs_blockdev_getro (guestfs_h *handle, const char *device); +extern int guestfs_blockdev_getss (guestfs_h *handle, const char *device); +extern int guestfs_blockdev_getbsz (guestfs_h *handle, const char *device); +extern int guestfs_blockdev_setbsz (guestfs_h *handle, const char *device, int blocksize); +extern int64_t guestfs_blockdev_getsz (guestfs_h *handle, const char *device); +extern int64_t guestfs_blockdev_getsize64 (guestfs_h *handle, const char *device); +extern int guestfs_blockdev_flushbufs (guestfs_h *handle, const char *device); +extern int guestfs_blockdev_rereadpt (guestfs_h *handle, const char *device); diff --git a/src/guestfs_protocol.c b/src/guestfs_protocol.c index 33de1dc..eb90d75 100644 --- a/src/guestfs_protocol.c +++ b/src/guestfs_protocol.c @@ -1035,6 +1035,158 @@ xdr_guestfs_tune2fs_l_ret (XDR *xdrs, guestfs_tune2fs_l_ret *objp) } bool_t +xdr_guestfs_blockdev_setro_args (XDR *xdrs, guestfs_blockdev_setro_args *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->device, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_blockdev_setrw_args (XDR *xdrs, guestfs_blockdev_setrw_args *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->device, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_blockdev_getro_args (XDR *xdrs, guestfs_blockdev_getro_args *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->device, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_blockdev_getro_ret (XDR *xdrs, guestfs_blockdev_getro_ret *objp) +{ + register int32_t *buf; + + if (!xdr_bool (xdrs, &objp->ro)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_blockdev_getss_args (XDR *xdrs, guestfs_blockdev_getss_args *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->device, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_blockdev_getss_ret (XDR *xdrs, guestfs_blockdev_getss_ret *objp) +{ + register int32_t *buf; + + if (!xdr_int (xdrs, &objp->sectorsize)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_blockdev_getbsz_args (XDR *xdrs, guestfs_blockdev_getbsz_args *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->device, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_blockdev_getbsz_ret (XDR *xdrs, guestfs_blockdev_getbsz_ret *objp) +{ + register int32_t *buf; + + if (!xdr_int (xdrs, &objp->blocksize)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_blockdev_setbsz_args (XDR *xdrs, guestfs_blockdev_setbsz_args *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->device, ~0)) + return FALSE; + if (!xdr_int (xdrs, &objp->blocksize)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_blockdev_getsz_args (XDR *xdrs, guestfs_blockdev_getsz_args *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->device, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_blockdev_getsz_ret (XDR *xdrs, guestfs_blockdev_getsz_ret *objp) +{ + register int32_t *buf; + + if (!xdr_quad_t (xdrs, &objp->sizeinsectors)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_blockdev_getsize64_args (XDR *xdrs, guestfs_blockdev_getsize64_args *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->device, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_blockdev_getsize64_ret (XDR *xdrs, guestfs_blockdev_getsize64_ret *objp) +{ + register int32_t *buf; + + if (!xdr_quad_t (xdrs, &objp->sizeinbytes)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_blockdev_flushbufs_args (XDR *xdrs, guestfs_blockdev_flushbufs_args *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->device, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_blockdev_rereadpt_args (XDR *xdrs, guestfs_blockdev_rereadpt_args *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->device, ~0)) + return FALSE; + return TRUE; +} + +bool_t xdr_guestfs_procedure (XDR *xdrs, guestfs_procedure *objp) { register int32_t *buf; diff --git a/src/guestfs_protocol.h b/src/guestfs_protocol.h index 270571e..822d960 100644 --- a/src/guestfs_protocol.h +++ b/src/guestfs_protocol.h @@ -540,6 +540,82 @@ struct guestfs_tune2fs_l_ret { }; typedef struct guestfs_tune2fs_l_ret guestfs_tune2fs_l_ret; +struct guestfs_blockdev_setro_args { + char *device; +}; +typedef struct guestfs_blockdev_setro_args guestfs_blockdev_setro_args; + +struct guestfs_blockdev_setrw_args { + char *device; +}; +typedef struct guestfs_blockdev_setrw_args guestfs_blockdev_setrw_args; + +struct guestfs_blockdev_getro_args { + char *device; +}; +typedef struct guestfs_blockdev_getro_args guestfs_blockdev_getro_args; + +struct guestfs_blockdev_getro_ret { + bool_t ro; +}; +typedef struct guestfs_blockdev_getro_ret guestfs_blockdev_getro_ret; + +struct guestfs_blockdev_getss_args { + char *device; +}; +typedef struct guestfs_blockdev_getss_args guestfs_blockdev_getss_args; + +struct guestfs_blockdev_getss_ret { + int sectorsize; +}; +typedef struct guestfs_blockdev_getss_ret guestfs_blockdev_getss_ret; + +struct guestfs_blockdev_getbsz_args { + char *device; +}; +typedef struct guestfs_blockdev_getbsz_args guestfs_blockdev_getbsz_args; + +struct guestfs_blockdev_getbsz_ret { + int blocksize; +}; +typedef struct guestfs_blockdev_getbsz_ret guestfs_blockdev_getbsz_ret; + +struct guestfs_blockdev_setbsz_args { + char *device; + int blocksize; +}; +typedef struct guestfs_blockdev_setbsz_args guestfs_blockdev_setbsz_args; + +struct guestfs_blockdev_getsz_args { + char *device; +}; +typedef struct guestfs_blockdev_getsz_args guestfs_blockdev_getsz_args; + +struct guestfs_blockdev_getsz_ret { + quad_t sizeinsectors; +}; +typedef struct guestfs_blockdev_getsz_ret guestfs_blockdev_getsz_ret; + +struct guestfs_blockdev_getsize64_args { + char *device; +}; +typedef struct guestfs_blockdev_getsize64_args guestfs_blockdev_getsize64_args; + +struct guestfs_blockdev_getsize64_ret { + quad_t sizeinbytes; +}; +typedef struct guestfs_blockdev_getsize64_ret guestfs_blockdev_getsize64_ret; + +struct guestfs_blockdev_flushbufs_args { + char *device; +}; +typedef struct guestfs_blockdev_flushbufs_args guestfs_blockdev_flushbufs_args; + +struct guestfs_blockdev_rereadpt_args { + char *device; +}; +typedef struct guestfs_blockdev_rereadpt_args guestfs_blockdev_rereadpt_args; + enum guestfs_procedure { GUESTFS_PROC_MOUNT = 1, GUESTFS_PROC_SYNC = 2, @@ -596,7 +672,17 @@ enum guestfs_procedure { GUESTFS_PROC_LSTAT = 53, GUESTFS_PROC_STATVFS = 54, GUESTFS_PROC_TUNE2FS_L = 55, - GUESTFS_PROC_dummy = 55 + 1, + GUESTFS_PROC_BLOCKDEV_SETRO = 56, + GUESTFS_PROC_BLOCKDEV_SETRW = 57, + GUESTFS_PROC_BLOCKDEV_GETRO = 58, + GUESTFS_PROC_BLOCKDEV_GETSS = 59, + GUESTFS_PROC_BLOCKDEV_GETBSZ = 60, + GUESTFS_PROC_BLOCKDEV_SETBSZ = 61, + GUESTFS_PROC_BLOCKDEV_GETSZ = 62, + GUESTFS_PROC_BLOCKDEV_GETSIZE64 = 63, + GUESTFS_PROC_BLOCKDEV_FLUSHBUFS = 64, + GUESTFS_PROC_BLOCKDEV_REREADPT = 65, + GUESTFS_PROC_dummy = 65 + 1, }; typedef enum guestfs_procedure guestfs_procedure; #define GUESTFS_MESSAGE_MAX 4194304 @@ -712,6 +798,21 @@ extern bool_t xdr_guestfs_statvfs_args (XDR *, guestfs_statvfs_args*); extern bool_t xdr_guestfs_statvfs_ret (XDR *, guestfs_statvfs_ret*); extern bool_t xdr_guestfs_tune2fs_l_args (XDR *, guestfs_tune2fs_l_args*); extern bool_t xdr_guestfs_tune2fs_l_ret (XDR *, guestfs_tune2fs_l_ret*); +extern bool_t xdr_guestfs_blockdev_setro_args (XDR *, guestfs_blockdev_setro_args*); +extern bool_t xdr_guestfs_blockdev_setrw_args (XDR *, guestfs_blockdev_setrw_args*); +extern bool_t xdr_guestfs_blockdev_getro_args (XDR *, guestfs_blockdev_getro_args*); +extern bool_t xdr_guestfs_blockdev_getro_ret (XDR *, guestfs_blockdev_getro_ret*); +extern bool_t xdr_guestfs_blockdev_getss_args (XDR *, guestfs_blockdev_getss_args*); +extern bool_t xdr_guestfs_blockdev_getss_ret (XDR *, guestfs_blockdev_getss_ret*); +extern bool_t xdr_guestfs_blockdev_getbsz_args (XDR *, guestfs_blockdev_getbsz_args*); +extern bool_t xdr_guestfs_blockdev_getbsz_ret (XDR *, guestfs_blockdev_getbsz_ret*); +extern bool_t xdr_guestfs_blockdev_setbsz_args (XDR *, guestfs_blockdev_setbsz_args*); +extern bool_t xdr_guestfs_blockdev_getsz_args (XDR *, guestfs_blockdev_getsz_args*); +extern bool_t xdr_guestfs_blockdev_getsz_ret (XDR *, guestfs_blockdev_getsz_ret*); +extern bool_t xdr_guestfs_blockdev_getsize64_args (XDR *, guestfs_blockdev_getsize64_args*); +extern bool_t xdr_guestfs_blockdev_getsize64_ret (XDR *, guestfs_blockdev_getsize64_ret*); +extern bool_t xdr_guestfs_blockdev_flushbufs_args (XDR *, guestfs_blockdev_flushbufs_args*); +extern bool_t xdr_guestfs_blockdev_rereadpt_args (XDR *, guestfs_blockdev_rereadpt_args*); extern bool_t xdr_guestfs_procedure (XDR *, guestfs_procedure*); extern bool_t xdr_guestfs_message_direction (XDR *, guestfs_message_direction*); extern bool_t xdr_guestfs_message_status (XDR *, guestfs_message_status*); @@ -797,6 +898,21 @@ extern bool_t xdr_guestfs_statvfs_args (); extern bool_t xdr_guestfs_statvfs_ret (); extern bool_t xdr_guestfs_tune2fs_l_args (); extern bool_t xdr_guestfs_tune2fs_l_ret (); +extern bool_t xdr_guestfs_blockdev_setro_args (); +extern bool_t xdr_guestfs_blockdev_setrw_args (); +extern bool_t xdr_guestfs_blockdev_getro_args (); +extern bool_t xdr_guestfs_blockdev_getro_ret (); +extern bool_t xdr_guestfs_blockdev_getss_args (); +extern bool_t xdr_guestfs_blockdev_getss_ret (); +extern bool_t xdr_guestfs_blockdev_getbsz_args (); +extern bool_t xdr_guestfs_blockdev_getbsz_ret (); +extern bool_t xdr_guestfs_blockdev_setbsz_args (); +extern bool_t xdr_guestfs_blockdev_getsz_args (); +extern bool_t xdr_guestfs_blockdev_getsz_ret (); +extern bool_t xdr_guestfs_blockdev_getsize64_args (); +extern bool_t xdr_guestfs_blockdev_getsize64_ret (); +extern bool_t xdr_guestfs_blockdev_flushbufs_args (); +extern bool_t xdr_guestfs_blockdev_rereadpt_args (); extern bool_t xdr_guestfs_procedure (); extern bool_t xdr_guestfs_message_direction (); extern bool_t xdr_guestfs_message_status (); diff --git a/src/guestfs_protocol.x b/src/guestfs_protocol.x index 1b6e717..ba5d70c 100644 --- a/src/guestfs_protocol.x +++ b/src/guestfs_protocol.x @@ -414,6 +414,67 @@ struct guestfs_tune2fs_l_ret { str superblock<>; }; +struct guestfs_blockdev_setro_args { + string device<>; +}; + +struct guestfs_blockdev_setrw_args { + string device<>; +}; + +struct guestfs_blockdev_getro_args { + string device<>; +}; + +struct guestfs_blockdev_getro_ret { + bool ro; +}; + +struct guestfs_blockdev_getss_args { + string device<>; +}; + +struct guestfs_blockdev_getss_ret { + int sectorsize; +}; + +struct guestfs_blockdev_getbsz_args { + string device<>; +}; + +struct guestfs_blockdev_getbsz_ret { + int blocksize; +}; + +struct guestfs_blockdev_setbsz_args { + string device<>; + int blocksize; +}; + +struct guestfs_blockdev_getsz_args { + string device<>; +}; + +struct guestfs_blockdev_getsz_ret { + hyper sizeinsectors; +}; + +struct guestfs_blockdev_getsize64_args { + string device<>; +}; + +struct guestfs_blockdev_getsize64_ret { + hyper sizeinbytes; +}; + +struct guestfs_blockdev_flushbufs_args { + string device<>; +}; + +struct guestfs_blockdev_rereadpt_args { + string device<>; +}; + enum guestfs_procedure { GUESTFS_PROC_MOUNT = 1, GUESTFS_PROC_SYNC = 2, @@ -470,6 +531,16 @@ enum guestfs_procedure { GUESTFS_PROC_LSTAT = 53, GUESTFS_PROC_STATVFS = 54, GUESTFS_PROC_TUNE2FS_L = 55, + GUESTFS_PROC_BLOCKDEV_SETRO = 56, + GUESTFS_PROC_BLOCKDEV_SETRW = 57, + GUESTFS_PROC_BLOCKDEV_GETRO = 58, + GUESTFS_PROC_BLOCKDEV_GETSS = 59, + GUESTFS_PROC_BLOCKDEV_GETBSZ = 60, + GUESTFS_PROC_BLOCKDEV_SETBSZ = 61, + GUESTFS_PROC_BLOCKDEV_GETSZ = 62, + GUESTFS_PROC_BLOCKDEV_GETSIZE64 = 63, + GUESTFS_PROC_BLOCKDEV_FLUSHBUFS = 64, + GUESTFS_PROC_BLOCKDEV_REREADPT = 65, GUESTFS_PROC_dummy }; diff --git a/tests.c b/tests.c index aef5dd0..b3d2f49 100644 --- a/tests.c +++ b/tests.c @@ -45,6 +45,7 @@ static void print_strings (char * const * const argv) printf ("\t%s\n", argv[argc]); } +/* static void print_table (char * const * const argv) { int i; @@ -52,50 +53,52 @@ static void print_table (char * const * const argv) for (i = 0; argv[i] != NULL; i += 2) printf ("%s: %s\n", argv[i], argv[i+1]); } +*/ static void no_test_warnings (void) { - fprintf (stderr, "warning: \"launch\" has no tests\n"); - fprintf (stderr, "warning: \"wait_ready\" has no tests\n"); - fprintf (stderr, "warning: \"kill_subprocess\" has no tests\n"); - fprintf (stderr, "warning: \"add_drive\" has no tests\n"); - fprintf (stderr, "warning: \"add_cdrom\" has no tests\n"); - fprintf (stderr, "warning: \"config\" has no tests\n"); - fprintf (stderr, "warning: \"set_path\" has no tests\n"); - fprintf (stderr, "warning: \"get_path\" has no tests\n"); - fprintf (stderr, "warning: \"set_autosync\" has no tests\n"); - fprintf (stderr, "warning: \"get_autosync\" has no tests\n"); - fprintf (stderr, "warning: \"set_verbose\" has no tests\n"); - fprintf (stderr, "warning: \"get_verbose\" has no tests\n"); - fprintf (stderr, "warning: \"ll\" has no tests\n"); - fprintf (stderr, "warning: \"pvs_full\" has no tests\n"); - fprintf (stderr, "warning: \"vgs_full\" has no tests\n"); - fprintf (stderr, "warning: \"lvs_full\" has no tests\n"); - fprintf (stderr, "warning: \"aug_init\" has no tests\n"); - fprintf (stderr, "warning: \"aug_close\" has no tests\n"); - fprintf (stderr, "warning: \"aug_defvar\" has no tests\n"); - fprintf (stderr, "warning: \"aug_defnode\" has no tests\n"); - fprintf (stderr, "warning: \"aug_get\" has no tests\n"); - fprintf (stderr, "warning: \"aug_set\" has no tests\n"); - fprintf (stderr, "warning: \"aug_insert\" has no tests\n"); - fprintf (stderr, "warning: \"aug_rm\" has no tests\n"); - fprintf (stderr, "warning: \"aug_mv\" has no tests\n"); - fprintf (stderr, "warning: \"aug_match\" has no tests\n"); - fprintf (stderr, "warning: \"aug_save\" has no tests\n"); - fprintf (stderr, "warning: \"aug_load\" has no tests\n"); - fprintf (stderr, "warning: \"aug_ls\" has no tests\n"); - fprintf (stderr, "warning: \"chmod\" has no tests\n"); - fprintf (stderr, "warning: \"chown\" has no tests\n"); - fprintf (stderr, "warning: \"sfdisk\" has no tests\n"); - fprintf (stderr, "warning: \"lvm_remove_all\" has no tests\n"); - fprintf (stderr, "warning: \"command\" has no tests\n"); - fprintf (stderr, "warning: \"command_lines\" has no tests\n"); - fprintf (stderr, "warning: \"tune2fs_l\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_launch\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_wait_ready\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_kill_subprocess\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_add_drive\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_add_cdrom\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_config\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_set_path\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_get_path\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_set_autosync\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_get_autosync\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_set_verbose\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_get_verbose\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_ll\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_pvs_full\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_vgs_full\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_lvs_full\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_aug_init\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_aug_close\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_aug_defvar\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_aug_defnode\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_aug_get\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_aug_set\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_aug_insert\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_aug_rm\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_aug_mv\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_aug_match\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_aug_save\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_aug_load\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_aug_ls\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_chmod\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_chown\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_sfdisk\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_lvm_remove_all\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_command\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_command_lines\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_tune2fs_l\" has no tests\n"); + fprintf (stderr, "warning: \"guestfs_blockdev_setbsz\" has no tests\n"); } -static int test_mount_0 (void) +static int test_blockdev_rereadpt_0 (void) { - /* InitEmpty for mount (0) */ + /* InitEmpty for blockdev_rereadpt (0) */ { int r; suppress_error = 0; @@ -110,57 +113,48 @@ static int test_mount_0 (void) if (r == -1) return -1; } - /* TestOutput for mount (0) */ + /* TestRun for blockdev_rereadpt (0) */ { - char *lines[] = { - ",", - NULL - }; int r; suppress_error = 0; - r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); + r = guestfs_blockdev_rereadpt (g, "/dev/sda"); if (r == -1) return -1; } + return 0; +} + +static int test_blockdev_flushbufs_0 (void) +{ + /* InitEmpty for blockdev_flushbufs (0) */ { int r; suppress_error = 0; - r = guestfs_mkfs (g, "ext2", "/dev/sda1"); + r = guestfs_umount_all (g); if (r == -1) return -1; } { int r; suppress_error = 0; - r = guestfs_mount (g, "/dev/sda1", "/"); + r = guestfs_lvm_remove_all (g); if (r == -1) return -1; } + /* TestRun for blockdev_flushbufs (0) */ { int r; suppress_error = 0; - r = guestfs_write_file (g, "/new", "new file contents", 0); + r = guestfs_blockdev_flushbufs (g, "/dev/sda"); if (r == -1) return -1; } - { - char *r; - suppress_error = 0; - r = guestfs_cat (g, "/new"); - if (r == NULL) - return -1; - if (strcmp (r, "new file contents") != 0) { - fprintf (stderr, "test_mount_0: expected \"new file contents\" but got \"%s\"\n", r); - return -1; - } - free (r); - } return 0; } -static int test_sync_0 (void) +static int test_blockdev_getsize64_0 (void) { - /* InitEmpty for sync (0) */ + /* InitEmpty for blockdev_getsize64 (0) */ { int r; suppress_error = 0; @@ -175,20 +169,24 @@ static int test_sync_0 (void) if (r == -1) return -1; } - /* TestRun for sync (0) */ + /* TestOutputInt for blockdev_getsize64 (0) */ { - int r; + int64_t r; suppress_error = 0; - r = guestfs_sync (g); + r = guestfs_blockdev_getsize64 (g, "/dev/sda"); if (r == -1) return -1; + if (r != 524288000) { + fprintf (stderr, "test_blockdev_getsize64_0: expected 524288000 but got %d\n", (int) r); + return -1; + } } return 0; } -static int test_touch_0 (void) +static int test_blockdev_getsz_0 (void) { - /* InitBasicFS for touch (0): create ext2 on /dev/sda1 */ + /* InitEmpty for blockdev_getsz (0) */ { int r; suppress_error = 0; @@ -203,56 +201,56 @@ static int test_touch_0 (void) if (r == -1) return -1; } + /* TestOutputInt for blockdev_getsz (0) */ { - char *lines[] = { - ",", - NULL - }; - int r; + int64_t r; suppress_error = 0; - r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); + r = guestfs_blockdev_getsz (g, "/dev/sda"); if (r == -1) return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_mkfs (g, "ext2", "/dev/sda1"); - if (r == -1) + if (r != 1024000) { + fprintf (stderr, "test_blockdev_getsz_0: expected 1024000 but got %d\n", (int) r); return -1; + } } + return 0; +} + +static int test_blockdev_getbsz_0 (void) +{ + /* InitEmpty for blockdev_getbsz (0) */ { int r; suppress_error = 0; - r = guestfs_mount (g, "/dev/sda1", "/"); + r = guestfs_umount_all (g); if (r == -1) return -1; } - /* TestOutputTrue for touch (0) */ { int r; suppress_error = 0; - r = guestfs_touch (g, "/new"); + r = guestfs_lvm_remove_all (g); if (r == -1) return -1; } + /* TestOutputInt for blockdev_getbsz (0) */ { int r; suppress_error = 0; - r = guestfs_exists (g, "/new"); + r = guestfs_blockdev_getbsz (g, "/dev/sda"); if (r == -1) return -1; - if (!r) { - fprintf (stderr, "test_touch_0: expected true, got false\n"); + if (r != 4096) { + fprintf (stderr, "test_blockdev_getbsz_0: expected 4096 but got %d\n", (int) r); return -1; } } return 0; } -static int test_cat_0 (void) +static int test_blockdev_getss_0 (void) { - /* InitBasicFS for cat (0): create ext2 on /dev/sda1 */ + /* InitEmpty for blockdev_getss (0) */ { int r; suppress_error = 0; @@ -267,57 +265,63 @@ static int test_cat_0 (void) if (r == -1) return -1; } + /* TestOutputInt for blockdev_getss (0) */ { - char *lines[] = { - ",", - NULL - }; int r; suppress_error = 0; - r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); + r = guestfs_blockdev_getss (g, "/dev/sda"); if (r == -1) return -1; + if (r != 512) { + fprintf (stderr, "test_blockdev_getss_0: expected 512 but got %d\n", (int) r); + return -1; + } } + return 0; +} + +static int test_blockdev_getro_0 (void) +{ + /* InitEmpty for blockdev_getro (0) */ { int r; suppress_error = 0; - r = guestfs_mkfs (g, "ext2", "/dev/sda1"); + r = guestfs_umount_all (g); if (r == -1) return -1; } { int r; suppress_error = 0; - r = guestfs_mount (g, "/dev/sda1", "/"); + r = guestfs_lvm_remove_all (g); if (r == -1) return -1; } - /* TestOutput for cat (0) */ + /* TestOutputTrue for blockdev_getro (0) */ { int r; suppress_error = 0; - r = guestfs_write_file (g, "/new", "new file contents", 0); + r = guestfs_blockdev_setro (g, "/dev/sda"); if (r == -1) return -1; } { - char *r; + int r; suppress_error = 0; - r = guestfs_cat (g, "/new"); - if (r == NULL) + r = guestfs_blockdev_getro (g, "/dev/sda"); + if (r == -1) return -1; - if (strcmp (r, "new file contents") != 0) { - fprintf (stderr, "test_cat_0: expected \"new file contents\" but got \"%s\"\n", r); + if (!r) { + fprintf (stderr, "test_blockdev_getro_0: expected true, got false\n"); return -1; } - free (r); } return 0; } -static int test_ls_0 (void) +static int test_blockdev_setrw_0 (void) { - /* InitBasicFS for ls (0): create ext2 on /dev/sda1 */ + /* InitEmpty for blockdev_setrw (0) */ { int r; suppress_error = 0; @@ -332,111 +336,70 @@ static int test_ls_0 (void) if (r == -1) return -1; } + /* TestOutputFalse for blockdev_setrw (0) */ { - char *lines[] = { - ",", - NULL - }; int r; suppress_error = 0; - r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); + r = guestfs_blockdev_setrw (g, "/dev/sda"); if (r == -1) return -1; } { int r; suppress_error = 0; - r = guestfs_mkfs (g, "ext2", "/dev/sda1"); + r = guestfs_blockdev_getro (g, "/dev/sda"); if (r == -1) return -1; + if (r) { + fprintf (stderr, "test_blockdev_setrw_0: expected false, got true\n"); + return -1; + } } + return 0; +} + +static int test_blockdev_setro_0 (void) +{ + /* InitEmpty for blockdev_setro (0) */ { int r; suppress_error = 0; - r = guestfs_mount (g, "/dev/sda1", "/"); + r = guestfs_umount_all (g); if (r == -1) return -1; } - /* TestOutputList for ls (0) */ { int r; suppress_error = 0; - r = guestfs_touch (g, "/new"); + r = guestfs_lvm_remove_all (g); if (r == -1) return -1; } + /* TestOutputTrue for blockdev_setro (0) */ { int r; suppress_error = 0; - r = guestfs_touch (g, "/newer"); + r = guestfs_blockdev_setro (g, "/dev/sda"); if (r == -1) return -1; } { int r; suppress_error = 0; - r = guestfs_touch (g, "/newest"); + r = guestfs_blockdev_getro (g, "/dev/sda"); if (r == -1) return -1; - } - { - char **r; - int i; - suppress_error = 0; - r = guestfs_ls (g, "/"); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_ls_0: short list returned from command\n"); - print_strings (r); - return -1; - } - if (strcmp (r[0], "lost+found") != 0) { - fprintf (stderr, "test_ls_0: expected \"lost+found\" but got \"%s\"\n", r[0]); - return -1; - } - if (!r[1]) { - fprintf (stderr, "test_ls_0: short list returned from command\n"); - print_strings (r); - return -1; - } - if (strcmp (r[1], "new") != 0) { - fprintf (stderr, "test_ls_0: expected \"new\" but got \"%s\"\n", r[1]); - return -1; - } - if (!r[2]) { - fprintf (stderr, "test_ls_0: short list returned from command\n"); - print_strings (r); - return -1; - } - if (strcmp (r[2], "newer") != 0) { - fprintf (stderr, "test_ls_0: expected \"newer\" but got \"%s\"\n", r[2]); - return -1; - } - if (!r[3]) { - fprintf (stderr, "test_ls_0: short list returned from command\n"); - print_strings (r); - return -1; - } - if (strcmp (r[3], "newest") != 0) { - fprintf (stderr, "test_ls_0: expected \"newest\" but got \"%s\"\n", r[3]); - return -1; - } - if (r[4] != NULL) { - fprintf (stderr, "test_ls_0: extra elements returned from command\n"); - print_strings (r); + if (!r) { + fprintf (stderr, "test_blockdev_setro_0: expected true, got false\n"); return -1; } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); - free (r); } return 0; } -static int test_list_devices_0 (void) +static int test_statvfs_0 (void) { - /* InitEmpty for list_devices (0) */ + /* InitBasicFS for statvfs (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -451,56 +414,61 @@ static int test_list_devices_0 (void) if (r == -1) return -1; } - /* TestOutputList for list_devices (0) */ { - char **r; - int i; + char *lines[] = { + ",", + NULL + }; + int r; suppress_error = 0; - r = guestfs_list_devices (g); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_list_devices_0: short list returned from command\n"); - print_strings (r); + r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); + if (r == -1) return -1; - } - if (strcmp (r[0], "/dev/sda") != 0) { - fprintf (stderr, "test_list_devices_0: expected \"/dev/sda\" but got \"%s\"\n", r[0]); + } + { + int r; + suppress_error = 0; + r = guestfs_mkfs (g, "ext2", "/dev/sda1"); + if (r == -1) return -1; - } - if (!r[1]) { - fprintf (stderr, "test_list_devices_0: short list returned from command\n"); - print_strings (r); + } + { + int r; + suppress_error = 0; + r = guestfs_mount (g, "/dev/sda1", "/"); + if (r == -1) return -1; - } - if (strcmp (r[1], "/dev/sdb") != 0) { - fprintf (stderr, "test_list_devices_0: expected \"/dev/sdb\" but got \"%s\"\n", r[1]); + } + /* TestOutputStruct for statvfs (0) */ + { + struct guestfs_statvfs *r; + suppress_error = 0; + r = guestfs_statvfs (g, "/"); + if (r == NULL) return -1; - } - if (!r[2]) { - fprintf (stderr, "test_list_devices_0: short list returned from command\n"); - print_strings (r); + if (r->bfree != 487702) { + fprintf (stderr, "test_statvfs_0: bfree was %d, expected 487702\n", + (int) r->bfree); return -1; } - if (strcmp (r[2], "/dev/sdc") != 0) { - fprintf (stderr, "test_list_devices_0: expected \"/dev/sdc\" but got \"%s\"\n", r[2]); + if (r->blocks != 490020) { + fprintf (stderr, "test_statvfs_0: blocks was %d, expected 490020\n", + (int) r->blocks); return -1; } - if (r[3] != NULL) { - fprintf (stderr, "test_list_devices_0: extra elements returned from command\n"); - print_strings (r); + if (r->bsize != 1024) { + fprintf (stderr, "test_statvfs_0: bsize was %d, expected 1024\n", + (int) r->bsize); return -1; } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); free (r); } return 0; } -static int test_list_partitions_0 (void) +static int test_lstat_0 (void) { - /* InitBasicFS for list_partitions (0): create ext2 on /dev/sda1 */ + /* InitBasicFS for lstat (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -540,38 +508,33 @@ static int test_list_partitions_0 (void) if (r == -1) return -1; } - /* TestOutputList for list_partitions (0) */ + /* TestOutputStruct for lstat (0) */ { - char **r; - int i; + int r; suppress_error = 0; - r = guestfs_list_partitions (g); - if (r == NULL) + r = guestfs_touch (g, "/new"); + if (r == -1) return -1; - if (!r[0]) { - fprintf (stderr, "test_list_partitions_0: short list returned from command\n"); - print_strings (r); + } + { + struct guestfs_stat *r; + suppress_error = 0; + r = guestfs_lstat (g, "/new"); + if (r == NULL) return -1; - } - if (strcmp (r[0], "/dev/sda1") != 0) { - fprintf (stderr, "test_list_partitions_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]); - return -1; - } - if (r[1] != NULL) { - fprintf (stderr, "test_list_partitions_0: extra elements returned from command\n"); - print_strings (r); + if (r->size != 0) { + fprintf (stderr, "test_lstat_0: size was %d, expected 0\n", + (int) r->size); return -1; } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); free (r); } return 0; } -static int test_list_partitions_1 (void) +static int test_stat_0 (void) { - /* InitEmpty for list_partitions (1) */ + /* InitBasicFS for stat (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -586,11 +549,8 @@ static int test_list_partitions_1 (void) if (r == -1) return -1; } - /* TestOutputList for list_partitions (1) */ { char *lines[] = { - ",10", - ",20", ",", NULL }; @@ -601,54 +561,46 @@ static int test_list_partitions_1 (void) return -1; } { - char **r; - int i; + int r; suppress_error = 0; - r = guestfs_list_partitions (g); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_list_partitions_1: short list returned from command\n"); - print_strings (r); - return -1; - } - if (strcmp (r[0], "/dev/sda1") != 0) { - fprintf (stderr, "test_list_partitions_1: expected \"/dev/sda1\" but got \"%s\"\n", r[0]); - return -1; - } - if (!r[1]) { - fprintf (stderr, "test_list_partitions_1: short list returned from command\n"); - print_strings (r); + r = guestfs_mkfs (g, "ext2", "/dev/sda1"); + if (r == -1) return -1; - } - if (strcmp (r[1], "/dev/sda2") != 0) { - fprintf (stderr, "test_list_partitions_1: expected \"/dev/sda2\" but got \"%s\"\n", r[1]); + } + { + int r; + suppress_error = 0; + r = guestfs_mount (g, "/dev/sda1", "/"); + if (r == -1) return -1; - } - if (!r[2]) { - fprintf (stderr, "test_list_partitions_1: short list returned from command\n"); - print_strings (r); + } + /* TestOutputStruct for stat (0) */ + { + int r; + suppress_error = 0; + r = guestfs_touch (g, "/new"); + if (r == -1) return -1; - } - if (strcmp (r[2], "/dev/sda3") != 0) { - fprintf (stderr, "test_list_partitions_1: expected \"/dev/sda3\" but got \"%s\"\n", r[2]); + } + { + struct guestfs_stat *r; + suppress_error = 0; + r = guestfs_stat (g, "/new"); + if (r == NULL) return -1; - } - if (r[3] != NULL) { - fprintf (stderr, "test_list_partitions_1: extra elements returned from command\n"); - print_strings (r); + if (r->size != 0) { + fprintf (stderr, "test_stat_0: size was %d, expected 0\n", + (int) r->size); return -1; } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); free (r); } return 0; } -static int test_pvs_0 (void) +static int test_file_0 (void) { - /* InitBasicFSonLVM for pvs (0): create ext2 on /dev/VG/LV */ + /* InitBasicFS for file (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -677,74 +629,43 @@ static int test_pvs_0 (void) { int r; suppress_error = 0; - r = guestfs_pvcreate (g, "/dev/sda1"); - if (r == -1) - return -1; - } - { - char *physvols[] = { - "/dev/sda1", - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, "VG", physvols); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, "LV", "VG", 8); + r = guestfs_mkfs (g, "ext2", "/dev/sda1"); if (r == -1) return -1; } { int r; suppress_error = 0; - r = guestfs_mkfs (g, "ext2", "/dev/VG/LV"); + r = guestfs_mount (g, "/dev/sda1", "/"); if (r == -1) return -1; } + /* TestOutput for file (0) */ { int r; suppress_error = 0; - r = guestfs_mount (g, "/dev/VG/LV", "/"); + r = guestfs_touch (g, "/new"); if (r == -1) return -1; } - /* TestOutputList for pvs (0) */ { - char **r; - int i; + char *r; suppress_error = 0; - r = guestfs_pvs (g); + r = guestfs_file (g, "/new"); if (r == NULL) return -1; - if (!r[0]) { - fprintf (stderr, "test_pvs_0: short list returned from command\n"); - print_strings (r); - return -1; - } - if (strcmp (r[0], "/dev/sda1") != 0) { - fprintf (stderr, "test_pvs_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]); - return -1; - } - if (r[1] != NULL) { - fprintf (stderr, "test_pvs_0: extra elements returned from command\n"); - print_strings (r); + if (strcmp (r, "empty") != 0) { + fprintf (stderr, "test_file_0: expected \"empty\" but got \"%s\"\n", r); return -1; } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); free (r); } return 0; } -static int test_pvs_1 (void) +static int test_file_1 (void) { - /* InitEmpty for pvs (1) */ + /* InitBasicFS for file (1): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -759,11 +680,8 @@ static int test_pvs_1 (void) if (r == -1) return -1; } - /* TestOutputList for pvs (1) */ { char *lines[] = { - ",10", - ",20", ",", NULL }; @@ -776,73 +694,43 @@ static int test_pvs_1 (void) { int r; suppress_error = 0; - r = guestfs_pvcreate (g, "/dev/sda1"); + r = guestfs_mkfs (g, "ext2", "/dev/sda1"); if (r == -1) return -1; } { int r; suppress_error = 0; - r = guestfs_pvcreate (g, "/dev/sda2"); + r = guestfs_mount (g, "/dev/sda1", "/"); if (r == -1) return -1; } + /* TestOutput for file (1) */ { int r; suppress_error = 0; - r = guestfs_pvcreate (g, "/dev/sda3"); + r = guestfs_write_file (g, "/new", "some content\n", 0); if (r == -1) return -1; } { - char **r; - int i; + char *r; suppress_error = 0; - r = guestfs_pvs (g); + r = guestfs_file (g, "/new"); if (r == NULL) return -1; - if (!r[0]) { - fprintf (stderr, "test_pvs_1: short list returned from command\n"); - print_strings (r); - return -1; - } - if (strcmp (r[0], "/dev/sda1") != 0) { - fprintf (stderr, "test_pvs_1: expected \"/dev/sda1\" but got \"%s\"\n", r[0]); - return -1; - } - if (!r[1]) { - fprintf (stderr, "test_pvs_1: short list returned from command\n"); - print_strings (r); - return -1; - } - if (strcmp (r[1], "/dev/sda2") != 0) { - fprintf (stderr, "test_pvs_1: expected \"/dev/sda2\" but got \"%s\"\n", r[1]); - return -1; - } - if (!r[2]) { - fprintf (stderr, "test_pvs_1: short list returned from command\n"); - print_strings (r); - return -1; - } - if (strcmp (r[2], "/dev/sda3") != 0) { - fprintf (stderr, "test_pvs_1: expected \"/dev/sda3\" but got \"%s\"\n", r[2]); - return -1; - } - if (r[3] != NULL) { - fprintf (stderr, "test_pvs_1: extra elements returned from command\n"); - print_strings (r); + if (strcmp (r, "ASCII text") != 0) { + fprintf (stderr, "test_file_1: expected \"ASCII text\" but got \"%s\"\n", r); return -1; } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); free (r); } return 0; } -static int test_vgs_0 (void) +static int test_file_2 (void) { - /* InitBasicFSonLVM for vgs (0): create ext2 on /dev/VG/LV */ + /* InitBasicFS for file (2): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -871,74 +759,32 @@ static int test_vgs_0 (void) { int r; suppress_error = 0; - r = guestfs_pvcreate (g, "/dev/sda1"); - if (r == -1) - return -1; - } - { - char *physvols[] = { - "/dev/sda1", - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, "VG", physvols); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, "LV", "VG", 8); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_mkfs (g, "ext2", "/dev/VG/LV"); + r = guestfs_mkfs (g, "ext2", "/dev/sda1"); if (r == -1) return -1; } { int r; suppress_error = 0; - r = guestfs_mount (g, "/dev/VG/LV", "/"); + r = guestfs_mount (g, "/dev/sda1", "/"); if (r == -1) return -1; } - /* TestOutputList for vgs (0) */ + /* TestLastFail for file (2) */ { - char **r; - int i; - suppress_error = 0; - r = guestfs_vgs (g); - if (r == NULL) - return -1; - if (!r[0]) { - fprintf (stderr, "test_vgs_0: short list returned from command\n"); - print_strings (r); - return -1; - } - if (strcmp (r[0], "VG") != 0) { - fprintf (stderr, "test_vgs_0: expected \"VG\" but got \"%s\"\n", r[0]); - return -1; - } - if (r[1] != NULL) { - fprintf (stderr, "test_vgs_0: extra elements returned from command\n"); - print_strings (r); + char *r; + suppress_error = 1; + r = guestfs_file (g, "/nofile"); + if (r != NULL) return -1; - } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); free (r); } return 0; } -static int test_vgs_1 (void) +static int test_umount_all_0 (void) { - /* InitEmpty for vgs (1) */ + /* InitBasicFS for umount_all (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -953,11 +799,8 @@ static int test_vgs_1 (void) if (r == -1) return -1; } - /* TestOutputList for vgs (1) */ { char *lines[] = { - ",10", - ",20", ",", NULL }; @@ -970,44 +813,22 @@ static int test_vgs_1 (void) { int r; suppress_error = 0; - r = guestfs_pvcreate (g, "/dev/sda1"); + r = guestfs_mkfs (g, "ext2", "/dev/sda1"); if (r == -1) return -1; } { int r; suppress_error = 0; - r = guestfs_pvcreate (g, "/dev/sda2"); + r = guestfs_mount (g, "/dev/sda1", "/"); if (r == -1) return -1; } + /* TestOutputList for umount_all (0) */ { int r; suppress_error = 0; - r = guestfs_pvcreate (g, "/dev/sda3"); - if (r == -1) - return -1; - } - { - char *physvols[] = { - "/dev/sda1", - "/dev/sda2", - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, "VG1", physvols); - if (r == -1) - return -1; - } - { - char *physvols[] = { - "/dev/sda3", - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, "VG2", physvols); + r = guestfs_umount_all (g); if (r == -1) return -1; } @@ -1015,29 +836,11 @@ static int test_vgs_1 (void) char **r; int i; suppress_error = 0; - r = guestfs_vgs (g); + r = guestfs_mounts (g); if (r == NULL) return -1; - if (!r[0]) { - fprintf (stderr, "test_vgs_1: short list returned from command\n"); - print_strings (r); - return -1; - } - if (strcmp (r[0], "VG1") != 0) { - fprintf (stderr, "test_vgs_1: expected \"VG1\" but got \"%s\"\n", r[0]); - return -1; - } - if (!r[1]) { - fprintf (stderr, "test_vgs_1: short list returned from command\n"); - print_strings (r); - return -1; - } - if (strcmp (r[1], "VG2") != 0) { - fprintf (stderr, "test_vgs_1: expected \"VG2\" but got \"%s\"\n", r[1]); - return -1; - } - if (r[2] != NULL) { - fprintf (stderr, "test_vgs_1: extra elements returned from command\n"); + if (r[0] != NULL) { + fprintf (stderr, "test_umount_all_0: extra elements returned from command\n"); print_strings (r); return -1; } @@ -1048,9 +851,9 @@ static int test_vgs_1 (void) return 0; } -static int test_lvs_0 (void) +static int test_mounts_0 (void) { - /* InitBasicFSonLVM for lvs (0): create ext2 on /dev/VG/LV */ + /* InitBasicFS for mounts (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -1079,61 +882,36 @@ static int test_lvs_0 (void) { int r; suppress_error = 0; - r = guestfs_pvcreate (g, "/dev/sda1"); - if (r == -1) - return -1; - } - { - char *physvols[] = { - "/dev/sda1", - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, "VG", physvols); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, "LV", "VG", 8); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_mkfs (g, "ext2", "/dev/VG/LV"); + r = guestfs_mkfs (g, "ext2", "/dev/sda1"); if (r == -1) return -1; } { int r; suppress_error = 0; - r = guestfs_mount (g, "/dev/VG/LV", "/"); + r = guestfs_mount (g, "/dev/sda1", "/"); if (r == -1) return -1; } - /* TestOutputList for lvs (0) */ + /* TestOutputList for mounts (0) */ { char **r; int i; suppress_error = 0; - r = guestfs_lvs (g); + r = guestfs_mounts (g); if (r == NULL) return -1; if (!r[0]) { - fprintf (stderr, "test_lvs_0: short list returned from command\n"); + fprintf (stderr, "test_mounts_0: short list returned from command\n"); print_strings (r); return -1; } - if (strcmp (r[0], "/dev/VG/LV") != 0) { - fprintf (stderr, "test_lvs_0: expected \"/dev/VG/LV\" but got \"%s\"\n", r[0]); + if (strcmp (r[0], "/dev/sda1") != 0) { + fprintf (stderr, "test_mounts_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]); return -1; } if (r[1] != NULL) { - fprintf (stderr, "test_lvs_0: extra elements returned from command\n"); + fprintf (stderr, "test_mounts_0: extra elements returned from command\n"); print_strings (r); return -1; } @@ -1144,9 +922,9 @@ static int test_lvs_0 (void) return 0; } -static int test_lvs_1 (void) +static int test_umount_0 (void) { - /* InitEmpty for lvs (1) */ + /* InitEmpty for umount (0) */ { int r; suppress_error = 0; @@ -1161,11 +939,9 @@ static int test_lvs_1 (void) if (r == -1) return -1; } - /* TestOutputList for lvs (1) */ + /* TestOutputList for umount (0) */ { char *lines[] = { - ",10", - ",20", ",", NULL }; @@ -1178,65 +954,14 @@ static int test_lvs_1 (void) { int r; suppress_error = 0; - r = guestfs_pvcreate (g, "/dev/sda1"); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, "/dev/sda2"); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_pvcreate (g, "/dev/sda3"); - if (r == -1) - return -1; - } - { - char *physvols[] = { - "/dev/sda1", - "/dev/sda2", - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, "VG1", physvols); - if (r == -1) - return -1; - } - { - char *physvols[] = { - "/dev/sda3", - NULL - }; - int r; - suppress_error = 0; - r = guestfs_vgcreate (g, "VG2", physvols); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, "LV1", "VG1", 50); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, "LV2", "VG1", 50); + r = guestfs_mkfs (g, "ext2", "/dev/sda1"); if (r == -1) return -1; } { int r; suppress_error = 0; - r = guestfs_lvcreate (g, "LV3", "VG2", 50); + r = guestfs_mount (g, "/dev/sda1", "/"); if (r == -1) return -1; } @@ -1244,38 +969,20 @@ static int test_lvs_1 (void) char **r; int i; suppress_error = 0; - r = guestfs_lvs (g); + r = guestfs_mounts (g); if (r == NULL) return -1; if (!r[0]) { - fprintf (stderr, "test_lvs_1: short list returned from command\n"); - print_strings (r); - return -1; - } - if (strcmp (r[0], "/dev/VG1/LV1") != 0) { - fprintf (stderr, "test_lvs_1: expected \"/dev/VG1/LV1\" but got \"%s\"\n", r[0]); - return -1; - } - if (!r[1]) { - fprintf (stderr, "test_lvs_1: short list returned from command\n"); - print_strings (r); - return -1; - } - if (strcmp (r[1], "/dev/VG1/LV2") != 0) { - fprintf (stderr, "test_lvs_1: expected \"/dev/VG1/LV2\" but got \"%s\"\n", r[1]); - return -1; - } - if (!r[2]) { - fprintf (stderr, "test_lvs_1: short list returned from command\n"); + fprintf (stderr, "test_umount_0: short list returned from command\n"); print_strings (r); return -1; } - if (strcmp (r[2], "/dev/VG2/LV3") != 0) { - fprintf (stderr, "test_lvs_1: expected \"/dev/VG2/LV3\" but got \"%s\"\n", r[2]); + if (strcmp (r[0], "/dev/sda1") != 0) { + fprintf (stderr, "test_umount_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]); return -1; } - if (r[3] != NULL) { - fprintf (stderr, "test_lvs_1: extra elements returned from command\n"); + if (r[1] != NULL) { + fprintf (stderr, "test_umount_0: extra elements returned from command\n"); print_strings (r); return -1; } @@ -1286,9 +993,9 @@ static int test_lvs_1 (void) return 0; } -static int test_read_lines_0 (void) +static int test_umount_1 (void) { - /* InitBasicFS for read_lines (0): create ext2 on /dev/sda1 */ + /* InitEmpty for umount (1) */ { int r; suppress_error = 0; @@ -1303,6 +1010,7 @@ static int test_read_lines_0 (void) if (r == -1) return -1; } + /* TestOutputList for umount (1) */ { char *lines[] = { ",", @@ -1328,11 +1036,10 @@ static int test_read_lines_0 (void) if (r == -1) return -1; } - /* TestOutputList for read_lines (0) */ { int r; suppress_error = 0; - r = guestfs_write_file (g, "/new", "line1\r\nline2\nline3", 0); + r = guestfs_umount (g, "/"); if (r == -1) return -1; } @@ -1340,38 +1047,11 @@ static int test_read_lines_0 (void) char **r; int i; suppress_error = 0; - r = guestfs_read_lines (g, "/new"); + r = guestfs_mounts (g); if (r == NULL) return -1; - if (!r[0]) { - fprintf (stderr, "test_read_lines_0: short list returned from command\n"); - print_strings (r); - return -1; - } - if (strcmp (r[0], "line1") != 0) { - fprintf (stderr, "test_read_lines_0: expected \"line1\" but got \"%s\"\n", r[0]); - return -1; - } - if (!r[1]) { - fprintf (stderr, "test_read_lines_0: short list returned from command\n"); - print_strings (r); - return -1; - } - if (strcmp (r[1], "line2") != 0) { - fprintf (stderr, "test_read_lines_0: expected \"line2\" but got \"%s\"\n", r[1]); - return -1; - } - if (!r[2]) { - fprintf (stderr, "test_read_lines_0: short list returned from command\n"); - print_strings (r); - return -1; - } - if (strcmp (r[2], "line3") != 0) { - fprintf (stderr, "test_read_lines_0: expected \"line3\" but got \"%s\"\n", r[2]); - return -1; - } - if (r[3] != NULL) { - fprintf (stderr, "test_read_lines_0: extra elements returned from command\n"); + if (r[0] != NULL) { + fprintf (stderr, "test_umount_1: extra elements returned from command\n"); print_strings (r); return -1; } @@ -1382,9 +1062,9 @@ static int test_read_lines_0 (void) return 0; } -static int test_read_lines_1 (void) +static int test_write_file_0 (void) { - /* InitBasicFS for read_lines (1): create ext2 on /dev/sda1 */ + /* InitEmpty for write_file (0) */ { int r; suppress_error = 0; @@ -1399,6 +1079,7 @@ static int test_read_lines_1 (void) if (r == -1) return -1; } + /* TestOutput for write_file (0) */ { char *lines[] = { ",", @@ -1424,36 +1105,31 @@ static int test_read_lines_1 (void) if (r == -1) return -1; } - /* TestOutputList for read_lines (1) */ { int r; suppress_error = 0; - r = guestfs_write_file (g, "/new", "", 0); + r = guestfs_write_file (g, "/new", "new file contents", 0); if (r == -1) return -1; } { - char **r; - int i; + char *r; suppress_error = 0; - r = guestfs_read_lines (g, "/new"); + r = guestfs_cat (g, "/new"); if (r == NULL) return -1; - if (r[0] != NULL) { - fprintf (stderr, "test_read_lines_1: extra elements returned from command\n"); - print_strings (r); + if (strcmp (r, "new file contents") != 0) { + fprintf (stderr, "test_write_file_0: expected \"new file contents\" but got \"%s\"\n", r); return -1; } - for (i = 0; r[i] != NULL; ++i) - free (r[i]); free (r); } return 0; } -static int test_rm_0 (void) +static int test_mkfs_0 (void) { - /* InitBasicFS for rm (0): create ext2 on /dev/sda1 */ + /* InitEmpty for mkfs (0) */ { int r; suppress_error = 0; @@ -1468,6 +1144,7 @@ static int test_rm_0 (void) if (r == -1) return -1; } + /* TestOutput for mkfs (0) */ { char *lines[] = { ",", @@ -1493,27 +1170,607 @@ static int test_rm_0 (void) if (r == -1) return -1; } - /* TestRun for rm (0) */ { int r; suppress_error = 0; - r = guestfs_touch (g, "/new"); + r = guestfs_write_file (g, "/new", "new file contents", 0); if (r == -1) return -1; } { - int r; + char *r; suppress_error = 0; - r = guestfs_rm (g, "/new"); + r = guestfs_cat (g, "/new"); + if (r == NULL) + return -1; + if (strcmp (r, "new file contents") != 0) { + fprintf (stderr, "test_mkfs_0: expected \"new file contents\" but got \"%s\"\n", r); + return -1; + } + free (r); + } + return 0; +} + +static int test_lvcreate_0 (void) +{ + /* InitEmpty for lvcreate (0) */ + { + int r; + suppress_error = 0; + r = guestfs_umount_all (g); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_lvm_remove_all (g); + if (r == -1) + return -1; + } + /* TestOutputList for lvcreate (0) */ + { + char *lines[] = { + ",10", + ",20", + ",", + NULL + }; + int r; + suppress_error = 0; + r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_pvcreate (g, "/dev/sda1"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_pvcreate (g, "/dev/sda2"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_pvcreate (g, "/dev/sda3"); + if (r == -1) + return -1; + } + { + char *physvols[] = { + "/dev/sda1", + "/dev/sda2", + NULL + }; + int r; + suppress_error = 0; + r = guestfs_vgcreate (g, "VG1", physvols); + if (r == -1) + return -1; + } + { + char *physvols[] = { + "/dev/sda3", + NULL + }; + int r; + suppress_error = 0; + r = guestfs_vgcreate (g, "VG2", physvols); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_lvcreate (g, "LV1", "VG1", 50); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_lvcreate (g, "LV2", "VG1", 50); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_lvcreate (g, "LV3", "VG2", 50); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_lvcreate (g, "LV4", "VG2", 50); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_lvcreate (g, "LV5", "VG2", 50); + if (r == -1) + return -1; + } + { + char **r; + int i; + suppress_error = 0; + r = guestfs_lvs (g); + if (r == NULL) + return -1; + if (!r[0]) { + fprintf (stderr, "test_lvcreate_0: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[0], "/dev/VG1/LV1") != 0) { + fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG1/LV1\" but got \"%s\"\n", r[0]); + return -1; + } + if (!r[1]) { + fprintf (stderr, "test_lvcreate_0: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[1], "/dev/VG1/LV2") != 0) { + fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG1/LV2\" but got \"%s\"\n", r[1]); + return -1; + } + if (!r[2]) { + fprintf (stderr, "test_lvcreate_0: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[2], "/dev/VG2/LV3") != 0) { + fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG2/LV3\" but got \"%s\"\n", r[2]); + return -1; + } + if (!r[3]) { + fprintf (stderr, "test_lvcreate_0: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[3], "/dev/VG2/LV4") != 0) { + fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG2/LV4\" but got \"%s\"\n", r[3]); + return -1; + } + if (!r[4]) { + fprintf (stderr, "test_lvcreate_0: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[4], "/dev/VG2/LV5") != 0) { + fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG2/LV5\" but got \"%s\"\n", r[4]); + return -1; + } + if (r[5] != NULL) { + fprintf (stderr, "test_lvcreate_0: extra elements returned from command\n"); + print_strings (r); + return -1; + } + for (i = 0; r[i] != NULL; ++i) + free (r[i]); + free (r); + } + return 0; +} + +static int test_vgcreate_0 (void) +{ + /* InitEmpty for vgcreate (0) */ + { + int r; + suppress_error = 0; + r = guestfs_umount_all (g); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_lvm_remove_all (g); + if (r == -1) + return -1; + } + /* TestOutputList for vgcreate (0) */ + { + char *lines[] = { + ",10", + ",20", + ",", + NULL + }; + int r; + suppress_error = 0; + r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_pvcreate (g, "/dev/sda1"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_pvcreate (g, "/dev/sda2"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_pvcreate (g, "/dev/sda3"); + if (r == -1) + return -1; + } + { + char *physvols[] = { + "/dev/sda1", + "/dev/sda2", + NULL + }; + int r; + suppress_error = 0; + r = guestfs_vgcreate (g, "VG1", physvols); + if (r == -1) + return -1; + } + { + char *physvols[] = { + "/dev/sda3", + NULL + }; + int r; + suppress_error = 0; + r = guestfs_vgcreate (g, "VG2", physvols); + if (r == -1) + return -1; + } + { + char **r; + int i; + suppress_error = 0; + r = guestfs_vgs (g); + if (r == NULL) + return -1; + if (!r[0]) { + fprintf (stderr, "test_vgcreate_0: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[0], "VG1") != 0) { + fprintf (stderr, "test_vgcreate_0: expected \"VG1\" but got \"%s\"\n", r[0]); + return -1; + } + if (!r[1]) { + fprintf (stderr, "test_vgcreate_0: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[1], "VG2") != 0) { + fprintf (stderr, "test_vgcreate_0: expected \"VG2\" but got \"%s\"\n", r[1]); + return -1; + } + if (r[2] != NULL) { + fprintf (stderr, "test_vgcreate_0: extra elements returned from command\n"); + print_strings (r); + return -1; + } + for (i = 0; r[i] != NULL; ++i) + free (r[i]); + free (r); + } + return 0; +} + +static int test_pvcreate_0 (void) +{ + /* InitEmpty for pvcreate (0) */ + { + int r; + suppress_error = 0; + r = guestfs_umount_all (g); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_lvm_remove_all (g); + if (r == -1) + return -1; + } + /* TestOutputList for pvcreate (0) */ + { + char *lines[] = { + ",10", + ",20", + ",", + NULL + }; + int r; + suppress_error = 0; + r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_pvcreate (g, "/dev/sda1"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_pvcreate (g, "/dev/sda2"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_pvcreate (g, "/dev/sda3"); + if (r == -1) + return -1; + } + { + char **r; + int i; + suppress_error = 0; + r = guestfs_pvs (g); + if (r == NULL) + return -1; + if (!r[0]) { + fprintf (stderr, "test_pvcreate_0: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[0], "/dev/sda1") != 0) { + fprintf (stderr, "test_pvcreate_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]); + return -1; + } + if (!r[1]) { + fprintf (stderr, "test_pvcreate_0: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[1], "/dev/sda2") != 0) { + fprintf (stderr, "test_pvcreate_0: expected \"/dev/sda2\" but got \"%s\"\n", r[1]); + return -1; + } + if (!r[2]) { + fprintf (stderr, "test_pvcreate_0: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[2], "/dev/sda3") != 0) { + fprintf (stderr, "test_pvcreate_0: expected \"/dev/sda3\" but got \"%s\"\n", r[2]); + return -1; + } + if (r[3] != NULL) { + fprintf (stderr, "test_pvcreate_0: extra elements returned from command\n"); + print_strings (r); + return -1; + } + for (i = 0; r[i] != NULL; ++i) + free (r[i]); + free (r); + } + return 0; +} + +static int test_is_dir_0 (void) +{ + /* InitBasicFS for is_dir (0): create ext2 on /dev/sda1 */ + { + int r; + suppress_error = 0; + r = guestfs_umount_all (g); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_lvm_remove_all (g); + if (r == -1) + return -1; + } + { + char *lines[] = { + ",", + NULL + }; + int r; + suppress_error = 0; + r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mkfs (g, "ext2", "/dev/sda1"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mount (g, "/dev/sda1", "/"); + if (r == -1) + return -1; + } + /* TestOutputFalse for is_dir (0) */ + { + int r; + suppress_error = 0; + r = guestfs_touch (g, "/new"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_is_dir (g, "/new"); + if (r == -1) + return -1; + if (r) { + fprintf (stderr, "test_is_dir_0: expected false, got true\n"); + return -1; + } + } + return 0; +} + +static int test_is_dir_1 (void) +{ + /* InitBasicFS for is_dir (1): create ext2 on /dev/sda1 */ + { + int r; + suppress_error = 0; + r = guestfs_umount_all (g); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_lvm_remove_all (g); + if (r == -1) + return -1; + } + { + char *lines[] = { + ",", + NULL + }; + int r; + suppress_error = 0; + r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mkfs (g, "ext2", "/dev/sda1"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mount (g, "/dev/sda1", "/"); + if (r == -1) + return -1; + } + /* TestOutputTrue for is_dir (1) */ + { + int r; + suppress_error = 0; + r = guestfs_mkdir (g, "/new"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_is_dir (g, "/new"); + if (r == -1) + return -1; + if (!r) { + fprintf (stderr, "test_is_dir_1: expected true, got false\n"); + return -1; + } + } + return 0; +} + +static int test_is_file_0 (void) +{ + /* InitBasicFS for is_file (0): create ext2 on /dev/sda1 */ + { + int r; + suppress_error = 0; + r = guestfs_umount_all (g); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_lvm_remove_all (g); + if (r == -1) + return -1; + } + { + char *lines[] = { + ",", + NULL + }; + int r; + suppress_error = 0; + r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mkfs (g, "ext2", "/dev/sda1"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mount (g, "/dev/sda1", "/"); + if (r == -1) + return -1; + } + /* TestOutputTrue for is_file (0) */ + { + int r; + suppress_error = 0; + r = guestfs_touch (g, "/new"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_is_file (g, "/new"); if (r == -1) return -1; + if (!r) { + fprintf (stderr, "test_is_file_0: expected true, got false\n"); + return -1; + } } return 0; } -static int test_rm_1 (void) +static int test_is_file_1 (void) { - /* InitBasicFS for rm (1): create ext2 on /dev/sda1 */ + /* InitBasicFS for is_file (1): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -1553,20 +1810,31 @@ static int test_rm_1 (void) if (r == -1) return -1; } - /* TestLastFail for rm (1) */ + /* TestOutputFalse for is_file (1) */ { int r; - suppress_error = 1; - r = guestfs_rm (g, "/new"); - if (r != -1) + suppress_error = 0; + r = guestfs_mkdir (g, "/new"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_is_file (g, "/new"); + if (r == -1) + return -1; + if (r) { + fprintf (stderr, "test_is_file_1: expected false, got true\n"); return -1; + } } return 0; } -static int test_rm_2 (void) +static int test_exists_0 (void) { - /* InitBasicFS for rm (2): create ext2 on /dev/sda1 */ + /* InitBasicFS for exists (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -1606,27 +1874,31 @@ static int test_rm_2 (void) if (r == -1) return -1; } - /* TestLastFail for rm (2) */ + /* TestOutputTrue for exists (0) */ { int r; suppress_error = 0; - r = guestfs_mkdir (g, "/new"); + r = guestfs_touch (g, "/new"); if (r == -1) return -1; } { int r; - suppress_error = 1; - r = guestfs_rm (g, "/new"); - if (r != -1) + suppress_error = 0; + r = guestfs_exists (g, "/new"); + if (r == -1) + return -1; + if (!r) { + fprintf (stderr, "test_exists_0: expected true, got false\n"); return -1; + } } return 0; } -static int test_rmdir_0 (void) +static int test_exists_1 (void) { - /* InitBasicFS for rmdir (0): create ext2 on /dev/sda1 */ + /* InitBasicFS for exists (1): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -1666,7 +1938,7 @@ static int test_rmdir_0 (void) if (r == -1) return -1; } - /* TestRun for rmdir (0) */ + /* TestOutputTrue for exists (1) */ { int r; suppress_error = 0; @@ -1677,16 +1949,20 @@ static int test_rmdir_0 (void) { int r; suppress_error = 0; - r = guestfs_rmdir (g, "/new"); + r = guestfs_exists (g, "/new"); if (r == -1) return -1; + if (!r) { + fprintf (stderr, "test_exists_1: expected true, got false\n"); + return -1; + } } return 0; } -static int test_rmdir_1 (void) +static int test_mkdir_p_0 (void) { - /* InitBasicFS for rmdir (1): create ext2 on /dev/sda1 */ + /* InitBasicFS for mkdir_p (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -1726,20 +2002,31 @@ static int test_rmdir_1 (void) if (r == -1) return -1; } - /* TestLastFail for rmdir (1) */ + /* TestOutputTrue for mkdir_p (0) */ { int r; - suppress_error = 1; - r = guestfs_rmdir (g, "/new"); - if (r != -1) + suppress_error = 0; + r = guestfs_mkdir_p (g, "/new/foo/bar"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_is_dir (g, "/new/foo/bar"); + if (r == -1) + return -1; + if (!r) { + fprintf (stderr, "test_mkdir_p_0: expected true, got false\n"); return -1; + } } return 0; } -static int test_rmdir_2 (void) +static int test_mkdir_p_1 (void) { - /* InitBasicFS for rmdir (2): create ext2 on /dev/sda1 */ + /* InitBasicFS for mkdir_p (1): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -1779,27 +2066,31 @@ static int test_rmdir_2 (void) if (r == -1) return -1; } - /* TestLastFail for rmdir (2) */ + /* TestOutputTrue for mkdir_p (1) */ { int r; suppress_error = 0; - r = guestfs_touch (g, "/new"); + r = guestfs_mkdir_p (g, "/new/foo/bar"); if (r == -1) return -1; } { int r; - suppress_error = 1; - r = guestfs_rmdir (g, "/new"); - if (r != -1) + suppress_error = 0; + r = guestfs_is_dir (g, "/new/foo"); + if (r == -1) return -1; + if (!r) { + fprintf (stderr, "test_mkdir_p_1: expected true, got false\n"); + return -1; + } } return 0; } -static int test_rm_rf_0 (void) +static int test_mkdir_p_2 (void) { - /* InitBasicFS for rm_rf (0): create ext2 on /dev/sda1 */ + /* InitBasicFS for mkdir_p (2): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -1839,43 +2130,22 @@ static int test_rm_rf_0 (void) if (r == -1) return -1; } - /* TestOutputFalse for rm_rf (0) */ - { - int r; - suppress_error = 0; - r = guestfs_mkdir (g, "/new"); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_mkdir (g, "/new/foo"); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_touch (g, "/new/foo/bar"); - if (r == -1) - return -1; - } + /* TestOutputTrue for mkdir_p (2) */ { int r; suppress_error = 0; - r = guestfs_rm_rf (g, "/new"); + r = guestfs_mkdir_p (g, "/new/foo/bar"); if (r == -1) return -1; } { int r; suppress_error = 0; - r = guestfs_exists (g, "/new"); + r = guestfs_is_dir (g, "/new"); if (r == -1) return -1; - if (r) { - fprintf (stderr, "test_rm_rf_0: expected false, got true\n"); + if (!r) { + fprintf (stderr, "test_mkdir_p_2: expected true, got false\n"); return -1; } } @@ -1999,9 +2269,9 @@ static int test_mkdir_1 (void) return 0; } -static int test_mkdir_p_0 (void) +static int test_rm_rf_0 (void) { - /* InitBasicFS for mkdir_p (0): create ext2 on /dev/sda1 */ + /* InitBasicFS for rm_rf (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -2041,95 +2311,52 @@ static int test_mkdir_p_0 (void) if (r == -1) return -1; } - /* TestOutputTrue for mkdir_p (0) */ - { - int r; - suppress_error = 0; - r = guestfs_mkdir_p (g, "/new/foo/bar"); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_is_dir (g, "/new/foo/bar"); - if (r == -1) - return -1; - if (!r) { - fprintf (stderr, "test_mkdir_p_0: expected true, got false\n"); - return -1; - } - } - return 0; -} - -static int test_mkdir_p_1 (void) -{ - /* InitBasicFS for mkdir_p (1): create ext2 on /dev/sda1 */ - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } + /* TestOutputFalse for rm_rf (0) */ { - char *lines[] = { - ",", - NULL - }; int r; suppress_error = 0; - r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); + r = guestfs_mkdir (g, "/new"); if (r == -1) return -1; } { int r; suppress_error = 0; - r = guestfs_mkfs (g, "ext2", "/dev/sda1"); + r = guestfs_mkdir (g, "/new/foo"); if (r == -1) return -1; } { int r; suppress_error = 0; - r = guestfs_mount (g, "/dev/sda1", "/"); + r = guestfs_touch (g, "/new/foo/bar"); if (r == -1) return -1; } - /* TestOutputTrue for mkdir_p (1) */ { int r; suppress_error = 0; - r = guestfs_mkdir_p (g, "/new/foo/bar"); + r = guestfs_rm_rf (g, "/new"); if (r == -1) return -1; } { int r; suppress_error = 0; - r = guestfs_is_dir (g, "/new/foo"); + r = guestfs_exists (g, "/new"); if (r == -1) return -1; - if (!r) { - fprintf (stderr, "test_mkdir_p_1: expected true, got false\n"); + if (r) { + fprintf (stderr, "test_rm_rf_0: expected false, got true\n"); return -1; } } return 0; } -static int test_mkdir_p_2 (void) +static int test_rmdir_0 (void) { - /* InitBasicFS for mkdir_p (2): create ext2 on /dev/sda1 */ + /* InitBasicFS for rmdir (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -2169,31 +2396,27 @@ static int test_mkdir_p_2 (void) if (r == -1) return -1; } - /* TestOutputTrue for mkdir_p (2) */ + /* TestRun for rmdir (0) */ { int r; suppress_error = 0; - r = guestfs_mkdir_p (g, "/new/foo/bar"); + r = guestfs_mkdir (g, "/new"); if (r == -1) return -1; } { int r; suppress_error = 0; - r = guestfs_is_dir (g, "/new"); + r = guestfs_rmdir (g, "/new"); if (r == -1) return -1; - if (!r) { - fprintf (stderr, "test_mkdir_p_2: expected true, got false\n"); - return -1; - } } return 0; } -static int test_exists_0 (void) +static int test_rmdir_1 (void) { - /* InitBasicFS for exists (0): create ext2 on /dev/sda1 */ + /* InitBasicFS for rmdir (1): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -2233,31 +2456,20 @@ static int test_exists_0 (void) if (r == -1) return -1; } - /* TestOutputTrue for exists (0) */ - { - int r; - suppress_error = 0; - r = guestfs_touch (g, "/new"); - if (r == -1) - return -1; - } + /* TestLastFail for rmdir (1) */ { int r; - suppress_error = 0; - r = guestfs_exists (g, "/new"); - if (r == -1) - return -1; - if (!r) { - fprintf (stderr, "test_exists_0: expected true, got false\n"); + suppress_error = 1; + r = guestfs_rmdir (g, "/new"); + if (r != -1) return -1; - } } return 0; } -static int test_exists_1 (void) +static int test_rmdir_2 (void) { - /* InitBasicFS for exists (1): create ext2 on /dev/sda1 */ + /* InitBasicFS for rmdir (2): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -2297,31 +2509,27 @@ static int test_exists_1 (void) if (r == -1) return -1; } - /* TestOutputTrue for exists (1) */ - { - int r; - suppress_error = 0; - r = guestfs_mkdir (g, "/new"); - if (r == -1) - return -1; - } + /* TestLastFail for rmdir (2) */ { int r; suppress_error = 0; - r = guestfs_exists (g, "/new"); + r = guestfs_touch (g, "/new"); if (r == -1) return -1; - if (!r) { - fprintf (stderr, "test_exists_1: expected true, got false\n"); + } + { + int r; + suppress_error = 1; + r = guestfs_rmdir (g, "/new"); + if (r != -1) return -1; - } } return 0; } -static int test_is_file_0 (void) +static int test_rm_0 (void) { - /* InitBasicFS for is_file (0): create ext2 on /dev/sda1 */ + /* InitBasicFS for rm (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -2361,7 +2569,7 @@ static int test_is_file_0 (void) if (r == -1) return -1; } - /* TestOutputTrue for is_file (0) */ + /* TestRun for rm (0) */ { int r; suppress_error = 0; @@ -2372,20 +2580,16 @@ static int test_is_file_0 (void) { int r; suppress_error = 0; - r = guestfs_is_file (g, "/new"); + r = guestfs_rm (g, "/new"); if (r == -1) return -1; - if (!r) { - fprintf (stderr, "test_is_file_0: expected true, got false\n"); - return -1; - } } return 0; } -static int test_is_file_1 (void) +static int test_rm_1 (void) { - /* InitBasicFS for is_file (1): create ext2 on /dev/sda1 */ + /* InitBasicFS for rm (1): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -2425,31 +2629,20 @@ static int test_is_file_1 (void) if (r == -1) return -1; } - /* TestOutputFalse for is_file (1) */ - { - int r; - suppress_error = 0; - r = guestfs_mkdir (g, "/new"); - if (r == -1) - return -1; - } + /* TestLastFail for rm (1) */ { int r; - suppress_error = 0; - r = guestfs_is_file (g, "/new"); - if (r == -1) - return -1; - if (r) { - fprintf (stderr, "test_is_file_1: expected false, got true\n"); + suppress_error = 1; + r = guestfs_rm (g, "/new"); + if (r != -1) return -1; - } } return 0; } -static int test_is_dir_0 (void) +static int test_rm_2 (void) { - /* InitBasicFS for is_dir (0): create ext2 on /dev/sda1 */ + /* InitBasicFS for rm (2): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -2489,31 +2682,27 @@ static int test_is_dir_0 (void) if (r == -1) return -1; } - /* TestOutputFalse for is_dir (0) */ + /* TestLastFail for rm (2) */ { int r; suppress_error = 0; - r = guestfs_touch (g, "/new"); + r = guestfs_mkdir (g, "/new"); if (r == -1) return -1; } { int r; - suppress_error = 0; - r = guestfs_is_dir (g, "/new"); - if (r == -1) - return -1; - if (r) { - fprintf (stderr, "test_is_dir_0: expected false, got true\n"); + suppress_error = 1; + r = guestfs_rm (g, "/new"); + if (r != -1) return -1; - } } return 0; } -static int test_is_dir_1 (void) +static int test_read_lines_0 (void) { - /* InitBasicFS for is_dir (1): create ext2 on /dev/sda1 */ + /* InitBasicFS for read_lines (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -2553,31 +2742,63 @@ static int test_is_dir_1 (void) if (r == -1) return -1; } - /* TestOutputTrue for is_dir (1) */ + /* TestOutputList for read_lines (0) */ { int r; suppress_error = 0; - r = guestfs_mkdir (g, "/new"); + r = guestfs_write_file (g, "/new", "line1\r\nline2\nline3", 0); if (r == -1) return -1; } { - int r; + char **r; + int i; suppress_error = 0; - r = guestfs_is_dir (g, "/new"); - if (r == -1) + r = guestfs_read_lines (g, "/new"); + if (r == NULL) return -1; - if (!r) { - fprintf (stderr, "test_is_dir_1: expected true, got false\n"); + if (!r[0]) { + fprintf (stderr, "test_read_lines_0: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[0], "line1") != 0) { + fprintf (stderr, "test_read_lines_0: expected \"line1\" but got \"%s\"\n", r[0]); + return -1; + } + if (!r[1]) { + fprintf (stderr, "test_read_lines_0: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[1], "line2") != 0) { + fprintf (stderr, "test_read_lines_0: expected \"line2\" but got \"%s\"\n", r[1]); + return -1; + } + if (!r[2]) { + fprintf (stderr, "test_read_lines_0: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[2], "line3") != 0) { + fprintf (stderr, "test_read_lines_0: expected \"line3\" but got \"%s\"\n", r[2]); + return -1; + } + if (r[3] != NULL) { + fprintf (stderr, "test_read_lines_0: extra elements returned from command\n"); + print_strings (r); return -1; } + for (i = 0; r[i] != NULL; ++i) + free (r[i]); + free (r); } return 0; } -static int test_pvcreate_0 (void) +static int test_read_lines_1 (void) { - /* InitEmpty for pvcreate (0) */ + /* InitBasicFS for read_lines (1): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -2592,11 +2813,8 @@ static int test_pvcreate_0 (void) if (r == -1) return -1; } - /* TestOutputList for pvcreate (0) */ { char *lines[] = { - ",10", - ",20", ",", NULL }; @@ -2609,21 +2827,22 @@ static int test_pvcreate_0 (void) { int r; suppress_error = 0; - r = guestfs_pvcreate (g, "/dev/sda1"); + r = guestfs_mkfs (g, "ext2", "/dev/sda1"); if (r == -1) return -1; } { int r; suppress_error = 0; - r = guestfs_pvcreate (g, "/dev/sda2"); + r = guestfs_mount (g, "/dev/sda1", "/"); if (r == -1) return -1; } + /* TestOutputList for read_lines (1) */ { int r; suppress_error = 0; - r = guestfs_pvcreate (g, "/dev/sda3"); + r = guestfs_write_file (g, "/new", "", 0); if (r == -1) return -1; } @@ -2631,38 +2850,11 @@ static int test_pvcreate_0 (void) char **r; int i; suppress_error = 0; - r = guestfs_pvs (g); + r = guestfs_read_lines (g, "/new"); if (r == NULL) return -1; - if (!r[0]) { - fprintf (stderr, "test_pvcreate_0: short list returned from command\n"); - print_strings (r); - return -1; - } - if (strcmp (r[0], "/dev/sda1") != 0) { - fprintf (stderr, "test_pvcreate_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]); - return -1; - } - if (!r[1]) { - fprintf (stderr, "test_pvcreate_0: short list returned from command\n"); - print_strings (r); - return -1; - } - if (strcmp (r[1], "/dev/sda2") != 0) { - fprintf (stderr, "test_pvcreate_0: expected \"/dev/sda2\" but got \"%s\"\n", r[1]); - return -1; - } - if (!r[2]) { - fprintf (stderr, "test_pvcreate_0: short list returned from command\n"); - print_strings (r); - return -1; - } - if (strcmp (r[2], "/dev/sda3") != 0) { - fprintf (stderr, "test_pvcreate_0: expected \"/dev/sda3\" but got \"%s\"\n", r[2]); - return -1; - } - if (r[3] != NULL) { - fprintf (stderr, "test_pvcreate_0: extra elements returned from command\n"); + if (r[0] != NULL) { + fprintf (stderr, "test_read_lines_1: extra elements returned from command\n"); print_strings (r); return -1; } @@ -2673,9 +2865,9 @@ static int test_pvcreate_0 (void) return 0; } -static int test_vgcreate_0 (void) +static int test_lvs_0 (void) { - /* InitEmpty for vgcreate (0) */ + /* InitBasicFSonLVM for lvs (0): create ext2 on /dev/VG/LV */ { int r; suppress_error = 0; @@ -2690,11 +2882,8 @@ static int test_vgcreate_0 (void) if (r == -1) return -1; } - /* TestOutputList for vgcreate (0) */ { char *lines[] = { - ",10", - ",20", ",", NULL }; @@ -2712,69 +2901,56 @@ static int test_vgcreate_0 (void) return -1; } { + char *physvols[] = { + "/dev/sda1", + NULL + }; int r; suppress_error = 0; - r = guestfs_pvcreate (g, "/dev/sda2"); + r = guestfs_vgcreate (g, "VG", physvols); if (r == -1) return -1; } { int r; suppress_error = 0; - r = guestfs_pvcreate (g, "/dev/sda3"); + r = guestfs_lvcreate (g, "LV", "VG", 8); if (r == -1) return -1; } { - char *physvols[] = { - "/dev/sda1", - "/dev/sda2", - NULL - }; int r; suppress_error = 0; - r = guestfs_vgcreate (g, "VG1", physvols); + r = guestfs_mkfs (g, "ext2", "/dev/VG/LV"); if (r == -1) return -1; } { - char *physvols[] = { - "/dev/sda3", - NULL - }; int r; suppress_error = 0; - r = guestfs_vgcreate (g, "VG2", physvols); + r = guestfs_mount (g, "/dev/VG/LV", "/"); if (r == -1) return -1; } + /* TestOutputList for lvs (0) */ { char **r; int i; suppress_error = 0; - r = guestfs_vgs (g); + r = guestfs_lvs (g); if (r == NULL) return -1; if (!r[0]) { - fprintf (stderr, "test_vgcreate_0: short list returned from command\n"); - print_strings (r); - return -1; - } - if (strcmp (r[0], "VG1") != 0) { - fprintf (stderr, "test_vgcreate_0: expected \"VG1\" but got \"%s\"\n", r[0]); - return -1; - } - if (!r[1]) { - fprintf (stderr, "test_vgcreate_0: short list returned from command\n"); + fprintf (stderr, "test_lvs_0: short list returned from command\n"); print_strings (r); return -1; } - if (strcmp (r[1], "VG2") != 0) { - fprintf (stderr, "test_vgcreate_0: expected \"VG2\" but got \"%s\"\n", r[1]); + if (strcmp (r[0], "/dev/VG/LV") != 0) { + fprintf (stderr, "test_lvs_0: expected \"/dev/VG/LV\" but got \"%s\"\n", r[0]); return -1; } - if (r[2] != NULL) { - fprintf (stderr, "test_vgcreate_0: extra elements returned from command\n"); + if (r[1] != NULL) { + fprintf (stderr, "test_lvs_0: extra elements returned from command\n"); print_strings (r); return -1; } @@ -2785,9 +2961,9 @@ static int test_vgcreate_0 (void) return 0; } -static int test_lvcreate_0 (void) +static int test_lvs_1 (void) { - /* InitEmpty for lvcreate (0) */ + /* InitEmpty for lvs (1) */ { int r; suppress_error = 0; @@ -2802,7 +2978,7 @@ static int test_lvcreate_0 (void) if (r == -1) return -1; } - /* TestOutputList for lvcreate (0) */ + /* TestOutputList for lvs (1) */ { char *lines[] = { ",10", @@ -2882,20 +3058,6 @@ static int test_lvcreate_0 (void) return -1; } { - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, "LV4", "VG2", 50); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvcreate (g, "LV5", "VG2", 50); - if (r == -1) - return -1; - } - { char **r; int i; suppress_error = 0; @@ -2903,52 +3065,34 @@ static int test_lvcreate_0 (void) if (r == NULL) return -1; if (!r[0]) { - fprintf (stderr, "test_lvcreate_0: short list returned from command\n"); + fprintf (stderr, "test_lvs_1: short list returned from command\n"); print_strings (r); return -1; } if (strcmp (r[0], "/dev/VG1/LV1") != 0) { - fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG1/LV1\" but got \"%s\"\n", r[0]); + fprintf (stderr, "test_lvs_1: expected \"/dev/VG1/LV1\" but got \"%s\"\n", r[0]); return -1; } if (!r[1]) { - fprintf (stderr, "test_lvcreate_0: short list returned from command\n"); + fprintf (stderr, "test_lvs_1: short list returned from command\n"); print_strings (r); return -1; } if (strcmp (r[1], "/dev/VG1/LV2") != 0) { - fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG1/LV2\" but got \"%s\"\n", r[1]); - return -1; - } - if (!r[2]) { - fprintf (stderr, "test_lvcreate_0: short list returned from command\n"); - print_strings (r); - return -1; - } - if (strcmp (r[2], "/dev/VG2/LV3") != 0) { - fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG2/LV3\" but got \"%s\"\n", r[2]); - return -1; - } - if (!r[3]) { - fprintf (stderr, "test_lvcreate_0: short list returned from command\n"); - print_strings (r); - return -1; - } - if (strcmp (r[3], "/dev/VG2/LV4") != 0) { - fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG2/LV4\" but got \"%s\"\n", r[3]); + fprintf (stderr, "test_lvs_1: expected \"/dev/VG1/LV2\" but got \"%s\"\n", r[1]); return -1; } - if (!r[4]) { - fprintf (stderr, "test_lvcreate_0: short list returned from command\n"); + if (!r[2]) { + fprintf (stderr, "test_lvs_1: short list returned from command\n"); print_strings (r); return -1; } - if (strcmp (r[4], "/dev/VG2/LV5") != 0) { - fprintf (stderr, "test_lvcreate_0: expected \"/dev/VG2/LV5\" but got \"%s\"\n", r[4]); + if (strcmp (r[2], "/dev/VG2/LV3") != 0) { + fprintf (stderr, "test_lvs_1: expected \"/dev/VG2/LV3\" but got \"%s\"\n", r[2]); return -1; } - if (r[5] != NULL) { - fprintf (stderr, "test_lvcreate_0: extra elements returned from command\n"); + if (r[3] != NULL) { + fprintf (stderr, "test_lvs_1: extra elements returned from command\n"); print_strings (r); return -1; } @@ -2959,9 +3103,9 @@ static int test_lvcreate_0 (void) return 0; } -static int test_mkfs_0 (void) +static int test_vgs_0 (void) { - /* InitEmpty for mkfs (0) */ + /* InitBasicFSonLVM for vgs (0): create ext2 on /dev/VG/LV */ { int r; suppress_error = 0; @@ -2976,7 +3120,6 @@ static int test_mkfs_0 (void) if (r == -1) return -1; } - /* TestOutput for mkfs (0) */ { char *lines[] = { ",", @@ -2991,42 +3134,74 @@ static int test_mkfs_0 (void) { int r; suppress_error = 0; - r = guestfs_mkfs (g, "ext2", "/dev/sda1"); + r = guestfs_pvcreate (g, "/dev/sda1"); if (r == -1) return -1; } { + char *physvols[] = { + "/dev/sda1", + NULL + }; int r; suppress_error = 0; - r = guestfs_mount (g, "/dev/sda1", "/"); + r = guestfs_vgcreate (g, "VG", physvols); if (r == -1) return -1; } { int r; suppress_error = 0; - r = guestfs_write_file (g, "/new", "new file contents", 0); + r = guestfs_lvcreate (g, "LV", "VG", 8); if (r == -1) return -1; } { - char *r; + int r; suppress_error = 0; - r = guestfs_cat (g, "/new"); + r = guestfs_mkfs (g, "ext2", "/dev/VG/LV"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mount (g, "/dev/VG/LV", "/"); + if (r == -1) + return -1; + } + /* TestOutputList for vgs (0) */ + { + char **r; + int i; + suppress_error = 0; + r = guestfs_vgs (g); if (r == NULL) return -1; - if (strcmp (r, "new file contents") != 0) { - fprintf (stderr, "test_mkfs_0: expected \"new file contents\" but got \"%s\"\n", r); + if (!r[0]) { + fprintf (stderr, "test_vgs_0: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[0], "VG") != 0) { + fprintf (stderr, "test_vgs_0: expected \"VG\" but got \"%s\"\n", r[0]); + return -1; + } + if (r[1] != NULL) { + fprintf (stderr, "test_vgs_0: extra elements returned from command\n"); + print_strings (r); return -1; } + for (i = 0; r[i] != NULL; ++i) + free (r[i]); free (r); } return 0; } -static int test_write_file_0 (void) +static int test_vgs_1 (void) { - /* InitEmpty for write_file (0) */ + /* InitEmpty for vgs (1) */ { int r; suppress_error = 0; @@ -3041,9 +3216,11 @@ static int test_write_file_0 (void) if (r == -1) return -1; } - /* TestOutput for write_file (0) */ + /* TestOutputList for vgs (1) */ { char *lines[] = { + ",10", + ",20", ",", NULL }; @@ -3056,79 +3233,44 @@ static int test_write_file_0 (void) { int r; suppress_error = 0; - r = guestfs_mkfs (g, "ext2", "/dev/sda1"); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_mount (g, "/dev/sda1", "/"); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_write_file (g, "/new", "new file contents", 0); + r = guestfs_pvcreate (g, "/dev/sda1"); if (r == -1) return -1; } { - char *r; - suppress_error = 0; - r = guestfs_cat (g, "/new"); - if (r == NULL) - return -1; - if (strcmp (r, "new file contents") != 0) { - fprintf (stderr, "test_write_file_0: expected \"new file contents\" but got \"%s\"\n", r); - return -1; - } - free (r); - } - return 0; -} - -static int test_umount_0 (void) -{ - /* InitEmpty for umount (0) */ - { int r; suppress_error = 0; - r = guestfs_umount_all (g); + r = guestfs_pvcreate (g, "/dev/sda2"); if (r == -1) return -1; } { int r; suppress_error = 0; - r = guestfs_lvm_remove_all (g); + r = guestfs_pvcreate (g, "/dev/sda3"); if (r == -1) return -1; } - /* TestOutputList for umount (0) */ { - char *lines[] = { - ",", + char *physvols[] = { + "/dev/sda1", + "/dev/sda2", NULL }; int r; suppress_error = 0; - r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_mkfs (g, "ext2", "/dev/sda1"); + r = guestfs_vgcreate (g, "VG1", physvols); if (r == -1) return -1; } { + char *physvols[] = { + "/dev/sda3", + NULL + }; int r; suppress_error = 0; - r = guestfs_mount (g, "/dev/sda1", "/"); + r = guestfs_vgcreate (g, "VG2", physvols); if (r == -1) return -1; } @@ -3136,20 +3278,29 @@ static int test_umount_0 (void) char **r; int i; suppress_error = 0; - r = guestfs_mounts (g); + r = guestfs_vgs (g); if (r == NULL) return -1; if (!r[0]) { - fprintf (stderr, "test_umount_0: short list returned from command\n"); + fprintf (stderr, "test_vgs_1: short list returned from command\n"); print_strings (r); return -1; } - if (strcmp (r[0], "/dev/sda1") != 0) { - fprintf (stderr, "test_umount_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]); + if (strcmp (r[0], "VG1") != 0) { + fprintf (stderr, "test_vgs_1: expected \"VG1\" but got \"%s\"\n", r[0]); return -1; } - if (r[1] != NULL) { - fprintf (stderr, "test_umount_0: extra elements returned from command\n"); + if (!r[1]) { + fprintf (stderr, "test_vgs_1: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[1], "VG2") != 0) { + fprintf (stderr, "test_vgs_1: expected \"VG2\" but got \"%s\"\n", r[1]); + return -1; + } + if (r[2] != NULL) { + fprintf (stderr, "test_vgs_1: extra elements returned from command\n"); print_strings (r); return -1; } @@ -3160,9 +3311,9 @@ static int test_umount_0 (void) return 0; } -static int test_umount_1 (void) +static int test_pvs_0 (void) { - /* InitEmpty for umount (1) */ + /* InitBasicFSonLVM for pvs (0): create ext2 on /dev/VG/LV */ { int r; suppress_error = 0; @@ -3177,7 +3328,6 @@ static int test_umount_1 (void) if (r == -1) return -1; } - /* TestOutputList for umount (1) */ { char *lines[] = { ",", @@ -3192,33 +3342,61 @@ static int test_umount_1 (void) { int r; suppress_error = 0; - r = guestfs_mkfs (g, "ext2", "/dev/sda1"); + r = guestfs_pvcreate (g, "/dev/sda1"); + if (r == -1) + return -1; + } + { + char *physvols[] = { + "/dev/sda1", + NULL + }; + int r; + suppress_error = 0; + r = guestfs_vgcreate (g, "VG", physvols); if (r == -1) return -1; } { int r; suppress_error = 0; - r = guestfs_mount (g, "/dev/sda1", "/"); + r = guestfs_lvcreate (g, "LV", "VG", 8); if (r == -1) return -1; } { int r; suppress_error = 0; - r = guestfs_umount (g, "/"); + r = guestfs_mkfs (g, "ext2", "/dev/VG/LV"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_mount (g, "/dev/VG/LV", "/"); if (r == -1) return -1; } + /* TestOutputList for pvs (0) */ { char **r; int i; suppress_error = 0; - r = guestfs_mounts (g); + r = guestfs_pvs (g); if (r == NULL) return -1; - if (r[0] != NULL) { - fprintf (stderr, "test_umount_1: extra elements returned from command\n"); + if (!r[0]) { + fprintf (stderr, "test_pvs_0: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[0], "/dev/sda1") != 0) { + fprintf (stderr, "test_pvs_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]); + return -1; + } + if (r[1] != NULL) { + fprintf (stderr, "test_pvs_0: extra elements returned from command\n"); print_strings (r); return -1; } @@ -3229,9 +3407,9 @@ static int test_umount_1 (void) return 0; } -static int test_mounts_0 (void) +static int test_pvs_1 (void) { - /* InitBasicFS for mounts (0): create ext2 on /dev/sda1 */ + /* InitEmpty for pvs (1) */ { int r; suppress_error = 0; @@ -3246,8 +3424,11 @@ static int test_mounts_0 (void) if (r == -1) return -1; } + /* TestOutputList for pvs (1) */ { char *lines[] = { + ",10", + ",20", ",", NULL }; @@ -3260,36 +3441,60 @@ static int test_mounts_0 (void) { int r; suppress_error = 0; - r = guestfs_mkfs (g, "ext2", "/dev/sda1"); + r = guestfs_pvcreate (g, "/dev/sda1"); if (r == -1) return -1; } { int r; suppress_error = 0; - r = guestfs_mount (g, "/dev/sda1", "/"); + r = guestfs_pvcreate (g, "/dev/sda2"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_pvcreate (g, "/dev/sda3"); if (r == -1) return -1; } - /* TestOutputList for mounts (0) */ { char **r; int i; suppress_error = 0; - r = guestfs_mounts (g); + r = guestfs_pvs (g); if (r == NULL) return -1; if (!r[0]) { - fprintf (stderr, "test_mounts_0: short list returned from command\n"); + fprintf (stderr, "test_pvs_1: short list returned from command\n"); print_strings (r); return -1; } if (strcmp (r[0], "/dev/sda1") != 0) { - fprintf (stderr, "test_mounts_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]); + fprintf (stderr, "test_pvs_1: expected \"/dev/sda1\" but got \"%s\"\n", r[0]); return -1; } - if (r[1] != NULL) { - fprintf (stderr, "test_mounts_0: extra elements returned from command\n"); + if (!r[1]) { + fprintf (stderr, "test_pvs_1: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[1], "/dev/sda2") != 0) { + fprintf (stderr, "test_pvs_1: expected \"/dev/sda2\" but got \"%s\"\n", r[1]); + return -1; + } + if (!r[2]) { + fprintf (stderr, "test_pvs_1: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[2], "/dev/sda3") != 0) { + fprintf (stderr, "test_pvs_1: expected \"/dev/sda3\" but got \"%s\"\n", r[2]); + return -1; + } + if (r[3] != NULL) { + fprintf (stderr, "test_pvs_1: extra elements returned from command\n"); print_strings (r); return -1; } @@ -3300,9 +3505,9 @@ static int test_mounts_0 (void) return 0; } -static int test_umount_all_0 (void) +static int test_list_partitions_0 (void) { - /* InitBasicFS for umount_all (0): create ext2 on /dev/sda1 */ + /* InitBasicFS for list_partitions (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -3342,23 +3547,25 @@ static int test_umount_all_0 (void) if (r == -1) return -1; } - /* TestOutputList for umount_all (0) */ - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } + /* TestOutputList for list_partitions (0) */ { char **r; int i; suppress_error = 0; - r = guestfs_mounts (g); + r = guestfs_list_partitions (g); if (r == NULL) return -1; - if (r[0] != NULL) { - fprintf (stderr, "test_umount_all_0: extra elements returned from command\n"); + if (!r[0]) { + fprintf (stderr, "test_list_partitions_0: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[0], "/dev/sda1") != 0) { + fprintf (stderr, "test_list_partitions_0: expected \"/dev/sda1\" but got \"%s\"\n", r[0]); + return -1; + } + if (r[1] != NULL) { + fprintf (stderr, "test_list_partitions_0: extra elements returned from command\n"); print_strings (r); return -1; } @@ -3369,9 +3576,9 @@ static int test_umount_all_0 (void) return 0; } -static int test_file_0 (void) +static int test_list_partitions_1 (void) { - /* InitBasicFS for file (0): create ext2 on /dev/sda1 */ + /* InitEmpty for list_partitions (1) */ { int r; suppress_error = 0; @@ -3386,8 +3593,11 @@ static int test_file_0 (void) if (r == -1) return -1; } + /* TestOutputList for list_partitions (1) */ { char *lines[] = { + ",10", + ",20", ",", NULL }; @@ -3398,45 +3608,118 @@ static int test_file_0 (void) return -1; } { - int r; + char **r; + int i; suppress_error = 0; - r = guestfs_mkfs (g, "ext2", "/dev/sda1"); - if (r == -1) + r = guestfs_list_partitions (g); + if (r == NULL) + return -1; + if (!r[0]) { + fprintf (stderr, "test_list_partitions_1: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[0], "/dev/sda1") != 0) { + fprintf (stderr, "test_list_partitions_1: expected \"/dev/sda1\" but got \"%s\"\n", r[0]); + return -1; + } + if (!r[1]) { + fprintf (stderr, "test_list_partitions_1: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[1], "/dev/sda2") != 0) { + fprintf (stderr, "test_list_partitions_1: expected \"/dev/sda2\" but got \"%s\"\n", r[1]); + return -1; + } + if (!r[2]) { + fprintf (stderr, "test_list_partitions_1: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[2], "/dev/sda3") != 0) { + fprintf (stderr, "test_list_partitions_1: expected \"/dev/sda3\" but got \"%s\"\n", r[2]); return -1; + } + if (r[3] != NULL) { + fprintf (stderr, "test_list_partitions_1: extra elements returned from command\n"); + print_strings (r); + return -1; + } + for (i = 0; r[i] != NULL; ++i) + free (r[i]); + free (r); } + return 0; +} + +static int test_list_devices_0 (void) +{ + /* InitEmpty for list_devices (0) */ { int r; suppress_error = 0; - r = guestfs_mount (g, "/dev/sda1", "/"); + r = guestfs_umount_all (g); if (r == -1) return -1; } - /* TestOutput for file (0) */ { int r; suppress_error = 0; - r = guestfs_touch (g, "/new"); + r = guestfs_lvm_remove_all (g); if (r == -1) return -1; } + /* TestOutputList for list_devices (0) */ { - char *r; + char **r; + int i; suppress_error = 0; - r = guestfs_file (g, "/new"); + r = guestfs_list_devices (g); if (r == NULL) return -1; - if (strcmp (r, "empty") != 0) { - fprintf (stderr, "test_file_0: expected \"empty\" but got \"%s\"\n", r); + if (!r[0]) { + fprintf (stderr, "test_list_devices_0: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[0], "/dev/sda") != 0) { + fprintf (stderr, "test_list_devices_0: expected \"/dev/sda\" but got \"%s\"\n", r[0]); + return -1; + } + if (!r[1]) { + fprintf (stderr, "test_list_devices_0: short list returned from command\n"); + print_strings (r); return -1; } + if (strcmp (r[1], "/dev/sdb") != 0) { + fprintf (stderr, "test_list_devices_0: expected \"/dev/sdb\" but got \"%s\"\n", r[1]); + return -1; + } + if (!r[2]) { + fprintf (stderr, "test_list_devices_0: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[2], "/dev/sdc") != 0) { + fprintf (stderr, "test_list_devices_0: expected \"/dev/sdc\" but got \"%s\"\n", r[2]); + return -1; + } + if (r[3] != NULL) { + fprintf (stderr, "test_list_devices_0: extra elements returned from command\n"); + print_strings (r); + return -1; + } + for (i = 0; r[i] != NULL; ++i) + free (r[i]); free (r); } return 0; } -static int test_file_1 (void) +static int test_ls_0 (void) { - /* InitBasicFS for file (1): create ext2 on /dev/sda1 */ + /* InitBasicFS for ls (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -3476,32 +3759,86 @@ static int test_file_1 (void) if (r == -1) return -1; } - /* TestOutput for file (1) */ + /* TestOutputList for ls (0) */ { int r; suppress_error = 0; - r = guestfs_write_file (g, "/new", "some content\n", 0); + r = guestfs_touch (g, "/new"); if (r == -1) return -1; } { - char *r; + int r; suppress_error = 0; - r = guestfs_file (g, "/new"); + r = guestfs_touch (g, "/newer"); + if (r == -1) + return -1; + } + { + int r; + suppress_error = 0; + r = guestfs_touch (g, "/newest"); + if (r == -1) + return -1; + } + { + char **r; + int i; + suppress_error = 0; + r = guestfs_ls (g, "/"); if (r == NULL) return -1; - if (strcmp (r, "ASCII text") != 0) { - fprintf (stderr, "test_file_1: expected \"ASCII text\" but got \"%s\"\n", r); + if (!r[0]) { + fprintf (stderr, "test_ls_0: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[0], "lost+found") != 0) { + fprintf (stderr, "test_ls_0: expected \"lost+found\" but got \"%s\"\n", r[0]); + return -1; + } + if (!r[1]) { + fprintf (stderr, "test_ls_0: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[1], "new") != 0) { + fprintf (stderr, "test_ls_0: expected \"new\" but got \"%s\"\n", r[1]); + return -1; + } + if (!r[2]) { + fprintf (stderr, "test_ls_0: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[2], "newer") != 0) { + fprintf (stderr, "test_ls_0: expected \"newer\" but got \"%s\"\n", r[2]); + return -1; + } + if (!r[3]) { + fprintf (stderr, "test_ls_0: short list returned from command\n"); + print_strings (r); + return -1; + } + if (strcmp (r[3], "newest") != 0) { + fprintf (stderr, "test_ls_0: expected \"newest\" but got \"%s\"\n", r[3]); + return -1; + } + if (r[4] != NULL) { + fprintf (stderr, "test_ls_0: extra elements returned from command\n"); + print_strings (r); return -1; } + for (i = 0; r[i] != NULL; ++i) + free (r[i]); free (r); } return 0; } -static int test_file_2 (void) +static int test_cat_0 (void) { - /* InitBasicFS for file (2): create ext2 on /dev/sda1 */ + /* InitBasicFS for cat (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -3541,21 +3878,32 @@ static int test_file_2 (void) if (r == -1) return -1; } - /* TestLastFail for file (2) */ + /* TestOutput for cat (0) */ + { + int r; + suppress_error = 0; + r = guestfs_write_file (g, "/new", "new file contents", 0); + if (r == -1) + return -1; + } { char *r; - suppress_error = 1; - r = guestfs_file (g, "/nofile"); - if (r != NULL) + suppress_error = 0; + r = guestfs_cat (g, "/new"); + if (r == NULL) + return -1; + if (strcmp (r, "new file contents") != 0) { + fprintf (stderr, "test_cat_0: expected \"new file contents\" but got \"%s\"\n", r); return -1; + } free (r); } return 0; } -static int test_stat_0 (void) +static int test_touch_0 (void) { - /* InitBasicFS for stat (0): create ext2 on /dev/sda1 */ + /* InitBasicFS for touch (0): create ext2 on /dev/sda1 */ { int r; suppress_error = 0; @@ -3595,7 +3943,7 @@ static int test_stat_0 (void) if (r == -1) return -1; } - /* TestOutputStruct for stat (0) */ + /* TestOutputTrue for touch (0) */ { int r; suppress_error = 0; @@ -3604,90 +3952,50 @@ static int test_stat_0 (void) return -1; } { - struct guestfs_stat *r; + int r; suppress_error = 0; - r = guestfs_stat (g, "/new"); - if (r == NULL) + r = guestfs_exists (g, "/new"); + if (r == -1) return -1; - if (r->size != 0) { - fprintf (stderr, "test_stat_0: size was %d, expected 0\n", - (int) r->size); + if (!r) { + fprintf (stderr, "test_touch_0: expected true, got false\n"); return -1; } - free (r); } return 0; } -static int test_lstat_0 (void) +static int test_sync_0 (void) { - /* InitBasicFS for lstat (0): create ext2 on /dev/sda1 */ - { - int r; - suppress_error = 0; - r = guestfs_umount_all (g); - if (r == -1) - return -1; - } - { - int r; - suppress_error = 0; - r = guestfs_lvm_remove_all (g); - if (r == -1) - return -1; - } - { - char *lines[] = { - ",", - NULL - }; - int r; - suppress_error = 0; - r = guestfs_sfdisk (g, "/dev/sda", 0, 0, 0, lines); - if (r == -1) - return -1; - } + /* InitEmpty for sync (0) */ { int r; suppress_error = 0; - r = guestfs_mkfs (g, "ext2", "/dev/sda1"); + r = guestfs_umount_all (g); if (r == -1) return -1; } { int r; suppress_error = 0; - r = guestfs_mount (g, "/dev/sda1", "/"); + r = guestfs_lvm_remove_all (g); if (r == -1) return -1; } - /* TestOutputStruct for lstat (0) */ + /* TestRun for sync (0) */ { int r; suppress_error = 0; - r = guestfs_touch (g, "/new"); + r = guestfs_sync (g); if (r == -1) return -1; } - { - struct guestfs_stat *r; - suppress_error = 0; - r = guestfs_lstat (g, "/new"); - if (r == NULL) - return -1; - if (r->size != 0) { - fprintf (stderr, "test_lstat_0: size was %d, expected 0\n", - (int) r->size); - return -1; - } - free (r); - } return 0; } -static int test_statvfs_0 (void) +static int test_mount_0 (void) { - /* InitBasicFS for statvfs (0): create ext2 on /dev/sda1 */ + /* InitEmpty for mount (0) */ { int r; suppress_error = 0; @@ -3702,6 +4010,7 @@ static int test_statvfs_0 (void) if (r == -1) return -1; } + /* TestOutput for mount (0) */ { char *lines[] = { ",", @@ -3727,26 +4036,21 @@ static int test_statvfs_0 (void) if (r == -1) return -1; } - /* TestOutputStruct for statvfs (0) */ { - struct guestfs_statvfs *r; + int r; suppress_error = 0; - r = guestfs_statvfs (g, "/"); - if (r == NULL) - return -1; - if (r->bfree != 487702) { - fprintf (stderr, "test_statvfs_0: bfree was %d, expected 487702\n", - (int) r->bfree); + r = guestfs_write_file (g, "/new", "new file contents", 0); + if (r == -1) return -1; - } - if (r->blocks != 490020) { - fprintf (stderr, "test_statvfs_0: blocks was %d, expected 490020\n", - (int) r->blocks); + } + { + char *r; + suppress_error = 0; + r = guestfs_cat (g, "/new"); + if (r == NULL) return -1; - } - if (r->bsize != 1024) { - fprintf (stderr, "test_statvfs_0: bsize was %d, expected 1024\n", - (int) r->bsize); + if (strcmp (r, "new file contents") != 0) { + fprintf (stderr, "test_mount_0: expected \"new file contents\" but got \"%s\"\n", r); return -1; } free (r); @@ -3761,7 +4065,7 @@ int main (int argc, char *argv[]) const char *srcdir; int fd; char buf[256]; - int nr_tests; + int nr_tests, test_num = 0; no_test_warnings (); @@ -3870,250 +4174,354 @@ int main (int argc, char *argv[]) exit (1); } - nr_tests = 49; - printf (" 1/%3d test_mount_0\n", nr_tests); - if (test_mount_0 () == -1) { - printf ("test_mount_0 FAILED\n"); + nr_tests = 58; + + test_num++; + printf ("%3d/%3d test_blockdev_rereadpt_0\n", test_num, nr_tests); + if (test_blockdev_rereadpt_0 () == -1) { + printf ("test_blockdev_rereadpt_0 FAILED\n"); failed++; } - printf (" 2/%3d test_sync_0\n", nr_tests); - if (test_sync_0 () == -1) { - printf ("test_sync_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_blockdev_flushbufs_0\n", test_num, nr_tests); + if (test_blockdev_flushbufs_0 () == -1) { + printf ("test_blockdev_flushbufs_0 FAILED\n"); failed++; } - printf (" 3/%3d test_touch_0\n", nr_tests); - if (test_touch_0 () == -1) { - printf ("test_touch_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_blockdev_getsize64_0\n", test_num, nr_tests); + if (test_blockdev_getsize64_0 () == -1) { + printf ("test_blockdev_getsize64_0 FAILED\n"); failed++; } - printf (" 4/%3d test_cat_0\n", nr_tests); - if (test_cat_0 () == -1) { - printf ("test_cat_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_blockdev_getsz_0\n", test_num, nr_tests); + if (test_blockdev_getsz_0 () == -1) { + printf ("test_blockdev_getsz_0 FAILED\n"); failed++; } - printf (" 5/%3d test_ls_0\n", nr_tests); - if (test_ls_0 () == -1) { - printf ("test_ls_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_blockdev_getbsz_0\n", test_num, nr_tests); + if (test_blockdev_getbsz_0 () == -1) { + printf ("test_blockdev_getbsz_0 FAILED\n"); failed++; } - printf (" 6/%3d test_list_devices_0\n", nr_tests); - if (test_list_devices_0 () == -1) { - printf ("test_list_devices_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_blockdev_getss_0\n", test_num, nr_tests); + if (test_blockdev_getss_0 () == -1) { + printf ("test_blockdev_getss_0 FAILED\n"); failed++; } - printf (" 7/%3d test_list_partitions_0\n", nr_tests); - if (test_list_partitions_0 () == -1) { - printf ("test_list_partitions_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_blockdev_getro_0\n", test_num, nr_tests); + if (test_blockdev_getro_0 () == -1) { + printf ("test_blockdev_getro_0 FAILED\n"); failed++; } - printf (" 8/%3d test_list_partitions_1\n", nr_tests); - if (test_list_partitions_1 () == -1) { - printf ("test_list_partitions_1 FAILED\n"); + test_num++; + printf ("%3d/%3d test_blockdev_setrw_0\n", test_num, nr_tests); + if (test_blockdev_setrw_0 () == -1) { + printf ("test_blockdev_setrw_0 FAILED\n"); failed++; } - printf (" 9/%3d test_pvs_0\n", nr_tests); - if (test_pvs_0 () == -1) { - printf ("test_pvs_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_blockdev_setro_0\n", test_num, nr_tests); + if (test_blockdev_setro_0 () == -1) { + printf ("test_blockdev_setro_0 FAILED\n"); failed++; } - printf (" 10/%3d test_pvs_1\n", nr_tests); - if (test_pvs_1 () == -1) { - printf ("test_pvs_1 FAILED\n"); + test_num++; + printf ("%3d/%3d test_statvfs_0\n", test_num, nr_tests); + if (test_statvfs_0 () == -1) { + printf ("test_statvfs_0 FAILED\n"); failed++; } - printf (" 11/%3d test_vgs_0\n", nr_tests); - if (test_vgs_0 () == -1) { - printf ("test_vgs_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_lstat_0\n", test_num, nr_tests); + if (test_lstat_0 () == -1) { + printf ("test_lstat_0 FAILED\n"); failed++; } - printf (" 12/%3d test_vgs_1\n", nr_tests); - if (test_vgs_1 () == -1) { - printf ("test_vgs_1 FAILED\n"); + test_num++; + printf ("%3d/%3d test_stat_0\n", test_num, nr_tests); + if (test_stat_0 () == -1) { + printf ("test_stat_0 FAILED\n"); failed++; } - printf (" 13/%3d test_lvs_0\n", nr_tests); - if (test_lvs_0 () == -1) { - printf ("test_lvs_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_file_0\n", test_num, nr_tests); + if (test_file_0 () == -1) { + printf ("test_file_0 FAILED\n"); failed++; } - printf (" 14/%3d test_lvs_1\n", nr_tests); - if (test_lvs_1 () == -1) { - printf ("test_lvs_1 FAILED\n"); + test_num++; + printf ("%3d/%3d test_file_1\n", test_num, nr_tests); + if (test_file_1 () == -1) { + printf ("test_file_1 FAILED\n"); failed++; } - printf (" 15/%3d test_read_lines_0\n", nr_tests); - if (test_read_lines_0 () == -1) { - printf ("test_read_lines_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_file_2\n", test_num, nr_tests); + if (test_file_2 () == -1) { + printf ("test_file_2 FAILED\n"); failed++; } - printf (" 16/%3d test_read_lines_1\n", nr_tests); - if (test_read_lines_1 () == -1) { - printf ("test_read_lines_1 FAILED\n"); + test_num++; + printf ("%3d/%3d test_umount_all_0\n", test_num, nr_tests); + if (test_umount_all_0 () == -1) { + printf ("test_umount_all_0 FAILED\n"); failed++; } - printf (" 17/%3d test_rm_0\n", nr_tests); - if (test_rm_0 () == -1) { - printf ("test_rm_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_mounts_0\n", test_num, nr_tests); + if (test_mounts_0 () == -1) { + printf ("test_mounts_0 FAILED\n"); failed++; } - printf (" 18/%3d test_rm_1\n", nr_tests); - if (test_rm_1 () == -1) { - printf ("test_rm_1 FAILED\n"); + test_num++; + printf ("%3d/%3d test_umount_0\n", test_num, nr_tests); + if (test_umount_0 () == -1) { + printf ("test_umount_0 FAILED\n"); failed++; } - printf (" 19/%3d test_rm_2\n", nr_tests); - if (test_rm_2 () == -1) { - printf ("test_rm_2 FAILED\n"); + test_num++; + printf ("%3d/%3d test_umount_1\n", test_num, nr_tests); + if (test_umount_1 () == -1) { + printf ("test_umount_1 FAILED\n"); failed++; } - printf (" 20/%3d test_rmdir_0\n", nr_tests); - if (test_rmdir_0 () == -1) { - printf ("test_rmdir_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_write_file_0\n", test_num, nr_tests); + if (test_write_file_0 () == -1) { + printf ("test_write_file_0 FAILED\n"); failed++; } - printf (" 21/%3d test_rmdir_1\n", nr_tests); - if (test_rmdir_1 () == -1) { - printf ("test_rmdir_1 FAILED\n"); + test_num++; + printf ("%3d/%3d test_mkfs_0\n", test_num, nr_tests); + if (test_mkfs_0 () == -1) { + printf ("test_mkfs_0 FAILED\n"); failed++; } - printf (" 22/%3d test_rmdir_2\n", nr_tests); - if (test_rmdir_2 () == -1) { - printf ("test_rmdir_2 FAILED\n"); + test_num++; + printf ("%3d/%3d test_lvcreate_0\n", test_num, nr_tests); + if (test_lvcreate_0 () == -1) { + printf ("test_lvcreate_0 FAILED\n"); failed++; } - printf (" 23/%3d test_rm_rf_0\n", nr_tests); - if (test_rm_rf_0 () == -1) { - printf ("test_rm_rf_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_vgcreate_0\n", test_num, nr_tests); + if (test_vgcreate_0 () == -1) { + printf ("test_vgcreate_0 FAILED\n"); failed++; } - printf (" 24/%3d test_mkdir_0\n", nr_tests); - if (test_mkdir_0 () == -1) { - printf ("test_mkdir_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_pvcreate_0\n", test_num, nr_tests); + if (test_pvcreate_0 () == -1) { + printf ("test_pvcreate_0 FAILED\n"); failed++; } - printf (" 25/%3d test_mkdir_1\n", nr_tests); - if (test_mkdir_1 () == -1) { - printf ("test_mkdir_1 FAILED\n"); + test_num++; + printf ("%3d/%3d test_is_dir_0\n", test_num, nr_tests); + if (test_is_dir_0 () == -1) { + printf ("test_is_dir_0 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_is_dir_1\n", test_num, nr_tests); + if (test_is_dir_1 () == -1) { + printf ("test_is_dir_1 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_is_file_0\n", test_num, nr_tests); + if (test_is_file_0 () == -1) { + printf ("test_is_file_0 FAILED\n"); failed++; } - printf (" 26/%3d test_mkdir_p_0\n", nr_tests); + test_num++; + printf ("%3d/%3d test_is_file_1\n", test_num, nr_tests); + if (test_is_file_1 () == -1) { + printf ("test_is_file_1 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_exists_0\n", test_num, nr_tests); + if (test_exists_0 () == -1) { + printf ("test_exists_0 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_exists_1\n", test_num, nr_tests); + if (test_exists_1 () == -1) { + printf ("test_exists_1 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_mkdir_p_0\n", test_num, nr_tests); if (test_mkdir_p_0 () == -1) { printf ("test_mkdir_p_0 FAILED\n"); failed++; } - printf (" 27/%3d test_mkdir_p_1\n", nr_tests); + test_num++; + printf ("%3d/%3d test_mkdir_p_1\n", test_num, nr_tests); if (test_mkdir_p_1 () == -1) { printf ("test_mkdir_p_1 FAILED\n"); failed++; } - printf (" 28/%3d test_mkdir_p_2\n", nr_tests); + test_num++; + printf ("%3d/%3d test_mkdir_p_2\n", test_num, nr_tests); if (test_mkdir_p_2 () == -1) { printf ("test_mkdir_p_2 FAILED\n"); failed++; } - printf (" 29/%3d test_exists_0\n", nr_tests); - if (test_exists_0 () == -1) { - printf ("test_exists_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_mkdir_0\n", test_num, nr_tests); + if (test_mkdir_0 () == -1) { + printf ("test_mkdir_0 FAILED\n"); failed++; } - printf (" 30/%3d test_exists_1\n", nr_tests); - if (test_exists_1 () == -1) { - printf ("test_exists_1 FAILED\n"); + test_num++; + printf ("%3d/%3d test_mkdir_1\n", test_num, nr_tests); + if (test_mkdir_1 () == -1) { + printf ("test_mkdir_1 FAILED\n"); failed++; } - printf (" 31/%3d test_is_file_0\n", nr_tests); - if (test_is_file_0 () == -1) { - printf ("test_is_file_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_rm_rf_0\n", test_num, nr_tests); + if (test_rm_rf_0 () == -1) { + printf ("test_rm_rf_0 FAILED\n"); failed++; } - printf (" 32/%3d test_is_file_1\n", nr_tests); - if (test_is_file_1 () == -1) { - printf ("test_is_file_1 FAILED\n"); + test_num++; + printf ("%3d/%3d test_rmdir_0\n", test_num, nr_tests); + if (test_rmdir_0 () == -1) { + printf ("test_rmdir_0 FAILED\n"); failed++; } - printf (" 33/%3d test_is_dir_0\n", nr_tests); - if (test_is_dir_0 () == -1) { - printf ("test_is_dir_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_rmdir_1\n", test_num, nr_tests); + if (test_rmdir_1 () == -1) { + printf ("test_rmdir_1 FAILED\n"); failed++; } - printf (" 34/%3d test_is_dir_1\n", nr_tests); - if (test_is_dir_1 () == -1) { - printf ("test_is_dir_1 FAILED\n"); + test_num++; + printf ("%3d/%3d test_rmdir_2\n", test_num, nr_tests); + if (test_rmdir_2 () == -1) { + printf ("test_rmdir_2 FAILED\n"); failed++; } - printf (" 35/%3d test_pvcreate_0\n", nr_tests); - if (test_pvcreate_0 () == -1) { - printf ("test_pvcreate_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_rm_0\n", test_num, nr_tests); + if (test_rm_0 () == -1) { + printf ("test_rm_0 FAILED\n"); failed++; } - printf (" 36/%3d test_vgcreate_0\n", nr_tests); - if (test_vgcreate_0 () == -1) { - printf ("test_vgcreate_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_rm_1\n", test_num, nr_tests); + if (test_rm_1 () == -1) { + printf ("test_rm_1 FAILED\n"); failed++; } - printf (" 37/%3d test_lvcreate_0\n", nr_tests); - if (test_lvcreate_0 () == -1) { - printf ("test_lvcreate_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_rm_2\n", test_num, nr_tests); + if (test_rm_2 () == -1) { + printf ("test_rm_2 FAILED\n"); failed++; } - printf (" 38/%3d test_mkfs_0\n", nr_tests); - if (test_mkfs_0 () == -1) { - printf ("test_mkfs_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_read_lines_0\n", test_num, nr_tests); + if (test_read_lines_0 () == -1) { + printf ("test_read_lines_0 FAILED\n"); failed++; } - printf (" 39/%3d test_write_file_0\n", nr_tests); - if (test_write_file_0 () == -1) { - printf ("test_write_file_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_read_lines_1\n", test_num, nr_tests); + if (test_read_lines_1 () == -1) { + printf ("test_read_lines_1 FAILED\n"); failed++; } - printf (" 40/%3d test_umount_0\n", nr_tests); - if (test_umount_0 () == -1) { - printf ("test_umount_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_lvs_0\n", test_num, nr_tests); + if (test_lvs_0 () == -1) { + printf ("test_lvs_0 FAILED\n"); failed++; } - printf (" 41/%3d test_umount_1\n", nr_tests); - if (test_umount_1 () == -1) { - printf ("test_umount_1 FAILED\n"); + test_num++; + printf ("%3d/%3d test_lvs_1\n", test_num, nr_tests); + if (test_lvs_1 () == -1) { + printf ("test_lvs_1 FAILED\n"); failed++; } - printf (" 42/%3d test_mounts_0\n", nr_tests); - if (test_mounts_0 () == -1) { - printf ("test_mounts_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_vgs_0\n", test_num, nr_tests); + if (test_vgs_0 () == -1) { + printf ("test_vgs_0 FAILED\n"); failed++; } - printf (" 43/%3d test_umount_all_0\n", nr_tests); - if (test_umount_all_0 () == -1) { - printf ("test_umount_all_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_vgs_1\n", test_num, nr_tests); + if (test_vgs_1 () == -1) { + printf ("test_vgs_1 FAILED\n"); failed++; } - printf (" 44/%3d test_file_0\n", nr_tests); - if (test_file_0 () == -1) { - printf ("test_file_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_pvs_0\n", test_num, nr_tests); + if (test_pvs_0 () == -1) { + printf ("test_pvs_0 FAILED\n"); failed++; } - printf (" 45/%3d test_file_1\n", nr_tests); - if (test_file_1 () == -1) { - printf ("test_file_1 FAILED\n"); + test_num++; + printf ("%3d/%3d test_pvs_1\n", test_num, nr_tests); + if (test_pvs_1 () == -1) { + printf ("test_pvs_1 FAILED\n"); failed++; } - printf (" 46/%3d test_file_2\n", nr_tests); - if (test_file_2 () == -1) { - printf ("test_file_2 FAILED\n"); + test_num++; + printf ("%3d/%3d test_list_partitions_0\n", test_num, nr_tests); + if (test_list_partitions_0 () == -1) { + printf ("test_list_partitions_0 FAILED\n"); failed++; } - printf (" 47/%3d test_stat_0\n", nr_tests); - if (test_stat_0 () == -1) { - printf ("test_stat_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_list_partitions_1\n", test_num, nr_tests); + if (test_list_partitions_1 () == -1) { + printf ("test_list_partitions_1 FAILED\n"); failed++; } - printf (" 48/%3d test_lstat_0\n", nr_tests); - if (test_lstat_0 () == -1) { - printf ("test_lstat_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_list_devices_0\n", test_num, nr_tests); + if (test_list_devices_0 () == -1) { + printf ("test_list_devices_0 FAILED\n"); failed++; } - printf (" 49/%3d test_statvfs_0\n", nr_tests); - if (test_statvfs_0 () == -1) { - printf ("test_statvfs_0 FAILED\n"); + test_num++; + printf ("%3d/%3d test_ls_0\n", test_num, nr_tests); + if (test_ls_0 () == -1) { + printf ("test_ls_0 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_cat_0\n", test_num, nr_tests); + if (test_cat_0 () == -1) { + printf ("test_cat_0 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_touch_0\n", test_num, nr_tests); + if (test_touch_0 () == -1) { + printf ("test_touch_0 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_sync_0\n", test_num, nr_tests); + if (test_sync_0 () == -1) { + printf ("test_sync_0 FAILED\n"); + failed++; + } + test_num++; + printf ("%3d/%3d test_mount_0\n", test_num, nr_tests); + if (test_mount_0 () == -1) { + printf ("test_mount_0 FAILED\n"); failed++; } -- 1.8.3.1