#include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef HAVE_SYS_SWAP_H # include #endif #include "nls.h" #include "c.h" #include "closestream.h" #include "swapon-common.h" #ifndef SWAPON_HAS_TWO_ARGS /* libc is insane, let's call the kernel */ # include # define swapoff(path) syscall(SYS_swapoff, path) #endif static int verbose; static int all; #define QUIET 1 #define CANONIC 1 static int do_swapoff(const char *orig_special, int quiet, int canonic) { const char *special = orig_special; if (verbose) printf(_("swapoff %s\n"), orig_special); if (!canonic) { special = mnt_resolve_spec(orig_special, mntcache); if (!special) return cannot_find(orig_special); } if (swapoff(special) == 0) return 0; /* success */ if (errno == EPERM) errx(EXIT_FAILURE, _("Not superuser.")); if (!quiet || errno == ENOMEM) warn(_("%s: swapoff failed"), orig_special); return -1; } static int swapoff_by_label(const char *label, int quiet) { const char *special = mnt_resolve_tag("LABEL", label, mntcache); return special ? do_swapoff(special, quiet, CANONIC) : cannot_find(label); } static int swapoff_by_uuid(const char *uuid, int quiet) { const char *special = mnt_resolve_tag("UUID", uuid, mntcache); return special ? do_swapoff(special, quiet, CANONIC) : cannot_find(uuid); } static void usage(FILE *out, int n) { fputs(_("\nUsage:\n"), out); fprintf(out, _(" %s [options] []\n"), program_invocation_short_name); fputs(_("\nOptions:\n"), out); fputs(_(" -a, --all disable all swaps from /proc/swaps\n" " -h, --help display help and exit\n" " -v, --verbose verbose mode\n" " -V, --version display version and exit\n"), out); fputs(_("\nThe parameter:\n" \ " -L