]> git.hungrycats.org Git - btrfs-progs/commitdiff
btrfs-progs: utils: parse any number of optional fields in mountinfo
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Fri, 30 Oct 2026 03:28:01 +0000 (23:28 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Fri, 30 Oct 2026 03:28:06 +0000 (23:28 -0400)
parse_mntinfo_line() skips exactly one token between the mount options
(field 5) and the "-" separator, but the optional fields in between are a
list of zero or more entries.  A mount with private propagation (e.g. in a
container or after "unshare -m --propagation private") has none, and the
parser then reads the device name as the filesystem type; a slave mount
that is also shared ("shared:N master:M") has two, and the parser reads
the "-" as the filesystem type.  Either way the line is not recognized as
a btrfs mount and find_mount_fsroot() never finds it, so for instance
"btrfs inspect-internal logical-resolve" reports every subvolume as "not
mounted".

Skip optional fields up to the lone hyphen instead.  libmount, which
find_mount_fsroot() used before, did this correctly.

Link: https://github.com/kdave/btrfs-progs/issues/400
Fixes: e31679c1ec3e ("btrfs-progs: reimplement find_mount_fsroot without libmount")
Assisted-by: Claude:claude-opus-5-5
common/utils.c

index 819830dc6da167cd8f2be8a9313d4efaf1fc6535..11ca82f8ae57cd4f8aa188cedcfaf2a0cecaf963 100644 (file)
@@ -490,6 +490,11 @@ static char *read_path(char **line)
 272 265 0:49 /subvol /mnt/path rw,noatime shared:145 - btrfs /dev/sda1 rw,subvolid=5598,subvol=/subvol
 0   1   2    3      4          5          6          7 8     9         10
 
+ * Field 6 is a list of zero or more optional fields (e.g. "shared:145",
+ * "master:12", "propagate_from:3", "unbindable"), terminated by a single
+ * hyphen (7).  A mount with private propagation has none, so the hyphen
+ * immediately follows field 5; a slave mount that is also shared has two.
+ *
  * Fields related to paths and options are parsed, @line is changed in place,
  * separators are replaced by NUL char, paths could be unmangled.
  */
@@ -514,12 +519,15 @@ static void parse_mntinfo_line(char *line, struct mnt_entry *ent)
        ent->options1 = line;
        skip_nonsep(&line);
        skip_sep(&line);
-       /* Skip 6 */
-       skip_nonsep(&line);
-       skip_sep(&line);
-       /* Skip 7 */
-       skip_nonsep(&line);
-       skip_sep(&line);
+       /* Skip 6 (any number of optional fields) and the 7 separator "-" */
+       while (*line) {
+               bool is_hyphen = (line[0] == '-' && (line[1] == 0 || is_sep(line[1])));
+
+               skip_nonsep(&line);
+               skip_sep(&line);
+               if (is_hyphen)
+                       break;
+       }
        /* Read 8 */
        ent->fstype = line;
        skip_nonsep(&line);