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 \
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include "mount_paths.h"
+#include "pathnames.h"
#include "fsprobe.h"
#include "sundries.h" /* for xstrdup */
#include "nls.h"
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)
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;
}
*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)
#include "fsprobe.h"
#include "realpath.h"
-#include "mount_paths.h"
+#include "pathnames.h"
#include "sundries.h"
enum probe_type {
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);
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);
#include <sys/stat.h>
#include <sys/time.h>
#include <time.h>
+#include <mntent.h>
#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;
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;
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;
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);
}
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;
/*
* 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;
/*
* 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;
if (we_created_lockfile) {
close(lockfile_fd);
lockfile_fd = -1;
- unlink (MOUNTED_LOCK);
+ unlink (_PATH_MOUNTED_LOCK);
we_created_lockfile = 0;
}
}
/* 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~.<pid> 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
struct flock flock;
int errsv, j;
- j = link(linktargetfile, MOUNTED_LOCK);
+ j = link(linktargetfile, _PATH_MOUNTED_LOCK);
errsv = errno;
if (j == 0)
(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? */
(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;
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 */
}
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);
(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);
}
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;
}
/* 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;
}
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));
}
}
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;
}
* 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;
}
}
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:
#include <sys/mount.h>
#include <mntent.h>
-#include <paths.h>
#ifdef HAVE_LIBSELINUX
#include <selinux/selinux.h>
#include <selinux/context.h>
#endif
+#include "pathnames.h"
#include "fsprobe.h"
#include "mount_constants.h"
#include "sundries.h"
#include "lomount.h"
#include "loop.h"
#include "getusername.h"
-#include "mount_paths.h"
#include "env.h"
#include "nls.h"
#include "blkdev.h"
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 */
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)
int errsv = errno;
die (EX_FILEIO,
_("mount: error changing mode of %s: %s"),
- MOUNTED, strerror (errsv));
+ _PATH_MOUNTED, strerror (errsv));
}
my_endmntent (mfp);
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
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);
}
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;
if (!nomtab && mtab_does_not_exist()) {
if (verbose > 1)
printf(_("mount: no %s found - creating it..\n"),
- MOUNTED);
+ _PATH_MOUNTED);
create_mtab ();
}
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),
+++ /dev/null
-#ifndef MOUNT_PATHS_H
-#define MOUNT_PATHS_H
-
-#include <mntent.h>
-
-#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 */
#include "nls.h"
#include "fsprobe.h"
#include "realpath.h"
-#include "mount_paths.h"
+#include "pathnames.h"
#ifdef HAVE_SYS_SWAP_H
# include <sys/swap.h>
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;
}
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;
}
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);
}
* 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) {
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
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