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
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.
*/
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);