diff --git a/daemon/ext2.c b/daemon/ext2.c index e8d265521..ebaf0f076 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 @@ -125,12 +126,22 @@ do_tune2fs_l (const char *device) 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); + 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; } char * diff --git a/daemon/labels.c b/daemon/labels.c index eec5b9686..e3830f9fd 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); @@ -47,27 +46,6 @@ dosfslabel (const char *device, const char *label) return 0; } -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) { @@ -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 = do_set_e2label (mountable->device, label); else if (STREQ (vfs_type, "ntfs")) r = ntfslabel (mountable->device, label);