[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH 5/5] New API: btrfs_filesystem_set_label



Signed-off-by: Hu Tao <hutao cn fujitsu com>
---
 daemon/btrfs.c       | 33 +++++++++++++++++++++++++++++++++
 generator/actions.ml | 16 ++++++++++++++++
 src/MAX_PROC_NR      |  2 +-
 3 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/daemon/btrfs.c b/daemon/btrfs.c
index 32b1b05..f9e35be 100644
--- a/daemon/btrfs.c
+++ b/daemon/btrfs.c
@@ -1463,3 +1463,36 @@ do_btrfs_filesystem_defragment (const char *path)
 
   return 0;
 }
+
+int
+do_btrfs_filesystem_set_label (const char *path, const char *label)
+{
+  const size_t MAX_ARGS = 64;
+  const char *argv[MAX_ARGS];
+  size_t i = 0;
+  CLEANUP_FREE char *path_buf = NULL;
+  CLEANUP_FREE char *err = NULL;
+  CLEANUP_FREE char *out = NULL;
+  int r;
+
+  path_buf = sysroot_path (path);
+  if (path_buf == NULL) {
+    reply_with_perror ("malloc");
+    return -1;
+  }
+
+  ADD_ARG (argv, i, str_btrfs);
+  ADD_ARG (argv, i, "filesystem");
+  ADD_ARG (argv, i, "label");
+  ADD_ARG (argv, i, path_buf);
+  ADD_ARG (argv, i, label);
+  ADD_ARG (argv, i, NULL);
+
+  r = commandv (&out, &err, argv);
+  if (r == -1) {
+    reply_with_error ("%s: %s", path, err);
+    return -1;
+  }
+
+  return 0;
+}
diff --git a/generator/actions.ml b/generator/actions.ml
index 4b24f8a..7e1f3ed 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -12316,6 +12316,22 @@ Get a btrfs filesystem's label." };
     longdesc = "\
 Defragment a file or directory." };
 
+  { defaults with
+    name = "btrfs_filesystem_set_label";
+    style = RErr, [Pathname "path"; String "label"], [];
+    proc_nr = Some 439;
+    optional = Some "btrfs"; camel_name = "BTRFSFilesystemSetLabel";
+    tests = [
+      InitPartition, Always, TestResultString (
+        [["mkfs_btrfs"; "/dev/sda1"; ""; ""; "NOARG"; ""; "NOARG"; "NOARG"; ""; ""];
+         ["mount"; "/dev/sda1"; "/"];
+         ["btrfs_filesystem_set_label"; "/"; "newlabel"];
+         ["btrfs_filesystem_get_label"; "/"]], "newlabel"), [];
+    ];
+    shortdesc = "set a btrfs filesystem's label";
+    longdesc = "\
+Set a btrfs filesystem's label." };
+
 ]
 
 (* Non-API meta-commands available only in guestfish.
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index c8eb588..99dea3b 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-438
+439
-- 
2.2.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]