mount: clean up getfs* (fstab.c) interface

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2007-05-25 11:09:44 +02:00
parent baae33d0b3
commit 8c61f43a4c
4 changed files with 45 additions and 32 deletions

View File

@ -315,38 +315,38 @@ has_uuid(const char *device, const char *uuid){
return ret;
}
/* Find the entry (SPEC,FILE) in fstab */
/* Find the entry (SPEC,DIR) in fstab */
struct mntentchn *
getfsspecfile (const char *spec, const char *file) {
getfs_by_specdir (const char *spec, const char *dir) {
struct mntentchn *mc, *mc0;
mc0 = fstab_head();
/* first attempt: names occur precisely as given */
for (mc = mc0->nxt; mc && mc != mc0; mc = mc->nxt)
if (streq(mc->m.mnt_dir, file) &&
if (streq(mc->m.mnt_dir, dir) &&
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))
if ((streq(mc->m.mnt_dir, dir) ||
streq(canonicalize(mc->m.mnt_dir), dir))
&& (streq(mc->m.mnt_fsname, spec) ||
streq(canonicalize(mc->m.mnt_fsname), spec)))
streq(canonicalize(mc->m.mnt_fsname), dir)))
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, dir) ||
streq(canonicalize(mc->m.mnt_dir), dir))) {
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, dir) ||
streq(canonicalize(mc->m.mnt_dir), dir))) {
if (has_uuid(spec, mc->m.mnt_fsname+5))
return mc;
}
@ -354,33 +354,40 @@ getfsspecfile (const char *spec, const char *file) {
return NULL;
}
/* Find the dir FILE in fstab. */
/* Find the dir DIR in fstab. */
struct mntentchn *
getfsfile (const char *file) {
getfs_by_dir (const char *dir) {
struct mntentchn *mc, *mc0;
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, dir))
return mc;
return NULL;
}
/* Find the device SPEC in fstab. */
struct mntentchn *
getfsspec (const char *spec) {
getfs_by_spec (const char *spec) {
return getfs_by_devname(spec);
}
/* Find the device in fstab. */
struct mntentchn *
getfs_by_devname (const char *devname) {
struct mntentchn *mc, *mc0;
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, devname))
return mc;
return NULL;
}
/* Find the uuid UUID in fstab. */
struct mntentchn *
getfsuuidspec (const char *uuid) {
getfs_by_uuid (const char *uuid) {
struct mntentchn *mc, *mc0;
mc0 = fstab_head();
@ -393,7 +400,7 @@ getfsuuidspec (const char *uuid) {
/* Find the label LABEL in fstab. */
struct mntentchn *
getfsvolspec (const char *label) {
getfs_by_label (const char *label) {
struct mntentchn *mc, *mc0;
mc0 = fstab_head();

View File

@ -1,3 +1,6 @@
#ifndef MOUNT_FSTAB_H
#define MOUNT_FSTAB_H
#include "mount_mntent.h"
int mtab_is_writable(void);
int mtab_does_not_exist(void);
@ -15,12 +18,15 @@ struct mntentchn *getmntdirbackward (const char *dir, struct mntentchn *mc);
struct mntentchn *getmntdevbackward (const char *dev, struct mntentchn *mc);
struct mntentchn *fstab_head (void);
struct mntentchn *getfsfile (const char *file);
struct mntentchn *getfsspec (const char *spec);
struct mntentchn *getfsspecfile (const char *spec, const char *file);
struct mntentchn *getfsuuidspec (const char *uuid);
struct mntentchn *getfsvolspec (const char *label);
struct mntentchn *getfs_by_dir (const char *dir);
struct mntentchn *getfs_by_spec (const char *spec);
struct mntentchn *getfs_by_devname (const char *devname);
struct mntentchn *getfs_by_specdir (const char *spec, const char *dir);
struct mntentchn *getfs_by_uuid (const char *uuid);
struct mntentchn *getfs_by_label (const char *label);
void lock_mtab (void);
void unlock_mtab (void);
void update_mtab (const char *special, struct my_mntent *with);
#endif /* MOUNT_FSTAB_H */

View File

@ -539,7 +539,7 @@ create_mtab (void) {
}
/* Find the root entry by looking it up in fstab */
if ((fstab = getfsfile ("/")) || (fstab = getfsfile ("root"))) {
if ((fstab = getfs_by_dir ("/")) || (fstab = getfs_by_dir ("root"))) {
char *extra_opts;
parse_opts (fstab->m.mnt_opts, &flags, &extra_opts);
mnt.mnt_dir = "/";
@ -1872,10 +1872,10 @@ main(int argc, char *argv[]) {
usage (stderr, EX_USAGE);
if (specseen) {
/* We know the device. Where shall we mount it? */
mc = (uuid ? getfsuuidspec (uuid)
: getfsvolspec (volumelabel));
mc = (uuid ? getfs_by_uuid (uuid)
: getfs_by_label (volumelabel));
if (mc == NULL)
mc = getfsspec (spec);
mc = getfs_by_spec (spec);
if (mc == NULL)
die (EX_USAGE,
_("mount: cannot find %s in %s"),
@ -1884,12 +1884,12 @@ main(int argc, char *argv[]) {
} else {
/* Try to find the other pathname in fstab. */
spec = canonicalize (*argv);
if ((mc = getfsspec (spec)) == NULL &&
(mc = getfsfile (spec)) == NULL &&
if ((mc = getfs_by_spec (spec)) == NULL &&
(mc = getfs_by_dir (spec)) == NULL &&
/* Try noncanonical name in fstab
perhaps /dev/cdrom or /dos is a symlink */
(mc = getfsspec (*argv)) == NULL &&
(mc = getfsfile (*argv)) == NULL &&
(mc = getfs_by_spec (*argv)) == NULL &&
(mc = getfs_by_dir (*argv)) == NULL &&
/* Try mtab - maybe this was a remount */
(mc = getmntfile (spec)) == NULL)
die (EX_USAGE,

View File

@ -490,9 +490,9 @@ umount_file (char *arg) {
then "mount /dev/sda4" followed by "umount /mnt/zip"
used to fail. So, we must not look for file, but for
the pair (spec,file) in fstab. */
fs = getfsspecfile(mc->m.mnt_fsname, mc->m.mnt_dir);
fs = getfs_by_specdir(mc->m.mnt_fsname, mc->m.mnt_dir);
if (!fs) {
if (!getfsspec (file) && !getfsfile (file))
if (!getfs_by_spec (file) && !getfs_by_dir (file))
die (2,
_("umount: %s is not in the fstab "
"(and you are not root)"),