Generated code for 'du' command.
authorRichard W.M. Jones <rjones@redhat.com>
Mon, 29 Jun 2009 11:47:20 +0000 (12:47 +0100)
committerRichard W.M. Jones <rjones@redhat.com>
Mon, 29 Jun 2009 11:47:20 +0000 (12:47 +0100)
24 files changed:
capitests/tests.c
daemon/actions.h
daemon/stubs.c
fish/cmds.c
fish/completion.c
guestfish-actions.pod
guestfs-actions.pod
haskell/Guestfs.hs
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/MAX_PROC_NR
src/guestfs-actions.c
src/guestfs-actions.h
src/guestfs_protocol.c
src/guestfs_protocol.h
src/guestfs_protocol.x

index 08f64ee..6e31c40 100644 (file)
@@ -155,6 +155,105 @@ static void no_test_warnings (void)
   fprintf (stderr, "warning: \"guestfs_df_h\" has no tests\n");
 }
 
   fprintf (stderr, "warning: \"guestfs_df_h\" has no tests\n");
 }
 
+static int test_du_0_skip (void)
+{
+  const char *str;
+
+  str = getenv ("TEST_ONLY");
+  if (str)
+    return strstr (str, "du") == NULL;
+  str = getenv ("SKIP_TEST_DU_0");
+  if (str && strcmp (str, "1") == 0) return 1;
+  str = getenv ("SKIP_TEST_DU");
+  if (str && strcmp (str, "1") == 0) return 1;
+  return 0;
+}
+
+static int test_du_0 (void)
+{
+  if (test_du_0_skip ()) {
+    printf ("%s skipped (reason: environment variable set)\n", "test_du_0");
+    return 0;
+  }
+
+  /* InitBasicFS for test_du_0: create ext2 on /dev/sda1 */
+  {
+    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;
+  }
+  {
+    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 fstype[] = "ext2";
+    char device[] = "/dev/sda1";
+    int r;
+    suppress_error = 0;
+    r = guestfs_mkfs (g, fstype, device);
+    if (r == -1)
+      return -1;
+  }
+  {
+    char device[] = "/dev/sda1";
+    char mountpoint[] = "/";
+    int r;
+    suppress_error = 0;
+    r = guestfs_mount (g, device, mountpoint);
+    if (r == -1)
+      return -1;
+  }
+  /* TestOutputInt for du (0) */
+  {
+    char path[] = "/p";
+    int r;
+    suppress_error = 0;
+    r = guestfs_mkdir (g, path);
+    if (r == -1)
+      return -1;
+  }
+  {
+    char path[] = "/p";
+    int64_t r;
+    suppress_error = 0;
+    r = guestfs_du (g, path);
+    if (r == -1)
+      return -1;
+    if (r != 1) {
+      fprintf (stderr, "test_du_0: expected 1 but got %d\n",               (int) r);
+      return -1;
+    }
+  }
+  return 0;
+}
+
 static int test_tail_n_0_skip (void)
 {
   const char *str;
 static int test_tail_n_0_skip (void)
 {
   const char *str;
@@ -18509,9 +18608,15 @@ int main (int argc, char *argv[])
   /* Cancel previous alarm. */
   alarm (0);
 
   /* Cancel previous alarm. */
   alarm (0);
 
-  nr_tests = 164;
+  nr_tests = 165;
 
   test_num++;
 
   test_num++;
+  printf ("%3d/%3d test_du_0\n", test_num, nr_tests);
+  if (test_du_0 () == -1) {
+    printf ("test_du_0 FAILED\n");
+    failed++;
+  }
+  test_num++;
   printf ("%3d/%3d test_tail_n_0\n", test_num, nr_tests);
   if (test_tail_n_0 () == -1) {
     printf ("test_tail_n_0 FAILED\n");
   printf ("%3d/%3d test_tail_n_0\n", test_num, nr_tests);
   if (test_tail_n_0 () == -1) {
     printf ("test_tail_n_0 FAILED\n");
index 8f38163..7d87b67 100644 (file)
@@ -147,3 +147,4 @@ extern char **do_tail (char *path);
 extern char **do_tail_n (int nrlines, char *path);
 extern char *do_df (void);
 extern char *do_df_h (void);
 extern char **do_tail_n (int nrlines, char *path);
 extern char *do_df (void);
 extern char *do_df_h (void);
+extern int64_t do_du (char *path);
index 0c311a9..67e6ef5 100644 (file)
@@ -3179,6 +3179,32 @@ static void df_h_stub (XDR *xdr_in)
 done: ;
 }
 
 done: ;
 }
 
+static void du_stub (XDR *xdr_in)
+{
+  int64_t r;
+  struct guestfs_du_args args;
+  char *path;
+
+  memset (&args, 0, sizeof args);
+
+  if (!xdr_guestfs_du_args (xdr_in, &args)) {
+    reply_with_error ("%s: daemon failed to decode procedure arguments", "du");
+    return;
+  }
+  path = args.path;
+
+  r = do_du (path);
+  if (r == -1)
+    /* do_du has already called reply_with_error */
+    goto done;
+
+  struct guestfs_du_ret ret;
+  ret.sizekb = r;
+  reply ((xdrproc_t) &xdr_guestfs_du_ret, (char *) &ret);
+done:
+  xdr_free ((xdrproc_t) xdr_guestfs_du_args, (char *) &args);
+}
+
 void dispatch_incoming_message (XDR *xdr_in)
 {
   switch (proc_nr) {
 void dispatch_incoming_message (XDR *xdr_in)
 {
   switch (proc_nr) {
@@ -3560,6 +3586,9 @@ void dispatch_incoming_message (XDR *xdr_in)
     case GUESTFS_PROC_DF_H:
       df_h_stub (xdr_in);
       break;
     case GUESTFS_PROC_DF_H:
       df_h_stub (xdr_in);
       break;
+    case GUESTFS_PROC_DU:
+      du_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);
   }
     default:
       reply_with_error ("dispatch_incoming_message: unknown procedure number %d, set LIBGUESTFS_PATH to point to the matching libguestfs appliance directory", proc_nr);
   }
index 6067eed..c802f90 100644 (file)
@@ -72,6 +72,7 @@ void list_commands (void)
   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", "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", "du", "estimate file space usage");
   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", "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");
@@ -624,6 +625,9 @@ void display_command (const char *cmd)
   if (strcasecmp (cmd, "df_h") == 0 || strcasecmp (cmd, "df-h") == 0)
     pod2text ("df-h - report file system disk space usage (human readable)", " df-h\n\nThis command runs the C<df -h> command to report disk space used\nin human-readable format.\n\nThis command is mostly useful for interactive sessions.  It\nis I<not> intended that you try to parse the output string.\nUse C<statvfs> from programs.");
   else
   if (strcasecmp (cmd, "df_h") == 0 || strcasecmp (cmd, "df-h") == 0)
     pod2text ("df-h - report file system disk space usage (human readable)", " df-h\n\nThis command runs the C<df -h> command to report disk space used\nin human-readable format.\n\nThis command is mostly useful for interactive sessions.  It\nis I<not> intended that you try to parse the output string.\nUse C<statvfs> from programs.");
   else
+  if (strcasecmp (cmd, "du") == 0)
+    pod2text ("du - estimate file space usage", " du <path>\n\nThis command runs the C<du -s> command to estimate file space\nusage for C<path>.\n\nC<path> can be a file or a directory.  If C<path> is a directory\nthen the estimate includes the contents of the directory and all\nsubdirectories (recursively).\n\nThe result is the estimated size in I<kilobytes>\n(ie. units of 1024 bytes).");
+  else
     display_builtin_command (cmd);
 }
 
     display_builtin_command (cmd);
 }
 
@@ -3062,6 +3066,22 @@ static int run_df_h (const char *cmd, int argc, char *argv[])
   return 0;
 }
 
   return 0;
 }
 
