121180Sdist /* 221180Sdist * Copyright (c) 1980 Regents of the University of California. 3*34922Sbostic * All rights reserved. 4*34922Sbostic * 5*34922Sbostic * Redistribution and use in source and binary forms are permitted 6*34922Sbostic * provided that the above copyright notice and this paragraph are 7*34922Sbostic * duplicated in all such forms and that any documentation, 8*34922Sbostic * advertising materials, and other materials related to such 9*34922Sbostic * distribution and use acknowledge that the software was developed 10*34922Sbostic * by the University of California, Berkeley. The name of the 11*34922Sbostic * University may not be used to endorse or promote products derived 12*34922Sbostic * from this software without specific prior written permission. 13*34922Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*34922Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*34922Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1621180Sdist */ 1721180Sdist 1821180Sdist #ifndef lint 1921180Sdist char copyright[] = 2021180Sdist "@(#) Copyright (c) 1980 Regents of the University of California.\n\ 2121180Sdist All rights reserved.\n"; 22*34922Sbostic #endif /* not lint */ 2321180Sdist 2421180Sdist #ifndef lint 25*34922Sbostic static char sccsid[] = "@(#)swapon.c 5.3 (Berkeley) 06/30/88"; 26*34922Sbostic #endif /* not lint */ 2721180Sdist 281417Sbill #include <fstab.h> 2917878Sbloom #include <errno.h> 30*34922Sbostic #include <stdio.h> 311113Sbill 321113Sbill main(argc, argv) 331113Sbill int argc; 34*34922Sbostic char **argv; 351113Sbill { 36*34922Sbostic extern char *optarg; 37*34922Sbostic extern int optind; 38*34922Sbostic register struct fstab *fsp; 39*34922Sbostic register int stat; 40*34922Sbostic int ch, doall; 411113Sbill 42*34922Sbostic doall = 0; 43*34922Sbostic while ((ch = getopt(argc, argv, "a")) != EOF) 44*34922Sbostic switch((char)ch) { 45*34922Sbostic case 'a': 46*34922Sbostic doall = 1; 47*34922Sbostic break; 48*34922Sbostic case '?': 49*34922Sbostic default: 50*34922Sbostic usage(); 51*34922Sbostic } 52*34922Sbostic argv += optind; 53*34922Sbostic 54*34922Sbostic stat = 0; 55*34922Sbostic if (doall) 56*34922Sbostic while (fsp = getfsent()) { 57*34922Sbostic if (strcmp(fsp->fs_type, FSTAB_SW)) 581417Sbill continue; 59*34922Sbostic if (add(fsp->fs_spec, 1)) 60*34922Sbostic stat = 1; 61*34922Sbostic else 62*34922Sbostic printf("swapon: adding %s as swap device\n", 6318444Skarels fsp->fs_spec); 641417Sbill } 65*34922Sbostic else if (!*argv) 66*34922Sbostic usage(); 67*34922Sbostic for (; *argv; ++argv) 68*34922Sbostic stat |= add(*argv, 0); 69*34922Sbostic exit(stat); 70*34922Sbostic } 7117878Sbloom 72*34922Sbostic static 73*34922Sbostic add(name, ignoreebusy) 74*34922Sbostic char *name; 75*34922Sbostic int ignoreebusy; 76*34922Sbostic { 77*34922Sbostic extern int errno; 7817878Sbloom 79*34922Sbostic if (swapon(name) == -1) { 80*34922Sbostic switch (errno) { 81*34922Sbostic case EINVAL: 82*34922Sbostic fprintf(stderr, "swapon: %s: device not configured\n", 83*34922Sbostic name); 84*34922Sbostic break; 85*34922Sbostic case EBUSY: 86*34922Sbostic if (!ignoreebusy) 87*34922Sbostic fprintf(stderr, 88*34922Sbostic "swapon: %s: device already in use\n", 89*34922Sbostic name); 90*34922Sbostic break; 91*34922Sbostic default: 92*34922Sbostic fprintf(stderr, "swapon: %s: ", name); 93*34922Sbostic perror((char *)NULL); 94*34922Sbostic break; 951113Sbill } 96*34922Sbostic return(1); 97*34922Sbostic } 98*34922Sbostic return(0); 991113Sbill } 100*34922Sbostic 101*34922Sbostic static 102*34922Sbostic usage() 103*34922Sbostic { 104*34922Sbostic fprintf(stderr, "usage: swapon [-a] [special_file ...]\n"); 105*34922Sbostic exit(1); 106*34922Sbostic } 107