diff --git a/Makefile b/Makefile index cf60823..2ff14ad 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,8 @@ SRC += \ mkswap.c \ reboot.c \ rmmod.c \ - swapoff.c + swapoff.c \ + swapon.c endif OBJ = $(SRC:.c=.o) $(LIB) diff --git a/swapon.c b/swapon.c new file mode 100644 index 0000000..c5429e0 --- /dev/null +++ b/swapon.c @@ -0,0 +1,41 @@ +/* See LICENSE file for copyright and license details. */ +#include +#include +#include +#include +#include "util.h" + +static void +usage(void) +{ + eprintf("usage: %s [-d] swapfile\n", argv0); +} + +int +main(int argc, char *argv[]) +{ + int i; + int ret = 0; + int flags = 0; + + ARGBEGIN { + case 'd': + flags |= SWAP_FLAG_DISCARD; + break; + default: + usage(); + } ARGEND; + + if (argc < 1) + usage(); + + for (i = 0; i < argc; i++) { + ret = swapon(argv[i], flags); + if (ret < 0) { + fprintf(stderr, "swapon %s: %s\n", + argv[i], strerror(errno)); + ret = 1; + } + } + return ret; +}