BSD 4_1c_2 release
[unix-history] / usr / src / etc / swapon.c
CommitLineData
e804469b 1static char *sccsid = "@(#)swapon.c 4.4 (Berkeley) 10/16/80";
1885c525 2#include <stdio.h>
f0861f40 3#include <fstab.h>
1885c525
BJ
4
5#define VSWAPON 85
6
7main(argc, argv)
8 int argc;
9 char *argv[];
10{
11 int stat = 0;
12
13 --argc, argv++;
14 if (argc == 0) {
15 fprintf(stderr, "usage: swapon name...\n");
16 exit(1);
17 }
f0861f40 18 if (argc == 1 && !strcmp(*argv, "-a")) {
8d6ccf8b
BJ
19 struct fstab *fsp;
20 if (setfsent() == 0)
21 perror(FSTAB), exit(1);
22 while ( (fsp = getfsent()) != 0){
23 if (strcmp(fsp->fs_type, FSTAB_SW) != 0)
f0861f40 24 continue;
687c01bb 25 printf("Adding %s as swap device\n",
8d6ccf8b
BJ
26 fsp->fs_spec);
27 if (syscall(VSWAPON, fsp->fs_spec) == -1) {
687c01bb
BJ
28 extern errno;
29 extern char *sys_errlist[];
30 printf("%s: %s\n",
31 sys_errlist[errno]);
f0861f40
BJ
32 stat = 1;
33 }
34 }
8d6ccf8b 35 endfsent();
f0861f40
BJ
36 exit(stat);
37 }
1885c525
BJ
38 do {
39 if (syscall(VSWAPON, *argv++) == -1) {
40 stat = 1;
41 perror(argv[-1]);
42 }
43 argc--;
44 } while (argc > 0);
45 exit(stat);
46}