summaryrefslogtreecommitdiffstats
path: root/mount
diff options
context:
space:
mode:
authorKarel Zak2009-02-03 22:12:03 +0100
committerKarel Zak2009-02-11 23:55:51 +0100
commit74a9c6f7b709cb2c3e3863cb91ed1c869a25da84 (patch)
treed34c59a70ec060a556f0c22174bf3c21c5be7f24 /mount
parentblkid: fix typo (syntax error) (diff)
downloadkernel-qcow2-util-linux-74a9c6f7b709cb2c3e3863cb91ed1c869a25da84.tar.gz
kernel-qcow2-util-linux-74a9c6f7b709cb2c3e3863cb91ed1c869a25da84.tar.xz
kernel-qcow2-util-linux-74a9c6f7b709cb2c3e3863cb91ed1c869a25da84.zip
mount: move realpath.c code to lib/
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'mount')
-rw-r--r--mount/Makefile.am21
-rw-r--r--mount/fsprobe.c1
-rw-r--r--mount/fsprobe_volumeid.c1
-rw-r--r--mount/fstab.c5
-rw-r--r--mount/lomount.c1
-rw-r--r--mount/mount.c1
-rw-r--r--mount/realpath.c177
-rw-r--r--mount/realpath.h14
-rw-r--r--mount/sundries.c48
-rw-r--r--mount/sundries.h5
-rw-r--r--mount/swapon.c1
-rw-r--r--mount/umount.c1
12 files changed, 64 insertions, 212 deletions
diff --git a/mount/Makefile.am b/mount/Makefile.am
index 3963fdaf6..90d956ebf 100644
--- a/mount/Makefile.am
+++ b/mount/Makefile.am
@@ -6,15 +6,15 @@ bin_PROGRAMS = mount umount
sbin_PROGRAMS = losetup swapon
dist_man_MANS = fstab.5 mount.8 swapoff.8 swapon.8 umount.8 losetup.8
-utils_common = sundries.c xmalloc.c realpath.c fsprobe.c
+utils_common = sundries.c xmalloc.c ../lib/canonicalize.c
headers_common = fstab.h mount_mntent.h mount_constants.h \
- lomount.h fsprobe.h realpath.h xmalloc.h \
+ lomount.h fsprobe.h xmalloc.h \
getusername.h loop.h sundries.h
mount_common = fstab.c mount_mntent.c getusername.c lomount.c \
$(utils_common) $(headers_common) ../lib/env.c ../lib/linux_version.c \
- ../lib/blkdev.c
+ ../lib/blkdev.c fsprobe.c
mount_SOURCES = mount.c $(mount_common) ../lib/setproctitle.c
mount_CFLAGS = $(SUID_CFLAGS) $(AM_CFLAGS)
@@ -25,10 +25,10 @@ umount_CFLAGS = $(SUID_CFLAGS) $(AM_CFLAGS)
umount_LDFLAGS = $(SUID_LDFLAGS) $(AM_LDFLAGS)
swapon_SOURCES = swapon.c swap_constants.h $(utils_common) \
- ../lib/linux_version.c ../lib/blkdev.c
+ ../lib/linux_version.c ../lib/blkdev.c fsprobe.c
-losetup_SOURCES = lomount.c sundries.c xmalloc.c realpath.c \
- loop.h lomount.h xmalloc.h sundries.h realpath.h
+losetup_SOURCES = lomount.c $(utils_common) \
+ loop.h lomount.h xmalloc.h sundries.h
losetup_CPPFLAGS = -DMAIN $(AM_CPPFLAGS)
mount_LDADD = $(LDADD_common)
@@ -61,7 +61,8 @@ losetup_static_CPPFLAGS = -DMAIN $(AM_CPPFLAGS)
endif
if HAVE_BLKID
-utils_common += fsprobe_blkid.c
+mount_common += fsprobe_blkid.c
+swapon_SOURCES += fsprobe_blkid.c
LDADD_common += $(BLKID_LIBS)
LDADD_common_static += $(BLKID_LIBS_STATIC)
endif
@@ -72,13 +73,15 @@ mount_static_LDADD += $(SELINUX_LIBS_STATIC)
endif
if HAVE_VOLUME_ID
-utils_common += fsprobe_volumeid.c
+mount_common += fsprobe_volumeid.c
+swapon_SOURCES += fsprobe_volumeid.c
LDADD_common += $(VOLUMEID_LIBS)
LDADD_common_static += $(VOLUMEID_LIBS_STATIC)
endif
noinst_PROGRAMS = mtab_lock_test
-mtab_lock_test_SOURCES = fstab.c sundries.c xmalloc.c $(headers_common)
+mtab_lock_test_SOURCES = fstab.c sundries.c xmalloc.c $(headers_common) \
+ ../lib/canonicalize.c
mtab_lock_test_CPPFLAGS = -DMAIN_TEST_MTABLOCK $(AM_CPPFLAGS)
install-exec-hook:
diff --git a/mount/fsprobe.c b/mount/fsprobe.c
index 07ffbd9ab..04e267f33 100644
--- a/mount/fsprobe.c
+++ b/mount/fsprobe.c
@@ -9,7 +9,6 @@
#include "fsprobe.h"
#include "sundries.h" /* for xstrdup */
#include "nls.h"
-#include "realpath.h"
/* list of already tested filesystems by fsprobe_procfsloop_mount() */
static struct tried {
diff --git a/mount/fsprobe_volumeid.c b/mount/fsprobe_volumeid.c
index b9b137b8a..a5c928230 100644
--- a/mount/fsprobe_volumeid.c
+++ b/mount/fsprobe_volumeid.c
@@ -12,7 +12,6 @@
#include "blkdev.h"
#include "fsprobe.h"
-#include "realpath.h"
#include "pathnames.h"
#include "sundries.h"
diff --git a/mount/fstab.c b/mount/fstab.c
index c60c5f4db..bcbc3a9db 100644
--- a/mount/fstab.c
+++ b/mount/fstab.c
@@ -19,7 +19,6 @@
#include "fsprobe.h"
#include "pathnames.h"
#include "nls.h"
-#include "realpath.h"
#define streq(s, t) (strcmp ((s), (t)) == 0)
@@ -924,10 +923,6 @@ mntFILE *my_setmntent (const char *file, char *mode) { return NULL; }
void my_endmntent (mntFILE *mfp) { }
int my_addmntent (mntFILE *mfp, struct my_mntent *mnt) { return 0; }
-char *canonicalize (const char *path) { return NULL; }
-char *canonicalize_spec (const char *path) { return NULL; }
-int is_pseudo_fs(const char *type) { return 0; };
-
int
main(int argc, char **argv)
{
diff --git a/mount/lomount.c b/mount/lomount.c
index 5675eac0a..ece0003e5 100644
--- a/mount/lomount.c
+++ b/mount/lomount.c
@@ -22,7 +22,6 @@
#include "nls.h"
#include "sundries.h"
#include "xmalloc.h"
-#include "realpath.h"
#include "pathnames.h"
#define SIZE(a) (sizeof(a)/sizeof(a[0]))
diff --git a/mount/mount.c b/mount/mount.c
index 23f27d676..e04dbdb51 100644
--- a/mount/mount.c
+++ b/mount/mount.c
@@ -40,7 +40,6 @@
#include "env.h"
#include "nls.h"
#include "blkdev.h"
-#include "realpath.h"
#define DO_PS_FIDDLING
diff --git a/mount/realpath.c b/mount/realpath.c
deleted file mode 100644
index 9b46951b5..000000000
--- a/mount/realpath.c
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * realpath.c -- canonicalize pathname by removing symlinks
- * Copyright (C) 1993 Rick Sladkey <jrs@world.std.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Library Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Library Public License for more details.
- */
-
-#define resolve_symlinks
-
-/*
- * This routine is part of libc. We include it nevertheless,
- * since the libc version has some security flaws.
- */
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include "realpath.h"
-#include "sundries.h" /* for xstrdup */
-
-#ifndef MAXSYMLINKS
-# define MAXSYMLINKS 256
-#endif
-
-int
-is_pseudo_fs(const char *type)
-{
- if (type == NULL || *type == '/')
- return 0;
- if (streq(type, "none") ||
- streq(type, "proc") ||
- streq(type, "tmpfs") ||
- streq(type, "sysfs") ||
- streq(type, "devpts"))
- return 1;
- return 0;
-}
-
-/* Make a canonical pathname from PATH. Returns a freshly malloced string.
- It is up the *caller* to ensure that the PATH is sensible. i.e.
- canonicalize ("/dev/fd0/.") returns "/dev/fd0" even though ``/dev/fd0/.''
- is not a legal pathname for ``/dev/fd0''. Anything we cannot parse
- we return unmodified. */
-char *
-canonicalize_spec (const char *path)
-{
- if (path == NULL)
- return NULL;
- if (is_pseudo_fs(path))
- return xstrdup(path);
- return canonicalize(path);
-}
-
-char *
-canonicalize (const char *path) {
- char canonical[PATH_MAX+2];
-
- if (path == NULL)
- return NULL;
-
- if (myrealpath (path, canonical, PATH_MAX+1))
- return xstrdup(canonical);
-
- return xstrdup(path);
-}
-
-char *
-myrealpath(const char *path, char *resolved_path, int maxreslth) {
- int readlinks = 0;
- char *npath;
- char link_path[PATH_MAX+1];
- int n;
- char *buf = NULL;
-
- npath = resolved_path;
-
- /* If it's a relative pathname use getcwd for starters. */
- if (*path != '/') {
- if (!getcwd(npath, maxreslth-2))
- return NULL;
- npath += strlen(npath);
- if (npath[-1] != '/')
- *npath++ = '/';
- } else {
- *npath++ = '/';
- path++;
- }
-
- /* Expand each slash-separated pathname component. */
- while (*path != '\0') {
- /* Ignore stray "/" */
- if (*path == '/') {
- path++;
- continue;
- }
- if (*path == '.' && (path[1] == '\0' || path[1] == '/')) {
- /* Ignore "." */
- path++;
- continue;
- }
- if (*path == '.' && path[1] == '.' &&
- (path[2] == '\0' || path[2] == '/')) {
- /* Backup for ".." */
- path += 2;
- while (npath > resolved_path+1 &&
- (--npath)[-1] != '/')
- ;
- continue;
- }
- /* Safely copy the next pathname component. */
- while (*path != '\0' && *path != '/') {
- if (npath-resolved_path > maxreslth-2) {
- errno = ENAMETOOLONG;
- goto err;
- }
- *npath++ = *path++;
- }
-
- /* Protect against infinite loops. */
- if (readlinks++ > MAXSYMLINKS) {
- errno = ELOOP;
- goto err;
- }
-
- /* See if last pathname component is a symlink. */
- *npath = '\0';
- n = readlink(resolved_path, link_path, PATH_MAX);
- if (n < 0) {
- /* EINVAL means the file exists but isn't a symlink. */
- if (errno != EINVAL)
- goto err;
- } else {
-#ifdef resolve_symlinks /* Richard Gooch dislikes sl resolution */
- int m;
- char *newbuf;
-
- /* Note: readlink doesn't add the null byte. */
- link_path[n] = '\0';
- if (*link_path == '/')
- /* Start over for an absolute symlink. */
- npath = resolved_path;
- else
- /* Otherwise back up over this component. */
- while (*(--npath) != '/')
- ;
-
- /* Insert symlink contents into path. */
- m = strlen(path);
- newbuf = xmalloc(m + n + 1);
- memcpy(newbuf, link_path, n);
- memcpy(newbuf + n, path, m + 1);
- free(buf);
- path = buf = newbuf;
-#endif
- }
- *npath++ = '/';
- }
- /* Delete trailing slash but don't whomp a lone slash. */
- if (npath != resolved_path+1 && npath[-1] == '/')
- npath--;
- /* Make sure it's null terminated. */
- *npath = '\0';
-
- free(buf);
- return resolved_path;
-
- err:
- free(buf);
- return NULL;
-}
diff --git a/mount/realpath.h b/mount/realpath.h
deleted file mode 100644
index 15450c1d7..000000000
--- a/mount/realpath.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef REALPATH_H
-#define REALPATH_H
-
-#include <limits.h>
-#ifndef PATH_MAX
-# define PATH_MAX 4096
-#endif
-
-extern char *myrealpath(const char *path, char *resolved_path, int m);
-extern char *canonicalize (const char *path);
-extern char *canonicalize_spec (const char *path);
-extern int is_pseudo_fs(const char *type);
-
-#endif /* REALPATH_H */
diff --git a/mount/sundries.c b/mount/sundries.c
index fad8eaec6..bdaf11722 100644
--- a/mount/sundries.c
+++ b/mount/sundries.c
@@ -11,9 +11,11 @@
#include <stdio.h>
#include <string.h>
#include <mntent.h> /* for MNTTYPE_SWAP */
+
+#include "canonicalize.h"
+
#include "fstab.h"
#include "sundries.h"
-#include "realpath.h"
#include "xmalloc.h"
#include "nls.h"
@@ -276,3 +278,47 @@ parse_spec(const char *spec, char **name, char **value)
return 0;
}
+int
+is_pseudo_fs(const char *type)
+{
+ if (type == NULL || *type == '/')
+ return 0;
+ if (streq(type, "none") ||
+ streq(type, "proc") ||
+ streq(type, "tmpfs") ||
+ streq(type, "sysfs") ||
+ streq(type, "devpts"))
+ return 1;
+ return 0;
+}
+
+/* Make a canonical pathname from PATH. Returns a freshly malloced string.
+ It is up the *caller* to ensure that the PATH is sensible. i.e.
+ canonicalize ("/dev/fd0/.") returns "/dev/fd0" even though ``/dev/fd0/.''
+ is not a legal pathname for ``/dev/fd0''. Anything we cannot parse
+ we return unmodified. */
+char *
+canonicalize_spec (const char *path)
+{
+ char *res;
+
+ if (path == NULL)
+ return NULL;
+ if (is_pseudo_fs(path))
+ return xstrdup(path);
+
+ res = canonicalize_path(path);
+ if (!res)
+ die(EX_SYSERR, _("not enough memory"));
+ return res;
+}
+
+char *canonicalize (const char *path)
+{
+ char *res = canonicalize_path(path);
+
+ if (!res)
+ die(EX_SYSERR, _("not enough memory"));
+ return res;
+}
+
diff --git a/mount/sundries.h b/mount/sundries.h
index f64d15dbd..c85701287 100644
--- a/mount/sundries.h
+++ b/mount/sundries.h
@@ -37,6 +37,11 @@ char *xstrconcat4 (char *, const char *, const char *, const char *);
int parse_spec(const char *spec, char **name, char **value);
+int is_pseudo_fs(const char *type);
+
+char *canonicalize (const char *path);
+char *canonicalize_spec (const char *path);
+
/* exit status - bits below are ORed */
#define EX_USAGE 1 /* incorrect invocation or permission */
#define EX_SYSERR 2 /* out of memory, cannot fork, ... */
diff --git a/mount/swapon.c b/mount/swapon.c
index 0d5067e04..c50c32ae5 100644
--- a/mount/swapon.c
+++ b/mount/swapon.c
@@ -20,7 +20,6 @@
#include "swap_constants.h"
#include "nls.h"
#include "fsprobe.h"
-#include "realpath.h"
#include "pathnames.h"
#include "sundries.h"
#include "swapheader.h"
diff --git a/mount/umount.c b/mount/umount.c
index 738d05c31..9901a809e 100644
--- a/mount/umount.c
+++ b/mount/umount.c
@@ -19,7 +19,6 @@
#include "fstab.h"
#include "env.h"
#include "nls.h"
-#include "realpath.h"
#if defined(MNT_FORCE)
/* Interesting ... it seems libc knows about MNT_FORCE and presumably