Add generated code for 'fsck' command.
authorRichard Jones <rjones@redhat.com>
Thu, 30 Apr 2009 17:57:07 +0000 (18:57 +0100)
committerRichard Jones <rjones@redhat.com>
Thu, 30 Apr 2009 17:57:07 +0000 (18:57 +0100)
24 files changed:
daemon/actions.h
daemon/daemon.h
daemon/guestfsd.c
daemon/stubs.c
fish/cmds.c
fish/completion.c
guestfish-actions.pod
guestfs-actions.pod
java/com/redhat/et/libguestfs/GuestFS.java
java/com_redhat_et_libguestfs_GuestFS.c
ocaml/guestfs.ml
ocaml/guestfs.mli
ocaml/guestfs_c_actions.c
perl/Guestfs.xs
perl/lib/Sys/Guestfs.pm
python/guestfs-py.c
python/guestfs.py
ruby/ext/guestfs/_guestfs.c
src/guestfs-actions.c
src/guestfs-actions.h
src/guestfs_protocol.c
src/guestfs_protocol.h
src/guestfs_protocol.x
tests.c

index 373e513..7455586 100644 (file)
@@ -104,3 +104,4 @@ extern int do_set_e2label (const char *device, const char *label);
 extern char *do_get_e2label (const char *device);
 extern int do_set_e2uuid (const char *device, const char *uuid);
 extern char *do_get_e2uuid (const char *device);
 extern char *do_get_e2label (const char *device);
 extern int do_set_e2uuid (const char *device, const char *uuid);
 extern char *do_get_e2uuid (const char *device);
+extern int do_fsck (const char *fstype, const char *device);
index 3f51056..001c703 100644 (file)
@@ -41,8 +41,11 @@ extern void free_strings (char **argv);
 extern void free_stringslen (char **argv, int len);
 
 extern int command (char **stdoutput, char **stderror, const char *name, ...);
 extern void free_stringslen (char **argv, int len);
 
 extern int command (char **stdoutput, char **stderror, const char *name, ...);
+extern int commandr (char **stdoutput, char **stderror, const char *name, ...);
 extern int commandv (char **stdoutput, char **stderror,
                     char * const* const argv);
 extern int commandv (char **stdoutput, char **stderror,
                     char * const* const argv);
+extern int commandrv (char **stdoutput, char **stderror,
+                     char * const* const argv);
 
 extern int shell_quote (char *out, int len, const char *in);
 
 
 extern int shell_quote (char *out, int len, const char *in);
 
index ba4035e..99055a9 100644 (file)
@@ -378,9 +378,69 @@ command (char **stdoutput, char **stderror, const char *name, ...)
   return r;
 }
 
   return r;
 }
 
+/* Same as 'command', but we allow the status code from the
+ * subcommand to be non-zero, and return that status code.
+ * We still return -1 if there was some other error.
+ */
+int
+commandr (char **stdoutput, char **stderror, const char *name, ...)
+{
+  va_list args;
+  char **argv, **p;
+  char *s;
+  int i, r;
+
+  /* Collect the command line arguments into an array. */
+  i = 2;
+  argv = malloc (sizeof (char *) * i);
+  if (argv == NULL) {
+    perror ("malloc");
+    return -1;
+  }
+  argv[0] = (char *) name;
+  argv[1] = NULL;
+
+  va_start (args, name);
+
+  while ((s = va_arg (args, char *)) != NULL) {
+    p = realloc (argv, sizeof (char *) * (++i));
+    if (p == NULL) {
+      perror ("realloc");
+      free (argv);
+      va_end (args);
+      return -1;
+    }
+    argv = p;
+    argv[i-2] = s;
+    argv[i-1] = NULL;
+  }
+
+  va_end (args);
+
+  r = commandrv (stdoutput, stderror, argv);
+
+  /* NB: Mustn't free the strings which are on the stack. */
+  free (argv);
+
+  return r;
+}
+
+/* Same as 'command', but passing an argv. */
 int
 commandv (char **stdoutput, char **stderror, char * const* const argv)
 {
 int
 commandv (char **stdoutput, char **stderror, char * const* const argv)
 {
+  int r;
+
+  r = commandrv (stdoutput, stderror, argv);
+  if (r == 0)
+    return 0;
+  else
+    return -1;
+}
+
+int
+commandrv (char **stdoutput, char **stderror, char * const* const argv)
+{
   int so_size = 0, se_size = 0;
   int so_fd[2], se_fd[2];
   int pid, r, quit, i;
   int so_size = 0, se_size = 0;
   int so_fd[2], se_fd[2];
   int pid, r, quit, i;
@@ -524,10 +584,7 @@ commandv (char **stdoutput, char **stderror, char * const* const argv)
   waitpid (pid, &r, 0);
 
   if (WIFEXITED (r)) {
   waitpid (pid, &r, 0);
 
   if (WIFEXITED (r)) {
-    if (WEXITSTATUS (r) == 0)
-      return 0;
-    else
-      return -1;
+    return WEXITSTATUS (r);
   } else
     return -1;
 }
   } else
     return -1;
 }
