mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
daemon: set-label: Convert to table-driven dispatch
Signed-off-by: Susant Sahani <ssahani@redhat.com>
This commit is contained in:
@@ -59,36 +59,36 @@ xfslabel (const char *device, const char *label)
|
|||||||
int
|
int
|
||||||
do_set_label (const mountable_t *mountable, const char *label)
|
do_set_label (const mountable_t *mountable, const char *label)
|
||||||
{
|
{
|
||||||
int r;
|
|
||||||
|
|
||||||
/* How we set the label depends on the filesystem type. */
|
/* How we set the label depends on the filesystem type. */
|
||||||
CLEANUP_FREE char *vfs_type = do_vfs_type (mountable);
|
CLEANUP_FREE char *vfs_type = do_vfs_type (mountable);
|
||||||
if (vfs_type == NULL)
|
if (vfs_type == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (STREQ (vfs_type, "btrfs"))
|
struct {
|
||||||
r = btrfs_set_label (mountable->device, label);
|
const char *fs;
|
||||||
|
int (*func)(const char *device, const char *label);
|
||||||
|
} const setters[] = {
|
||||||
|
{ "btrfs", btrfs_set_label },
|
||||||
|
{ "msdos", dosfslabel },
|
||||||
|
{ "vfat", dosfslabel },
|
||||||
|
{ "fat", dosfslabel },
|
||||||
|
{ "ntfs", ntfs_set_label },
|
||||||
|
{ "xfs", xfslabel },
|
||||||
|
{ "swap", swap_set_label },
|
||||||
|
{ NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
else if (STREQ (vfs_type, "msdos") ||
|
/* Special case: ext2/ext3/ext4 */
|
||||||
STREQ (vfs_type, "fat") ||
|
if (fstype_is_extfs (vfs_type))
|
||||||
STREQ (vfs_type, "vfat"))
|
return do_set_e2label (mountable->device, label);
|
||||||
r = dosfslabel (mountable->device, label);
|
|
||||||
|
|
||||||
else if (fstype_is_extfs (vfs_type))
|
for (size_t i = 0; setters[i].fs; ++i) {
|
||||||
r = do_set_e2label (mountable->device, label);
|
if (STREQ (vfs_type, setters[i].fs))
|
||||||
|
return setters[i].func (mountable->device, label);
|
||||||
|
}
|
||||||
|
|
||||||
else if (STREQ (vfs_type, "ntfs"))
|
/* Not supported */
|
||||||
r = ntfs_set_label (mountable->device, label);
|
NOT_SUPPORTED (-1,
|
||||||
|
"don't know how to set the label for '%s' filesystems",
|
||||||
else if (STREQ (vfs_type, "xfs"))
|
vfs_type);
|
||||||
r = xfslabel (mountable->device, label);
|
|
||||||
|
|
||||||
else if (STREQ (vfs_type, "swap"))
|
|
||||||
r = swap_set_label (mountable->device, label);
|
|
||||||
|
|
||||||
else
|
|
||||||
NOT_SUPPORTED (-1, "don't know how to set the label for '%s' filesystems",
|
|
||||||
vfs_type);
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user