+static int run_du (const char *cmd, int argc, char *argv[])
+{
+  int64_t r;
+  const char *path;
+  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;
+  }
+  path = argv[0];
+  r = guestfs_du (g, path);
+  if (r == -1) return -1;
+  printf ("%" PRIi64 "\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)
@@ -3505,6 +3525,9 @@ int run_action (const char *cmd, int argc, char *argv[])
   if (strcasecmp (cmd, "df_h") == 0 || strcasecmp (cmd, "df-h") == 0)
     return run_df_h (cmd, argc, argv);
   else
   if (strcasecmp (cmd, "df_h") == 0 || strcasecmp (cmd, "df-h") == 0)
     return run_df_h (cmd, argc, argv);
   else
+  if (strcasecmp (cmd, "du") == 0)
+    return run_du (cmd, argc, argv);
+  else
     {
       fprintf (stderr, "%s: unknown command\n", cmd);
       return -1;
     {
       fprintf (stderr, "%s: unknown command\n", cmd);
       return -1;
index 6b58bd2..5254a37 100644 (file)
@@ -193,6 +193,7 @@ static const char *const commands[] = {
   "tail-n",
   "df",
   "df-h",
   "tail-n",
   "df",
   "df-h",
+  "du",
   NULL
 };
 
   NULL
 };
 
index e22aad1..9f625c7 100644 (file)
@@ -540,6 +540,20 @@ Setting C<whattodrop> to 3 should drop everything.
 This automatically calls L<sync(2)> before the operation,
 so that the maximum guest memory is freed.
 
 This automatically calls L<sync(2)> before the operation,
 so that the maximum guest memory is freed.
 
+=head2 du
+
+ du path
+
+This command runs the C<du -s> command to estimate file space
+usage for C<path>.
+
+C<path> can be a file or a directory.  If C<path> is a directory
+then the estimate includes the contents of the directory and all
+subdirectories (recursively).
+
+The result is the estimated size in I<kilobytes>
+(ie. units of 1024 bytes).
+
 =head2 e2fsck-f
 
  e2fsck-f device
 =head2 e2fsck-f
 
  e2fsck-f device
index a48bbe6..039608d 100644 (file)
@@ -689,6 +689,23 @@ so that the maximum guest memory is freed.
 
 This function returns 0 on success or -1 on error.
 
 
 This function returns 0 on success or -1 on error.
 
+=head2 guestfs_du
+
+ int64_t guestfs_du (guestfs_h *handle,
+               const char *path);
+
+This command runs the C<du -s> command to estimate file space
+usage for C<path>.
+
+C<path> can be a file or a directory.  If C<path> is a directory
+then the estimate includes the contents of the directory and all
+subdirectories (recursively).
+
+The result is the estimated size in I<kilobytes>
+(ie. units of 1024 bytes).
+
+On error this function returns -1.
+
 =head2 guestfs_e2fsck_f
 
  int guestfs_e2fsck_f (guestfs_h *handle,
 =head2 guestfs_e2fsck_f
 
  int guestfs_e2fsck_f (guestfs_h *handle,
index dfa385a..9eefda1 100644 (file)
@@ -119,7 +119,8 @@ module Guestfs (
   scrub_freespace,
   wc_l,
   wc_w,
   scrub_freespace,
   wc_l,
   wc_w,
-  wc_c
+  wc_c,
+  du
   ) where
 import Foreign
 import Foreign.C
   ) where
 import Foreign
 import Foreign.C
@@ -1322,3 +1323,15 @@ wc_c h path = do
       fail err
     else return (fromIntegral r)
 
       fail err
     else return (fromIntegral r)
 
+foreign import ccall unsafe "guestfs_du" c_du
+  :: GuestfsP -> CString -> IO (Int64)
+
+du :: GuestfsH -> String -> IO (Integer)
+du h path = do
+  r <- withCString path $ \path -> withForeignPtr h (\p -> c_du p path)
+  if (r == -1)
+    then do
+      err <- last_error h
+      fail err
+    else return (fromIntegral r)
+
index 1d65581..6adeb21 100644 (file)
@@ -3769,4 +3769,29 @@ public HashMap<String,String> test0rhashtableerr ()
   private native String _df_h (long g)
     throws LibGuestFSException;
 
   private native String _df_h (long g)
     throws LibGuestFSException;
 
+  /**
+   * estimate file space usage
+   * <p>
+   * This command runs the "du -s" command to estimate file
+   * space usage for "path".
+   * <p>
+   * "path" can be a file or a directory. If "path" is a
+   * directory then the estimate includes the contents of the
+   * directory and all subdirectories (recursively).
+   * <p>
+   * The result is the estimated size in *kilobytes* (ie.
+   * units of 1024 bytes).
+   * <p>
+   * @throws LibGuestFSException
+   */
+  public long du (String path)
+    throws LibGuestFSException
+  {
+    if (g == 0)
+      throw new LibGuestFSException ("du: handle is closed");
+    return _du (g, path);
+  }
+  private native long _du (long g, String path)
+    throws LibGuestFSException;
+
 }
 }
index 206f2dc..3b91b40 100644 (file)
@@ -4371,3 +4371,21 @@ Java_com_redhat_et_libguestfs_GuestFS__1df_1h
   return jr;
 }
 
   return jr;
 }
 
