#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "bitops.h" #include "blkdev.h" #include "nls.h" #include "pathnames.h" #include "swapheader.h" #include "xalloc.h" #include "c.h" #include "closestream.h" #include "swapon-common.h" #define PATH_MKSWAP "/sbin/mkswap" #ifdef HAVE_SYS_SWAP_H # include #endif #ifndef SWAP_FLAG_DISCARD # define SWAP_FLAG_DISCARD 0x10000 /* discard swap cluster after use */ #endif #ifndef SWAP_FLAG_PREFER # define SWAP_FLAG_PREFER 0x8000 /* set if swap priority specified */ #endif #ifndef SWAP_FLAG_PRIO_MASK # define SWAP_FLAG_PRIO_MASK 0x7fff #endif #ifndef SWAP_FLAG_PRIO_SHIFT # define SWAP_FLAG_PRIO_SHIFT 0 #endif #ifndef SWAPON_HAS_TWO_ARGS /* libc is insane, let's call the kernel */ # include # define swapon(path, flags) syscall(SYS_swapon, path, flags) #endif #define streq(s, t) (strcmp ((s), (t)) == 0) #define QUIET 1 #define CANONIC 1 #define MAX_PAGESIZE (64 * 1024) enum { SIG_SWAPSPACE = 1, SIG_SWSUSPEND }; #define SWAP_SIGNATURE "SWAPSPACE2" #define SWAP_SIGNATURE_SZ (sizeof(SWAP_SIGNATURE) - 1) static int all; static int priority = -1; /* non-prioritized swap by default */ static int discard; /* If true, don't complain if the device/file doesn't exist */ static int ifexists; static int fixpgsz; static int verbose; static const struct option longswaponopts[] = { /* swapon only */ { "priority", required_argument, 0, 'p' }, { "discard", 0, 0, 'd' }, { "ifexists", 0, 0, 'e' }, { "summary", 0, 0, 's' }, { "fixpgsz", 0, 0, 'f' }, /* also for swapoff */ { "all", 0, 0, 'a' }, { "help", 0, 0, 'h' }, { "verbose", 0, 0, 'v' }, { "version", 0, 0, 'V' }, { NULL, 0, 0, 0 } }; #define PRINT_USAGE_SPECIAL(_fp) \ fputs(_("\nThe parameter:\n" \ " -L