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