1*21180Sdist /* 2*21180Sdist * Copyright (c) 1980 Regents of the University of California. 3*21180Sdist * All rights reserved. The Berkeley software License Agreement 4*21180Sdist * specifies the terms and conditions for redistribution. 5*21180Sdist */ 6*21180Sdist 7*21180Sdist #ifndef lint 8*21180Sdist char copyright[] = 9*21180Sdist "@(#) Copyright (c) 1980 Regents of the University of California.\n\ 10*21180Sdist All rights reserved.\n"; 11*21180Sdist #endif not lint 12*21180Sdist 13*21180Sdist #ifndef lint 14*21180Sdist static char sccsid[] = "@(#)swapon.c 5.1 (Berkeley) 05/28/85"; 15*21180Sdist #endif not lint 16*21180Sdist 171113Sbill #include <stdio.h> 181417Sbill #include <fstab.h> 1917878Sbloom #include <errno.h> 201113Sbill 211113Sbill #define VSWAPON 85 221113Sbill 2317878Sbloom extern int errno; 2417878Sbloom 251113Sbill main(argc, argv) 261113Sbill int argc; 271113Sbill char *argv[]; 281113Sbill { 291113Sbill int stat = 0; 301113Sbill 311113Sbill --argc, argv++; 321113Sbill if (argc == 0) { 331113Sbill fprintf(stderr, "usage: swapon name...\n"); 341113Sbill exit(1); 351113Sbill } 361417Sbill if (argc == 1 && !strcmp(*argv, "-a")) { 371444Sbill struct fstab *fsp; 381444Sbill if (setfsent() == 0) 391444Sbill perror(FSTAB), exit(1); 401444Sbill while ( (fsp = getfsent()) != 0){ 411444Sbill if (strcmp(fsp->fs_type, FSTAB_SW) != 0) 421417Sbill continue; 431444Sbill if (syscall(VSWAPON, fsp->fs_spec) == -1) { 4417878Sbloom switch(errno) { 4517878Sbloom case EINVAL: 4617878Sbloom fprintf(stderr, 4717878Sbloom "%s: Device not configured\n", 4817878Sbloom fsp->fs_spec); 4917878Sbloom stat = 1; 5017878Sbloom break; 5117878Sbloom 5217878Sbloom case EBUSY: /* ignore already in use */ 5317878Sbloom break; 5417878Sbloom 5517878Sbloom default: 5617878Sbloom perror(fsp->fs_spec); 5717878Sbloom stat = 1; 5817878Sbloom break; 5917878Sbloom } 6018444Skarels } else 6118444Skarels printf("Adding %s as swap device\n", 6218444Skarels fsp->fs_spec); 631417Sbill } 641444Sbill endfsent(); 651417Sbill exit(stat); 661417Sbill } 671113Sbill do { 681113Sbill if (syscall(VSWAPON, *argv++) == -1) { 691113Sbill stat = 1; 7017878Sbloom switch (errno) { 7117878Sbloom case EINVAL: 7217878Sbloom fprintf(stderr, "%s: Device not configured\n", 7317878Sbloom argv[-1]); 7417878Sbloom break; 7517878Sbloom 7617878Sbloom case EBUSY: 7717878Sbloom fprintf(stderr, "%s: Device already in use\n", 7817878Sbloom argv[-1]); 7917878Sbloom break; 8017878Sbloom 8117878Sbloom default: 8217878Sbloom perror(argv[-1]); 8317878Sbloom break; 8417878Sbloom } 851113Sbill } 861113Sbill argc--; 871113Sbill } while (argc > 0); 881113Sbill exit(stat); 891113Sbill } 90