2 #include <sys/syscall.h>
4 #if defined __NR_swapon && defined __NR_swapoff
12 error_msg(int error_num)
15 case ENOSYS: return "ENOSYS";
16 case EPERM: return "EPERM";
17 case EINVAL: return "EINVAL";
18 default: return "ENOENT";
25 static const char sample[] = "swap.sample";
27 int rc = syscall(__NR_swapon, sample, 0);
28 printf("swapon(\"%s\", 0) = %d %s (%m)\n",
29 sample, rc, error_msg(errno));
31 rc = syscall(__NR_swapon, sample, 42);
32 printf("swapon(\"%s\", %s) = %d %s (%m)\n",
33 sample, "42", rc, error_msg(errno));
35 rc = syscall(__NR_swapon, sample, SWAP_FLAG_PREFER);
36 printf("swapon(\"%s\", %s) = %d %s (%m)\n",
37 sample, "SWAP_FLAG_PREFER", rc, error_msg(errno));
39 rc = syscall(__NR_swapon, sample, SWAP_FLAG_PREFER | 42);
40 printf("swapon(\"%s\", %s) = %d %s (%m)\n",
41 sample, "SWAP_FLAG_PREFER|42", rc, error_msg(errno));
43 rc = syscall(__NR_swapon, sample, -1L);
44 printf("swapon(\"%s\", %s) = %d %s (%m)\n",
46 "SWAP_FLAG_PREFER|SWAP_FLAG_DISCARD|SWAP_FLAG_DISCARD_ONCE"
47 "|SWAP_FLAG_DISCARD_PAGES|0xfff80000|32767",
48 rc, error_msg(errno));
50 rc = syscall(__NR_swapoff, sample);
51 printf("swapoff(\"%s\") = %d %s (%m)\n",
52 sample, rc, error_msg(errno));
54 puts("+++ exited with 0 +++");
60 SKIP_MAIN_UNDEFINED("__NR_swapon && __NR_swapoff")