+JNIEXPORT jlong JNICALL
+Java_com_redhat_et_libguestfs_GuestFS__1du
+  (JNIEnv *env, jobject obj, jlong jg, jstring jpath)
+{
+  guestfs_h *g = (guestfs_h *) (long) jg;
+  int64_t r;
+  const char *path;
+
+  path = (*env)->GetStringUTFChars (env, jpath, NULL);
+  r = guestfs_du (g, path);
+  (*env)->ReleaseStringUTFChars (env, jpath, path);
+  if (r == -1) {
+    throw_exception (env, guestfs_last_error (g));
+    return 0;
+  }
+  return (jlong) r;
+}
+
index 52bd54c..90f3ca8 100644 (file)
@@ -293,3 +293,4 @@ external tail : t -> string -> string array = "ocaml_guestfs_tail"
 external tail_n : t -> int -> string -> string array = "ocaml_guestfs_tail_n"
 external df : t -> string = "ocaml_guestfs_df"
 external df_h : t -> string = "ocaml_guestfs_df_h"
 external tail_n : t -> int -> string -> string array = "ocaml_guestfs_tail_n"
 external df : t -> string = "ocaml_guestfs_df"
 external df_h : t -> string = "ocaml_guestfs_df_h"
+external du : t -> string -> int64 = "ocaml_guestfs_du"
index 390b6b9..39df504 100644 (file)
@@ -658,3 +658,6 @@ val df : t -> string
 val df_h : t -> string
 (** report file system disk space usage (human readable) *)
 
 val df_h : t -> string
 (** report file system disk space usage (human readable) *)
 
