fprintf (stderr, "warning: \"guestfs_mount_loop\" has no tests\n");
}
+static int test_mkswap_U_0_skip (void)
+{
+ const char *str;
+
+ str = getenv ("TEST_ONLY");
+ if (str)
+ return strstr (str, "mkswap_U") == NULL;
+ str = getenv ("SKIP_TEST_MKSWAP_U_0");
+ if (str && strcmp (str, "1") == 0) return 1;
+ str = getenv ("SKIP_TEST_MKSWAP_U");
+ if (str && strcmp (str, "1") == 0) return 1;
+ return 0;
+}
+
+static int test_mkswap_U_0 (void)
+{
+ if (test_mkswap_U_0_skip ()) {
+ printf ("%s skipped (reason: environment variable set)\n", "test_mkswap_U_0");
+ return 0;
+ }
+
+ /* InitNone|InitEmpty for test_mkswap_U_0 */
+ {
+ char device[] = "/dev/sda";
+ int r;
+ suppress_error = 0;
+ r = guestfs_blockdev_setrw (g, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ 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;
+ }
+ /* TestRun for mkswap_U (0) */
+ {
+ char device[] = "/dev/sda";
+ char lines_0[] = ",";
+ char *lines[] = {
+ lines_0,
+ NULL
+ };
+ int r;
+ suppress_error = 0;
+ r = guestfs_sfdisk (g, device, 0, 0, 0, lines);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char uuid[] = "a3a61220-882b-4f61-89f4-cf24dcc7297d";
+ char device[] = "/dev/sda1";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mkswap_U (g, uuid, device);
+ if (r == -1)
+ return -1;
+ }
+ return 0;
+}
+
+static int test_mkswap_L_0_skip (void)
+{
+ const char *str;
+
+ str = getenv ("TEST_ONLY");
+ if (str)
+ return strstr (str, "mkswap_L") == NULL;
+ str = getenv ("SKIP_TEST_MKSWAP_L_0");
+ if (str && strcmp (str, "1") == 0) return 1;
+ str = getenv ("SKIP_TEST_MKSWAP_L");
+ if (str && strcmp (str, "1") == 0) return 1;
+ return 0;
+}
+
+static int test_mkswap_L_0 (void)
+{
+ if (test_mkswap_L_0_skip ()) {
+ printf ("%s skipped (reason: environment variable set)\n", "test_mkswap_L_0");
+ return 0;
+ }
+
+ /* InitNone|InitEmpty for test_mkswap_L_0 */
+ {
+ char device[] = "/dev/sda";
+ int r;
+ suppress_error = 0;
+ r = guestfs_blockdev_setrw (g, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ 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;
+ }
+ /* TestRun for mkswap_L (0) */
+ {
+ char device[] = "/dev/sda";
+ char lines_0[] = ",";
+ char *lines[] = {
+ lines_0,
+ NULL
+ };
+ int r;
+ suppress_error = 0;
+ r = guestfs_sfdisk (g, device, 0, 0, 0, lines);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char label[] = "hello";
+ char device[] = "/dev/sda1";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mkswap_L (g, label, device);
+ if (r == -1)
+ return -1;
+ }
+ return 0;
+}
+
+static int test_mkswap_0_skip (void)
+{
+ const char *str;
+
+ str = getenv ("TEST_ONLY");
+ if (str)
+ return strstr (str, "mkswap") == NULL;
+ str = getenv ("SKIP_TEST_MKSWAP_0");
+ if (str && strcmp (str, "1") == 0) return 1;
+ str = getenv ("SKIP_TEST_MKSWAP");
+ if (str && strcmp (str, "1") == 0) return 1;
+ return 0;
+}
+
+static int test_mkswap_0 (void)
+{
+ if (test_mkswap_0_skip ()) {
+ printf ("%s skipped (reason: environment variable set)\n", "test_mkswap_0");
+ return 0;
+ }
+
+ /* InitNone|InitEmpty for test_mkswap_0 */
+ {
+ char device[] = "/dev/sda";
+ int r;
+ suppress_error = 0;
+ r = guestfs_blockdev_setrw (g, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ 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;
+ }
+ /* TestRun for mkswap (0) */
+ {
+ char device[] = "/dev/sda";
+ char lines_0[] = ",";
+ char *lines[] = {
+ lines_0,
+ NULL
+ };
+ int r;
+ suppress_error = 0;
+ r = guestfs_sfdisk (g, device, 0, 0, 0, lines);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char device[] = "/dev/sda1";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mkswap (g, device);
+ if (r == -1)
+ return -1;
+ }
+ return 0;
+}
+
static int test_initrd_list_0_skip (void)
{
const char *str;
/* Cancel previous alarm. */
alarm (0);
- nr_tests = 166;
+ nr_tests = 169;
test_num++;
+ printf ("%3d/%3d test_mkswap_U_0\n", test_num, nr_tests);
+ if (test_mkswap_U_0 () == -1) {
+ printf ("test_mkswap_U_0 FAILED\n");
+ failed++;
+ }
+ test_num++;
+ printf ("%3d/%3d test_mkswap_L_0\n", test_num, nr_tests);
+ if (test_mkswap_L_0 () == -1) {
+ printf ("test_mkswap_L_0 FAILED\n");
+ failed++;
+ }
+ test_num++;
+ printf ("%3d/%3d test_mkswap_0\n", test_num, nr_tests);
+ if (test_mkswap_0 () == -1) {
+ printf ("test_mkswap_0 FAILED\n");
+ failed++;
+ }
+ test_num++;
printf ("%3d/%3d test_initrd_list_0\n", test_num, nr_tests);
if (test_initrd_list_0 () == -1) {
printf ("test_initrd_list_0 FAILED\n");
extern int64_t do_du (char *path);
extern char **do_initrd_list (char *path);
extern int do_mount_loop (char *file, char *mountpoint);
+extern int do_mkswap (char *device);
+extern int do_mkswap_L (char *label, char *device);
+extern int do_mkswap_U (char *uuid, char *device);
xdr_free ((xdrproc_t) xdr_guestfs_mount_loop_args, (char *) &args);
}
+static void mkswap_stub (XDR *xdr_in)
+{
+ int r;
+ struct guestfs_mkswap_args args;
+ char *device;
+
+ memset (&args, 0, sizeof args);
+
+ if (!xdr_guestfs_mkswap_args (xdr_in, &args)) {
+ reply_with_error ("%s: daemon failed to decode procedure arguments", "mkswap");
+ return;
+ }
+ device = args.device;
+
+ r = do_mkswap (device);
+ if (r == -1)
+ /* do_mkswap has already called reply_with_error */
+ goto done;
+
+ reply (NULL, NULL);
+done:
+ xdr_free ((xdrproc_t) xdr_guestfs_mkswap_args, (char *) &args);
+}
+
+static void mkswap_L_stub (XDR *xdr_in)
+{
+ int r;
+ struct guestfs_mkswap_L_args args;
+ char *label;
+ char *device;
+
+ memset (&args, 0, sizeof args);
+
+ if (!xdr_guestfs_mkswap_L_args (xdr_in, &args)) {
+ reply_with_error ("%s: daemon failed to decode procedure arguments", "mkswap_L");
+ return;
+ }
+ label = args.label;
+ device = args.device;
+
+ r = do_mkswap_L (label, device);
+ if (r == -1)
+ /* do_mkswap_L has already called reply_with_error */
+ goto done;
+
+ reply (NULL, NULL);
+done:
+ xdr_free ((xdrproc_t) xdr_guestfs_mkswap_L_args, (char *) &args);
+}
+
+static void mkswap_U_stub (XDR *xdr_in)
+{
+ int r;
+ struct guestfs_mkswap_U_args args;
+ char *uuid;
+ char *device;
+
+ memset (&args, 0, sizeof args);
+
+ if (!xdr_guestfs_mkswap_U_args (xdr_in, &args)) {
+ reply_with_error ("%s: daemon failed to decode procedure arguments", "mkswap_U");
+ return;
+ }
+ uuid = args.uuid;
+ device = args.device;
+
+ r = do_mkswap_U (uuid, device);
+ if (r == -1)
+ /* do_mkswap_U has already called reply_with_error */
+ goto done;
+
+ reply (NULL, NULL);
+done:
+ xdr_free ((xdrproc_t) xdr_guestfs_mkswap_U_args, (char *) &args);
+}
+
void dispatch_incoming_message (XDR *xdr_in)
{
switch (proc_nr) {
case GUESTFS_PROC_MOUNT_LOOP:
mount_loop_stub (xdr_in);
break;
+ case GUESTFS_PROC_MKSWAP:
+ mkswap_stub (xdr_in);
+ break;
+ case GUESTFS_PROC_MKSWAP_L:
+ mkswap_L_stub (xdr_in);
+ break;
+ case GUESTFS_PROC_MKSWAP_U:
+ mkswap_U_stub (xdr_in);
+ break;
default:
reply_with_error ("dispatch_incoming_message: unknown procedure number %d, set LIBGUESTFS_PATH to point to the matching libguestfs appliance directory", proc_nr);
}
printf ("%-20s %s\n", "mkdir-p", "create a directory and parents");
printf ("%-20s %s\n", "mkdtemp", "create a temporary directory");
printf ("%-20s %s\n", "mkfs", "make a filesystem");
+ printf ("%-20s %s\n", "mkswap", "create a swap partition");
+ printf ("%-20s %s\n", "mkswap-L", "create a swap partition with a label");
+ printf ("%-20s %s\n", "mkswap-U", "create a swap partition with an explicit UUID");
printf ("%-20s %s\n", "mount", "mount a guest disk at a position in the filesystem");
printf ("%-20s %s\n", "mount-loop", "mount a file using the loop device");
printf ("%-20s %s\n", "mount-options", "mount a guest disk with mount options");
if (strcasecmp (cmd, "mount_loop") == 0 || strcasecmp (cmd, "mount-loop") == 0)
pod2text ("mount-loop - mount a file using the loop device", " mount-loop <file> <mountpoint>\n\nThis command lets you mount C<file> (a filesystem image\nin a file) on a mount point. It is entirely equivalent to\nthe command C<mount -o loop file mountpoint>.");
else
+ if (strcasecmp (cmd, "mkswap") == 0)
+ pod2text ("mkswap - create a swap partition", " mkswap <device>\n\nCreate a swap partition on C<device>.");
+ else
+ if (strcasecmp (cmd, "mkswap_L") == 0 || strcasecmp (cmd, "mkswap-L") == 0)
+ pod2text ("mkswap-L - create a swap partition with a label", " mkswap-L <label> <device>\n\nCreate a swap partition on C<device> with label C<label>.");
+ else
+ if (strcasecmp (cmd, "mkswap_U") == 0 || strcasecmp (cmd, "mkswap-U") == 0)
+ pod2text ("mkswap-U - create a swap partition with an explicit UUID", " mkswap-U <uuid> <device>\n\nCreate a swap partition on C<device> with UUID C<uuid>.");
+ else
display_builtin_command (cmd);
}
return r;
}
+static int run_mkswap (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_mkswap (g, device);
+ return r;
+}
+
+static int run_mkswap_L (const char *cmd, int argc, char *argv[])
+{
+ int r;
+ const char *label;
+ const char *device;
+ 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;
+ }
+ label = argv[0];
+ device = argv[1];
+ r = guestfs_mkswap_L (g, label, device);
+ return r;
+}
+
+static int run_mkswap_U (const char *cmd, int argc, char *argv[])
+{
+ int r;
+ const char *uuid;
+ const char *device;
+ 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;
+ }
+ uuid = argv[0];
+ device = argv[1];
+ r = guestfs_mkswap_U (g, uuid, device);
+ return r;
+}
+
int run_action (const char *cmd, int argc, char *argv[])
{
if (strcasecmp (cmd, "launch") == 0 || strcasecmp (cmd, "run") == 0)
if (strcasecmp (cmd, "mount_loop") == 0 || strcasecmp (cmd, "mount-loop") == 0)
return run_mount_loop (cmd, argc, argv);
else
+ if (strcasecmp (cmd, "mkswap") == 0)
+ return run_mkswap (cmd, argc, argv);
+ else
+ if (strcasecmp (cmd, "mkswap_L") == 0 || strcasecmp (cmd, "mkswap-L") == 0)
+ return run_mkswap_L (cmd, argc, argv);
+ else
+ if (strcasecmp (cmd, "mkswap_U") == 0 || strcasecmp (cmd, "mkswap-U") == 0)
+ return run_mkswap_U (cmd, argc, argv);
+ else
{
fprintf (stderr, "%s: unknown command\n", cmd);
return -1;
"du",
"initrd-list",
"mount-loop",
+ "mkswap",
+ "mkswap-L",
+ "mkswap-U",
NULL
};
or LVM logical volume). The filesystem type is C<fstype>, for
example C<ext3>.
+=head2 mkswap
+
+ mkswap device
+
+Create a swap partition on C<device>.
+
+=head2 mkswap-L
+
+ mkswap-L label device
+
+Create a swap partition on C<device> with label C<label>.
+
+=head2 mkswap-U
+
+ mkswap-U uuid device
+
+Create a swap partition on C<device> with UUID C<uuid>.
+
=head2 mount
mount device mountpoint
This function returns 0 on success or -1 on error.
+=head2 guestfs_mkswap
+
+ int guestfs_mkswap (guestfs_h *handle,
+ const char *device);
+
+Create a swap partition on C<device>.
+
+This function returns 0 on success or -1 on error.
+
+=head2 guestfs_mkswap_L
+
+ int guestfs_mkswap_L (guestfs_h *handle,
+ const char *label,
+ const char *device);
+
+Create a swap partition on C<device> with label C<label>.
+
+This function returns 0 on success or -1 on error.
+
+=head2 guestfs_mkswap_U
+
+ int guestfs_mkswap_U (guestfs_h *handle,
+ const char *uuid,
+ const char *device);
+
+Create a swap partition on C<device> with UUID C<uuid>.
+
+This function returns 0 on success or -1 on error.
+
=head2 guestfs_mount
int guestfs_mount (guestfs_h *handle,
wc_w,
wc_c,
du,
- mount_loop
+ mount_loop,
+ mkswap,
+ mkswap_L,
+ mkswap_U
) where
import Foreign
import Foreign.C
fail err
else return ()
+foreign import ccall unsafe "guestfs_mkswap" c_mkswap
+ :: GuestfsP -> CString -> IO (CInt)
+
+mkswap :: GuestfsH -> String -> IO ()
+mkswap h device = do
+ r <- withCString device $ \device -> withForeignPtr h (\p -> c_mkswap p device)
+ if (r == -1)
+ then do
+ err <- last_error h
+ fail err
+ else return ()
+
+foreign import ccall unsafe "guestfs_mkswap_L" c_mkswap_L
+ :: GuestfsP -> CString -> CString -> IO (CInt)
+
+mkswap_L :: GuestfsH -> String -> String -> IO ()
+mkswap_L h label device = do
+ r <- withCString label $ \label -> withCString device $ \device -> withForeignPtr h (\p -> c_mkswap_L p label device)
+ if (r == -1)
+ then do
+ err <- last_error h
+ fail err
+ else return ()
+
+foreign import ccall unsafe "guestfs_mkswap_U" c_mkswap_U
+ :: GuestfsP -> CString -> CString -> IO (CInt)
+
+mkswap_U :: GuestfsH -> String -> String -> IO ()
+mkswap_U h uuid device = do
+ r <- withCString uuid $ \uuid -> withCString device $ \device -> withForeignPtr h (\p -> c_mkswap_U p uuid device)
+ if (r == -1)
+ then do
+ err <- last_error h
+ fail err
+ else return ()
+
private native void _mount_loop (long g, String file, String mountpoint)
throws LibGuestFSException;
+ /**
+ * create a swap partition
+ * <p>
+ * Create a swap partition on "device".
+ * <p>
+ * @throws LibGuestFSException
+ */
+ public void mkswap (String device)
+ throws LibGuestFSException
+ {
+ if (g == 0)
+ throw new LibGuestFSException ("mkswap: handle is closed");
+ _mkswap (g, device);
+ }
+ private native void _mkswap (long g, String device)
+ throws LibGuestFSException;
+
+ /**
+ * create a swap partition with a label
+ * <p>
+ * Create a swap partition on "device" with label "label".
+ * <p>
+ * @throws LibGuestFSException
+ */
+ public void mkswap_L (String label, String device)
+ throws LibGuestFSException
+ {
+ if (g == 0)
+ throw new LibGuestFSException ("mkswap_L: handle is closed");
+ _mkswap_L (g, label, device);
+ }
+ private native void _mkswap_L (long g, String label, String device)
+ throws LibGuestFSException;
+
+ /**
+ * create a swap partition with an explicit UUID
+ * <p>
+ * Create a swap partition on "device" with UUID "uuid".
+ * <p>
+ * @throws LibGuestFSException
+ */
+ public void mkswap_U (String uuid, String device)
+ throws LibGuestFSException
+ {
+ if (g == 0)
+ throw new LibGuestFSException ("mkswap_U: handle is closed");
+ _mkswap_U (g, uuid, device);
+ }
+ private native void _mkswap_U (long g, String uuid, String device)
+ throws LibGuestFSException;
+
}
}
}
+JNIEXPORT void JNICALL
+Java_com_redhat_et_libguestfs_GuestFS__1mkswap
+ (JNIEnv *env, jobject obj, jlong jg, jstring jdevice)
+{
+ guestfs_h *g = (guestfs_h *) (long) jg;
+ int r;
+ const char *device;
+
+ device = (*env)->GetStringUTFChars (env, jdevice, NULL);
+ r = guestfs_mkswap (g, device);
+ (*env)->ReleaseStringUTFChars (env, jdevice, device);
+ if (r == -1) {
+ throw_exception (env, guestfs_last_error (g));
+ return ;
+ }
+}
+
+JNIEXPORT void JNICALL
+Java_com_redhat_et_libguestfs_GuestFS__1mkswap_1L
+ (JNIEnv *env, jobject obj, jlong jg, jstring jlabel, jstring jdevice)
+{
+ guestfs_h *g = (guestfs_h *) (long) jg;
+ int r;
+ const char *label;
+ const char *device;
+
+ label = (*env)->GetStringUTFChars (env, jlabel, NULL);
+ device = (*env)->GetStringUTFChars (env, jdevice, NULL);
+ r = guestfs_mkswap_L (g, label, device);
+ (*env)->ReleaseStringUTFChars (env, jlabel, label);
+ (*env)->ReleaseStringUTFChars (env, jdevice, device);
+ if (r == -1) {
+ throw_exception (env, guestfs_last_error (g));
+ return ;
+ }
+}
+
+JNIEXPORT void JNICALL
+Java_com_redhat_et_libguestfs_GuestFS__1mkswap_1U
+ (JNIEnv *env, jobject obj, jlong jg, jstring juuid, jstring jdevice)
+{
+ guestfs_h *g = (guestfs_h *) (long) jg;
+ int r;
+ const char *uuid;
+ const char *device;
+
+ uuid = (*env)->GetStringUTFChars (env, juuid, NULL);
+ device = (*env)->GetStringUTFChars (env, jdevice, NULL);
+ r = guestfs_mkswap_U (g, uuid, device);
+ (*env)->ReleaseStringUTFChars (env, juuid, uuid);
+ (*env)->ReleaseStringUTFChars (env, jdevice, device);
+ if (r == -1) {
+ throw_exception (env, guestfs_last_error (g));
+ return ;
+ }
+}
+
external du : t -> string -> int64 = "ocaml_guestfs_du"
external initrd_list : t -> string -> string array = "ocaml_guestfs_initrd_list"
external mount_loop : t -> string -> string -> unit = "ocaml_guestfs_mount_loop"
+external mkswap : t -> string -> unit = "ocaml_guestfs_mkswap"
+external mkswap_L : t -> string -> string -> unit = "ocaml_guestfs_mkswap_L"
+external mkswap_U : t -> string -> string -> unit = "ocaml_guestfs_mkswap_U"
val mount_loop : t -> string -> string -> unit
(** mount a file using the loop device *)
+val mkswap : t -> string -> unit
+(** create a swap partition *)
+
+val mkswap_L : t -> string -> string -> unit
+(** create a swap partition with a label *)
+
+val mkswap_U : t -> string -> string -> unit
+(** create a swap partition with an explicit UUID *)
+
CAMLreturn (rv);
}
+CAMLprim value
+ocaml_guestfs_mkswap (value gv, value devicev)
+{
+ CAMLparam2 (gv, devicev);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("mkswap: used handle after closing it");
+
+ const char *device = String_val (devicev);
+ int r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_mkswap (g, device);
+ caml_leave_blocking_section ();
+ if (r == -1)
+ ocaml_guestfs_raise_error (g, "mkswap");
+
+ rv = Val_unit;
+ CAMLreturn (rv);
+}
+
+CAMLprim value
+ocaml_guestfs_mkswap_L (value gv, value labelv, value devicev)
+{
+ CAMLparam3 (gv, labelv, devicev);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("mkswap_L: used handle after closing it");
+
+ const char *label = String_val (labelv);
+ const char *device = String_val (devicev);
+ int r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_mkswap_L (g, label, device);
+ caml_leave_blocking_section ();
+ if (r == -1)
+ ocaml_guestfs_raise_error (g, "mkswap_L");
+
+ rv = Val_unit;
+ CAMLreturn (rv);
+}
+
+CAMLprim value
+ocaml_guestfs_mkswap_U (value gv, value uuidv, value devicev)
+{
+ CAMLparam3 (gv, uuidv, devicev);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("mkswap_U: used handle after closing it");
+
+ const char *uuid = String_val (uuidv);
+ const char *device = String_val (devicev);
+ int r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_mkswap_U (g, uuid, device);
+ caml_leave_blocking_section ();
+ if (r == -1)
+ ocaml_guestfs_raise_error (g, "mkswap_U");
+
+ rv = Val_unit;
+ CAMLreturn (rv);
+}
+
if (r == -1)
croak ("mount_loop: %s", guestfs_last_error (g));
+void
+mkswap (g, device)
+ guestfs_h *g;
+ char *device;
+PREINIT:
+ int r;
+ PPCODE:
+ r = guestfs_mkswap (g, device);
+ if (r == -1)
+ croak ("mkswap: %s", guestfs_last_error (g));
+
+void
+mkswap_L (g, label, device)
+ guestfs_h *g;
+ char *label;
+ char *device;
+PREINIT:
+ int r;
+ PPCODE:
+ r = guestfs_mkswap_L (g, label, device);
+ if (r == -1)
+ croak ("mkswap_L: %s", guestfs_last_error (g));
+
+void
+mkswap_U (g, uuid, device)
+ guestfs_h *g;
+ char *uuid;
+ char *device;
+PREINIT:
+ int r;
+ PPCODE:
+ r = guestfs_mkswap_U (g, uuid, device);
+ if (r == -1)
+ croak ("mkswap_U: %s", guestfs_last_error (g));
+
or LVM logical volume). The filesystem type is C<fstype>, for
example C<ext3>.
+=item $h->mkswap ($device);
+
+Create a swap partition on C<device>.
+
+=item $h->mkswap_L ($label, $device);
+
+Create a swap partition on C<device> with label C<label>.
+
+=item $h->mkswap_U ($uuid, $device);
+
+Create a swap partition on C<device> with UUID C<uuid>.
+
=item $h->mount ($device, $mountpoint);
Mount a guest disk at a position in the filesystem. Block devices
return py_r;
}
+static PyObject *
+py_guestfs_mkswap (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_mkswap",
+ &py_g, &device))
+ return NULL;
+ g = get_handle (py_g);
+
+ r = guestfs_mkswap (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_mkswap_L (PyObject *self, PyObject *args)
+{
+ PyObject *py_g;
+ guestfs_h *g;
+ PyObject *py_r;
+ int r;
+ const char *label;
+ const char *device;
+
+ if (!PyArg_ParseTuple (args, (char *) "Oss:guestfs_mkswap_L",
+ &py_g, &label, &device))
+ return NULL;
+ g = get_handle (py_g);
+
+ r = guestfs_mkswap_L (g, label, 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_mkswap_U (PyObject *self, PyObject *args)
+{
+ PyObject *py_g;
+ guestfs_h *g;
+ PyObject *py_r;
+ int r;
+ const char *uuid;
+ const char *device;
+
+ if (!PyArg_ParseTuple (args, (char *) "Oss:guestfs_mkswap_U",
+ &py_g, &uuid, &device))
+ return NULL;
+ g = get_handle (py_g);
+
+ r = guestfs_mkswap_U (g, uuid, 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 },
{ (char *) "du", py_guestfs_du, METH_VARARGS, NULL },
{ (char *) "initrd_list", py_guestfs_initrd_list, METH_VARARGS, NULL },
{ (char *) "mount_loop", py_guestfs_mount_loop, METH_VARARGS, NULL },
+ { (char *) "mkswap", py_guestfs_mkswap, METH_VARARGS, NULL },
+ { (char *) "mkswap_L", py_guestfs_mkswap_L, METH_VARARGS, NULL },
+ { (char *) "mkswap_U", py_guestfs_mkswap_U, METH_VARARGS, NULL },
{ NULL, NULL, 0, NULL }
};
"""
return libguestfsmod.mount_loop (self._o, file, mountpoint)
+ def mkswap (self, device):
+ u"""Create a swap partition on "device".
+ """
+ return libguestfsmod.mkswap (self._o, device)
+
+ def mkswap_L (self, label, device):
+ u"""Create a swap partition on "device" with label "label".
+ """
+ return libguestfsmod.mkswap_L (self._o, label, device)
+
+ def mkswap_U (self, uuid, device):
+ u"""Create a swap partition on "device" with UUID "uuid".
+ """
+ return libguestfsmod.mkswap_U (self._o, uuid, device)
+
return Qnil;
}
+static VALUE ruby_guestfs_mkswap (VALUE gv, VALUE devicev)
+{
+ guestfs_h *g;
+ Data_Get_Struct (gv, guestfs_h, g);
+ if (!g)
+ rb_raise (rb_eArgError, "%s: used handle after closing it", "mkswap");
+
+ Check_Type (devicev, T_STRING);
+ const char *device = StringValueCStr (devicev);
+ if (!device)
+ rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+ "device", "mkswap");
+
+ int r;
+
+ r = guestfs_mkswap (g, device);
+ if (r == -1)
+ rb_raise (e_Error, "%s", guestfs_last_error (g));
+
+ return Qnil;
+}
+
+static VALUE ruby_guestfs_mkswap_L (VALUE gv, VALUE labelv, VALUE devicev)
+{
+ guestfs_h *g;
+ Data_Get_Struct (gv, guestfs_h, g);
+ if (!g)
+ rb_raise (rb_eArgError, "%s: used handle after closing it", "mkswap_L");
+
+ Check_Type (labelv, T_STRING);
+ const char *label = StringValueCStr (labelv);
+ if (!label)
+ rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+ "label", "mkswap_L");
+ Check_Type (devicev, T_STRING);
+ const char *device = StringValueCStr (devicev);
+ if (!device)
+ rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+ "device", "mkswap_L");
+
+ int r;
+
+ r = guestfs_mkswap_L (g, label, device);
+ if (r == -1)
+ rb_raise (e_Error, "%s", guestfs_last_error (g));
+
+ return Qnil;
+}
+
+static VALUE ruby_guestfs_mkswap_U (VALUE gv, VALUE uuidv, VALUE devicev)
+{
+ guestfs_h *g;
+ Data_Get_Struct (gv, guestfs_h, g);
+ if (!g)
+ rb_raise (rb_eArgError, "%s: used handle after closing it", "mkswap_U");
+
+ Check_Type (uuidv, T_STRING);
+ const char *uuid = StringValueCStr (uuidv);
+ if (!uuid)
+ rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+ "uuid", "mkswap_U");
+ Check_Type (devicev, T_STRING);
+ const char *device = StringValueCStr (devicev);
+ if (!device)
+ rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+ "device", "mkswap_U");
+
+ int r;
+
+ r = guestfs_mkswap_U (g, uuid, device);
+ if (r == -1)
+ rb_raise (e_Error, "%s", guestfs_last_error (g));
+
+ return Qnil;
+}
+
/* Initialize the module. */
void Init__guestfs ()
{
ruby_guestfs_initrd_list, 1);
rb_define_method (c_guestfs, "mount_loop",
ruby_guestfs_mount_loop, 2);
+ rb_define_method (c_guestfs, "mkswap",
+ ruby_guestfs_mkswap, 1);
+ rb_define_method (c_guestfs, "mkswap_L",
+ ruby_guestfs_mkswap_L, 2);
+ rb_define_method (c_guestfs, "mkswap_U",
+ ruby_guestfs_mkswap_U, 2);
}
return 0;
}
+struct mkswap_ctx {
+ /* This flag is set by the callbacks, so we know we've done
+ * the callbacks as expected, and in the right sequence.
+ * 0 = not called, 1 = reply_cb called.
+ */
+ int cb_sequence;
+ struct guestfs_message_header hdr;
+ struct guestfs_message_error err;
+};
+
+static void mkswap_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ struct mkswap_ctx *ctx = (struct mkswap_ctx *) data;
+
+ /* This should definitely not happen. */
+ if (ctx->cb_sequence != 0) {
+ ctx->cb_sequence = 9999;
+ error (g, "%s: internal error: reply callback called twice", "guestfs_mkswap");
+ return;
+ }
+
+ ml->main_loop_quit (ml, g);
+
+ if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+ error (g, "%s: failed to parse reply header", "guestfs_mkswap");
+ return;
+ }
+ if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+ if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+ error (g, "%s: failed to parse reply error", "guestfs_mkswap");
+ return;
+ }
+ goto done;
+ }
+ done:
+ ctx->cb_sequence = 1;
+}
+
+int guestfs_mkswap (guestfs_h *g,
+ const char *device)
+{
+ struct guestfs_mkswap_args args;
+ struct mkswap_ctx ctx;
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ int serial;
+
+ if (check_state (g, "guestfs_mkswap") == -1) return -1;
+ guestfs_set_busy (g);
+
+ memset (&ctx, 0, sizeof ctx);
+
+ args.device = (char *) device;
+ serial = guestfs__send_sync (g, GUESTFS_PROC_MKSWAP,
+ (xdrproc_t) xdr_guestfs_mkswap_args, (char *) &args);
+ if (serial == -1) {
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ guestfs__switch_to_receiving (g);
+ ctx.cb_sequence = 0;
+ guestfs_set_reply_callback (g, mkswap_reply_cb, &ctx);
+ (void) ml->main_loop_run (ml, g);
+ guestfs_set_reply_callback (g, NULL, NULL);
+ if (ctx.cb_sequence != 1) {
+ error (g, "%s reply failed, see earlier error messages", "guestfs_mkswap");
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKSWAP, serial) == -1) {
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+ error (g, "%s", ctx.err.error_message);
+ free (ctx.err.error_message);
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ guestfs_end_busy (g);
+ return 0;
+}
+
+struct mkswap_L_ctx {
+ /* This flag is set by the callbacks, so we know we've done
+ * the callbacks as expected, and in the right sequence.
+ * 0 = not called, 1 = reply_cb called.
+ */
+ int cb_sequence;
+ struct guestfs_message_header hdr;
+ struct guestfs_message_error err;
+};
+
+static void mkswap_L_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ struct mkswap_L_ctx *ctx = (struct mkswap_L_ctx *) data;
+
+ /* This should definitely not happen. */
+ if (ctx->cb_sequence != 0) {
+ ctx->cb_sequence = 9999;
+ error (g, "%s: internal error: reply callback called twice", "guestfs_mkswap_L");
+ return;
+ }
+
+ ml->main_loop_quit (ml, g);
+
+ if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+ error (g, "%s: failed to parse reply header", "guestfs_mkswap_L");
+ return;
+ }
+ if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+ if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+ error (g, "%s: failed to parse reply error", "guestfs_mkswap_L");
+ return;
+ }
+ goto done;
+ }
+ done:
+ ctx->cb_sequence = 1;
+}
+
+int guestfs_mkswap_L (guestfs_h *g,
+ const char *label,
+ const char *device)
+{
+ struct guestfs_mkswap_L_args args;
+ struct mkswap_L_ctx ctx;
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ int serial;
+
+ if (check_state (g, "guestfs_mkswap_L") == -1) return -1;
+ guestfs_set_busy (g);
+
+ memset (&ctx, 0, sizeof ctx);
+
+ args.label = (char *) label;
+ args.device = (char *) device;
+ serial = guestfs__send_sync (g, GUESTFS_PROC_MKSWAP_L,
+ (xdrproc_t) xdr_guestfs_mkswap_L_args, (char *) &args);
+ if (serial == -1) {
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ guestfs__switch_to_receiving (g);
+ ctx.cb_sequence = 0;
+ guestfs_set_reply_callback (g, mkswap_L_reply_cb, &ctx);
+ (void) ml->main_loop_run (ml, g);
+ guestfs_set_reply_callback (g, NULL, NULL);
+ if (ctx.cb_sequence != 1) {
+ error (g, "%s reply failed, see earlier error messages", "guestfs_mkswap_L");
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKSWAP_L, serial) == -1) {
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+ error (g, "%s", ctx.err.error_message);
+ free (ctx.err.error_message);
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ guestfs_end_busy (g);
+ return 0;
+}
+
+struct mkswap_U_ctx {
+ /* This flag is set by the callbacks, so we know we've done
+ * the callbacks as expected, and in the right sequence.
+ * 0 = not called, 1 = reply_cb called.
+ */
+ int cb_sequence;
+ struct guestfs_message_header hdr;
+ struct guestfs_message_error err;
+};
+
+static void mkswap_U_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ struct mkswap_U_ctx *ctx = (struct mkswap_U_ctx *) data;
+
+ /* This should definitely not happen. */
+ if (ctx->cb_sequence != 0) {
+ ctx->cb_sequence = 9999;
+ error (g, "%s: internal error: reply callback called twice", "guestfs_mkswap_U");
+ return;
+ }
+
+ ml->main_loop_quit (ml, g);
+
+ if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+ error (g, "%s: failed to parse reply header", "guestfs_mkswap_U");
+ return;
+ }
+ if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+ if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+ error (g, "%s: failed to parse reply error", "guestfs_mkswap_U");
+ return;
+ }
+ goto done;
+ }
+ done:
+ ctx->cb_sequence = 1;
+}
+
+int guestfs_mkswap_U (guestfs_h *g,
+ const char *uuid,
+ const char *device)
+{
+ struct guestfs_mkswap_U_args args;
+ struct mkswap_U_ctx ctx;
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ int serial;
+
+ if (check_state (g, "guestfs_mkswap_U") == -1) return -1;
+ guestfs_set_busy (g);
+
+ memset (&ctx, 0, sizeof ctx);
+
+ args.uuid = (char *) uuid;
+ args.device = (char *) device;
+ serial = guestfs__send_sync (g, GUESTFS_PROC_MKSWAP_U,
+ (xdrproc_t) xdr_guestfs_mkswap_U_args, (char *) &args);
+ if (serial == -1) {
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ guestfs__switch_to_receiving (g);
+ ctx.cb_sequence = 0;
+ guestfs_set_reply_callback (g, mkswap_U_reply_cb, &ctx);
+ (void) ml->main_loop_run (ml, g);
+ guestfs_set_reply_callback (g, NULL, NULL);
+ if (ctx.cb_sequence != 1) {
+ error (g, "%s reply failed, see earlier error messages", "guestfs_mkswap_U");
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKSWAP_U, serial) == -1) {
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+ error (g, "%s", ctx.err.error_message);
+ free (ctx.err.error_message);
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ guestfs_end_busy (g);
+ return 0;
+}
+
extern int64_t guestfs_du (guestfs_h *handle, const char *path);
extern char **guestfs_initrd_list (guestfs_h *handle, const char *path);
extern int guestfs_mount_loop (guestfs_h *handle, const char *file, const char *mountpoint);
+extern int guestfs_mkswap (guestfs_h *handle, const char *device);
+extern int guestfs_mkswap_L (guestfs_h *handle, const char *label, const char *device);
+extern int guestfs_mkswap_U (guestfs_h *handle, const char *uuid, const char *device);
}
bool_t
+xdr_guestfs_mkswap_args (XDR *xdrs, guestfs_mkswap_args *objp)
+{
+ register int32_t *buf;
+
+ if (!xdr_string (xdrs, &objp->device, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_guestfs_mkswap_L_args (XDR *xdrs, guestfs_mkswap_L_args *objp)
+{
+ register int32_t *buf;
+
+ if (!xdr_string (xdrs, &objp->label, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->device, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_guestfs_mkswap_U_args (XDR *xdrs, guestfs_mkswap_U_args *objp)
+{
+ register int32_t *buf;
+
+ if (!xdr_string (xdrs, &objp->uuid, ~0))
+ return FALSE;
+ 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;
};
typedef struct guestfs_mount_loop_args guestfs_mount_loop_args;
+struct guestfs_mkswap_args {
+ char *device;
+};
+typedef struct guestfs_mkswap_args guestfs_mkswap_args;
+
+struct guestfs_mkswap_L_args {
+ char *label;
+ char *device;
+};
+typedef struct guestfs_mkswap_L_args guestfs_mkswap_L_args;
+
+struct guestfs_mkswap_U_args {
+ char *uuid;
+ char *device;
+};
+typedef struct guestfs_mkswap_U_args guestfs_mkswap_U_args;
+
enum guestfs_procedure {
GUESTFS_PROC_MOUNT = 1,
GUESTFS_PROC_SYNC = 2,
GUESTFS_PROC_DU = 127,
GUESTFS_PROC_INITRD_LIST = 128,
GUESTFS_PROC_MOUNT_LOOP = 129,
- GUESTFS_PROC_NR_PROCS = 129 + 1,
+ GUESTFS_PROC_MKSWAP = 130,
+ GUESTFS_PROC_MKSWAP_L = 131,
+ GUESTFS_PROC_MKSWAP_U = 132,
+ GUESTFS_PROC_NR_PROCS = 132 + 1,
};
typedef enum guestfs_procedure guestfs_procedure;
#define GUESTFS_MESSAGE_MAX 4194304
extern bool_t xdr_guestfs_initrd_list_args (XDR *, guestfs_initrd_list_args*);
extern bool_t xdr_guestfs_initrd_list_ret (XDR *, guestfs_initrd_list_ret*);
extern bool_t xdr_guestfs_mount_loop_args (XDR *, guestfs_mount_loop_args*);
+extern bool_t xdr_guestfs_mkswap_args (XDR *, guestfs_mkswap_args*);
+extern bool_t xdr_guestfs_mkswap_L_args (XDR *, guestfs_mkswap_L_args*);
+extern bool_t xdr_guestfs_mkswap_U_args (XDR *, guestfs_mkswap_U_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*);
extern bool_t xdr_guestfs_initrd_list_args ();
extern bool_t xdr_guestfs_initrd_list_ret ();
extern bool_t xdr_guestfs_mount_loop_args ();
+extern bool_t xdr_guestfs_mkswap_args ();
+extern bool_t xdr_guestfs_mkswap_L_args ();
+extern bool_t xdr_guestfs_mkswap_U_args ();
extern bool_t xdr_guestfs_procedure ();
extern bool_t xdr_guestfs_message_direction ();
extern bool_t xdr_guestfs_message_status ();
string mountpoint<>;
};
+struct guestfs_mkswap_args {
+ string device<>;
+};
+
+struct guestfs_mkswap_L_args {
+ string label<>;
+ string device<>;
+};
+
+struct guestfs_mkswap_U_args {
+ string uuid<>;
+ string device<>;
+};
+
enum guestfs_procedure {
GUESTFS_PROC_MOUNT = 1,
GUESTFS_PROC_SYNC = 2,
GUESTFS_PROC_DU = 127,
GUESTFS_PROC_INITRD_LIST = 128,
GUESTFS_PROC_MOUNT_LOOP = 129,
+ GUESTFS_PROC_MKSWAP = 130,
+ GUESTFS_PROC_MKSWAP_L = 131,
+ GUESTFS_PROC_MKSWAP_U = 132,
GUESTFS_PROC_NR_PROCS
};