Changeset View
Changeset View
Standalone View
Standalone View
sbin/swapon/swapon.c
Show All 39 Lines | |||||
static char sccsid[] = "@(#)swapon.c 8.1 (Berkeley) 6/5/93"; | static char sccsid[] = "@(#)swapon.c 8.1 (Berkeley) 6/5/93"; | ||||
#endif /* not lint */ | #endif /* not lint */ | ||||
#endif | #endif | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/disk.h> | #include <sys/disk.h> | ||||
#include <sys/disklabel.h> | |||||
#include <sys/mdioctl.h> | #include <sys/mdioctl.h> | ||||
#include <sys/stat.h> | #include <sys/stat.h> | ||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <sys/wait.h> | #include <sys/wait.h> | ||||
#include <vm/vm_param.h> | #include <vm/vm_param.h> | ||||
#include <err.h> | #include <err.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
▲ Show 20 Lines • Show All 700 Lines • ▼ Show 20 Lines | swapon_trim(const char *name) | ||||
if (S_ISREG(sb.st_mode)) | if (S_ISREG(sb.st_mode)) | ||||
sz = sb.st_size; | sz = sb.st_size; | ||||
else if (S_ISCHR(sb.st_mode)) { | else if (S_ISCHR(sb.st_mode)) { | ||||
if (ioctl(fd, DIOCGMEDIASIZE, &sz) != 0) | if (ioctl(fd, DIOCGMEDIASIZE, &sz) != 0) | ||||
err(1, "ioctl(DIOCGMEDIASIZE)"); | err(1, "ioctl(DIOCGMEDIASIZE)"); | ||||
} else | } else | ||||
errx(1, "%s has an invalid file type", name); | errx(1, "%s has an invalid file type", name); | ||||
/* Trim the device. */ | /* Trim the device. */ | ||||
ioarg[0] = 0; | ioarg[0] = BBSIZE; | ||||
ioarg[1] = sz; | ioarg[1] = sz - BBSIZE; | ||||
if (ioctl(fd, DIOCGDELETE, ioarg) != 0) | if (ioctl(fd, DIOCGDELETE, ioarg) != 0) | ||||
warn("ioctl(DIOCGDELETE)"); | warn("ioctl(DIOCGDELETE)"); | ||||
/* Start using the device for swapping, creating a second consumer. */ | /* Start using the device for swapping, creating a second consumer. */ | ||||
error = swapon(name); | error = swapon(name); | ||||
/* | /* | ||||
* Do not close the device until the swap pager has attempted to create | * Do not close the device until the swap pager has attempted to create | ||||
▲ Show 20 Lines • Show All 158 Lines • Show Last 20 Lines |