index 019e4fb..9e0ce55 100644 (file)
@@ -2075,6 +2075,34 @@ done:
   xdr_free ((xdrproc_t) xdr_guestfs_get_e2uuid_args, (char *) &args);
 }
 
   xdr_free ((xdrproc_t) xdr_guestfs_get_e2uuid_args, (char *) &args);
 }
 
+static void fsck_stub (XDR *xdr_in)
+{
+  int r;
+  struct guestfs_fsck_args args;
+  const char *fstype;
+  const char *device;
+
+  memset (&args, 0, sizeof args);
+
+  if (!xdr_guestfs_fsck_args (xdr_in, &args)) {
+    reply_with_error ("%s: daemon failed to decode procedure arguments", "fsck");
+    return;
+  }
+  fstype = args.fstype;
+  device = args.device;
+
+  r = do_fsck (fstype, device);
+  if (r == -1)
+    /* do_fsck has already called reply_with_error */
+    goto done;
+
+  struct guestfs_fsck_ret ret;
+  ret.status = r;
+  reply ((xdrproc_t) &xdr_guestfs_fsck_ret, (char *) &ret);
+done:
+  xdr_free ((xdrproc_t) xdr_guestfs_fsck_args, (char *) &args);
+}
+
 void dispatch_incoming_message (XDR *xdr_in)
 {
   switch (proc_nr) {
 void dispatch_incoming_message (XDR *xdr_in)
 {
   switch (proc_nr) {
@@ -2327,6 +2355,9 @@ void dispatch_incoming_message (XDR *xdr_in)
     case GUESTFS_PROC_GET_E2UUID:
       get_e2uuid_stub (xdr_in);
       break;
     case GUESTFS_PROC_GET_E2UUID:
       get_e2uuid_stub (xdr_in);
       break;
+    case GUESTFS_PROC_FSCK:
+      fsck_stub (xdr_in);
+      break;
     default:
       reply_with_error ("dispatch_incoming_message: unknown procedure number %d", proc_nr);
   }
     default:
       reply_with_error ("dispatch_incoming_message: unknown procedure number %d", proc_nr);
   }
index 1e8cb30..e762521 100644 (file)
@@ -67,6 +67,7 @@ void list_commands (void)
   printf ("%-20s %s\n", "download", "download a file to the local machine");
   printf ("%-20s %s\n", "exists", "test if file or directory exists");
   printf ("%-20s %s\n", "file", "determine file type");
   printf ("%-20s %s\n", "download", "download a file to the local machine");
   printf ("%-20s %s\n", "exists", "test if file or directory exists");
   printf ("%-20s %s\n", "file", "determine file type");
+  printf ("%-20s %s\n", "fsck", "run the filesystem checker");
   printf ("%-20s %s\n", "get-autosync", "get autosync mode");
   printf ("%-20s %s\n", "get-e2label", "get the ext2/3/4 filesystem label");
   printf ("%-20s %s\n", "get-e2uuid", "get the ext2/3/4 filesystem UUID");
   printf ("%-20s %s\n", "get-autosync", "get autosync mode");
   printf ("%-20s %s\n", "get-e2label", "get the ext2/3/4 filesystem label");
   printf ("%-20s %s\n", "get-e2uuid", "get the ext2/3/4 filesystem UUID");
@@ -440,6 +441,9 @@ void display_command (const char *cmd)
   if (strcasecmp (cmd, "get_e2uuid") == 0 || strcasecmp (cmd, "get-e2uuid") == 0)
     pod2text ("get-e2uuid - get the ext2/3/4 filesystem UUID", " get-e2uuid <device>\n\nThis returns the ext2/3/4 filesystem UUID of the filesystem on\nC<device>.");
   else
   if (strcasecmp (cmd, "get_e2uuid") == 0 || strcasecmp (cmd, "get-e2uuid") == 0)
     pod2text ("get-e2uuid - get the ext2/3/4 filesystem UUID", " get-e2uuid <device>\n\nThis returns the ext2/3/4 filesystem UUID of the filesystem on\nC<device>.");
   else
+  if (strcasecmp (cmd, "fsck") == 0)
+    pod2text ("fsck - run the filesystem checker", " fsck <fstype> <device>\n\nThis runs the filesystem checker (fsck) on C<device> which\nshould have filesystem type C<fstype>.\n\nThe returned integer is the status.  See L<fsck(8)> for the\nlist of status codes from C<fsck>, and note that multiple\nstatus codes can be summed together.\n\nIt is entirely equivalent to running C<fsck -a -t fstype device>.\nNote that checking or repairing NTFS volumes is not supported\n(by linux-ntfs).");
+  else
     display_builtin_command (cmd);
 }
 
     display_builtin_command (cmd);
 }
 
