121180Sdist /* 221180Sdist * Copyright (c) 1980 Regents of the University of California. 334922Sbostic * All rights reserved. 434922Sbostic * 5*42712Sbostic * %sccs.include.redist.c% 621180Sdist */ 721180Sdist 821180Sdist #ifndef lint 921180Sdist char copyright[] = 1021180Sdist "@(#) Copyright (c) 1980 Regents of the University of California.\n\ 1121180Sdist All rights reserved.\n"; 1234922Sbostic #endif /* not lint */ 1321180Sdist 1421180Sdist #ifndef lint 15*42712Sbostic static char sccsid[] = "@(#)swapon.c 5.4 (Berkeley) 06/01/90"; 1634922Sbostic #endif /* not lint */ 1721180Sdist 181417Sbill #include <fstab.h> 1917878Sbloom #include <errno.h> 2034922Sbostic #include <stdio.h> 211113Sbill 221113Sbill main(argc, argv) 231113Sbill int argc; 2434922Sbostic char **argv; 251113Sbill { 2634922Sbostic extern char *optarg; 2734922Sbostic extern int optind; 2834922Sbostic register struct fstab *fsp; 2934922Sbostic register int stat; 3034922Sbostic int ch, doall; 311113Sbill 3234922Sbostic doall = 0; 3334922Sbostic while ((ch = getopt(argc, argv, "a")) != EOF) 3434922Sbostic switch((char)ch) { 3534922Sbostic case 'a': 3634922Sbostic doall = 1; 3734922Sbostic break; 3834922Sbostic case '?': 3934922Sbostic default: 4034922Sbostic usage(); 4134922Sbostic } 4234922Sbostic argv += optind; 4334922Sbostic 4434922Sbostic stat = 0; 4534922Sbostic if (doall) 4634922Sbostic while (fsp = getfsent()) { 4734922Sbostic if (strcmp(fsp->fs_type, FSTAB_SW)) 481417Sbill continue; 4934922Sbostic if (add(fsp->fs_spec, 1)) 5034922Sbostic stat = 1; 5134922Sbostic else 5234922Sbostic printf("swapon: adding %s as swap device\n", 5318444Skarels fsp->fs_spec); 541417Sbill } 5534922Sbostic else if (!*argv) 5634922Sbostic usage(); 5734922Sbostic for (; *argv; ++argv) 5834922Sbostic stat |= add(*argv, 0); 5934922Sbostic exit(stat); 6034922Sbostic } 6117878Sbloom 6234922Sbostic static 6334922Sbostic add(name, ignoreebusy) 6434922Sbostic char *name; 6534922Sbostic int ignoreebusy; 6634922Sbostic { 6734922Sbostic extern int errno; 6817878Sbloom 6934922Sbostic if (swapon(name) == -1) { 7034922Sbostic switch (errno) { 7134922Sbostic case EINVAL: 7234922Sbostic fprintf(stderr, "swapon: %s: device not configured\n", 7334922Sbostic name); 7434922Sbostic break; 7534922Sbostic case EBUSY: 7634922Sbostic if (!ignoreebusy) 7734922Sbostic fprintf(stderr, 7834922Sbostic "swapon: %s: device already in use\n", 7934922Sbostic name); 8034922Sbostic break; 8134922Sbostic default: 8234922Sbostic fprintf(stderr, "swapon: %s: ", name); 8334922Sbostic perror((char *)NULL); 8434922Sbostic break; 851113Sbill } 8634922Sbostic return(1); 8734922Sbostic } 8834922Sbostic return(0); 891113Sbill } 9034922Sbostic 9134922Sbostic static 9234922Sbostic usage() 9334922Sbostic { 9434922Sbostic fprintf(stderr, "usage: swapon [-a] [special_file ...]\n"); 9534922Sbostic exit(1); 9634922Sbostic } 97