mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

Blame SOURCES/0018-format-Add-label-option-for-setting-filesystem-label.patch

022f11
From 340ee2f41ee30f8699e676171c37feeb33ca1435 Mon Sep 17 00:00:00 2001
022f11
From: "Richard W.M. Jones" <rjones@redhat.com>
022f11
Date: Thu, 29 Aug 2013 11:32:05 +0100
022f11
Subject: [PATCH] format: Add --label option for setting filesystem label.
022f11
022f11
$ ./run ./format/virt-format -a /tmp/test.img --filesystem=ext2 --label=BOOT
022f11
$ ./run ./cat/virt-filesystems -a /tmp/test.img --all --long -h
022f11
Name       Type        VFS   Label  MBR  Size  Parent
022f11
/dev/sda1  filesystem  ext2  BOOT   -    1.0G  -
022f11
/dev/sda1  partition   -     -      83   1.0G  /dev/sda
022f11
/dev/sda   device      -     -      -    1.0G  -
022f11
022f11
Thanks: Gerd Hoffmann (kraxel)
022f11
(cherry picked from commit c46e41cb3c41f6283e0350cac6ef0b9178ed3941)
022f11
---
022f11
 format/format.c        | 10 ++++++++++
022f11
 format/virt-format.pod |  4 ++++
022f11
 2 files changed, 14 insertions(+)
022f11
022f11
diff --git a/format/format.c b/format/format.c
022f11
index 718fb2b..cff0d82 100644
022f11
--- a/format/format.c
022f11
+++ b/format/format.c
022f11
@@ -47,6 +47,7 @@ const char *libvirt_uri = NULL;
022f11
 static const char *filesystem = NULL;
022f11
 static const char *vg = NULL, *lv = NULL;
022f11
 static const char *partition = "DEFAULT";
022f11
+static const char *label = NULL;
022f11
 static int wipe = 0;
022f11
 static int have_wipefs;
022f11
 
022f11
@@ -77,6 +78,7 @@ usage (int status)
022f11
              "  --filesystem=..      Create empty filesystem\n"
022f11
              "  --format[=raw|..]    Force disk format for -a option\n"
022f11
              "  --help               Display brief help\n"
022f11
+             "  --label=..           Set filesystem label\n"
022f11
              "  --lvm=..             Create Linux LVM2 logical volume\n"
022f11
              "  --partition=..       Create / set partition type\n"
022f11
              "  -v|--verbose         Verbose messages\n"
022f11
@@ -107,6 +109,7 @@ main (int argc, char *argv[])
022f11
     { "filesystem", 1, 0, 0 },
022f11
     { "format", 2, 0, 0 },
022f11
     { "help", 0, 0, HELP_OPTION },
022f11
+    { "label", 1, 0, 0 },
022f11
     { "long-options", 0, 0, 0 },
022f11
     { "lvm", 2, 0, 0 },
022f11
     { "partition", 2, 0, 0 },
022f11
@@ -174,6 +177,8 @@ main (int argc, char *argv[])
022f11
           partition = optarg;
022f11
       } else if (STREQ (long_options[option_index].name, "wipe")) {
022f11
         wipe = 1;
022f11
+      } else if (STREQ (long_options[option_index].name, "label")) {
022f11
+        label = optarg;
022f11
       } else {
022f11
         fprintf (stderr, _("%s: unknown long option: %s (%d)\n"),
022f11
                  program_name, long_options[option_index].name, option_index);
022f11
@@ -415,6 +420,11 @@ do_format (void)
022f11
     if (filesystem) {
022f11
       if (guestfs_mkfs_opts (g, filesystem, dev, -1) == -1)
022f11
         exit (EXIT_FAILURE);
022f11
+
022f11
+      if (label) {
022f11
+        if (guestfs_set_label (g, dev, label) == -1)
022f11
+          exit (EXIT_FAILURE);
022f11
+      }
022f11
     }
022f11
 
022f11
     if (free_dev)
022f11
diff --git a/format/virt-format.pod b/format/virt-format.pod
022f11
index bcab888..ac2b8e6 100755
022f11
--- a/format/virt-format.pod
022f11
+++ b/format/virt-format.pod
022f11
@@ -114,6 +114,10 @@ If you have untrusted raw-format guest disk images, you should use
022f11
 this option to specify the disk format.  This avoids a possible
022f11
 security problem with malicious guests (CVE-2010-3851).
022f11
 
022f11
+=item B<--label=LABEL>
022f11
+
022f11
+Set the filesystem label.
022f11
+
022f11
 =item B<--lvm=/dev/I<VG>/I<LV>>
022f11
 
022f11
 Create a Linux LVM2 logical volume called C</dev/I<VG>/I<LV>>.  You
022f11
-- 
022f11
1.8.3.1
022f11