@@ -2142,6 +2146,24 @@ static int run_get_e2uuid (const char *cmd, int argc, char *argv[])
   return 0;
 }
 
   return 0;
 }
 
+static int run_fsck (const char *cmd, int argc, char *argv[])
+{
+  int r;
+  const char *fstype;
+  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;
+  }
+  fstype = argv[0];
+  device = argv[1];
+  r = guestfs_fsck (g, fstype, device);
+  if (r == -1) return -1;
+  printf ("%d\n", r);
+  return 0;
+}
+
 int run_action (const char *cmd, int argc, char *argv[])
 {
   if (strcasecmp (cmd, "launch") == 0 || strcasecmp (cmd, "run") == 0)
 int run_action (const char *cmd, int argc, char *argv[])
 {
   if (strcasecmp (cmd, "launch") == 0 || strcasecmp (cmd, "run") == 0)
@@ -2447,6 +2469,9 @@ int run_action (const char *cmd, int argc, char *argv[])
   if (strcasecmp (cmd, "get_e2uuid") == 0 || strcasecmp (cmd, "get-e2uuid") == 0)
     return run_get_e2uuid (cmd, argc, argv);
   else
   if (strcasecmp (cmd, "get_e2uuid") == 0 || strcasecmp (cmd, "get-e2uuid") == 0)
     return run_get_e2uuid (cmd, argc, argv);
   else
+  if (strcasecmp (cmd, "fsck") == 0)
+    return run_fsck (cmd, argc, argv);
+  else
     {
       fprintf (stderr, "%s: unknown command\n", cmd);
       return -1;
     {
       fprintf (stderr, "%s: unknown command\n", cmd);
       return -1;
index e44c388..cafb84d 100644 (file)
@@ -73,6 +73,7 @@ static const char *const commands[] = {
   "download",
   "exists",
   "file",
   "download",
   "exists",
   "file",
+  "fsck",
   "get-autosync",
   "get-e2label",
   "get-e2uuid",
   "get-autosync",
   "get-e2label",
   "get-e2uuid",
index fce1b31..c1981c5 100644 (file)
@@ -449,6 +449,21 @@ The exact command which runs is C<file -bsL path>.  Note in
 particular that the filename is not prepended to the output
 (the C<-b> option).
 
 particular that the filename is not prepended to the output
 (the C<-b> option).
 
+=head2 fsck
+
+ fsck fstype device
+
+This runs the filesystem checker (fsck) on C<device> which
+should have filesystem type C<fstype>.
+
+The returned integer is the status.  See L<fsck(8)> for the
+list of status codes from C<fsck>, and note that multiple
+status codes can be summed together.
+
+It is entirely equivalent to running C<fsck -a -t fstype device>.
+Note that checking or repairing NTFS volumes is not supported
+(by linux-ntfs).
+
 =head2 get-autosync
 
  get-autosync
 =head2 get-autosync
 
  get-autosync
index 210e825..07b35af 100644 (file)
@@ -582,6 +582,25 @@ particular that the filename is not prepended to the output
 This function returns a string, or NULL on error.
 I<The caller must free the returned string after use>.
 
 This function returns a string, or NULL on error.
 I<The caller must free the returned string after use>.
 
+=head2 guestfs_fsck
+
+ int guestfs_fsck (guestfs_h *handle,
+               const char *fstype,
+               const char *device);
+
+This runs the filesystem checker (fsck) on C<device> which
+should have filesystem type C<fstype>.
+
+The returned integer is the status.  See L<fsck(8)> for the
+list of status codes from C<fsck>, and note that multiple
+status codes can be summed together.
+
+It is entirely equivalent to running C<fsck -a -t fstype device>.
+Note that checking or repairing NTFS volumes is not supported
+(by linux-ntfs).
+
+On error this function returns -1.
+
 =head2 guestfs_get_autosync
 
  int guestfs_get_autosync (guestfs_h *handle);
 =head2 guestfs_get_autosync
 
  int guestfs_get_autosync (guestfs_h *handle);
index 7e7cd68..844c3b3 100644 (file)
@@ -2356,4 +2356,30 @@ public class GuestFS {
   private native String _get_e2uuid (long g, String device)
     throws LibGuestFSException;
 
   private native String _get_e2uuid (long g, String device)
     throws LibGuestFSException;
 
+  /**
+   * run the filesystem checker
+   *
+   * This runs the filesystem checker (fsck) on "device"
+   * which should have filesystem type "fstype".
+   * 
+   * The returned integer is the status. See fsck(8) for the
+   * list of status codes from "fsck", and note that multiple
+   * status codes can be summed together.
+   * 
+   * It is entirely equivalent to running "fsck -a -t fstype
+   * device". Note that checking or repairing NTFS volumes is
+   * not supported (by linux-ntfs).
+   * 
+   * @throws LibGuestFSException
+   */
+  public int fsck (String fstype, String device)
+    throws LibGuestFSException
+  {
+    if (g == 0)
+      throw new LibGuestFSException ("fsck: handle is closed");
+    return _fsck (g, fstype, device);
+  }
+  private native int _fsck (long g, String fstype, String device)
+    throws LibGuestFSException;
+
 }
 }
index f012a4b..1f5579e 100644 (file)
@@ -2399,3 +2399,24 @@ Java_com_redhat_et_libguestfs_GuestFS__1get_1e2uuid
   return jr;
 }
 
   return jr;
 }
 
+JNIEXPORT jint JNICALL
+Java_com_redhat_et_libguestfs_GuestFS__1fsck
+  (JNIEnv *env, jobject obj, jlong jg, jstring jfstype, jstring jdevice)
+{
+  guestfs_h *g = (guestfs_h *) (long) jg;
+  int r;
+  const char *fstype;
+  const char *device;
+
+  fstype = (*env)->GetStringUTFChars (env, jfstype, NULL);
+  device = (*env)->GetStringUTFChars (env, jdevice, NULL);
+  r = guestfs_fsck (g, fstype, device);
+  (*env)->ReleaseStringUTFChars (env, jfstype, fstype);
+  (*env)->ReleaseStringUTFChars (env, jdevice, device);
+  if (r == -1) {
+    throw_exception (env, guestfs_last_error (g));
+    return 0;
+  }
+  return (jint) r;
+}
+
index b8511a4..32e2264 100644 (file)
@@ -219,3 +219,4 @@ external set_e2label : t -> string -> string -> unit = "ocaml_guestfs_set_e2labe
 external get_e2label : t -> string -> string = "ocaml_guestfs_get_e2label"
 external set_e2uuid : t -> string -> string -> unit = "ocaml_guestfs_set_e2uuid"
 external get_e2uuid : t -> string -> string = "ocaml_guestfs_get_e2uuid"
 external get_e2label : t -> string -> string = "ocaml_guestfs_get_e2label"
 external set_e2uuid : t -> string -> string -> unit = "ocaml_guestfs_set_e2uuid"
 external get_e2uuid : t -> string -> string = "ocaml_guestfs_get_e2uuid"
+external fsck : t -> string -> string -> int = "ocaml_guestfs_fsck"
index 291f340..2cbd734 100644 (file)
@@ -436,3 +436,6 @@ val set_e2uuid : t -> string -> string -> unit
 val get_e2uuid : t -> string -> string
 (** get the ext2/3/4 filesystem UUID *)
 
 val get_e2uuid : t -> string -> string
 (** get the ext2/3/4 filesystem UUID *)
 
+val fsck : t -> string -> string -> int
+(** run the filesystem checker *)
+
index 9f860ba..22dc18f 100644 (file)
@@ -2799,3 +2799,27 @@ ocaml_guestfs_get_e2uuid (value gv, value devicev)
   CAMLreturn (rv);
 }
 
   CAMLreturn (rv);
 }
 
