1 /* swapon(8) without any sanity checks; simply calls swapon(2) directly. */
14 static void usage(const char *prog)
16 fprintf(stderr, "usage: %s [-v verb] PATH\n", prog);
24 TEST_MWRITE_BEFORE_AND_MWRITE_AFTER,
29 #define BUF_SIZE 262144
30 static char buf[BUF_SIZE];
32 static void handle_signal(int signal)
34 fprintf(stderr, "Caught signal %d, terminating...\n", signal);
38 int main(int argc, char **argv)
40 struct sigaction act = {
41 .sa_handler = handle_signal,
43 enum verbs verb = TEST_SWAPON;
49 memset(buf, 0x58, BUF_SIZE);
51 while ((c = getopt(argc, argv, "v:")) != -1) {
55 if (verb < TEST_SWAPON || verb >= MAX_TEST_VERBS) {
56 fprintf(stderr, "Verbs must be 0-%d.\n",
67 ret = sigaction(SIGSEGV, &act, NULL);
69 perror("sigsegv action");
73 ret = sigaction(SIGBUS, &act, NULL);
75 perror("sigbus action");
81 case TEST_MWRITE_AFTER:
82 case TEST_MWRITE_BEFORE_AND_MWRITE_AFTER:
83 case TEST_MWRITE_BEFORE:
84 fd = open(argv[optind], O_RDWR);
95 case TEST_MWRITE_BEFORE_AND_MWRITE_AFTER:
96 case TEST_MWRITE_BEFORE:
97 p = mmap(NULL, BUF_SIZE, PROT_WRITE | PROT_READ, MAP_SHARED,
99 if (p == MAP_FAILED) {
103 memcpy(p, buf, BUF_SIZE);
109 if (optind != argc - 1)
112 ret = swapon(argv[optind], 0);
120 sz = pwrite(fd, buf, BUF_SIZE, 65536);
126 case TEST_MWRITE_AFTER:
127 p = mmap(NULL, BUF_SIZE, PROT_WRITE | PROT_READ, MAP_SHARED,
129 if (p == MAP_FAILED) {
134 case TEST_MWRITE_BEFORE_AND_MWRITE_AFTER:
135 memcpy(p, buf, BUF_SIZE);