From: Karel Zak Date: Wed, 28 Nov 2007 13:35:24 +0000 (+0100) Subject: mount: cleanup usage of _PATH_* X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e270e3f480c6786d17722ea97ed72d374b66051;p=util-linux mount: cleanup usage of _PATH_* The macros MOUNTED and MNTTAB are deprecated. This patch standardize and consolidate all path macros and remove mount_paths.h. Signed-off-by: Karel Zak --- diff --git a/mount/Makefile.am b/mount/Makefile.am index 01643b20..6efc7554 100644 --- a/mount/Makefile.am +++ b/mount/Makefile.am @@ -9,7 +9,7 @@ man_MANS = fstab.5 mount.8 swapoff.8 swapon.8 umount.8 losetup.8 utils_common = sundries.c xmalloc.c realpath.c fsprobe.c headers_common = fstab.h mount_mntent.h mount_constants.h \ - mount_paths.h lomount.h fsprobe.h realpath.h xmalloc.h \ + lomount.h fsprobe.h realpath.h xmalloc.h \ getusername.h loop.h sundries.h mount_common = fstab.c mount_mntent.c getusername.c lomount.c \ diff --git a/mount/fsprobe.c b/mount/fsprobe.c index 0be73ac3..96548647 100644 --- a/mount/fsprobe.c +++ b/mount/fsprobe.c @@ -5,7 +5,7 @@ #include #include #include -#include "mount_paths.h" +#include "pathnames.h" #include "fsprobe.h" #include "sundries.h" /* for xstrdup */ #include "nls.h" @@ -76,7 +76,7 @@ fsprobe_known_fstype_in_procfs(const char *type) char *fsname; int ret = -1; - procfs = fopen(PROC_FILESYSTEMS, "r"); + procfs = fopen(_PATH_PROC_FILESYSTEMS, "r"); if (procfs) { ret = 0; while ((fsname = procfsnext(procfs)) != NULL) @@ -101,7 +101,7 @@ fsprobe_procfsloop_mount(int (*mount_fn)(struct mountargs *, int *, int *), const char **types, int *special, int *status) { - char *files[2] = { ETC_FILESYSTEMS, PROC_FILESYSTEMS }; + char *files[2] = { _PATH_FILESYSTEMS, _PATH_PROC_FILESYSTEMS }; FILE *procfs; char *fsname; const char *notypes = NULL; @@ -116,14 +116,14 @@ fsprobe_procfsloop_mount(int (*mount_fn)(struct mountargs *, int *, int *), } *types = NULL; - /* Use PROC_FILESYSTEMS only when ETC_FILESYSTEMS does not exist. - In some cases trying a filesystem that the kernel knows about - on the wrong data will crash the kernel; in such cases - ETC_FILESYSTEMS can be used to list the filesystems that we - are allowed to try, and in the order they should be tried. - End ETC_FILESYSTEMS with a line containing a single '*' only, - if PROC_FILESYSTEMS should be tried afterwards. */ - + /* Use _PATH_PROC_FILESYSTEMS only when _PATH_FILESYSTEMS + * (/etc/filesystems) does not exist. In some cases trying a + * filesystem that the kernel knows about on the wrong data will crash + * the kernel; in such cases _PATH_FILESYSTEMS can be used to list the + * filesystems that we are allowed to try, and in the order they should + * be tried. End _PATH_FILESYSTEMS with a line containing a single '*' + * only, if _PATH_PROC_FILESYSTEMS should be tried afterwards. + */ for (i=0; i<2; i++) { procfs = fopen(files[i], "r"); if (!procfs) diff --git a/mount/fsprobe_volumeid.c b/mount/fsprobe_volumeid.c index efdacc7d..7c98dc6e 100644 --- a/mount/fsprobe_volumeid.c +++ b/mount/fsprobe_volumeid.c @@ -12,7 +12,7 @@ #include "fsprobe.h" #include "realpath.h" -#include "mount_paths.h" +#include "pathnames.h" #include "sundries.h" enum probe_type { @@ -113,8 +113,8 @@ fsprobe_get_devname_by_uuid(const char *uuid) if (!uuid) return NULL; - strcpy(dev, PATH_DEV_BYUUID "/"); - len = strlen(PATH_DEV_BYUUID "/"); + strcpy(dev, _PATH_DEV_BYUUID "/"); + len = strlen(_PATH_DEV_BYUUID "/"); if (!volume_id_encode_string(uuid, &dev[len], sizeof(dev) - len) != 0) return NULL; return canonicalize(dev); @@ -128,8 +128,8 @@ fsprobe_get_devname_by_label(const char *label) if (!label) return NULL; - strcpy(dev, PATH_DEV_BYLABEL "/"); - len = strlen(PATH_DEV_BYLABEL "/"); + strcpy(dev, _PATH_DEV_BYLABEL "/"); + len = strlen(_PATH_DEV_BYLABEL "/"); if (!volume_id_encode_string(label, &dev[len], sizeof(dev) - len) != 0) return NULL; return canonicalize(dev); diff --git a/mount/fstab.c b/mount/fstab.c index cd756098..03ddf4ec 100644 --- a/mount/fstab.c +++ b/mount/fstab.c @@ -11,20 +11,18 @@ #include #include #include +#include #include "mount_mntent.h" #include "fstab.h" #include "sundries.h" #include "xmalloc.h" #include "fsprobe.h" -#include "mount_paths.h" +#include "pathnames.h" #include "nls.h" #include "realpath.h" #define streq(s, t) (strcmp ((s), (t)) == 0) -#define PROC_MOUNTS "/proc/mounts" - - /* Information about mtab. ------------------------------------*/ static int have_mtab_info = 0; static int var_mtab_does_not_exist = 0; @@ -35,7 +33,7 @@ get_mtab_info(void) { struct stat mtab_stat; if (!have_mtab_info) { - if (lstat(MOUNTED, &mtab_stat)) + if (lstat(_PATH_MOUNTED, &mtab_stat)) var_mtab_does_not_exist = 1; else if (S_ISLNK(mtab_stat.st_mode)) var_mtab_is_a_symlink = 1; @@ -66,7 +64,7 @@ mtab_is_writable() { if (mtab_is_a_symlink()) return 0; - fd = open(MOUNTED, O_RDWR | O_CREAT, 0644); + fd = open(_PATH_MOUNTED, O_RDWR | O_CREAT, 0644); if (fd >= 0) { close(fd); return 1; @@ -162,21 +160,21 @@ read_mounttable() { got_mtab = 1; mc->nxt = mc->prev = NULL; - fnam = MOUNTED; + fnam = _PATH_MOUNTED; mfp = my_setmntent (fnam, "r"); if (mfp == NULL || mfp->mntent_fp == NULL) { int errsv = errno; - fnam = PROC_MOUNTS; + fnam = _PATH_PROC_MOUNTS; mfp = my_setmntent (fnam, "r"); if (mfp == NULL || mfp->mntent_fp == NULL) { error(_("warning: can't open %s: %s"), - MOUNTED, strerror (errsv)); + _PATH_MOUNTED, strerror (errsv)); return; } if (verbose) printf (_("mount: could not open %s - " "using %s instead\n"), - MOUNTED, PROC_MOUNTS); + _PATH_MOUNTED, _PATH_PROC_MOUNTS); } read_mntentchn(mfp, fnam, mc); } @@ -190,19 +188,19 @@ read_fstab() { got_fstab = 1; mc->nxt = mc->prev = NULL; - fnam = _PATH_FSTAB; + fnam = _PATH_MNTTAB; mfp = my_setmntent (fnam, "r"); if (mfp == NULL || mfp->mntent_fp == NULL) { int errsv = errno; error(_("warning: can't open %s: %s"), - _PATH_FSTAB, strerror (errsv)); + _PATH_MNTTAB, strerror (errsv)); return; } read_mntentchn(mfp, fnam, mc); } - -/* Given the name NAME, try to find it in mtab. */ + +/* Given the name NAME, try to find it in mtab. */ struct mntentchn * getmntfile (const char *name) { struct mntentchn *mc, *mc0; @@ -218,7 +216,7 @@ getmntfile (const char *name) { /* * Given the directory name NAME, and the place MCPREV we found it last time, * try to find more occurrences. - */ + */ struct mntentchn * getmntdirbackward (const char *name, struct mntentchn *mcprev) { struct mntentchn *mc, *mc0; @@ -235,7 +233,7 @@ getmntdirbackward (const char *name, struct mntentchn *mcprev) { /* * 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; @@ -483,7 +481,7 @@ unlock_mtab (void) { if (we_created_lockfile) { close(lockfile_fd); lockfile_fd = -1; - unlink (MOUNTED_LOCK); + unlink (_PATH_MOUNTED_LOCK); we_created_lockfile = 0; } } @@ -505,8 +503,8 @@ unlock_mtab (void) { /* Where does the link point to? Obvious choices are mtab and mtab~~. HJLu points out that the latter leads to races. Right now we use mtab~. instead. Use 20 as upper bound for the length of %d. */ -#define MOUNTLOCK_LINKTARGET MOUNTED_LOCK "%d" -#define MOUNTLOCK_LINKTARGET_LTH (sizeof(MOUNTED_LOCK)+20) +#define MOUNTLOCK_LINKTARGET _PATH_MOUNTED_LOCK "%d" +#define MOUNTLOCK_LINKTARGET_LTH (sizeof(_PATH_MOUNTED_LOCK)+20) /* * The original mount locking code has used sleep(1) between attempts and @@ -582,7 +580,7 @@ lock_mtab (void) { struct flock flock; int errsv, j; - j = link(linktargetfile, MOUNTED_LOCK); + j = link(linktargetfile, _PATH_MOUNTED_LOCK); errsv = errno; if (j == 0) @@ -592,10 +590,10 @@ lock_mtab (void) { (void) unlink(linktargetfile); die (EX_FILEIO, _("can't link lock file %s: %s " "(use -n flag to override)"), - MOUNTED_LOCK, strerror (errsv)); + _PATH_MOUNTED_LOCK, strerror (errsv)); } - lockfile_fd = open (MOUNTED_LOCK, O_WRONLY); + lockfile_fd = open (_PATH_MOUNTED_LOCK, O_WRONLY); if (lockfile_fd < 0) { /* Strange... Maybe the file was just deleted? */ @@ -608,7 +606,7 @@ lock_mtab (void) { (void) unlink(linktargetfile); die (EX_FILEIO, _("can't open lock file %s: %s " "(use -n flag to override)"), - MOUNTED_LOCK, strerror (errsv)); + _PATH_MOUNTED_LOCK, strerror (errsv)); } flock.l_type = F_WRLCK; @@ -622,7 +620,7 @@ lock_mtab (void) { if (verbose) { int errsv = errno; printf(_("Can't lock lock file %s: %s\n"), - MOUNTED_LOCK, strerror (errsv)); + _PATH_MOUNTED_LOCK, strerror (errsv)); } /* proceed, since it was us who created the lockfile anyway */ } @@ -636,7 +634,7 @@ lock_mtab (void) { int errsv = errno; (void) unlink(linktargetfile); die (EX_FILEIO, _("can't lock lock file %s: %s"), - MOUNTED_LOCK, (errno == EINTR) ? + _PATH_MOUNTED_LOCK, (errno == EINTR) ? _("timed out") : strerror (errsv)); } alarm(0); @@ -646,7 +644,7 @@ lock_mtab (void) { (void) unlink(linktargetfile); die (EX_FILEIO, _("Cannot create link %s\n" "Perhaps there is a stale lock file?\n"), - MOUNTED_LOCK); + _PATH_MOUNTED_LOCK); } close(lockfile_fd); } @@ -666,7 +664,7 @@ lock_mtab (void) { void update_mtab (const char *dir, struct my_mntent *instead) { mntFILE *mfp, *mftmp; - const char *fnam = MOUNTED; + const char *fnam = _PATH_MOUNTED; struct mntentchn mtabhead; /* dummy */ struct mntentchn *mc, *mc0, *absent = NULL; struct stat sbuf; @@ -734,11 +732,11 @@ update_mtab (const char *dir, struct my_mntent *instead) { } /* write chain to mtemp */ - mftmp = my_setmntent (MOUNTED_TEMP, "w"); + mftmp = my_setmntent (_PATH_MOUNTED_TMP, "w"); if (mftmp == NULL || mftmp->mntent_fp == NULL) { int errsv = errno; error (_("cannot open %s (%s) - mtab not updated"), - MOUNTED_TEMP, strerror (errsv)); + _PATH_MOUNTED_TMP, strerror (errsv)); discard_mntentchn(mc0); goto leave; } @@ -747,7 +745,7 @@ update_mtab (const char *dir, struct my_mntent *instead) { if (my_addmntent(mftmp, &(mc->m)) == 1) { int errsv = errno; die (EX_FILEIO, _("error writing %s: %s"), - MOUNTED_TEMP, strerror (errsv)); + _PATH_MOUNTED_TMP, strerror (errsv)); } } @@ -765,7 +763,7 @@ update_mtab (const char *dir, struct my_mntent *instead) { if (fchmod(fd, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) < 0) { int errsv = errno; fprintf(stderr, _("error changing mode of %s: %s\n"), - MOUNTED_TEMP, strerror (errsv)); + _PATH_MOUNTED_TMP, strerror (errsv)); goto leave; } @@ -774,11 +772,11 @@ update_mtab (const char *dir, struct my_mntent *instead) { * then mtab.tmp might get the group of this user. Copy uid/gid * from the present mtab before renaming. */ - if (stat(MOUNTED, &sbuf) == 0) { + if (stat(_PATH_MOUNTED, &sbuf) == 0) { if (fchown(fd, sbuf.st_uid, sbuf.st_gid) < 0) { int errsv = errno; fprintf (stderr, _("error changing owner of %s: %s\n"), - MOUNTED_TEMP, strerror(errsv)); + _PATH_MOUNTED_TMP, strerror(errsv)); goto leave; } } @@ -786,10 +784,10 @@ update_mtab (const char *dir, struct my_mntent *instead) { my_endmntent (mftmp); /* rename mtemp to mtab */ - if (rename (MOUNTED_TEMP, MOUNTED) < 0) { + if (rename (_PATH_MOUNTED_TMP, _PATH_MOUNTED) < 0) { int errsv = errno; fprintf(stderr, _("can't rename %s to %s: %s\n"), - MOUNTED_TEMP, MOUNTED, strerror(errsv)); + _PATH_MOUNTED_TMP, _PATH_MOUNTED, strerror(errsv)); } leave: diff --git a/mount/mount.c b/mount/mount.c index 60fe4fec..a28da486 100644 --- a/mount/mount.c +++ b/mount/mount.c @@ -22,13 +22,13 @@ #include #include -#include #ifdef HAVE_LIBSELINUX #include #include #endif +#include "pathnames.h" #include "fsprobe.h" #include "mount_constants.h" #include "sundries.h" @@ -38,7 +38,6 @@ #include "lomount.h" #include "loop.h" #include "getusername.h" -#include "mount_paths.h" #include "env.h" #include "nls.h" #include "blkdev.h" @@ -524,11 +523,11 @@ create_mtab (void) { lock_mtab(); - mfp = my_setmntent (MOUNTED, "a+"); + mfp = my_setmntent (_PATH_MOUNTED, "a+"); if (mfp == NULL || mfp->mntent_fp == NULL) { int errsv = errno; die (EX_FILEIO, _("mount: can't open %s for writing: %s"), - MOUNTED, strerror (errsv)); + _PATH_MOUNTED, strerror (errsv)); } /* Find the root entry by looking it up in fstab */ @@ -545,7 +544,7 @@ create_mtab (void) { if (my_addmntent (mfp, &mnt) == 1) { int errsv = errno; die (EX_FILEIO, _("mount: error writing %s: %s"), - MOUNTED, strerror (errsv)); + _PATH_MOUNTED, strerror (errsv)); } } if (fchmod (fileno (mfp->mntent_fp), 0644) < 0) @@ -553,7 +552,7 @@ create_mtab (void) { int errsv = errno; die (EX_FILEIO, _("mount: error changing mode of %s: %s"), - MOUNTED, strerror (errsv)); + _PATH_MOUNTED, strerror (errsv)); } my_endmntent (mfp); @@ -693,7 +692,7 @@ guess_fstype_by_devname(const char *devname) if (!type) printf (_(" I will try all types mentioned in %s or %s\n"), - ETC_FILESYSTEMS, PROC_FILESYSTEMS); + _PATH_FILESYSTEMS, _PATH_PROC_FILESYSTEMS); else if (!strcmp(type, "swap")) printf (_(" and it looks like this is swapspace\n")); else @@ -988,16 +987,16 @@ update_mtab_entry(const char *spec, const char *node, const char *type, mntFILE *mfp; lock_mtab(); - mfp = my_setmntent(MOUNTED, "a+"); + mfp = my_setmntent(_PATH_MOUNTED, "a+"); if (mfp == NULL || mfp->mntent_fp == NULL) { int errsv = errno; - error(_("mount: can't open %s: %s"), MOUNTED, + error(_("mount: can't open %s: %s"), _PATH_MOUNTED, strerror (errsv)); } else { if ((my_addmntent (mfp, &mnt)) == 1) { int errsv = errno; error(_("mount: error writing %s: %s"), - MOUNTED, strerror (errsv)); + _PATH_MOUNTED, strerror (errsv)); } } my_endmntent(mfp); @@ -1959,9 +1958,10 @@ main(int argc, char *argv[]) { } if (verbose > 2) { - printf("mount: fstab path: \"%s\"\n", _PATH_FSTAB); - printf("mount: lock path: \"%s\"\n", MOUNTED_LOCK); - printf("mount: temp path: \"%s\"\n", MOUNTED_TEMP); + printf("mount: fstab path: \"%s\"\n", _PATH_MNTTAB); + printf("mount: mtab path: \"%s\"\n", _PATH_MOUNTED); + printf("mount: lock path: \"%s\"\n", _PATH_MOUNTED_LOCK); + printf("mount: temp path: \"%s\"\n", _PATH_MOUNTED_TMP); } argc -= optind; @@ -1985,7 +1985,7 @@ main(int argc, char *argv[]) { if (!nomtab && mtab_does_not_exist()) { if (verbose > 1) printf(_("mount: no %s found - creating it..\n"), - MOUNTED); + _PATH_MOUNTED); create_mtab (); } @@ -2018,7 +2018,7 @@ main(int argc, char *argv[]) { die (EX_USAGE, _("mount: can't find %s in %s or %s"), - *argv, _PATH_FSTAB, MOUNTED); + *argv, _PATH_MNTTAB, _PATH_MOUNTED); } result = mount_one (xstrdup (mc->m.mnt_fsname), diff --git a/mount/mount_paths.h b/mount/mount_paths.h deleted file mode 100644 index 06d5ebf2..00000000 --- a/mount/mount_paths.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef MOUNT_PATHS_H -#define MOUNT_PATHS_H - -#include - -#define _PATH_FSTAB "/etc/fstab" -#define PROC_SWAPS "/proc/swaps" - -#ifdef _PATH_MOUNTED -# define MOUNTED_LOCK _PATH_MOUNTED "~" -# define MOUNTED_TEMP _PATH_MOUNTED ".tmp" -#else -# define MOUNTED_LOCK "/etc/mtab~" -# define MOUNTED_TEMP "/etc/mtab.tmp" -#endif - -#define LOCK_TIMEOUT 10 - -#define ETC_FILESYSTEMS "/etc/filesystems" -#define PROC_FILESYSTEMS "/proc/filesystems" - -/* udev paths */ -#define PATH_DEV_BYLABEL "/dev/disk/by-label" -#define PATH_DEV_BYUUID "/dev/disk/by-uuid" - -#endif /* MOUNT_PATHS_H */ diff --git a/mount/swapon.c b/mount/swapon.c index 6c2c4866..2c8b4fc2 100644 --- a/mount/swapon.c +++ b/mount/swapon.c @@ -15,7 +15,7 @@ #include "nls.h" #include "fsprobe.h" #include "realpath.h" -#include "mount_paths.h" +#include "pathnames.h" #ifdef HAVE_SYS_SWAP_H # include @@ -108,14 +108,14 @@ read_proc_swaps(void) { numSwaps = 0; swapFiles = NULL; - swaps = fopen(PROC_SWAPS, "r"); + swaps = fopen(_PATH_PROC_SWAPS, "r"); if (swaps == NULL) return; /* nothing wrong */ /* skip the first line */ if (!fgets(line, sizeof(line), swaps)) { fprintf (stderr, _("%s: %s: unexpected file format\n"), - progname, PROC_SWAPS); + progname, _PATH_PROC_SWAPS); fclose(swaps); return; } @@ -161,9 +161,9 @@ display_summary(void) FILE *swaps; char line[1024] ; - if ((swaps = fopen(PROC_SWAPS, "r")) == NULL) { + if ((swaps = fopen(_PATH_PROC_SWAPS, "r")) == NULL) { int errsv = errno; - fprintf(stderr, "%s: %s: %s\n", progname, PROC_SWAPS, + fprintf(stderr, "%s: %s: %s\n", progname, _PATH_PROC_SWAPS, strerror(errsv)); return -1; } @@ -313,11 +313,11 @@ swapon_all(void) { read_proc_swaps(); - fp = setmntent(_PATH_FSTAB, "r"); + fp = setmntent(_PATH_MNTTAB, "r"); if (fp == NULL) { int errsv = errno; fprintf(stderr, _("%s: cannot open %s: %s\n"), - progname, _PATH_FSTAB, strerror(errsv)); + progname, _PATH_MNTTAB, strerror(errsv)); exit(2); } @@ -504,11 +504,11 @@ main_swapoff(int argc, char *argv[]) { * Probably it was unmounted already, so errors are not bad. * Doing swapoff -a twice should not give error messages. */ - fp = setmntent(_PATH_FSTAB, "r"); + fp = setmntent(_PATH_MNTTAB, "r"); if (fp == NULL) { int errsv = errno; fprintf(stderr, _("%s: cannot open %s: %s\n"), - progname, _PATH_FSTAB, strerror(errsv)); + progname, _PATH_MNTTAB, strerror(errsv)); exit(2); } while ((fstab = getmntent(fp)) != NULL) { diff --git a/tests/expected/ts-mount-paths b/tests/expected/ts-mount-paths index 6de4ece3..b292fb06 100644 --- a/tests/expected/ts-mount-paths +++ b/tests/expected/ts-mount-paths @@ -1,4 +1,5 @@ mount: fstab path: "/etc/fstab" +mount: mtab path: "/etc/mtab" mount: lock path: "/etc/mtab~" mount: temp path: "/etc/mtab.tmp" mount: no LABEL=, no UUID=, going to mount /dev/dummy by path diff --git a/tests/expected/ts-mount-special b/tests/expected/ts-mount-special index 0e97aa01..0d8e079b 100644 --- a/tests/expected/ts-mount-special +++ b/tests/expected/ts-mount-special @@ -1,4 +1,5 @@ mount: fstab path: "/etc/fstab" +mount: mtab path: "/etc/mtab" mount: lock path: "/etc/mtab~" mount: temp path: "/etc/mtab.tmp" mount: no LABEL=, no UUID=, going to mount /foo by path