+CAMLprim value
+ocaml_guestfs_fsck (value gv, value fstypev, value devicev)
+{
+  CAMLparam3 (gv, fstypev, devicev);
+  CAMLlocal1 (rv);
+
+  guestfs_h *g = Guestfs_val (gv);
+  if (g == NULL)
+    caml_failwith ("fsck: used handle after closing it");
+
+  const char *fstype = String_val (fstypev);
+  const char *device = String_val (devicev);
+  int r;
+
+  caml_enter_blocking_section ();
+  r = guestfs_fsck (g, fstype, device);
+  caml_leave_blocking_section ();
+  if (r == -1)
+    ocaml_guestfs_raise_error (g, "fsck");
+
+  rv = Val_int (r);
+  CAMLreturn (rv);
+}
+
index 9d8a49c..38c60c2 100644 (file)
@@ -1573,3 +1573,18 @@ PREINIT:
  OUTPUT:
       RETVAL
 
  OUTPUT:
       RETVAL
 
+SV *
+fsck (g, fstype, device)
+      guestfs_h *g;
+      char *fstype;
+      char *device;
+PREINIT:
+      int status;
+   CODE:
+      status = guestfs_fsck (g, fstype, device);
+      if (status == -1)
+        croak ("fsck: %s", guestfs_last_error (g));
+      RETVAL = newSViv (status);
+ OUTPUT:
+      RETVAL
+
index efc2845..5b87b27 100644 (file)
@@ -468,6 +468,19 @@ The exact command which runs is C<file -bsL path>.  Note in
 particular that the filename is not prepended to the output
 (the C<-b> option).
 
 particular that the filename is not prepended to the output
 (the C<-b> option).
 
