Changeset View
Changeset View
Standalone View
Standalone View
sbin/swapon/swapon.c
Show First 20 Lines • Show All 755 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] = BSD_LABEL_SIZE; | ||||
ioarg[1] = sz; | ioarg[1] = sz - BSD_LABEL_SIZE; | ||||
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 |