/* * A swapon(8)/swapoff(8) for Linux 0.99. */ #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 "mangle.h" #include "xalloc.h" #include "c.h" #include "closestream.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) # define swapoff(path) syscall(SYS_swapoff, path) #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 char *progname; 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 } }; static const struct option *longswapoffopts = &longswaponopts[4]; static int cannot_find(const char *special); #define PRINT_USAGE_SPECIAL(_fp) \ fputs(_("\nThe parameter:\n" \ " -L