+val du : t -> string -> int64
+(** estimate file space usage *)
+
index 04be818..a5e1894 100644 (file)
@@ -4588,3 +4588,26 @@ ocaml_guestfs_df_h (value gv)
   CAMLreturn (rv);
 }
 
   CAMLreturn (rv);
 }
 
+CAMLprim value
+ocaml_guestfs_du (value gv, value pathv)
+{
+  CAMLparam2 (gv, pathv);
+  CAMLlocal1 (rv);
+
+  guestfs_h *g = Guestfs_val (gv);
+  if (g == NULL)
+    caml_failwith ("du: used handle after closing it");
+
+  const char *path = String_val (pathv);
+  int64_t r;
+
+  caml_enter_blocking_section ();
+  r = guestfs_du (g, path);
+  caml_leave_blocking_section ();
+  if (r == -1)
+    ocaml_guestfs_raise_error (g, "du");
+
+  rv = caml_copy_int64 (r);
+  CAMLreturn (rv);
+}
+
index 6980bda..d6ef053 100644 (file)
@@ -2798,3 +2798,17 @@ PREINIT:
  OUTPUT:
       RETVAL
 
  OUTPUT:
       RETVAL
 
+SV *
+du (g, path)
+      guestfs_h *g;
+      char *path;
+PREINIT:
+      int64_t sizekb;
+   CODE:
+      sizekb = guestfs_du (g, path);
+      if (sizekb == -1)
+        croak ("du: %s", guestfs_last_error (g));
+      RETVAL = my_newSVll (sizekb);
+ OUTPUT:
+      RETVAL
+
index 69ffe8b..655624a 100644 (file)
@@ -549,6 +549,18 @@ Setting C<whattodrop> to 3 should drop everything.
 This automatically calls L<sync(2)> before the operation,
 so that the maximum guest memory is freed.
 
 This automatically calls L<sync(2)> before the operation,
 so that the maximum guest memory is freed.
 
