Signed-off-by: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
---
daemon/daemon.h | 1 +
daemon/ext2.c | 29 +++++++++++++++++++++++------
daemon/labels.c | 24 +-----------------------
3 files changed, 25 insertions(+), 29 deletions(-)
diff --git a/daemon/daemon.h b/daemon/daemon.h
index 783d739..0731b09 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -224,6 +224,7 @@ extern int sync_disks (void);
#define EXT2_LABEL_MAX 16
extern int fstype_is_extfs (const char *fstype);
extern int ext_set_uuid_random (const char *device);
+extern int ext_set_label (const char *device, const char *label);
/*-- in blkid.c --*/
extern char *get_blkid_tag (const char *device, const char *tag);
diff --git a/daemon/ext2.c b/daemon/ext2.c
index e8d2655..7bb1221 100644
--- a/daemon/ext2.c
+++ b/daemon/ext2.c
@@ -38,6 +38,7 @@ GUESTFSD_EXT_CMD(str_resize2fs, resize2fs);
GUESTFSD_EXT_CMD(str_mke2fs, mke2fs);
GUESTFSD_EXT_CMD(str_lsattr, lsattr);
GUESTFSD_EXT_CMD(str_chattr, chattr);
+GUESTFSD_EXT_CMD(str_e2label, e2label);
/*
https://bugzilla.redhat.com/show_bug.cgi?id=978302#c1 */
int
@@ -123,14 +124,30 @@ do_tune2fs_l (const char *device)
}
int
+ext_set_label (const char *device, const char *label)
+{
+ int r;
+ CLEANUP_FREE char *err = NULL;
+
+ if (strlen (label) > EXT2_LABEL_MAX) {
+ reply_with_error ("%s: ext2 labels are limited to %d bytes",
+ label, EXT2_LABEL_MAX);
+ return -1;
+ }
+
+ r = command (NULL, &err, str_e2label, device, label, NULL);
+ if (r == -1) {
+ reply_with_error ("%s", err);
+ return -1;
+ }
+
+ return 0;
+}
+
+int
do_set_e2label (const char *device, const char *label)
{
- const mountable_t mountable = {
- .type = MOUNTABLE_DEVICE,
- .device = /* not really ... */ (char *) device,
- .volume = NULL,
- };
- return do_set_label (&mountable, label);
+ return ext_set_label (device, label);
}
char *
diff --git a/daemon/labels.c b/daemon/labels.c
index eec5b96..1fadba4 100644
--- a/daemon/labels.c
+++ b/daemon/labels.c
@@ -28,7 +28,6 @@
#include "optgroups.h"
GUESTFSD_EXT_CMD(str_dosfslabel, dosfslabel);
-GUESTFSD_EXT_CMD(str_e2label, e2label);
GUESTFSD_EXT_CMD(str_ntfslabel, ntfslabel);
GUESTFSD_EXT_CMD(str_xfs_admin, xfs_admin);
@@ -48,27 +47,6 @@ dosfslabel (const char *device, const char *label)
}
static int
-e2label (const char *device, const char *label)
-{
- int r;
- CLEANUP_FREE char *err = NULL;
-
- if (strlen (label) > EXT2_LABEL_MAX) {
- reply_with_error ("%s: ext2 labels are limited to %d bytes",
- label, EXT2_LABEL_MAX);
- return -1;
- }
-
- r = command (NULL, &err, str_e2label, device, label, NULL);
- if (r == -1) {
- reply_with_error ("%s", err);
- return -1;
- }
-
- return 0;
-}
-
-static int
ntfslabel (const char *device, const char *label)
{
int r;
@@ -135,7 +113,7 @@ do_set_label (const mountable_t *mountable, const char *label)
r = dosfslabel (mountable->device, label);
else if (fstype_is_extfs (vfs_type))
- r = e2label (mountable->device, label);
+ r = ext_set_label (mountable->device, label);
else if (STREQ (vfs_type, "ntfs"))
r = ntfslabel (mountable->device, label);
--
2.1.0