- while (fgets(buffer, sizeof(buffer), f) != NULL) {
- char *device, *mntdir, *type, *flags;
- struct mount_options *options;
- char *line = buffer;
-
- next = strchr(line, '\n');
- if (next != NULL)
- *next = '\0';
-
- device = strtok(line, " \t");
- if (device == NULL)
- continue;
- mntdir = strtok(NULL, " \t");
- if (mntdir == NULL)
- continue;
- if (strcmp(device, mc->m.mnt_fsname) != 0 &&
- strcmp(mntdir, mc->m.mnt_dir) != 0)
+ pmc = getprocmntdirbackward(mc->m.mnt_dir, NULL);
+ if (!pmc)
+ goto not_found;
+
+ do {
+ size_t nlen = strlen(pmc->m.mnt_fsname);
+
+ /*
+ * It's possible the mount location string in /proc/mounts
+ * ends with a '/'. In this case, if the entry came from
+ * /etc/mtab, it won't have the trailing '/' so deal with
+ * it.
+ */
+ while (pmc->m.mnt_fsname[nlen - 1] == '/')
+ nlen--;
+ if (strncmp(pmc->m.mnt_fsname, mc->m.mnt_fsname, nlen) != 0)