diff options
Diffstat (limited to 'mount/fstab.c')
-rw-r--r-- | mount/fstab.c | 72 |
1 files changed, 52 insertions, 20 deletions
diff --git a/mount/fstab.c b/mount/fstab.c index 0d9b6e94f..85a5d2df3 100644 --- a/mount/fstab.c +++ b/mount/fstab.c @@ -100,7 +100,7 @@ read_mntentchn(mntFILE *mfp, const char *fnam, struct mntentchn *mc0) { struct mntent *mnt; while ((mnt = my_getmntent (mfp)) != NULL) { - if (!streq (mnt->mnt_type, MNTTYPE_IGNORE)) { + if (!streq(mnt->mnt_type, MNTTYPE_IGNORE)) { mc->nxt = (struct mntentchn *) xmalloc(sizeof(*mc)); mc->nxt->prev = mc; mc = mc->nxt; @@ -179,30 +179,62 @@ getmntfile (const char *name) { mc0 = mtab_head(); for (mc = mc0->nxt; mc && mc != mc0; mc = mc->nxt) - if (streq (mc->m.mnt_dir, name) || - streq (mc->m.mnt_fsname, name)) + if (streq(mc->m.mnt_dir, name) || + streq(mc->m.mnt_fsname, name)) return mc; return NULL; } /* - * Given the name NAME, and the place MCPREV we found it last time, + * Given the directory name NAME, and the place MCPREV we found it last time, * try to find more occurrences. */ struct mntentchn * -getmntfilesbackward (const char *name, struct mntentchn *mcprev) { +getmntdirbackward (const char *name, struct mntentchn *mcprev) { struct mntentchn *mc, *mc0; mc0 = mtab_head(); if (!mcprev) mcprev = mc0; for (mc = mcprev->prev; mc && mc != mc0; mc = mc->prev) - if (streq (mc->m.mnt_dir, name) || - streq (mc->m.mnt_fsname, name)) + if (streq(mc->m.mnt_dir, name)) return mc; return NULL; } +/* + * Given the device name NAME, and the place MCPREV we found it last time, + * try to find more occurrences. + */ +struct mntentchn * +getmntdevbackward (const char *name, struct mntentchn *mcprev) { + struct mntentchn *mc, *mc0; + + mc0 = mtab_head(); + if (!mcprev) + mcprev = mc0; + for (mc = mcprev->prev; mc && mc != mc0; mc = mc->prev) + if (streq(mc->m.mnt_fsname, name)) + return mc; + return NULL; +} + +/* + * Given the name NAME, check that it occurs precisely once as dir or dev. + */ +int +is_mounted_once(const char *name) { + struct mntentchn *mc, *mc0; + int ct = 0; + + mc0 = mtab_head(); + for (mc = mc0->prev; mc && mc != mc0; mc = mc->prev) + if (streq(mc->m.mnt_dir, name) || + streq(mc->m.mnt_fsname, name)) + ct++; + return (ct == 1); +} + /* Given the name FILE, try to find the option "loop=FILE" in mtab. */ struct mntentchn * getmntoptfile (const char *file) { @@ -253,29 +285,29 @@ getfsspecfile (const char *spec, const char *file) { /* first attempt: names occur precisely as given */ for (mc = mc0->nxt; mc && mc != mc0; mc = mc->nxt) - if (streq (mc->m.mnt_dir, file) && - streq (mc->m.mnt_fsname, spec)) + if (streq(mc->m.mnt_dir, file) && + streq(mc->m.mnt_fsname, spec)) return mc; /* second attempt: names found after symlink resolution */ for (mc = mc0->nxt; mc && mc != mc0; mc = mc->nxt) - if ((streq (mc->m.mnt_dir, file) || - streq (canonicalize(mc->m.mnt_dir), file)) - && (streq (mc->m.mnt_fsname, spec) || - streq (canonicalize(mc->m.mnt_fsname), spec))) + if ((streq(mc->m.mnt_dir, file) || + streq(canonicalize(mc->m.mnt_dir), file)) + && (streq(mc->m.mnt_fsname, spec) || + streq(canonicalize(mc->m.mnt_fsname), spec))) return mc; /* third attempt: names found after LABEL= or UUID= resolution */ for (mc = mc0->nxt; mc && mc != mc0; mc = mc->nxt) { if (!strncmp (mc->m.mnt_fsname, "LABEL=", 6) && - (streq (mc->m.mnt_dir, file) || - streq (canonicalize(mc->m.mnt_dir), file))) { + (streq(mc->m.mnt_dir, file) || + streq(canonicalize(mc->m.mnt_dir), file))) { if (has_label(spec, mc->m.mnt_fsname+6)) return mc; } if (!strncmp (mc->m.mnt_fsname, "UUID=", 5) && - (streq (mc->m.mnt_dir, file) || - streq (canonicalize(mc->m.mnt_dir), file))) { + (streq(mc->m.mnt_dir, file) || + streq(canonicalize(mc->m.mnt_dir), file))) { if (has_uuid(spec, mc->m.mnt_fsname+5)) return mc; } @@ -290,7 +322,7 @@ getfsfile (const char *file) { mc0 = fstab_head(); for (mc = mc0->nxt; mc && mc != mc0; mc = mc->nxt) - if (streq (mc->m.mnt_dir, file)) + if (streq(mc->m.mnt_dir, file)) return mc; return NULL; } @@ -302,7 +334,7 @@ getfsspec (const char *spec) { mc0 = fstab_head(); for (mc = mc0->nxt; mc && mc != mc0; mc = mc->nxt) - if (streq (mc->m.mnt_fsname, spec)) + if (streq(mc->m.mnt_fsname, spec)) return mc; return NULL; } @@ -531,7 +563,7 @@ update_mtab (const char *dir, struct mntent *instead) { /* find last occurrence of dir */ for (mc = mc0->prev; mc && mc != mc0; mc = mc->prev) - if (streq (mc->m.mnt_dir, dir)) + if (streq(mc->m.mnt_dir, dir)) break; if (mc && mc != mc0) { if (instead == NULL) { |