+=item $sizekb = $h->du ($path);
+
+This command runs the C<du -s> command to estimate file space
+usage for C<path>.
+
+C<path> can be a file or a directory.  If C<path> is a directory
+then the estimate includes the contents of the directory and all
+subdirectories (recursively).
+
+The result is the estimated size in I<kilobytes>
+(ie. units of 1024 bytes).
+
 =item $h->e2fsck_f ($device);
 
 This runs C<e2fsck -p -f device>, ie. runs the ext2/ext3
 =item $h->e2fsck_f ($device);
 
 This runs C<e2fsck -p -f device>, ie. runs the ext2/ext3
index 59a891f..ac1283b 100644 (file)
@@ -4853,6 +4853,30 @@ py_guestfs_df_h (PyObject *self, PyObject *args)
   return py_r;
 }
 
   return py_r;
 }
 
+static PyObject *
+py_guestfs_du (PyObject *self, PyObject *args)
+{
+  PyObject *py_g;
+  guestfs_h *g;
+  PyObject *py_r;
+  int64_t r;
+  const char *path;
+
+  if (!PyArg_ParseTuple (args, (char *) "Os:guestfs_du",
+                         &py_g, &path))
+    return NULL;
+  g = get_handle (py_g);
+
+  r = guestfs_du (g, path);
+  if (r == -1) {
+    PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g));
+    return NULL;
+  }
+
+  py_r = PyLong_FromLongLong (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 },
@@ -5034,6 +5058,7 @@ static PyMethodDef methods[] = {
   { (char *) "tail_n", py_guestfs_tail_n, METH_VARARGS, NULL },
   { (char *) "df", py_guestfs_df, METH_VARARGS, NULL },
   { (char *) "df_h", py_guestfs_df_h, METH_VARARGS, NULL },
   { (char *) "tail_n", py_guestfs_tail_n, METH_VARARGS, NULL },
   { (char *) "df", py_guestfs_df, METH_VARARGS, NULL },
   { (char *) "df_h", py_guestfs_df_h, METH_VARARGS, NULL },
+  { (char *) "du", py_guestfs_du, METH_VARARGS, NULL },
   { NULL, NULL, 0, NULL }
 };
 
   { NULL, NULL, 0, NULL }
 };
 
index d838aae..e62a527 100644 (file)
@@ -1827,3 +1827,16 @@ class GuestFS:
         """
         return libguestfsmod.df_h (self._o)
 
         """
         return libguestfsmod.df_h (self._o)
 
+    def du (self, path):
+        u"""This command runs the "du -s" command to estimate file
+        space usage for "path".
+        
+        "path" can be a file or a directory. If "path" is a
+        directory then the estimate includes the contents of the
+        directory and all subdirectories (recursively).
+        
+        The result is the estimated size in *kilobytes* (ie.
+        units of 1024 bytes).
+        """
+        return libguestfsmod.du (self._o, path)
+
index 336a3a4..679c5b0 100644 (file)
@@ -4559,6 +4559,28 @@ static VALUE ruby_guestfs_df_h (VALUE gv)
   return rv;
 }
 
   return rv;
 }
 
+static VALUE ruby_guestfs_du (VALUE gv, VALUE pathv)
+{
+  guestfs_h *g;
+  Data_Get_Struct (gv, guestfs_h, g);
+  if (!g)
+    rb_raise (rb_eArgError, "%s: used handle after closing it", "du");
+
+  Check_Type (pathv, T_STRING);
+  const char *path = StringValueCStr (pathv);
+  if (!path)
+    rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+              "path", "du");
+
+  int64_t r;
+
+  r = guestfs_du (g, path);
+  if (r == -1)
+    rb_raise (e_Error, "%s", guestfs_last_error (g));
+
+  return ULL2NUM (r);
+}
+
 /* Initialize the module. */
 void Init__guestfs ()
 {
 /* Initialize the module. */
 void Init__guestfs ()
 {
@@ -4925,4 +4947,6 @@ void Init__guestfs ()
         ruby_guestfs_df, 0);
   rb_define_method (c_guestfs, "df_h",
         ruby_guestfs_df_h, 0);
         ruby_guestfs_df, 0);
   rb_define_method (c_guestfs, "df_h",
         ruby_guestfs_df_h, 0);
