extern int do_lvresize (const char *device, int mbytes);
extern int do_resize2fs (const char *device);
extern char **do_find (const char *directory);
+extern int do_e2fsck_f (const char *device);
xdr_free ((xdrproc_t) xdr_guestfs_find_args, (char *) &args);
}
+static void e2fsck_f_stub (XDR *xdr_in)
+{
+ int r;
+ struct guestfs_e2fsck_f_args args;
+ const char *device;
+
+ memset (&args, 0, sizeof args);
+
+ if (!xdr_guestfs_e2fsck_f_args (xdr_in, &args)) {
+ reply_with_error ("%s: daemon failed to decode procedure arguments", "e2fsck_f");
+ return;
+ }
+ device = args.device;
+
+ r = do_e2fsck_f (device);
+ if (r == -1)
+ /* do_e2fsck_f has already called reply_with_error */
+ goto done;
+
+ reply (NULL, NULL);
+done:
+ xdr_free ((xdrproc_t) xdr_guestfs_e2fsck_f_args, (char *) &args);
+}
+
void dispatch_incoming_message (XDR *xdr_in)
{
switch (proc_nr) {
case GUESTFS_PROC_FIND:
find_stub (xdr_in);
break;
+ case GUESTFS_PROC_E2FSCK_F:
+ e2fsck_f_stub (xdr_in);
+ break;
default:
reply_with_error ("dispatch_incoming_message: unknown procedure number %d", proc_nr);
}
printf ("%-20s %s\n", "dmesg", "return kernel messages");
printf ("%-20s %s\n", "download", "download a file to the local machine");
printf ("%-20s %s\n", "drop-caches", "drop kernel page cache, dentries and inodes");
+ printf ("%-20s %s\n", "e2fsck-f", "check an ext2/ext3 filesystem");
printf ("%-20s %s\n", "equal", "test if two files have equal contents");
printf ("%-20s %s\n", "exists", "test if file or directory exists");
printf ("%-20s %s\n", "file", "determine file type");
pod2text ("lvresize - resize an LVM logical volume", " lvresize <device> <mbytes>\n\nThis resizes (expands or shrinks) an existing LVM logical\nvolume to C<mbytes>. When reducing, data in the reduced part\nis lost.");
else
if (strcasecmp (cmd, "resize2fs") == 0)
- pod2text ("resize2fs - resize an ext2/ext3 filesystem", " resize2fs <device>\n\nThis resizes an ext2 or ext3 filesystem to match the size of\nthe underlying device.");
+ pod2text ("resize2fs - resize an ext2/ext3 filesystem", " resize2fs <device>\n\nThis resizes an ext2 or ext3 filesystem to match the size of\nthe underlying device.\n\nI<Note:> It is sometimes required that you run C<e2fsck_f>\non the C<device> before calling this command. For unknown reasons\nC<resize2fs> sometimes gives an error about this and sometimes not.\nIn any case, it is always safe to call C<e2fsck_f> before\ncalling this function.");
else
if (strcasecmp (cmd, "find") == 0)
pod2text ("find - find all files and directories", " find <directory>\n\nThis command lists out all files and directories, recursively,\nstarting at C<directory>. It is essentially equivalent to\nrunning the shell command C<find directory -print> but some\npost-processing happens on the output, described below.\n\nThis returns a list of strings I<without any prefix>. Thus\nif the directory structure was:\n\n /tmp/a\n /tmp/b\n /tmp/c/d\n\nthen the returned list from C<find> C</tmp> would be\n4 elements:\n\n a\n b\n c\n c/d\n\nIf C<directory> is not a directory, then this command returns\nan error.\n\nThe returned list is sorted.");
else
+ if (strcasecmp (cmd, "e2fsck_f") == 0 || strcasecmp (cmd, "e2fsck-f") == 0)
+ pod2text ("e2fsck-f - check an ext2/ext3 filesystem", " e2fsck-f <device>\n\nThis runs C<e2fsck -p -f device>, ie. runs the ext2/ext3\nfilesystem checker on C<device>, noninteractively (C<-p>),\neven if the filesystem appears to be clean (C<-f>).\n\nThis command is only needed because of C<resize2fs>\n(q.v.). Normally you should use C<fsck>.");
+ else
display_builtin_command (cmd);
}
return 0;
}
+static int run_e2fsck_f (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_e2fsck_f (g, 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, "find") == 0)
return run_find (cmd, argc, argv);
else
+ if (strcasecmp (cmd, "e2fsck_f") == 0 || strcasecmp (cmd, "e2fsck-f") == 0)
+ return run_e2fsck_f (cmd, argc, argv);
+ else
{
fprintf (stderr, "%s: unknown command\n", cmd);
return -1;
"dmesg",
"download",
"drop-caches",
+ "e2fsck-f",
"equal",
"exists",
"file",
This automatically calls L<sync(2)> before the operation,
so that the maximum guest memory is freed.
+=head2 e2fsck-f
+
+ e2fsck-f device
+
+This runs C<e2fsck -p -f device>, ie. runs the ext2/ext3
+filesystem checker on C<device>, noninteractively (C<-p>),
+even if the filesystem appears to be clean (C<-f>).
+
+This command is only needed because of C<resize2fs>
+(q.v.). Normally you should use C<fsck>.
+
=head2 equal
equal file1 file2
This resizes an ext2 or ext3 filesystem to match the size of
the underlying device.
+I<Note:> It is sometimes required that you run C<e2fsck-f>
+on the C<device> before calling this command. For unknown reasons
+C<resize2fs> sometimes gives an error about this and sometimes not.
+In any case, it is always safe to call C<e2fsck-f> before
+calling this function.
+
=head2 rm
rm path
This function returns 0 on success or -1 on error.
+=head2 guestfs_e2fsck_f
+
+ int guestfs_e2fsck_f (guestfs_h *handle,
+ const char *device);
+
+This runs C<e2fsck -p -f device>, ie. runs the ext2/ext3
+filesystem checker on C<device>, noninteractively (C<-p>),
+even if the filesystem appears to be clean (C<-f>).
+
+This command is only needed because of C<guestfs_resize2fs>
+(q.v.). Normally you should use C<guestfs_fsck>.
+
+This function returns 0 on success or -1 on error.
+
=head2 guestfs_end_busy
int guestfs_end_busy (guestfs_h *handle);
This resizes an ext2 or ext3 filesystem to match the size of
the underlying device.
+I<Note:> It is sometimes required that you run C<guestfs_e2fsck_f>
+on the C<device> before calling this command. For unknown reasons
+C<resize2fs> sometimes gives an error about this and sometimes not.
+In any case, it is always safe to call C<guestfs_e2fsck_f> before
+calling this function.
+
This function returns 0 on success or -1 on error.
=head2 guestfs_rm
ping_daemon,
zerofree,
pvresize,
- resize2fs
+ resize2fs,
+ e2fsck_f
) where
import Foreign
import Foreign.C
fail err
else return ()
+foreign import ccall unsafe "guestfs_e2fsck_f" c_e2fsck_f
+ :: GuestfsP -> CString -> IO (CInt)
+
+e2fsck_f :: GuestfsH -> String -> IO ()
+e2fsck_f h device = do
+ r <- withCString device $ \device -> withForeignPtr h (\p -> c_e2fsck_f p device)
+ if (r == -1)
+ then do
+ err <- last_error h
+ fail err
+ else return ()
+
* This resizes an ext2 or ext3 filesystem to match the
* size of the underlying device.
*
+ * *Note:* It is sometimes required that you run
+ * "g.e2fsck_f" on the "device" before calling this
+ * command. For unknown reasons "resize2fs" sometimes gives
+ * an error about this and sometimes not. In any case, it
+ * is always safe to call "g.e2fsck_f" before calling this
+ * function.
+ *
* @throws LibGuestFSException
*/
public void resize2fs (String device)
private native String[] _find (long g, String directory)
throws LibGuestFSException;
+ /**
+ * check an ext2/ext3 filesystem
+ *
+ * This runs "e2fsck -p -f device", ie. runs the ext2/ext3
+ * filesystem checker on "device", noninteractively ("-p"),
+ * even if the filesystem appears to be clean ("-f").
+ *
+ * This command is only needed because of "g.resize2fs"
+ * (q.v.). Normally you should use "g.fsck".
+ *
+ * @throws LibGuestFSException
+ */
+ public void e2fsck_f (String device)
+ throws LibGuestFSException
+ {
+ if (g == 0)
+ throw new LibGuestFSException ("e2fsck_f: handle is closed");
+ _e2fsck_f (g, device);
+ }
+ private native void _e2fsck_f (long g, String device)
+ throws LibGuestFSException;
+
}
return jr;
}
+JNIEXPORT void JNICALL
+Java_com_redhat_et_libguestfs_GuestFS__1e2fsck_1f
+ (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_e2fsck_f (g, device);
+ (*env)->ReleaseStringUTFChars (env, jdevice, device);
+ if (r == -1) {
+ throw_exception (env, guestfs_last_error (g));
+ return ;
+ }
+}
+
external lvresize : t -> string -> int -> unit = "ocaml_guestfs_lvresize"
external resize2fs : t -> string -> unit = "ocaml_guestfs_resize2fs"
external find : t -> string -> string array = "ocaml_guestfs_find"
+external e2fsck_f : t -> string -> unit = "ocaml_guestfs_e2fsck_f"
val find : t -> string -> string array
(** find all files and directories *)
+val e2fsck_f : t -> string -> unit
+(** check an ext2/ext3 filesystem *)
+
CAMLreturn (rv);
}
+CAMLprim value
+ocaml_guestfs_e2fsck_f (value gv, value devicev)
+{
+ CAMLparam2 (gv, devicev);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("e2fsck_f: used handle after closing it");
+
+ const char *device = String_val (devicev);
+ int r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_e2fsck_f (g, device);
+ caml_leave_blocking_section ();
+ if (r == -1)
+ ocaml_guestfs_raise_error (g, "e2fsck_f");
+
+ rv = Val_unit;
+ CAMLreturn (rv);
+}
+
}
free (names);
+void
+e2fsck_f (g, device)
+ guestfs_h *g;
+ char *device;
+PREINIT:
+ int r;
+ PPCODE:
+ r = guestfs_e2fsck_f (g, device);
+ if (r == -1)
+ croak ("e2fsck_f: %s", guestfs_last_error (g));
+
This automatically calls L<sync(2)> before the operation,
so that the maximum guest memory is freed.
+=item $h->e2fsck_f ($device);
+
+This runs C<e2fsck -p -f device>, ie. runs the ext2/ext3
+filesystem checker on C<device>, noninteractively (C<-p>),
+even if the filesystem appears to be clean (C<-f>).
+
+This command is only needed because of C<$h-E<gt>resize2fs>
+(q.v.). Normally you should use C<$h-E<gt>fsck>.
+
=item $h->end_busy ();
This sets the state to C<READY>, or if in C<CONFIG> then it leaves the
This resizes an ext2 or ext3 filesystem to match the size of
the underlying device.
+I<Note:> It is sometimes required that you run C<$h-E<gt>e2fsck_f>
+on the C<device> before calling this command. For unknown reasons
+C<resize2fs> sometimes gives an error about this and sometimes not.
+In any case, it is always safe to call C<$h-E<gt>e2fsck_f> before
+calling this function.
+
=item $h->rm ($path);
Remove the single file C<path>.
return py_r;
}
+static PyObject *
+py_guestfs_e2fsck_f (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_e2fsck_f",
+ &py_g, &device))
+ return NULL;
+ g = get_handle (py_g);
+
+ r = guestfs_e2fsck_f (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 },
{ (char *) "lvresize", py_guestfs_lvresize, METH_VARARGS, NULL },
{ (char *) "resize2fs", py_guestfs_resize2fs, METH_VARARGS, NULL },
{ (char *) "find", py_guestfs_find, METH_VARARGS, NULL },
+ { (char *) "e2fsck_f", py_guestfs_e2fsck_f, METH_VARARGS, NULL },
{ NULL, NULL, 0, NULL }
};
def resize2fs (self, device):
u"""This resizes an ext2 or ext3 filesystem to match the
size of the underlying device.
+
+ *Note:* It is sometimes required that you run
+ "g.e2fsck_f" on the "device" before calling this
+ command. For unknown reasons "resize2fs" sometimes gives
+ an error about this and sometimes not. In any case, it
+ is always safe to call "g.e2fsck_f" before calling this
+ function.
"""
return libguestfsmod.resize2fs (self._o, device)
"""
return libguestfsmod.find (self._o, directory)
+ def e2fsck_f (self, device):
+ u"""This runs "e2fsck -p -f device", ie. runs the ext2/ext3
+ filesystem checker on "device", noninteractively ("-p"),
+ even if the filesystem appears to be clean ("-f").
+
+ This command is only needed because of "g.resize2fs"
+ (q.v.). Normally you should use "g.fsck".
+ """
+ return libguestfsmod.e2fsck_f (self._o, device)
+
return rv;
}
+static VALUE ruby_guestfs_e2fsck_f (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", "e2fsck_f");
+
+ const char *device = StringValueCStr (devicev);
+ if (!device)
+ rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+ "device", "e2fsck_f");
+
+ int r;
+
+ r = guestfs_e2fsck_f (g, device);
+ if (r == -1)
+ rb_raise (e_Error, "%s", guestfs_last_error (g));
+
+ return Qnil;
+}
+
/* Initialize the module. */
void Init__guestfs ()
{
ruby_guestfs_resize2fs, 1);
rb_define_method (c_guestfs, "find",
ruby_guestfs_find, 1);
+ rb_define_method (c_guestfs, "e2fsck_f",
+ ruby_guestfs_e2fsck_f, 1);
}
return ctx.ret.names.names_val;
}
+struct e2fsck_f_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 e2fsck_f_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ struct e2fsck_f_ctx *ctx = (struct e2fsck_f_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_e2fsck_f");
+ return;
+ }
+
+ ml->main_loop_quit (ml, g);
+
+ if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+ error (g, "%s: failed to parse reply header", "guestfs_e2fsck_f");
+ 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_e2fsck_f");
+ return;
+ }
+ goto done;
+ }
+ done:
+ ctx->cb_sequence = 1;
+}
+
+int guestfs_e2fsck_f (guestfs_h *g,
+ const char *device)
+{
+ struct guestfs_e2fsck_f_args args;
+ struct e2fsck_f_ctx ctx;
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ int serial;
+
+ if (check_state (g, "guestfs_e2fsck_f") == -1) return -1;
+ guestfs_set_busy (g);
+
+ memset (&ctx, 0, sizeof ctx);
+
+ args.device = (char *) device;
+ serial = guestfs__send_sync (g, GUESTFS_PROC_E2FSCK_F,
+ (xdrproc_t) xdr_guestfs_e2fsck_f_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, e2fsck_f_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_e2fsck_f");
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_E2FSCK_F, 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 int guestfs_lvresize (guestfs_h *handle, const char *device, int mbytes);
extern int guestfs_resize2fs (guestfs_h *handle, const char *device);
extern char **guestfs_find (guestfs_h *handle, const char *directory);
+extern int guestfs_e2fsck_f (guestfs_h *handle, const char *device);
}
bool_t
+xdr_guestfs_e2fsck_f_args (XDR *xdrs, guestfs_e2fsck_f_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;
};
typedef struct guestfs_find_ret guestfs_find_ret;
+struct guestfs_e2fsck_f_args {
+ char *device;
+};
+typedef struct guestfs_e2fsck_f_args guestfs_e2fsck_f_args;
+
enum guestfs_procedure {
GUESTFS_PROC_MOUNT = 1,
GUESTFS_PROC_SYNC = 2,
GUESTFS_PROC_LVRESIZE = 105,
GUESTFS_PROC_RESIZE2FS = 106,
GUESTFS_PROC_FIND = 107,
- GUESTFS_PROC_NR_PROCS = 107 + 1,
+ GUESTFS_PROC_E2FSCK_F = 108,
+ GUESTFS_PROC_NR_PROCS = 108 + 1,
};
typedef enum guestfs_procedure guestfs_procedure;
#define GUESTFS_MESSAGE_MAX 4194304
extern bool_t xdr_guestfs_resize2fs_args (XDR *, guestfs_resize2fs_args*);
extern bool_t xdr_guestfs_find_args (XDR *, guestfs_find_args*);
extern bool_t xdr_guestfs_find_ret (XDR *, guestfs_find_ret*);
+extern bool_t xdr_guestfs_e2fsck_f_args (XDR *, guestfs_e2fsck_f_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_resize2fs_args ();
extern bool_t xdr_guestfs_find_args ();
extern bool_t xdr_guestfs_find_ret ();
+extern bool_t xdr_guestfs_e2fsck_f_args ();
extern bool_t xdr_guestfs_procedure ();
extern bool_t xdr_guestfs_message_direction ();
extern bool_t xdr_guestfs_message_status ();
str names<>;
};
+struct guestfs_e2fsck_f_args {
+ string device<>;
+};
+
enum guestfs_procedure {
GUESTFS_PROC_MOUNT = 1,
GUESTFS_PROC_SYNC = 2,
GUESTFS_PROC_LVRESIZE = 105,
GUESTFS_PROC_RESIZE2FS = 106,
GUESTFS_PROC_FIND = 107,
+ GUESTFS_PROC_E2FSCK_F = 108,
GUESTFS_PROC_NR_PROCS
};
fprintf (stderr, "warning: \"guestfs_vg_activate_all\" has no tests\n");
fprintf (stderr, "warning: \"guestfs_vg_activate\" has no tests\n");
fprintf (stderr, "warning: \"guestfs_resize2fs\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_e2fsck_f\" has no tests\n");
}
static int test_find_0 (void)
char device[] = "/dev/VG/LV";
int r;
suppress_error = 0;
+ r = guestfs_e2fsck_f (g, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char device[] = "/dev/VG/LV";
+ int r;
+ suppress_error = 0;
r = guestfs_resize2fs (g, device);
if (r == -1)
return -1;