Git init
[external/busybox.git] / debian / patches / u-mount-FreeBSD-support.patch
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
5
6
7 Signed-off-by: Jeremie Koenig <jk@jk.fr.eu.org>
8 ---
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
18
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
24  config MOUNT
25         bool "mount"
26         default y
27 -       depends on PLATFORM_LINUX
28         help
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
32  config UMOUNT
33         bool "umount"
34         default y
35 -       depends on PLATFORM_LINUX
36         help
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"
42         default y
43 -       depends on MOUNT || UMOUNT
44 +       depends on (MOUNT || UMOUNT) && PLATFORM_LINUX
45         help
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
71 @@ -18,44 +18,9 @@
72  //
73  #include <mntent.h>
74  #include <syslog.h>
75 -#include <sys/mount.h>
76 -// Grab more as needed from util-linux's mount/mount_constants.h
77 -#ifndef MS_DIRSYNC
78 -# define MS_DIRSYNC     (1 << 7) // Directory modifications are synchronous
79 -#endif
80 -#ifndef MS_UNION
81 -# define MS_UNION       (1 << 8)
82 -#endif
83 -#ifndef MS_BIND
84 -# define MS_BIND        (1 << 12)
85 -#endif
86 -#ifndef MS_MOVE
87 -# define MS_MOVE        (1 << 13)
88 -#endif
89 -#ifndef MS_RECURSIVE
90 -# define MS_RECURSIVE   (1 << 14)
91 -#endif
92 -#ifndef MS_SILENT
93 -# define MS_SILENT      (1 << 15)
94 -#endif
95 -// The shared subtree stuff, which went in around 2.6.15
96 -#ifndef MS_UNBINDABLE
97 -# define MS_UNBINDABLE  (1 << 17)
98 -#endif
99 -#ifndef MS_PRIVATE
100 -# define MS_PRIVATE     (1 << 18)
101 -#endif
102 -#ifndef MS_SLAVE
103 -# define MS_SLAVE       (1 << 19)
104 -#endif
105 -#ifndef MS_SHARED
106 -# define MS_SHARED      (1 << 20)
107 -#endif
108 -#ifndef MS_RELATIME
109 -# define MS_RELATIME    (1 << 21)
110 -#endif
111  
112  #include "libbb.h"
113 +#include "xmount.h"
114  #if ENABLE_FEATURE_MOUNT_LABEL
115  # include "volume_id.h"
116  #else
117 @@ -288,7 +253,7 @@ static int verbose_mount(const char *source, const char *target,
118         int rc;
119  
120         errno = 0;
121 -       rc = mount(source, target, filesystemtype, mountflags, data);
122 +       rc = xmount(source, target, filesystemtype, mountflags, data);
123         if (verbose >= 2)
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,
127         return rc;
128  }
129  #else
130 -#define verbose_mount(...) mount(__VA_ARGS__)
131 +#define verbose_mount(...) xmount(__VA_ARGS__)
132  #endif
133  
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
139 @@ -8,40 +8,9 @@
140   * Licensed under GPL version 2, see file LICENSE in this tarball for details.
141   */
142  #include <mntent.h>
143 -#include <sys/mount.h>
144 -/* Make sure we have all the new mount flags we actually try to use. */
145 -#ifndef MS_BIND
146 -# define MS_BIND        (1 << 12)
147 -#endif
148 -#ifndef MS_MOVE
149 -# define MS_MOVE        (1 << 13)
150 -#endif
151 -#ifndef MS_RECURSIVE
152 -# define MS_RECURSIVE   (1 << 14)
153 -#endif
154 -#ifndef MS_SILENT
155 -# define MS_SILENT      (1 << 15)
156 -#endif
157 -/* The shared subtree stuff, which went in around 2.6.15. */
158 -#ifndef MS_UNBINDABLE
159 -# define MS_UNBINDABLE  (1 << 17)
160 -#endif
161 -#ifndef MS_PRIVATE
162 -# define MS_PRIVATE     (1 << 18)
163 -#endif
164 -#ifndef MS_SLAVE
165 -# define MS_SLAVE       (1 << 19)
166 -#endif
167 -#ifndef MS_SHARED
168 -# define MS_SHARED      (1 << 20)
169 -#endif
170 -#ifndef MS_RELATIME
171 -# define MS_RELATIME    (1 << 21)
172 -#endif
173 +
174  #include "libbb.h"
175 -#ifndef PATH_MAX
176 -# define PATH_MAX (4*1024)
177 -#endif
178 +#include "xmount.h"
179  
180  
181  #if defined(__dietlibc__)
182 @@ -154,11 +123,11 @@ int umount_main(int argc UNUSED_PARAM, char **argv)
183                 if (m) zapit = m->dir;
184  
185                 // Let's ask the thing nicely to unmount.
186 -               curstat = umount(zapit);
187 +               curstat = xumount(zapit, 0);
188  
189                 // Force the unmount, if necessary.
190                 if (curstat && doForce)
191 -                       curstat = umount2(zapit, doForce);
192 +                       curstat = xumount(zapit, doForce);
193  
194                 // If still can't umount, maybe remount read-only?
195                 if (curstat) {
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);
202                                 if (curstat) {
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
206 new file mode 100644
207 index 0000000..3f322b8
208 --- /dev/null
209 +++ b/util-linux/xmount.c
210 @@ -0,0 +1,70 @@
211 +#include "libbb.h"
212 +#include "xmount.h"
213 +
214 +#ifdef __linux__
215 +
216 +/* xmount and xumount short-circuited to mount and umount2 in xmount.h */
217 +
218 +#elif defined(__FreeBSD_kernel__)
219 +
220 +static void build_iovec(struct iovec **iov, int *iovlen, const char *name,
221 +               void *val, size_t len)
222 +{
223 +       int i;
224 +
225 +       if (*iovlen < 0)
226 +               return;
227 +       i = *iovlen;
228 +       *iov = realloc(*iov, sizeof **iov * (i + 2));
229 +       if (*iov == NULL) {
230 +               *iovlen = -1;
231 +               return;
232 +       }
233 +       (*iov)[i].iov_base = strdup(name);
234 +       (*iov)[i].iov_len = strlen(name) + 1;
235 +       i++;
236 +       (*iov)[i].iov_base = val;
237 +       if (len == (size_t)-1) {
238 +               if (val != NULL)
239 +                       len = strlen(val) + 1;
240 +               else
241 +                       len = 0;
242 +       }
243 +       (*iov)[i].iov_len = (int)len;
244 +       *iovlen = ++i;
245 +}
246 +
247 +int FAST_FUNC xmount(const char *source, const char *target,
248 +               const char *filesystemtype, unsigned long mountflags,
249 +               const void *data UNUSED_PARAM)
250 +{
251 +       struct iovec *iov = NULL;
252 +       int iovlen = 0;
253 +       char *fspath, *from;
254 +       int ret;
255 +
256 +       fspath = realpath(target, NULL);
257 +       from = realpath(source, NULL);
258 +
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);
264 +       else
265 +               build_iovec(&iov, &iovlen, "from", from, (size_t)-1);
266 +
267 +       ret = nmount(iov, iovlen, mountflags);
268 +
269 +       free(from);
270 +       free(fspath);
271 +       
272 +       return ret;
273 +}
274 +
275 +int FAST_FUNC xumount(const char *target, int flags)
276 +{
277 +       return unmount(target, flags);
278 +}
279 +
280 +#endif
281 diff --git a/util-linux/xmount.h b/util-linux/xmount.h
282 new file mode 100644
283 index 0000000..caef564
284 --- /dev/null
285 +++ b/util-linux/xmount.h
286 @@ -0,0 +1,97 @@
287 +/* vi: set sw=4 ts=4: */
288 +/*
289 + * System-specific definitions for mount.
290 + *
291 + * Copyright (C) 2010 by Jeremie Koenig <jk@jk.fr.eu.org>
292 + * Copyright (C) 2010 by Luca Favatella <slackydeb@gmail.com>
293 + *
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).
297 + */
298 +
299 +/*
300 + * Definitions for mount flags. Non-Linux systems are free to use whatever
301 + * their version of xmount() will work with.
302 + */
303 +
304 +#ifdef __linux__
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). */
308 +# ifndef MS_DIRSYNC
309 +#  define MS_DIRSYNC     (1 << 7) // Directory modifications are synchronous
310 +# endif
311 +# ifndef MS_UNION
312 +#  define MS_UNION       (1 << 8)
313 +# endif
314 +# ifndef MS_BIND
315 +#  define MS_BIND        (1 << 12)
316 +# endif
317 +# ifndef MS_MOVE
318 +#  define MS_MOVE        (1 << 13)
319 +# endif
320 +# ifndef MS_RECURSIVE
321 +#  define MS_RECURSIVE   (1 << 14)
322 +# endif
323 +# ifndef MS_SILENT
324 +#  define MS_SILENT      (1 << 15)
325 +# endif
326 +/* The shared subtree stuff, which went in around 2.6.15. */
327 +# ifndef MS_UNBINDABLE
328 +#  define MS_UNBINDABLE  (1 << 17)
329 +# endif
330 +# ifndef MS_PRIVATE
331 +#  define MS_PRIVATE     (1 << 18)
332 +# endif
333 +# ifndef MS_SLAVE
334 +#  define MS_SLAVE       (1 << 19)
335 +# endif
336 +# ifndef MS_SHARED
337 +#  define MS_SHARED      (1 << 20)
338 +# endif
339 +# ifndef MS_RELATIME
340 +#  define MS_RELATIME    (1 << 21)
341 +# endif
342 +
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
356 +# define MS_BIND        0
357 +# define MS_MOVE        0
358 +# define MS_SHARED      0
359 +# define MS_SLAVE       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
365 +
366 +#else
367 +# error There is no xmount() implementation for your system.
368 +#endif
369 +
370 +/*
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).
374 + */
375 +
376 +#ifdef __linux__
377 +# define xmount mount
378 +# define xumount umount2
379 +#else
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;
383 +#endif
384 -- 
385 1.7.1
386