+=item $status = $h->fsck ($fstype, $device);
+
+This runs the filesystem checker (fsck) on C<device> which
+should have filesystem type C<fstype>.
+
+The returned integer is the status.  See L<fsck(8)> for the
+list of status codes from C<fsck>, and note that multiple
+status codes can be summed together.
+
+It is entirely equivalent to running C<fsck -a -t fstype device>.
+Note that checking or repairing NTFS volumes is not supported
+(by linux-ntfs).
+
 =item $autosync = $h->get_autosync ();
 
 Get the autosync flag.
 =item $autosync = $h->get_autosync ();
 
 Get the autosync flag.
index 3f3cb4d..6b93b27 100644 (file)
@@ -3002,6 +3002,31 @@ py_guestfs_get_e2uuid (PyObject *self, PyObject *args)
   return py_r;
 }
 
   return py_r;
 }
 
+static PyObject *
+py_guestfs_fsck (PyObject *self, PyObject *args)
+{
+  PyObject *py_g;
+  guestfs_h *g;
+  PyObject *py_r;
+  int r;
+  const char *fstype;
+  const char *device;
+
+  if (!PyArg_ParseTuple (args, (char *) "Oss:guestfs_fsck",
+                         &py_g, &fstype, &device))
+    return NULL;
+  g = get_handle (py_g);
+
+  r = guestfs_fsck (g, fstype, device);
+  if (r == -1) {
+    PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g));
+    return NULL;
+  }
+
+  py_r = PyInt_FromLong ((long) r);
+  return py_r;
+}
+
 static PyMethodDef methods[] = {
   { (char *) "create", py_guestfs_create, METH_VARARGS, NULL },
   { (char *) "close", py_guestfs_close, METH_VARARGS, NULL },
 static PyMethodDef methods[] = {
   { (char *) "create", py_guestfs_create, METH_VARARGS, NULL },
   { (char *) "close", py_guestfs_close, METH_VARARGS, NULL },
@@ -3109,6 +3134,7 @@ static PyMethodDef methods[] = {
   { (char *) "get_e2label", py_guestfs_get_e2label, METH_VARARGS, NULL },
   { (char *) "set_e2uuid", py_guestfs_set_e2uuid, METH_VARARGS, NULL },
   { (char *) "get_e2uuid", py_guestfs_get_e2uuid, METH_VARARGS, NULL },
   { (char *) "get_e2label", py_guestfs_get_e2label, METH_VARARGS, NULL },
   { (char *) "set_e2uuid", py_guestfs_set_e2uuid, METH_VARARGS, NULL },
   { (char *) "get_e2uuid", py_guestfs_get_e2uuid, METH_VARARGS, NULL },
+  { (char *) "fsck", py_guestfs_fsck, METH_VARARGS, NULL },
   { NULL, NULL, 0, NULL }
 };
 
   { NULL, NULL, 0, NULL }
 };
 
index 2fced28..37dce2b 100644 (file)
@@ -1149,3 +1149,17 @@ class GuestFS:
         """
         return libguestfsmod.get_e2uuid (self._o, device)
 
         """
         return libguestfsmod.get_e2uuid (self._o, device)
 
+    def fsck (self, fstype, device):
+        u"""This runs the filesystem checker (fsck) on "device"
+        which should have filesystem type "fstype".
+        
+        The returned integer is the status. See fsck(8) for the
+        list of status codes from "fsck", and note that multiple
+        status codes can be summed together.
+        
+        It is entirely equivalent to running "fsck -a -t fstype
+        device". Note that checking or repairing NTFS volumes is
+        not supported (by linux-ntfs).
+        """
+        return libguestfsmod.fsck (self._o, fstype, device)
+
index e6c4236..56b3f21 100644 (file)
@@ -2515,6 +2515,31 @@ static VALUE ruby_guestfs_get_e2uuid (VALUE gv, VALUE devicev)
   return rv;
 }
 
   return rv;
 }
 
