Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F156840217
D20599.id58554.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D20599.id58554.diff
View Options
Index: swapon.c
===================================================================
--- swapon.c
+++ swapon.c
@@ -77,7 +77,7 @@
static enum { SWAPON, SWAPOFF, SWAPCTL } orig_prog, which_prog = SWAPCTL;
-static int qflag;
+static int Eflag, qflag;
int
main(int argc, char **argv)
@@ -100,7 +100,7 @@
doall = 0;
etc_fstab = NULL;
- while ((ch = getopt(argc, argv, "AadghklLmqsUF:")) != -1) {
+ while ((ch = getopt(argc, argv, "AadEghklLmqsUF:")) != -1) {
switch(ch) {
case 'A':
if (which_prog == SWAPCTL) {
@@ -121,6 +121,12 @@
else
usage();
break;
+ case 'E':
+ if (which_prog == SWAPON)
+ Eflag = 1;
+ else
+ usage();
+ break;
case 'g':
hflag = 'G';
break;
@@ -182,6 +188,8 @@
strstr(fsp->fs_mntops, "late") == NULL &&
late != 0)
continue;
+ if (strstr(fsp->fs_mntops, "trimonce") != NULL)
+ Eflag = 1;
swfile = swap_on_off(fsp->fs_spec, 1,
fsp->fs_mntops);
if (swfile == NULL) {
@@ -383,7 +391,8 @@
/* ignore known option */
} else if (strcmp(token, "noauto") == 0) {
/* ignore known option */
- } else if (strcmp(token, "sw") != 0) {
+ } else if (strcmp(token, "sw") != 0 &&
+ strcmp(token, "trimonce") != 0) {
warnx("Invalid option: %s", token);
free(ops);
return (NULL);
@@ -721,14 +730,46 @@
return (WEXITSTATUS(status));
}
+static void
+swap_trim(const char *name)
+{
+
+ struct stat sb;
+ off_t ioarg[2], sz;
+ int fd;
+
+ fd = open(name, O_WRONLY | O_DIRECT);
+ if (fd < 0)
+ return;
+ if (fstat(fd, &sb) >= 0) {
+ if (S_ISREG(sb.st_mode)) {
+ sz = sb.st_size;
+ } else if (S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode)) {
+ if (ioctl(fd, DIOCGMEDIASIZE, &sz) != 0)
+ err(1, "ioctl(DIOCGMEDIASIZE)");
+ } else {
+ errx(1, "%s has an invalid file type", name);
+ }
+
+ ioarg[0] = 0;
+ ioarg[1] = sz;
+ if (ioctl(fd, DIOCGDELETE, ioarg) != 0)
+ warn(1, "ioctl(DIOCGDELETE)");
+ }
+ close(fd);
+}
+
static const char *
swap_on_off_sfile(const char *name, int doingall)
{
+
int error;
- if (which_prog == SWAPON)
+ if (which_prog == SWAPON) {
+ if (Eflag)
+ swap_trim(name);
error = swapon(name);
- else /* SWAPOFF */
+ } else /* SWAPOFF */
error = swapoff(name);
if (error == -1) {
@@ -759,6 +800,8 @@
fprintf(stderr, "usage: %s ", getprogname());
switch(orig_prog) {
case SWAPON:
+ fprintf(stderr, "[-F fstab] -aELq | file ...\n");
+ break;
case SWAPOFF:
fprintf(stderr, "[-F fstab] -aLq | file ...\n");
break;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, May 17, 8:16 PM (10 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33207048
Default Alt Text
D20599.id58554.diff (2 KB)
Attached To
Mode
D20599: simple trimming before swapon
Attached
Detach File
Event Timeline
Log In to Comment