summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2009-06-29 12:47:20 +0100
committerRichard W.M. Jones <rjones@redhat.com>2009-06-29 12:47:20 +0100
commite492608f2f3809a824cb70ee03ff305964b69dd7 (patch)
tree953ec56c34431549dab177eec9e0fe979606e5eb
parent9a92446bcad09b492dee42dd5950bac67073fbea (diff)
downloadlibguestfs-e492608f2f3809a824cb70ee03ff305964b69dd7.tar.gz
libguestfs-e492608f2f3809a824cb70ee03ff305964b69dd7.tar.xz
libguestfs-e492608f2f3809a824cb70ee03ff305964b69dd7.zip
Generated code for 'du' command.
-rw-r--r--capitests/tests.c107
-rw-r--r--daemon/actions.h1
-rw-r--r--daemon/stubs.c29
-rw-r--r--fish/cmds.c23
-rw-r--r--fish/completion.c1
-rw-r--r--guestfish-actions.pod14
-rw-r--r--guestfs-actions.pod17
-rw-r--r--haskell/Guestfs.hs15
-rw-r--r--java/com/redhat/et/libguestfs/GuestFS.java25
-rw-r--r--java/com_redhat_et_libguestfs_GuestFS.c18
-rw-r--r--ocaml/guestfs.ml1
-rw-r--r--ocaml/guestfs.mli3
-rw-r--r--ocaml/guestfs_c_actions.c23
-rw-r--r--perl/Guestfs.xs14
-rw-r--r--perl/lib/Sys/Guestfs.pm12
-rw-r--r--python/guestfs-py.c25
-rw-r--r--python/guestfs.py13
-rw-r--r--ruby/ext/guestfs/_guestfs.c24
-rw-r--r--src/MAX_PROC_NR2
-rw-r--r--src/guestfs-actions.c92
-rw-r--r--src/guestfs-actions.h1
-rw-r--r--src/guestfs_protocol.c20
-rw-r--r--src/guestfs_protocol.h17
-rw-r--r--src/guestfs_protocol.x9
24 files changed, 502 insertions, 4 deletions
diff --git a/capitests/tests.c b/capitests/tests.c
index 08f64ee1..6e31c401 100644
--- a/capitests/tests.c
+++ b/capitests/tests.c
@@ -155,6 +155,105 @@ static void no_test_warnings (void)
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;
@@ -18509,9 +18608,15 @@ int main (int argc, char *argv[])
/* Cancel previous alarm. */
alarm (0);
- nr_tests = 164;
+ nr_tests = 165;
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");
diff --git a/daemon/actions.h b/daemon/actions.h
index 8f381634..7d87b677 100644
--- a/daemon/actions.h
+++ b/daemon/actions.h
@@ -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 int64_t do_du (char *path);
diff --git a/daemon/stubs.c b/daemon/stubs.c
index 0c311a9d..67e6ef5b 100644
--- a/daemon/stubs.c
+++ b/daemon/stubs.c
@@ -3179,6 +3179,32 @@ static void df_h_stub (XDR *xdr_in)
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) {
@@ -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_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);
}
diff --git a/fish/cmds.c b/fish/cmds.c
index 6067eed9..c802f90b 100644
--- a/fish/cmds.c
+++ b/fish/cmds.c
@@ -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", "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");
@@ -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, "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);
}
@@ -3062,6 +3066,22 @@ static int run_df_h (const char *cmd, int argc, char *argv[])
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)
@@ -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, "du") == 0)
+ return run_du (cmd, argc, argv);
+ else
{
fprintf (stderr, "%s: unknown command\n", cmd);
return -1;
diff --git a/fish/completion.c b/fish/completion.c
index 6b58bd2c..5254a373 100644
--- a/fish/completion.c
+++ b/fish/completion.c
@@ -193,6 +193,7 @@ static const char *const commands[] = {
"tail-n",
"df",
"df-h",
+ "du",
NULL
};
diff --git a/guestfish-actions.pod b/guestfish-actions.pod
index e22aad12..9f625c71 100644
--- a/guestfish-actions.pod
+++ b/guestfish-actions.pod
@@ -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.
+=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
diff --git a/guestfs-actions.pod b/guestfs-actions.pod
index a48bbe68..039608d5 100644
--- a/guestfs-actions.pod
+++ b/guestfs-actions.pod
@@ -689,6 +689,23 @@ so that the maximum guest memory is freed.
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,
diff --git a/haskell/Guestfs.hs b/haskell/Guestfs.hs
index dfa385ac..9eefda11 100644
--- a/haskell/Guestfs.hs
+++ b/haskell/Guestfs.hs
@@ -119,7 +119,8 @@ module Guestfs (
scrub_freespace,
wc_l,
wc_w,
- wc_c
+ wc_c,
+ du
) where
import Foreign
import Foreign.C
@@ -1322,3 +1323,15 @@ wc_c h path = do
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)
+
diff --git a/java/com/redhat/et/libguestfs/GuestFS.java b/java/com/redhat/et/libguestfs/GuestFS.java
index 1d65581a..6adeb211 100644
--- a/java/com/redhat/et/libguestfs/GuestFS.java
+++ b/java/com/redhat/et/libguestfs/GuestFS.java
@@ -3769,4 +3769,29 @@ public HashMap<String,String> test0rhashtableerr ()
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;
+
}
diff --git a/java/com_redhat_et_libguestfs_GuestFS.c b/java/com_redhat_et_libguestfs_GuestFS.c
index 206f2dc3..3b91b40c 100644
--- a/java/com_redhat_et_libguestfs_GuestFS.c
+++ b/java/com_redhat_et_libguestfs_GuestFS.c
@@ -4371,3 +4371,21 @@ Java_com_redhat_et_libguestfs_GuestFS__1df_1h
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;
+}
+
diff --git a/ocaml/guestfs.ml b/ocaml/guestfs.ml
index 52bd54c2..90f3ca8d 100644
--- a/ocaml/guestfs.ml
+++ b/ocaml/guestfs.ml
@@ -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 du : t -> string -> int64 = "ocaml_guestfs_du"
diff --git a/ocaml/guestfs.mli b/ocaml/guestfs.mli
index 390b6b9c..39df5045 100644
--- a/ocaml/guestfs.mli
+++ b/ocaml/guestfs.mli
@@ -658,3 +658,6 @@ val df : t -> string
val df_h : t -> string
(** report file system disk space usage (human readable) *)
+val du : t -> string -> int64
+(** estimate file space usage *)
+
diff --git a/ocaml/guestfs_c_actions.c b/ocaml/guestfs_c_actions.c
index 04be8180..a5e18940 100644
--- a/ocaml/guestfs_c_actions.c
+++ b/ocaml/guestfs_c_actions.c
@@ -4588,3 +4588,26 @@ ocaml_guestfs_df_h (value gv)
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);
+}
+
diff --git a/perl/Guestfs.xs b/perl/Guestfs.xs
index 6980bdac..d6ef053d 100644
--- a/perl/Guestfs.xs
+++ b/perl/Guestfs.xs
@@ -2798,3 +2798,17 @@ PREINIT:
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
+
diff --git a/perl/lib/Sys/Guestfs.pm b/perl/lib/Sys/Guestfs.pm
index 69ffe8b3..655624a9 100644
--- a/perl/lib/Sys/Guestfs.pm
+++ b/perl/lib/Sys/Guestfs.pm
@@ -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.
+=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
diff --git a/python/guestfs-py.c b/python/guestfs-py.c
index 59a891ff..ac1283be 100644
--- a/python/guestfs-py.c
+++ b/python/guestfs-py.c
@@ -4853,6 +4853,30 @@ py_guestfs_df_h (PyObject *self, PyObject *args)
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 },
@@ -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 *) "du", py_guestfs_du, METH_VARARGS, NULL },
{ NULL, NULL, 0, NULL }
};
diff --git a/python/guestfs.py b/python/guestfs.py
index d838aaea..e62a5271 100644
--- a/python/guestfs.py
+++ b/python/guestfs.py
@@ -1827,3 +1827,16 @@ class GuestFS:
"""
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)
+
diff --git a/ruby/ext/guestfs/_guestfs.c b/ruby/ext/guestfs/_guestfs.c
index 336a3a42..679c5b0f 100644
--- a/ruby/ext/guestfs/_guestfs.c
+++ b/ruby/ext/guestfs/_guestfs.c
@@ -4559,6 +4559,28 @@ static VALUE ruby_guestfs_df_h (VALUE gv)
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 ()
{
@@ -4925,4 +4947,6 @@ void Init__guestfs ()
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);
}
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index 0a3e7b04..c75acbe2 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-126
+127
diff --git a/src/guestfs-actions.c b/src/guestfs-actions.c
index 745a52bc..b34c8017 100644
--- a/src/guestfs-actions.c
+++ b/src/guestfs-actions.c
@@ -11557,3 +11557,95 @@ char *guestfs_df_h (guestfs_h *g)
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;
+}
+
diff --git a/src/guestfs-actions.h b/src/guestfs-actions.h
index cbf5ff76..3c983325 100644
--- a/src/guestfs-actions.h
+++ b/src/guestfs-actions.h
@@ -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 int64_t guestfs_du (guestfs_h *handle, const char *path);
diff --git a/src/guestfs_protocol.c b/src/guestfs_protocol.c
index 2830bf2a..050d9282 100644
--- a/src/guestfs_protocol.c
+++ b/src/guestfs_protocol.c
@@ -2151,6 +2151,26 @@ xdr_guestfs_df_h_ret (XDR *xdrs, guestfs_df_h_ret *objp)
}
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;
diff --git a/src/guestfs_protocol.h b/src/guestfs_protocol.h
index 16db25af..c8231a0d 100644
--- a/src/guestfs_protocol.h
+++ b/src/guestfs_protocol.h
@@ -1101,6 +1101,16 @@ struct 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,
@@ -1228,7 +1238,8 @@ enum guestfs_procedure {
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
@@ -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_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*);
@@ -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_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 ();
diff --git a/src/guestfs_protocol.x b/src/guestfs_protocol.x
index 702df5bf..a895b6d5 100644
--- a/src/guestfs_protocol.x
+++ b/src/guestfs_protocol.x
@@ -842,6 +842,14 @@ struct guestfs_df_h_ret {
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,
@@ -969,6 +977,7 @@ enum guestfs_procedure {
GUESTFS_PROC_TAIL_N = 124,
GUESTFS_PROC_DF = 125,
GUESTFS_PROC_DF_H = 126,
+ GUESTFS_PROC_DU = 127,
GUESTFS_PROC_NR_PROCS
};