Commit | Line | Data |
---|---|---|
df60bdb5 | 1 | static char *sccsid = "@(#)swapon.c 4.8 (Berkeley) %G%"; |
1885c525 | 2 | #include <stdio.h> |
f0861f40 | 3 | #include <fstab.h> |
ad372055 | 4 | #include <errno.h> |
1885c525 BJ |
5 | |
6 | #define VSWAPON 85 | |
7 | ||
ad372055 JB |
8 | extern int errno; |
9 | ||
1885c525 BJ |
10 | main(argc, argv) |
11 | int argc; | |
12 | char *argv[]; | |
13 | { | |
14 | int stat = 0; | |
15 | ||
16 | --argc, argv++; | |
17 | if (argc == 0) { | |
18 | fprintf(stderr, "usage: swapon name...\n"); | |
19 | exit(1); | |
20 | } | |
f0861f40 | 21 | if (argc == 1 && !strcmp(*argv, "-a")) { |
8d6ccf8b BJ |
22 | struct fstab *fsp; |
23 | if (setfsent() == 0) | |
24 | perror(FSTAB), exit(1); | |
25 | while ( (fsp = getfsent()) != 0){ | |
26 | if (strcmp(fsp->fs_type, FSTAB_SW) != 0) | |
f0861f40 | 27 | continue; |
8d6ccf8b | 28 | if (syscall(VSWAPON, fsp->fs_spec) == -1) { |
ad372055 JB |
29 | switch(errno) { |
30 | case EINVAL: | |
31 | fprintf(stderr, | |
32 | "%s: Device not configured\n", | |
33 | fsp->fs_spec); | |
34 | stat = 1; | |
35 | break; | |
36 | ||
37 | case EBUSY: /* ignore already in use */ | |
38 | break; | |
39 | ||
40 | default: | |
41 | perror(fsp->fs_spec); | |
42 | stat = 1; | |
43 | break; | |
44 | } | |
df60bdb5 MK |
45 | } else |
46 | printf("Adding %s as swap device\n", | |
47 | fsp->fs_spec); | |
f0861f40 | 48 | } |
8d6ccf8b | 49 | endfsent(); |
f0861f40 BJ |
50 | exit(stat); |
51 | } | |
1885c525 BJ |
52 | do { |
53 | if (syscall(VSWAPON, *argv++) == -1) { | |
54 | stat = 1; | |
ad372055 JB |
55 | switch (errno) { |
56 | case EINVAL: | |
57 | fprintf(stderr, "%s: Device not configured\n", | |
58 | argv[-1]); | |
59 | break; | |
60 | ||
61 | case EBUSY: | |
62 | fprintf(stderr, "%s: Device already in use\n", | |
63 | argv[-1]); | |
64 | break; | |
65 | ||
66 | default: | |
67 | perror(argv[-1]); | |
68 | break; | |
69 | } | |
1885c525 BJ |
70 | } |
71 | argc--; | |
72 | } while (argc > 0); | |
73 | exit(stat); | |
74 | } |