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