summaryrefslogtreecommitdiffstats
path: root/mount
diff options
context:
space:
mode:
authorKarel Zak2007-10-22 15:49:26 +0200
committerKarel Zak2007-10-25 21:50:59 +0200
commit89fde75b38cf8c99c1cc5c6b6c206de521e551f4 (patch)
tree51fcd85dad2bc9421e619ec696f8795cdae235f5 /mount
parentdocs: add info about .bugfix releases and branches (diff)
downloadkernel-qcow2-util-linux-89fde75b38cf8c99c1cc5c6b6c206de521e551f4.tar.gz
kernel-qcow2-util-linux-89fde75b38cf8c99c1cc5c6b6c206de521e551f4.tar.xz
kernel-qcow2-util-linux-89fde75b38cf8c99c1cc5c6b6c206de521e551f4.zip
mount: cleanup canonicalize() usage
This patch renames canonicalize() to canonicalize_mountpoint() and moves this function to realpath.c where is all cannonicalize code. The canonicalize_mountpoint() function checks for special "none", "proc", "swap" pseudo mointpoint. The patch also adds a new generic canonicalize() function. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'mount')
-rw-r--r--mount/fsprobe.c1
-rw-r--r--mount/fstab.c9
-rw-r--r--mount/mount.c5
-rw-r--r--mount/realpath.c32
-rw-r--r--mount/realpath.h2
-rw-r--r--mount/sundries.c25
-rw-r--r--mount/sundries.h1
-rw-r--r--mount/umount.c1
8 files changed, 45 insertions, 31 deletions
diff --git a/mount/fsprobe.c b/mount/fsprobe.c
index 9be16fcb8..9808fbeba 100644
--- a/mount/fsprobe.c
+++ b/mount/fsprobe.c
@@ -10,6 +10,7 @@
#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/fstab.c b/mount/fstab.c
index 694f4a66a..4d045cea0 100644
--- a/mount/fstab.c
+++ b/mount/fstab.c
@@ -18,6 +18,7 @@
#include "fsprobe.h"
#include "mount_paths.h"
#include "nls.h"
+#include "realpath.h"
#define streq(s, t) (strcmp ((s), (t)) == 0)
@@ -325,7 +326,7 @@ getfs_by_specdir (const char *spec, const char *dir) {
for (mc = mc0->nxt; mc && mc != mc0; mc = mc->nxt) {
/* dir */
if (!streq(mc->m.mnt_dir, dir)) {
- char *dr = canonicalize(mc->m.mnt_dir);
+ char *dr = canonicalize_mountpoint(mc->m.mnt_dir);
int ok = 0;
if (streq(dr, dir))
@@ -371,7 +372,7 @@ getfs_by_dir (const char *dir) {
if (streq(mc->m.mnt_dir, dir))
return mc;
- cdir = canonicalize(dir);
+ cdir = canonicalize_mountpoint(dir);
for (mc = mc0->nxt; mc && mc != mc0; mc = mc->nxt) {
if (streq(mc->m.mnt_dir, cdir)) {
free(cdir);
@@ -823,7 +824,9 @@ struct my_mntent *my_getmntent (mntFILE *mfp) { return NULL; }
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 *myrealpath(const char *path, char *resolved_path, int m) { return NULL; }
+
+char *canonicalize (const char *path) { return NULL; }
+char *canonicalize_mountpoint (const char *path) { return NULL; }
int
main(int argc, char **argv)
diff --git a/mount/mount.c b/mount/mount.c
index b65ee62ce..42f87b03e 100644
--- a/mount/mount.c
+++ b/mount/mount.c
@@ -42,6 +42,7 @@
#include "mount_paths.h"
#include "env.h"
#include "nls.h"
+#include "realpath.h"
#define DO_PS_FIDDLING
@@ -926,7 +927,7 @@ update_mtab_entry(const char *spec, const char *node, const char *type,
struct my_mntent mnt;
mnt.mnt_fsname = canonicalize (spec);
- mnt.mnt_dir = canonicalize (node);
+ mnt.mnt_dir = canonicalize_mountpoint (node);
mnt.mnt_type = type;
mnt.mnt_opts = opts;
mnt.mnt_freq = freq;
@@ -1451,7 +1452,7 @@ mounted (const char *spec0, const char *node0) {
return ret;
spec = canonicalize(spec0);
- node = canonicalize(node0);
+ node = canonicalize_mountpoint(node0);
mc0 = mtab_head();
for (mc = mc0->nxt; mc && mc != mc0; mc = mc->nxt)
diff --git a/mount/realpath.c b/mount/realpath.c
index d659685a8..fdb15b7cd 100644
--- a/mount/realpath.c
+++ b/mount/realpath.c
@@ -29,6 +29,38 @@
# define MAXSYMLINKS 256
#endif
+
+/* 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_mountpoint (const char *path) {
+ if (path == NULL)
+ return NULL;
+
+ if (streq(path, "none") ||
+ streq(path, "proc") ||
+ streq(path, "devpts"))
+ 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;
diff --git a/mount/realpath.h b/mount/realpath.h
index 016fc4849..a8fad639a 100644
--- a/mount/realpath.h
+++ b/mount/realpath.h
@@ -7,5 +7,7 @@
#endif
extern char *myrealpath(const char *path, char *resolved_path, int m);
+extern char *canonicalize (const char *path);
+extern char *canonicalize_mountpoint (const char *path);
#endif /* REALPATH_H */
diff --git a/mount/sundries.c b/mount/sundries.c
index 45404c5cf..1669554c0 100644
--- a/mount/sundries.c
+++ b/mount/sundries.c
@@ -224,31 +224,6 @@ matching_opts (const char *options, const char *test_opts) {
return 1;
}
-/* 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 (const char *path) {
- char canonical[PATH_MAX+2];
-
- if (path == NULL)
- return NULL;
-
-#if 1
- if (streq(path, "none") ||
- streq(path, "proc") ||
- streq(path, "devpts"))
- return xstrdup(path);
-#endif
- if (myrealpath (path, canonical, PATH_MAX+1))
- return xstrdup(canonical);
-
- return xstrdup(path);
-}
-
-
/*
* Parses NAME=value, returns -1 on parse error, 0 success. The success is also
* when the 'spec' doesn't contain name=value pair (because the spec could be
diff --git a/mount/sundries.h b/mount/sundries.h
index 95d4bea7a..3d6a1bd22 100644
--- a/mount/sundries.h
+++ b/mount/sundries.h
@@ -24,7 +24,6 @@ extern int sloppy;
/* Functions in sundries.c that are used in mount.c and umount.c */
void block_signals (int how);
-char *canonicalize (const char *path);
void error (const char *fmt, ...);
int matching_type (const char *type, const char *types);
int matching_opts (const char *options, const char *test_opts);
diff --git a/mount/umount.c b/mount/umount.c
index 6af43546e..4327dd70d 100644
--- a/mount/umount.c
+++ b/mount/umount.c
@@ -19,6 +19,7 @@
#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