+static VALUE ruby_guestfs_fsck (VALUE gv, VALUE fstypev, VALUE devicev)
+{
+  guestfs_h *g;
+  Data_Get_Struct (gv, guestfs_h, g);
+  if (!g)
+    rb_raise (rb_eArgError, "%s: used handle after closing it", "fsck");
+
+  const char *fstype = StringValueCStr (fstypev);
+  if (!fstype)
+    rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+              "fstype", "fsck");
+  const char *device = StringValueCStr (devicev);
+  if (!device)
+    rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+              "device", "fsck");
+
+  int r;
+
+  r = guestfs_fsck (g, fstype, device);
+  if (r == -1)
+    rb_raise (e_Error, "%s", guestfs_last_error (g));
+
+  return INT2NUM (r);
+}
+
 /* Initialize the module. */
 void Init__guestfs ()
 {
 /* Initialize the module. */
 void Init__guestfs ()
 {
@@ -2733,4 +2758,6 @@ void Init__guestfs ()
         ruby_guestfs_set_e2uuid, 2);
   rb_define_method (c_guestfs, "get_e2uuid",
         ruby_guestfs_get_e2uuid, 1);
         ruby_guestfs_set_e2uuid, 2);
   rb_define_method (c_guestfs, "get_e2uuid",
         ruby_guestfs_get_e2uuid, 1);
+  rb_define_method (c_guestfs, "fsck",
+        ruby_guestfs_fsck, 2);
 }
 }
index f39aa75..a075b80 100644 (file)
@@ -7549,3 +7549,96 @@ char *guestfs_get_e2uuid (guestfs_h *g,
   return ctx.ret.uuid; /* caller will free */
 }
 
   return ctx.ret.uuid; /* caller will free */
 }
 
+struct fsck_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;
+  struct guestfs_fsck_ret ret;
+};
+
+static void fsck_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct fsck_ctx *ctx = (struct fsck_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_fsck");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_fsck");
+    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_fsck");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_fsck_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_fsck");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int guestfs_fsck (guestfs_h *g,
+               const char *fstype,
+               const char *device)
+{
+  struct guestfs_fsck_args args;
+  struct fsck_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_fsck") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.fstype = (char *) fstype;
+  args.device = (char *) device;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_FSCK,
+        (xdrproc_t) xdr_guestfs_fsck_args, (char *) &args);
+  if (serial == -1) {
+    guestfs_set_ready (g);
+    return -1;
+  }
+
+  guestfs__switch_to_receiving (g);
+  ctx.cb_sequence = 0;
+  guestfs_set_reply_callback (g, fsck_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_fsck");
+    guestfs_set_ready (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_FSCK, serial) == -1) {
+    guestfs_set_ready (g);
+    return -1;
+  }
+
+  if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+    error (g, "%s", ctx.err.error_message);
+    guestfs_set_ready (g);
+    return -1;
+  }
+
+  guestfs_set_ready (g);
+  return ctx.ret.status;
+}
+
index c8570b0..6e56099 100644 (file)
@@ -123,3 +123,4 @@ extern int guestfs_set_e2label (guestfs_h *handle, const char *device, const cha
 extern char *guestfs_get_e2label (guestfs_h *handle, const char *device);
 extern int guestfs_set_e2uuid (guestfs_h *handle, const char *device, const char *uuid);
 extern char *guestfs_get_e2uuid (guestfs_h *handle, const char *device);
 extern char *guestfs_get_e2label (guestfs_h *handle, const char *device);
 extern int guestfs_set_e2uuid (guestfs_h *handle, const char *device, const char *uuid);
 extern char *guestfs_get_e2uuid (guestfs_h *handle, const char *device);
+extern int guestfs_fsck (guestfs_h *handle, const char *fstype, const char *device);
index c26d539..16e80f1 100644 (file)
@@ -1428,6 +1428,28 @@ xdr_guestfs_get_e2uuid_ret (XDR *xdrs, guestfs_get_e2uuid_ret *objp)
 }
 
 bool_t
 }
 
 bool_t
