Skip to content

Commit

Permalink
inspection: Fix parsing of btrfs subvolumes in /etc/fstab.
Browse files Browse the repository at this point in the history
The code to parse btrfs subvol entries in /etc/fstab failed if the
entry had more than one comma-separated option, for example:

/dev/sda4 /home btrfs rw,user,subvol=foo 0 0

This commit fixes that code to use Augeas correctly.

Fixes commit 7ba0e10.

Reported by: Zhongfu Li
https://bugs.launchpad.net/ubuntu/+source/libguestfs/+bug/1615337
  • Loading branch information
rwmjones committed Aug 25, 2016
1 parent ecbf093 commit 738c3bf
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/inspect-fs-unix.c
Expand Up @@ -1347,27 +1347,28 @@ check_fstab (guestfs_h *g, struct inspect_fs *fs)
if (vfstype == NULL) return -1;

if (STREQ (vfstype, "btrfs")) {
char **opt;
size_t i;

snprintf (augpath, sizeof augpath, "%s/opt", *entry);
CLEANUP_FREE_STRING_LIST char **opts = guestfs_aug_match (g, augpath);
if (opts == NULL) return -1;

for (opt = opts; *opt; opt++) {
CLEANUP_FREE char *optname = guestfs_aug_get (g, augpath);
for (i = 0; opts[i] != NULL; ++i) {
CLEANUP_FREE char *optname = NULL, *optvalue = NULL, *subvol = NULL;
char *old_mountable;

optname = guestfs_aug_get (g, opts[i]);
if (optname == NULL) return -1;

if (STREQ (optname, "subvol")) {
CLEANUP_FREE char *subvol = NULL;
char *new;
optvalue = safe_asprintf (g, "%s/value", opts[i]);

snprintf (augpath, sizeof augpath, "%s/value", *opt);
subvol = guestfs_aug_get (g, augpath);
subvol = guestfs_aug_get (g, optvalue);
if (subvol == NULL) return -1;

new = safe_asprintf (g, "btrfsvol:%s/%s", mountable, subvol);
free (mountable);
mountable = new;
old_mountable = mountable;
mountable = safe_asprintf (g, "btrfsvol:%s/%s", mountable, subvol);
free (old_mountable);
}
}
}
Expand Down

0 comments on commit 738c3bf

Please sign in to comment.