+  rb_define_method (c_guestfs, "du",
+        ruby_guestfs_du, 1);
 }
 }
index 0a3e7b0..c75acbe 100644 (file)
@@ -1 +1 @@
-126
+127
index 745a52b..b34c801 100644 (file)
@@ -11557,3 +11557,95 @@ char *guestfs_df_h (guestfs_h *g)
   return ctx.ret.output; /* caller will free */
 }
 
   return ctx.ret.output; /* caller will free */
 }
 
+struct du_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_du_ret ret;
+};
+
+static void du_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  struct du_ctx *ctx = (struct du_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_du");
+    return;
+  }
+
+  ml->main_loop_quit (ml, g);
+
+  if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+    error (g, "%s: failed to parse reply header", "guestfs_du");
+    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_du");
+      return;
+    }
+    goto done;
+  }
+  if (!xdr_guestfs_du_ret (xdr, &ctx->ret)) {
+    error (g, "%s: failed to parse reply", "guestfs_du");
+    return;
+  }
+ done:
+  ctx->cb_sequence = 1;
+}
+
+int64_t guestfs_du (guestfs_h *g,
+               const char *path)
+{
+  struct guestfs_du_args args;
+  struct du_ctx ctx;
+  guestfs_main_loop *ml = guestfs_get_main_loop (g);
+  int serial;
+
+  if (check_state (g, "guestfs_du") == -1) return -1;
+  guestfs_set_busy (g);
+
+  memset (&ctx, 0, sizeof ctx);
+
+  args.path = (char *) path;
+  serial = guestfs__send_sync (g, GUESTFS_PROC_DU,
+        (xdrproc_t) xdr_guestfs_du_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, du_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_du");
+    guestfs_end_busy (g);
+    return -1;
+  }
+
+  if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_DU, 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 ctx.ret.sizekb;
+}
+
index cbf5ff7..3c98332 100644 (file)
@@ -197,3 +197,4 @@ extern char **guestfs_tail (guestfs_h *handle, const char *path);
 extern char **guestfs_tail_n (guestfs_h *handle, int nrlines, const char *path);
 extern char *guestfs_df (guestfs_h *handle);
 extern char *guestfs_df_h (guestfs_h *handle);
 extern char **guestfs_tail_n (guestfs_h *handle, int nrlines, const char *path);
 extern char *guestfs_df (guestfs_h *handle);
 extern char *guestfs_df_h (guestfs_h *handle);
+extern int64_t guestfs_du (guestfs_h *handle, const char *path);
index 2830bf2..050d928 100644 (file)
@@ -2151,6 +2151,26 @@ xdr_guestfs_df_h_ret (XDR *xdrs, guestfs_df_h_ret *objp)
 }
 
 bool_t
 }
 
 bool_t
+xdr_guestfs_du_args (XDR *xdrs, guestfs_du_args *objp)
+{
+       register int32_t *buf;
+
+        if (!xdr_string (xdrs, &objp->path, ~0))
+                return FALSE;
+       return TRUE;
+}
+
+bool_t
+xdr_guestfs_du_ret (XDR *xdrs, guestfs_du_ret *objp)
+{
+       register int32_t *buf;
+
+        if (!xdr_quad_t (xdrs, &objp->sizekb))
+                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 16db25a..c8231a0 100644 (file)
@@ -1101,6 +1101,16 @@ struct guestfs_df_h_ret {
 };
 typedef struct guestfs_df_h_ret guestfs_df_h_ret;
 
 };
 typedef struct guestfs_df_h_ret guestfs_df_h_ret;
 