+xdr_guestfs_fsck_args (XDR *xdrs, guestfs_fsck_args *objp)
+{
+       register int32_t *buf;
+
+        if (!xdr_string (xdrs, &objp->fstype, ~0))
+                return FALSE;
+        if (!xdr_string (xdrs, &objp->device, ~0))
+                return FALSE;
+       return TRUE;
+}
+
+bool_t
+xdr_guestfs_fsck_ret (XDR *xdrs, guestfs_fsck_ret *objp)
+{
+       register int32_t *buf;
+
+        if (!xdr_int (xdrs, &objp->status))
+                return FALSE;
+       return TRUE;
+}
+
+bool_t
 xdr_guestfs_procedure (XDR *xdrs, guestfs_procedure *objp)
 {
        register int32_t *buf;
 xdr_guestfs_procedure (XDR *xdrs, guestfs_procedure *objp)
 {
        register int32_t *buf;
index 90b0ede..64e4b4d 100644 (file)
@@ -739,6 +739,17 @@ struct guestfs_get_e2uuid_ret {
 };
 typedef struct guestfs_get_e2uuid_ret guestfs_get_e2uuid_ret;
 
 };
 typedef struct guestfs_get_e2uuid_ret guestfs_get_e2uuid_ret;
 
+struct guestfs_fsck_args {
+       char *fstype;
+       char *device;
+};
+typedef struct guestfs_fsck_args guestfs_fsck_args;
+
+struct guestfs_fsck_ret {
+       int status;
+};
+typedef struct guestfs_fsck_ret guestfs_fsck_ret;
+
 enum guestfs_procedure {
        GUESTFS_PROC_MOUNT = 1,
        GUESTFS_PROC_SYNC = 2,
 enum guestfs_procedure {
        GUESTFS_PROC_MOUNT = 1,
        GUESTFS_PROC_SYNC = 2,
@@ -823,7 +834,8 @@ enum guestfs_procedure {
        GUESTFS_PROC_GET_E2LABEL = 81,
        GUESTFS_PROC_SET_E2UUID = 82,
        GUESTFS_PROC_GET_E2UUID = 83,
        GUESTFS_PROC_GET_E2LABEL = 81,
        GUESTFS_PROC_SET_E2UUID = 82,
        GUESTFS_PROC_GET_E2UUID = 83,
-       GUESTFS_PROC_NR_PROCS = 83 + 1,
+       GUESTFS_PROC_FSCK = 84,
+       GUESTFS_PROC_NR_PROCS = 84 + 1,
 };
 typedef enum guestfs_procedure guestfs_procedure;
 #define GUESTFS_MESSAGE_MAX 4194304
 };
 typedef enum guestfs_procedure guestfs_procedure;
 #define GUESTFS_MESSAGE_MAX 4194304
@@ -988,6 +1000,8 @@ extern  bool_t xdr_guestfs_get_e2label_ret (XDR *, guestfs_get_e2label_ret*);
 extern  bool_t xdr_guestfs_set_e2uuid_args (XDR *, guestfs_set_e2uuid_args*);
 extern  bool_t xdr_guestfs_get_e2uuid_args (XDR *, guestfs_get_e2uuid_args*);
 extern  bool_t xdr_guestfs_get_e2uuid_ret (XDR *, guestfs_get_e2uuid_ret*);
 extern  bool_t xdr_guestfs_set_e2uuid_args (XDR *, guestfs_set_e2uuid_args*);
 extern  bool_t xdr_guestfs_get_e2uuid_args (XDR *, guestfs_get_e2uuid_args*);
 extern  bool_t xdr_guestfs_get_e2uuid_ret (XDR *, guestfs_get_e2uuid_ret*);
+extern  bool_t xdr_guestfs_fsck_args (XDR *, guestfs_fsck_args*);
+extern  bool_t xdr_guestfs_fsck_ret (XDR *, guestfs_fsck_ret*);
 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_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*);
@@ -1111,6 +1125,8 @@ extern bool_t xdr_guestfs_get_e2label_ret ();
 extern bool_t xdr_guestfs_set_e2uuid_args ();
 extern bool_t xdr_guestfs_get_e2uuid_args ();
 extern bool_t xdr_guestfs_get_e2uuid_ret ();
 extern bool_t xdr_guestfs_set_e2uuid_args ();
 extern bool_t xdr_guestfs_get_e2uuid_args ();
 extern bool_t xdr_guestfs_get_e2uuid_ret ();
+extern bool_t xdr_guestfs_fsck_args ();
+extern bool_t xdr_guestfs_fsck_ret ();
 extern bool_t xdr_guestfs_procedure ();
 extern bool_t xdr_guestfs_message_direction ();
 extern bool_t xdr_guestfs_message_status ();
 extern bool_t xdr_guestfs_procedure ();
 extern bool_t xdr_guestfs_message_direction ();
 extern bool_t xdr_guestfs_message_status ();
index 0cfb8ee..92dc8ea 100644 (file)
@@ -573,6 +573,15 @@ struct guestfs_get_e2uuid_ret {
   string uuid<>;
 };
 
   string uuid<>;
 };
 
