|
|
022f11 |
From 48035cf253bdf27a1a7d460b86e19e53cfc82e3b Mon Sep 17 00:00:00 2001
|
|
|
022f11 |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
022f11 |
Date: Thu, 29 Aug 2013 11:41:46 +0100
|
|
|
022f11 |
Subject: [PATCH] daemon: Allow labels to be set on DOS filesystems using
|
|
|
022f11 |
'dosfslabel'.
|
|
|
022f11 |
|
|
|
022f11 |
You can now use virt-format or virt-make-fs --label option to set a
|
|
|
022f11 |
label for a DOS filesystem:
|
|
|
022f11 |
|
|
|
022f11 |
$ ./run ./format/virt-format -a /tmp/test.img --filesystem=vfat --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 vfat BOOT - 1.0G -
|
|
|
022f11 |
/dev/sda1 partition - - 0b 1.0G /dev/sda
|
|
|
022f11 |
/dev/sda device - - - 1.0G -
|
|
|
022f11 |
|
|
|
022f11 |
This also contains a small code refactoring.
|
|
|
022f11 |
|
|
|
022f11 |
Thanks: Gerd Hoffmann (kraxel)
|
|
|
022f11 |
(cherry picked from commit a75ca610b80614253f8a9d9828a97dc61d919b8a)
|
|
|
022f11 |
---
|
|
|
022f11 |
daemon/labels.c | 61 ++++++++++++++++++++++++++++++++++++++-------------------
|
|
|
022f11 |
1 file changed, 41 insertions(+), 20 deletions(-)
|
|
|
022f11 |
|
|
|
022f11 |
diff --git a/daemon/labels.c b/daemon/labels.c
|
|
|
022f11 |
index 10e40dc..f417c57 100644
|
|
|
022f11 |
--- a/daemon/labels.c
|
|
|
022f11 |
+++ b/daemon/labels.c
|
|
|
022f11 |
@@ -28,11 +28,43 @@
|
|
|
022f11 |
#include "optgroups.h"
|
|
|
022f11 |
|
|
|
022f11 |
GUESTFSD_EXT_CMD(str_btrfs, btrfs);
|
|
|
022f11 |
+GUESTFSD_EXT_CMD(str_dosfslabel, dosfslabel);
|
|
|
022f11 |
GUESTFSD_EXT_CMD(str_e2label, e2label);
|
|
|
022f11 |
GUESTFSD_EXT_CMD(str_ntfslabel, ntfslabel);
|
|
|
022f11 |
GUESTFSD_EXT_CMD(str_xfs_admin, xfs_admin);
|
|
|
022f11 |
|
|
|
022f11 |
static int
|
|
|
022f11 |
+btrfslabel (const char *device, const char *label)
|
|
|
022f11 |
+{
|
|
|
022f11 |
+ int r;
|
|
|
022f11 |
+ CLEANUP_FREE char *err = NULL;
|
|
|
022f11 |
+
|
|
|
022f11 |
+ r = command (NULL, &err, str_btrfs, "filesystem", "label",
|
|
|
022f11 |
+ device, label, NULL);
|
|
|
022f11 |
+ if (r == -1) {
|
|
|
022f11 |
+ reply_with_error ("%s", err);
|
|
|
022f11 |
+ return -1;
|
|
|
022f11 |
+ }
|
|
|
022f11 |
+
|
|
|
022f11 |
+ return 0;
|
|
|
022f11 |
+}
|
|
|
022f11 |
+
|
|
|
022f11 |
+static int
|
|
|
022f11 |
+dosfslabel (const char *device, const char *label)
|
|
|
022f11 |
+{
|
|
|
022f11 |
+ int r;
|
|
|
022f11 |
+ CLEANUP_FREE char *err = NULL;
|
|
|
022f11 |
+
|
|
|
022f11 |
+ r = command (NULL, &err, str_dosfslabel, device, label, NULL);
|
|
|
022f11 |
+ if (r == -1) {
|
|
|
022f11 |
+ reply_with_error ("%s", err);
|
|
|
022f11 |
+ return -1;
|
|
|
022f11 |
+ }
|
|
|
022f11 |
+
|
|
|
022f11 |
+ return 0;
|
|
|
022f11 |
+}
|
|
|
022f11 |
+
|
|
|
022f11 |
+static int
|
|
|
022f11 |
e2label (const char *device, const char *label)
|
|
|
022f11 |
{
|
|
|
022f11 |
int r;
|
|
|
022f11 |
@@ -95,22 +127,6 @@ xfslabel (const char *device, const char *label)
|
|
|
022f11 |
return 0;
|
|
|
022f11 |
}
|
|
|
022f11 |
|
|
|
022f11 |
-static int
|
|
|
022f11 |
-btrfslabel (const char *device, const char *label)
|
|
|
022f11 |
-{
|
|
|
022f11 |
- int r;
|
|
|
022f11 |
- CLEANUP_FREE char *err = NULL;
|
|
|
022f11 |
-
|
|
|
022f11 |
- r = command (NULL, &err, str_btrfs, "filesystem", "label",
|
|
|
022f11 |
- device, label, NULL);
|
|
|
022f11 |
- if (r == -1) {
|
|
|
022f11 |
- reply_with_error ("%s", err);
|
|
|
022f11 |
- return -1;
|
|
|
022f11 |
- }
|
|
|
022f11 |
-
|
|
|
022f11 |
- return 0;
|
|
|
022f11 |
-}
|
|
|
022f11 |
-
|
|
|
022f11 |
int
|
|
|
022f11 |
do_set_label (const mountable_t *mountable, const char *label)
|
|
|
022f11 |
{
|
|
|
022f11 |
@@ -121,7 +137,15 @@ do_set_label (const mountable_t *mountable, const char *label)
|
|
|
022f11 |
if (vfs_type == NULL)
|
|
|
022f11 |
return -1;
|
|
|
022f11 |
|
|
|
022f11 |
- if (fstype_is_extfs (vfs_type))
|
|
|
022f11 |
+ if (STREQ (vfs_type, "btrfs"))
|
|
|
022f11 |
+ r = btrfslabel (mountable->device, label);
|
|
|
022f11 |
+
|
|
|
022f11 |
+ else if (STREQ (vfs_type, "msdos") ||
|
|
|
022f11 |
+ STREQ (vfs_type, "fat") ||
|
|
|
022f11 |
+ STREQ (vfs_type, "vfat"))
|
|
|
022f11 |
+ r = dosfslabel (mountable->device, label);
|
|
|
022f11 |
+
|
|
|
022f11 |
+ else if (fstype_is_extfs (vfs_type))
|
|
|
022f11 |
r = e2label (mountable->device, label);
|
|
|
022f11 |
|
|
|
022f11 |
else if (STREQ (vfs_type, "ntfs"))
|
|
|
022f11 |
@@ -130,9 +154,6 @@ do_set_label (const mountable_t *mountable, const char *label)
|
|
|
022f11 |
else if (STREQ (vfs_type, "xfs"))
|
|
|
022f11 |
r = xfslabel (mountable->device, label);
|
|
|
022f11 |
|
|
|
022f11 |
- else if (STREQ (vfs_type, "btrfs"))
|
|
|
022f11 |
- r = btrfslabel (mountable->device, label);
|
|
|
022f11 |
-
|
|
|
022f11 |
else {
|
|
|
022f11 |
reply_with_error ("don't know how to set the label for '%s' filesystems",
|
|
|
022f11 |
vfs_type);
|
|
|
022f11 |
--
|
|
|
022f11 |
1.8.3.1
|
|
|
022f11 |
|