+struct guestfs_du_args {
+       char *path;
+};
+typedef struct guestfs_du_args guestfs_du_args;
+
+struct guestfs_du_ret {
+       quad_t sizekb;
+};
+typedef struct guestfs_du_ret guestfs_du_ret;
+
 enum guestfs_procedure {
        GUESTFS_PROC_MOUNT = 1,
        GUESTFS_PROC_SYNC = 2,
 enum guestfs_procedure {
        GUESTFS_PROC_MOUNT = 1,
        GUESTFS_PROC_SYNC = 2,
@@ -1228,7 +1238,8 @@ enum guestfs_procedure {
        GUESTFS_PROC_TAIL_N = 124,
        GUESTFS_PROC_DF = 125,
        GUESTFS_PROC_DF_H = 126,
        GUESTFS_PROC_TAIL_N = 124,
        GUESTFS_PROC_DF = 125,
        GUESTFS_PROC_DF_H = 126,
-       GUESTFS_PROC_NR_PROCS = 126 + 1,
+       GUESTFS_PROC_DU = 127,
+       GUESTFS_PROC_NR_PROCS = 127 + 1,
 };
 typedef enum guestfs_procedure guestfs_procedure;
 #define GUESTFS_MESSAGE_MAX 4194304
 };
 typedef enum guestfs_procedure guestfs_procedure;
 #define GUESTFS_MESSAGE_MAX 4194304
@@ -1456,6 +1467,8 @@ extern  bool_t xdr_guestfs_tail_n_args (XDR *, guestfs_tail_n_args*);
 extern  bool_t xdr_guestfs_tail_n_ret (XDR *, guestfs_tail_n_ret*);
 extern  bool_t xdr_guestfs_df_ret (XDR *, guestfs_df_ret*);
 extern  bool_t xdr_guestfs_df_h_ret (XDR *, guestfs_df_h_ret*);
 extern  bool_t xdr_guestfs_tail_n_ret (XDR *, guestfs_tail_n_ret*);
 extern  bool_t xdr_guestfs_df_ret (XDR *, guestfs_df_ret*);
 extern  bool_t xdr_guestfs_df_h_ret (XDR *, guestfs_df_h_ret*);
+extern  bool_t xdr_guestfs_du_args (XDR *, guestfs_du_args*);
+extern  bool_t xdr_guestfs_du_ret (XDR *, guestfs_du_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*);
@@ -1642,6 +1655,8 @@ extern bool_t xdr_guestfs_tail_n_args ();
 extern bool_t xdr_guestfs_tail_n_ret ();
 extern bool_t xdr_guestfs_df_ret ();
 extern bool_t xdr_guestfs_df_h_ret ();
 extern bool_t xdr_guestfs_tail_n_ret ();
 extern bool_t xdr_guestfs_df_ret ();
 extern bool_t xdr_guestfs_df_h_ret ();
+extern bool_t xdr_guestfs_du_args ();
+extern bool_t xdr_guestfs_du_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 702df5b..a895b6d 100644 (file)
@@ -842,6 +842,14 @@ struct guestfs_df_h_ret {
   string output<>;
 };
 
   string output<>;
 };
 
+struct guestfs_du_args {
+  string path<>;
+};
+
+struct guestfs_du_ret {
+  hyper sizekb;
+};
+
 enum guestfs_procedure {
   GUESTFS_PROC_MOUNT = 1,
   GUESTFS_PROC_SYNC = 2,
 enum guestfs_procedure {
   GUESTFS_PROC_MOUNT = 1,
   GUESTFS_PROC_SYNC = 2,
@@ -969,6 +977,7 @@ enum guestfs_procedure {
   GUESTFS_PROC_TAIL_N = 124,
   GUESTFS_PROC_DF = 125,
   GUESTFS_PROC_DF_H = 126,
   GUESTFS_PROC_TAIL_N = 124,
   GUESTFS_PROC_DF = 125,
   GUESTFS_PROC_DF_H = 126,
+  GUESTFS_PROC_DU = 127,
   GUESTFS_PROC_NR_PROCS
 };
 
   GUESTFS_PROC_NR_PROCS
 };