labels: move e2label to ext2.c and call it directly

ext2 should not call function in labels

Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
This commit is contained in:
Chen Hanxiao
2015-07-08 17:34:42 +08:00
committed by Pino Toscano
parent 16232ffd58
commit d5a60f2148
2 changed files with 18 additions and 29 deletions

View File

@@ -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 *

View File

@@ -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);