Subject: [PATCH 19/19] swaponoff: FreeBSD support From: Jeremie Koenig Date: Thu, 29 Jul 2010 21:59:54 +0200 Last-Update: 2017-08-17 Signed-off-by: Jeremie Koenig --- a/util-linux/swaponoff.c +++ b/util-linux/swaponoff.c @@ -76,10 +76,8 @@ #include "libbb.h" #include "common_bufsiz.h" +#include "xmount.h" #include -#ifndef __BIONIC__ -# include -#endif #if ENABLE_FEATURE_SWAPONOFF_LABEL # include "volume_id.h" @@ -156,7 +154,7 @@ resolve_mount_spec(&device); if (do_swapoff) { - err = swapoff(device); + err = xswapoff(device); /* Don't complain on OPT_ALL if not a swap device or if it doesn't exist */ quiet = (OPT_ALL && (errno == EINVAL || errno == ENOENT)); } else { @@ -170,7 +168,7 @@ return 1; } } - err = swapon(device, g_flags); + err = xswapon(device, g_flags); /* Don't complain on swapon -a if device is already in use */ quiet = (OPT_ALL && errno == EBUSY); } --- a/util-linux/xmount.c +++ b/util-linux/xmount.c @@ -67,4 +67,14 @@ return unmount(target, flags); } +int FAST_FUNC xswapon(const char *path, int swapflags UNUSED_PARAM) +{ + return swapon(path); +} + +int FAST_FUNC xswapoff(const char *path) +{ + return swapoff(path); +} + #endif --- a/util-linux/xmount.h +++ b/util-linux/xmount.h @@ -5,9 +5,9 @@ * Copyright (C) 2010 by Jeremie Koenig * Copyright (C) 2010 by Luca Favatella * - * The Linux prototypes for mount() and umount2() are used as a reference for - * our xmount() and xumount(), which should be implemented as a compatibility - * wrappers for non-Linux systems (see xmount.c). + * The Linux prototypes for mount(), umount2(), swapon() and swapoff() are + * used as a reference for our versions of them. On non-Linux system those + * should be implemented as compatibility wrappers (see xmount.c). */ /* @@ -17,6 +17,7 @@ #ifdef __linux__ # include +# include /* Make sure we have all the new mount flags we actually try to use * (grab more as needed from util-linux's mount/mount_constants.h). */ # ifndef MS_DIRSYNC @@ -59,6 +60,7 @@ #elif defined(__FreeBSD_kernel__) # include +# include # define MS_NOSUID MNT_NOSUID # ifdef MNT_NODEV # define MS_NODEV MNT_NODEV @@ -90,16 +92,18 @@ #endif /* - * Prototypes for xmount() and xumount(): on Linux we use the system calls - * directly, otherwise xmount() and xumount() should be implemented as - * compatibility wrappers (see xmount.c). + * Prototypes for the compatibility wrappers */ #ifdef __linux__ # define xmount mount # define xumount umount2 +# define xswapon swapon +# define xswapoff swapoff #else int xmount(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags, const void *data) FAST_FUNC; int xumount(const char *target, int flags) FAST_FUNC; +int xswapon(const char *path, int swapflags) FAST_FUNC; +int xswapoff(const char *path) FAST_FUNC; #endif