da273f513ab7e8e2dae166ffed1357385b2e6ad4
[external/busybox.git] / packaging / swaponoff-FreeBSD-support.patch
1 From a5b837c34a96bdbb53151af455912b691c9aaa52 Mon Sep 17 00:00:00 2001
2 From: Jeremie Koenig <jk@jk.fr.eu.org>
3 Date: Thu, 29 Jul 2010 21:59:54 +0200
4 Subject: [PATCH 19/19] swaponoff: FreeBSD support
5
6
7 Signed-off-by: Jeremie Koenig <jk@jk.fr.eu.org>
8 ---
9  util-linux/Config.src  |    3 +--
10  util-linux/swaponoff.c |    6 +++---
11  util-linux/xmount.c    |   10 ++++++++++
12  util-linux/xmount.h    |   16 ++++++++++------
13  4 files changed, 24 insertions(+), 11 deletions(-)
14
15 diff --git a/util-linux/Config.src b/util-linux/Config.src
16 index 99a6fbe..cb4de95 100644
17 --- a/util-linux/Config.src
18 +++ b/util-linux/Config.src
19 @@ -639,7 +639,6 @@ config SETARCH
20  config SWAPONOFF
21         bool "swaponoff"
22         default y
23 -       depends on PLATFORM_LINUX
24         help
25           This option enables both the 'swapon' and the 'swapoff' utilities.
26           Once you have created some swap space using 'mkswap', you also need
27 @@ -651,7 +650,7 @@ config SWAPONOFF
28  config FEATURE_SWAPON_PRI
29         bool "Support priority option -p"
30         default y
31 -       depends on SWAPONOFF
32 +       depends on SWAPONOFF && PLATFORM_LINUX
33         help
34           Enable support for setting swap device priority in swapon.
35  
36 diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c
37 index f2f52fb..d13c37e 100644
38 --- a/util-linux/swaponoff.c
39 +++ b/util-linux/swaponoff.c
40 @@ -8,8 +8,8 @@
41   */
42  
43  #include "libbb.h"
44 +#include "xmount.h"
45  #include <mntent.h>
46 -#include <sys/swap.h>
47  
48  #if ENABLE_FEATURE_MOUNT_LABEL
49  # include "volume_id.h"
50 @@ -43,9 +43,9 @@ static int swap_enable_disable(char *device)
51  #endif
52  
53         if (applet_name[5] == 'n')
54 -               status = swapon(device, g_flags);
55 +               status = xswapon(device, g_flags);
56         else
57 -               status = swapoff(device);
58 +               status = xswapoff(device);
59  
60         if (status != 0) {
61                 bb_simple_perror_msg(device);
62 diff --git a/util-linux/xmount.c b/util-linux/xmount.c
63 index 3f322b8..16543f1 100644
64 --- a/util-linux/xmount.c
65 +++ b/util-linux/xmount.c
66 @@ -63,4 +63,14 @@ int FAST_FUNC xumount(const char *target, int flags)
67         return unmount(target, flags);
68  }
69  
70 +int FAST_FUNC xswapon(const char *path, int swapflags UNUSED_PARAM)
71 +{
72 +       return swapon(path);
73 +}
74 +
75 +int FAST_FUNC xswapoff(const char *path)
76 +{
77 +       return swapoff(path);
78 +}
79 +
80  #endif
81 diff --git a/util-linux/xmount.h b/util-linux/xmount.h
82 index caef564..bcd6d18 100644
83 --- a/util-linux/xmount.h
84 +++ b/util-linux/xmount.h
85 @@ -5,9 +5,9 @@
86   * Copyright (C) 2010 by Jeremie Koenig <jk@jk.fr.eu.org>
87   * Copyright (C) 2010 by Luca Favatella <slackydeb@gmail.com>
88   *
89 - * The Linux prototypes for mount() and umount2() are used as a reference for
90 - * our xmount() and xumount(), which should be implemented as a compatibility
91 - * wrappers for non-Linux systems (see xmount.c).
92 + * The Linux prototypes for mount(), umount2(), swapon() and swapoff()  are
93 + * used as a reference for our versions of them. On non-Linux system those
94 + * should be implemented as compatibility wrappers (see xmount.c).
95   */
96  
97  /*
98 @@ -17,6 +17,7 @@
99  
100  #ifdef __linux__
101  # include <sys/mount.h>
102 +# include <sys/swap.h>
103  /* Make sure we have all the new mount flags we actually try to use
104   * (grab more as needed from util-linux's mount/mount_constants.h). */
105  # ifndef MS_DIRSYNC
106 @@ -56,6 +57,7 @@
107  
108  #elif defined(__FreeBSD_kernel__)
109  # include <sys/mount.h>
110 +# include <sys/swap.h>
111  # define MS_NOSUID      MNT_NOSUID
112  # define MS_NODEV       MNT_NODEV
113  # define MS_NOEXEC      MNT_NOEXEC
114 @@ -82,16 +84,18 @@
115  #endif
116  
117  /*
118 - * Prototypes for xmount() and xumount(): on Linux we use the system calls
119 - * directly, otherwise xmount() and xumount() should be implemented as
120 - * compatibility wrappers (see xmount.c).
121 + * Prototypes for the compatibility wrappers
122   */
123  
124  #ifdef __linux__
125  # define xmount mount
126  # define xumount umount2
127 +# define xswapon swapon
128 +# define xswapoff swapoff
129  #else
130  int xmount(const char *source, const char *target, const char *filesystemtype,
131                 unsigned long mountflags, const void *data) FAST_FUNC;
132  int xumount(const char *target, int flags) FAST_FUNC;
133 +int xswapon(const char *path, int swapflags) FAST_FUNC;
134 +int xswapoff(const char *path) FAST_FUNC;
135  #endif
136 -- 
137 1.7.1
138