1 From 5a075618b1deb735a6170e322052c7ba54b17d9e Mon Sep 17 00:00:00 2001
2 From: Jeremie Koenig <jk@jk.fr.eu.org>
3 Date: Thu, 29 Jul 2010 21:16:09 +0200
4 Subject: [PATCH 18/19] (u)mount: FreeBSD support
7 Signed-off-by: Jeremie Koenig <jk@jk.fr.eu.org>
9 util-linux/Config.src | 4 +--
10 util-linux/Kbuild.src | 4 +-
11 util-linux/mount.c | 41 ++-------------------
12 util-linux/umount.c | 41 +++------------------
13 util-linux/xmount.c | 66 +++++++++++++++++++++++++++++++++
14 util-linux/xmount.h | 97 +++++++++++++++++++++++++++++++++++++++++++++++++
15 6 files changed, 174 insertions(+), 79 deletions(-)
16 create mode 100644 util-linux/xmount.c
17 create mode 100644 util-linux/xmount.h
19 diff --git a/util-linux/Config.src b/util-linux/Config.src
20 index 98953c1..99a6fbe 100644
21 --- a/util-linux/Config.src
22 +++ b/util-linux/Config.src
23 @@ -492,7 +492,6 @@ config FEATURE_USE_TERMIOS
27 - depends on PLATFORM_LINUX
29 All files and filesystems in Unix are arranged into one big directory
30 tree. The 'mount' utility is used to graft a filesystem onto a
31 @@ -679,7 +678,6 @@ config SWITCH_ROOT
35 - depends on PLATFORM_LINUX
37 When you want to remove a mounted filesystem from its current mount
38 point, for example when you are shutting down the system, the
39 @@ -699,7 +697,7 @@ comment "Common options for mount/umount"
40 config FEATURE_MOUNT_LOOP
41 bool "Support loopback mounts"
43 - depends on MOUNT || UMOUNT
44 + depends on (MOUNT || UMOUNT) && PLATFORM_LINUX
46 Enabling this feature allows automatic mounting of files (containing
47 filesystem images) via the linux kernel's loopback devices.
48 diff --git a/util-linux/Kbuild.src b/util-linux/Kbuild.src
49 index afc0db5..312fc9e 100644
50 --- a/util-linux/Kbuild.src
51 +++ b/util-linux/Kbuild.src
52 @@ -33,7 +33,7 @@ lib-$(CONFIG_MKFS_REISER) += mkfs_reiser.o
53 lib-$(CONFIG_MKFS_VFAT) += mkfs_vfat.o
54 lib-$(CONFIG_MKSWAP) += mkswap.o
55 lib-$(CONFIG_MORE) += more.o
56 -lib-$(CONFIG_MOUNT) += mount.o
57 +lib-$(CONFIG_MOUNT) += mount.o xmount.o
58 lib-$(CONFIG_PIVOT_ROOT) += pivot_root.o
59 lib-$(CONFIG_RDATE) += rdate.o
60 lib-$(CONFIG_RDEV) += rdev.o
61 @@ -44,4 +44,4 @@ lib-$(CONFIG_SCRIPTREPLAY) += scriptreplay.o
62 lib-$(CONFIG_SETARCH) += setarch.o
63 lib-$(CONFIG_SWAPONOFF) += swaponoff.o
64 lib-$(CONFIG_SWITCH_ROOT) += switch_root.o
65 -lib-$(CONFIG_UMOUNT) += umount.o
66 +lib-$(CONFIG_UMOUNT) += umount.o xmount.o
67 diff --git a/util-linux/mount.c b/util-linux/mount.c
68 index 9107e43..a62c4e8 100644
69 --- a/util-linux/mount.c
70 +++ b/util-linux/mount.c
75 -#include <sys/mount.h>
76 -// Grab more as needed from util-linux's mount/mount_constants.h
78 -# define MS_DIRSYNC (1 << 7) // Directory modifications are synchronous
81 -# define MS_UNION (1 << 8)
84 -# define MS_BIND (1 << 12)
87 -# define MS_MOVE (1 << 13)
90 -# define MS_RECURSIVE (1 << 14)
93 -# define MS_SILENT (1 << 15)
95 -// The shared subtree stuff, which went in around 2.6.15
96 -#ifndef MS_UNBINDABLE
97 -# define MS_UNBINDABLE (1 << 17)
100 -# define MS_PRIVATE (1 << 18)
103 -# define MS_SLAVE (1 << 19)
106 -# define MS_SHARED (1 << 20)
109 -# define MS_RELATIME (1 << 21)
114 #if ENABLE_FEATURE_MOUNT_LABEL
115 # include "volume_id.h"
117 @@ -288,7 +253,7 @@ static int verbose_mount(const char *source, const char *target,
121 - rc = mount(source, target, filesystemtype, mountflags, data);
122 + rc = xmount(source, target, filesystemtype, mountflags, data);
124 bb_perror_msg("mount('%s','%s','%s',0x%08lx,'%s'):%d",
125 source, target, filesystemtype,
126 @@ -296,7 +261,7 @@ static int verbose_mount(const char *source, const char *target,
130 -#define verbose_mount(...) mount(__VA_ARGS__)
131 +#define verbose_mount(...) xmount(__VA_ARGS__)
134 // Append mount options to string
135 diff --git a/util-linux/umount.c b/util-linux/umount.c
136 index a19f86c..781e019 100644
137 --- a/util-linux/umount.c
138 +++ b/util-linux/umount.c
140 * Licensed under GPL version 2, see file LICENSE in this tarball for details.
143 -#include <sys/mount.h>
144 -/* Make sure we have all the new mount flags we actually try to use. */
146 -# define MS_BIND (1 << 12)
149 -# define MS_MOVE (1 << 13)
151 -#ifndef MS_RECURSIVE
152 -# define MS_RECURSIVE (1 << 14)
155 -# define MS_SILENT (1 << 15)
157 -/* The shared subtree stuff, which went in around 2.6.15. */
158 -#ifndef MS_UNBINDABLE
159 -# define MS_UNBINDABLE (1 << 17)
162 -# define MS_PRIVATE (1 << 18)
165 -# define MS_SLAVE (1 << 19)
168 -# define MS_SHARED (1 << 20)
171 -# define MS_RELATIME (1 << 21)
176 -# define PATH_MAX (4*1024)
181 #if defined(__dietlibc__)
182 @@ -154,11 +123,11 @@ int umount_main(int argc UNUSED_PARAM, char **argv)
183 if (m) zapit = m->dir;
185 // Let's ask the thing nicely to unmount.
186 - curstat = umount(zapit);
187 + curstat = xumount(zapit, 0);
189 // Force the unmount, if necessary.
190 if (curstat && doForce)
191 - curstat = umount2(zapit, doForce);
192 + curstat = xumount(zapit, doForce);
194 // If still can't umount, maybe remount read-only?
196 @@ -166,7 +135,7 @@ int umount_main(int argc UNUSED_PARAM, char **argv)
197 // Note! Even if we succeed here, later we should not
198 // free loop device or erase mtab entry!
199 const char *msg = "%s busy - remounted read-only";
200 - curstat = mount(m->device, zapit, NULL, MS_REMOUNT|MS_RDONLY, NULL);
201 + curstat = xmount(m->device, zapit, NULL, MS_REMOUNT|MS_RDONLY, NULL);
203 msg = "can't remount %s read-only";
204 status = EXIT_FAILURE;
205 diff --git a/util-linux/xmount.c b/util-linux/xmount.c
207 index 0000000..3f322b8
209 +++ b/util-linux/xmount.c
216 +/* xmount and xumount short-circuited to mount and umount2 in xmount.h */
218 +#elif defined(__FreeBSD_kernel__)
220 +static void build_iovec(struct iovec **iov, int *iovlen, const char *name,
221 + void *val, size_t len)
228 + *iov = realloc(*iov, sizeof **iov * (i + 2));
229 + if (*iov == NULL) {
233 + (*iov)[i].iov_base = strdup(name);
234 + (*iov)[i].iov_len = strlen(name) + 1;
236 + (*iov)[i].iov_base = val;
237 + if (len == (size_t)-1) {
239 + len = strlen(val) + 1;
243 + (*iov)[i].iov_len = (int)len;
247 +int FAST_FUNC xmount(const char *source, const char *target,
248 + const char *filesystemtype, unsigned long mountflags,
249 + const void *data UNUSED_PARAM)
251 + struct iovec *iov = NULL;
253 + char *fspath, *from;
256 + fspath = realpath(target, NULL);
257 + from = realpath(source, NULL);
259 + build_iovec(&iov, &iovlen, "fstype", (void*)filesystemtype, (size_t)-1);
260 + build_iovec(&iov, &iovlen, "fspath", fspath, (size_t)-1);
261 + if (!strcmp(filesystemtype, "nullfs"))
262 + /* nullfs uses a "target" instead of "from" */
263 + build_iovec(&iov, &iovlen, "target", from, (size_t)-1);
265 + build_iovec(&iov, &iovlen, "from", from, (size_t)-1);
267 + ret = nmount(iov, iovlen, mountflags);
275 +int FAST_FUNC xumount(const char *target, int flags)
277 + return unmount(target, flags);
281 diff --git a/util-linux/xmount.h b/util-linux/xmount.h
283 index 0000000..caef564
285 +++ b/util-linux/xmount.h
287 +/* vi: set sw=4 ts=4: */
289 + * System-specific definitions for mount.
291 + * Copyright (C) 2010 by Jeremie Koenig <jk@jk.fr.eu.org>
292 + * Copyright (C) 2010 by Luca Favatella <slackydeb@gmail.com>
294 + * The Linux prototypes for mount() and umount2() are used as a reference for
295 + * our xmount() and xumount(), which should be implemented as a compatibility
296 + * wrappers for non-Linux systems (see xmount.c).
300 + * Definitions for mount flags. Non-Linux systems are free to use whatever
301 + * their version of xmount() will work with.
305 +# include <sys/mount.h>
306 +/* Make sure we have all the new mount flags we actually try to use
307 + * (grab more as needed from util-linux's mount/mount_constants.h). */
309 +# define MS_DIRSYNC (1 << 7) // Directory modifications are synchronous
312 +# define MS_UNION (1 << 8)
315 +# define MS_BIND (1 << 12)
318 +# define MS_MOVE (1 << 13)
320 +# ifndef MS_RECURSIVE
321 +# define MS_RECURSIVE (1 << 14)
324 +# define MS_SILENT (1 << 15)
326 +/* The shared subtree stuff, which went in around 2.6.15. */
327 +# ifndef MS_UNBINDABLE
328 +# define MS_UNBINDABLE (1 << 17)
331 +# define MS_PRIVATE (1 << 18)
334 +# define MS_SLAVE (1 << 19)
337 +# define MS_SHARED (1 << 20)
339 +# ifndef MS_RELATIME
340 +# define MS_RELATIME (1 << 21)
343 +#elif defined(__FreeBSD_kernel__)
344 +# include <sys/mount.h>
345 +# define MS_NOSUID MNT_NOSUID
346 +# define MS_NODEV MNT_NODEV
347 +# define MS_NOEXEC MNT_NOEXEC
348 +# define MS_SYNCHRONOUS MNT_SYNCHRONOUS
349 +# define MS_DIRSYNC 0
350 +# define MS_NOATIME MNT_NOATIME
351 +# define MS_NODIRATIME 0
352 +# define MS_MANDLOCK 0
353 +# define MS_RELATIME 0
354 +# define MS_SILENT 0
355 +# define MS_UNION MNT_UNION
358 +# define MS_SHARED 0
360 +# define MS_PRIVATE 0
361 +# define MS_UNBINDABLE 0
362 +# define MS_RECURSIVE 0
363 +# define MS_RDONLY MNT_RDONLY
364 +# define MS_REMOUNT MNT_UPDATE
367 +# error There is no xmount() implementation for your system.
371 + * Prototypes for xmount() and xumount(): on Linux we use the system calls
372 + * directly, otherwise xmount() and xumount() should be implemented as
373 + * compatibility wrappers (see xmount.c).
377 +# define xmount mount
378 +# define xumount umount2
380 +int xmount(const char *source, const char *target, const char *filesystemtype,
381 + unsigned long mountflags, const void *data) FAST_FUNC;
382 +int xumount(const char *target, int flags) FAST_FUNC;