+struct guestfs_fsck_args {
+  string fstype<>;
+  string device<>;
+};
+
+struct guestfs_fsck_ret {
+  int status;
+};
+
 enum guestfs_procedure {
   GUESTFS_PROC_MOUNT = 1,
   GUESTFS_PROC_SYNC = 2,
 enum guestfs_procedure {
   GUESTFS_PROC_MOUNT = 1,
   GUESTFS_PROC_SYNC = 2,
@@ -657,6 +666,7 @@ enum guestfs_procedure {
   GUESTFS_PROC_GET_E2LABEL = 81,
   GUESTFS_PROC_SET_E2UUID = 82,
   GUESTFS_PROC_GET_E2UUID = 83,
   GUESTFS_PROC_GET_E2LABEL = 81,
   GUESTFS_PROC_SET_E2UUID = 82,
   GUESTFS_PROC_GET_E2UUID = 83,
+  GUESTFS_PROC_FSCK = 84,
   GUESTFS_PROC_NR_PROCS
 };
 
   GUESTFS_PROC_NR_PROCS
 };
 
diff --git a/tests.c b/tests.c
index 9a45cce..dddb971 100644 (file)
--- a/tests.c
+++ b/tests.c
@@ -112,6 +112,59 @@ static void no_test_warnings (void)
   fprintf (stderr, "warning: \"guestfs_get_e2uuid\" has no tests\n");
 }
 
   fprintf (stderr, "warning: \"guestfs_get_e2uuid\" has no tests\n");
 }
 
+static int test_fsck_0 (void)
+{
+  /* InitBasicFS for fsck (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;
+  }
+  /* TestRun for fsck (0) */
+  {
+    int r;
+    suppress_error = 0;
+    r = guestfs_fsck (g, "ext2", "/dev/sda1");
+    if (r == -1)
+      return -1;
+  }
+  return 0;
+}
+
 static int test_set_e2uuid_0 (void)
 {
   /* InitBasicFS for set_e2uuid (0): create ext2 on /dev/sda1 */
 static int test_set_e2uuid_0 (void)
 {
   /* InitBasicFS for set_e2uuid (0): create ext2 on /dev/sda1 */
@@ -6513,9 +6566,15 @@ int main (int argc, char *argv[])
     exit (1);
   }
 
     exit (1);
   }
 
-  nr_tests = 91;
+  nr_tests = 92;
 
   test_num++;
 
   test_num++;
+  printf ("%3d/%3d test_fsck_0\n", test_num, nr_tests);
+  if (test_fsck_0 () == -1) {
+    printf ("test_fsck_0 FAILED\n");
+    failed++;
+  }
+  test_num++;
   printf ("%3d/%3d test_set_e2uuid_0\n", test_num, nr_tests);
   if (test_set_e2uuid_0 () == -1) {
     printf ("test_set_e2uuid_0 FAILED\n");
   printf ("%3d/%3d test_set_e2uuid_0\n", test_num, nr_tests);
   if (test_set_e2uuid_0 () == -1) {
     printf ("test_set_e2uuid_0 FAILED\n");