aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2016-01-17 14:45:45 -0600
committerRob Landley <rob@landley.net>2016-01-17 14:45:45 -0600
commit3b17f66c10af679f7ce3cd7b17af3b13664cde0c (patch)
treea5ce4ca6dfa0f649c6426bd4e0d0caa0a06e0c3c
parent544c1ec1614cd9a8dcedac3478701e4b97b0f8a0 (diff)
downloadtoybox-3b17f66c10af679f7ce3cd7b17af3b13664cde0c.tar.gz
Add -L label and UUID support to mkswap.
-rw-r--r--toys/other/mkswap.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/toys/other/mkswap.c b/toys/other/mkswap.c
index ff864244..49e0b942 100644
--- a/toys/other/mkswap.c
+++ b/toys/other/mkswap.c
@@ -2,24 +2,30 @@
*
* Copyright 2009 Rob Landley <rob@landley.net>
-USE_MKSWAP(NEWTOY(mkswap, "<1>1", TOYFLAG_SBIN))
+USE_MKSWAP(NEWTOY(mkswap, "<1>1L:", TOYFLAG_SBIN))
config MKSWAP
bool "mkswap"
default y
help
- usage: mkswap DEVICE
+ usage: mkswap [-L LABEL] DEVICE
Sets up a Linux swap area on a device or file.
*/
+#define FOR_mkswap
#include "toys.h"
+GLOBALS(
+ char *L;
+)
+
void mkswap_main(void)
{
int fd = xopen(*toys.optargs, O_RDWR), pagesize = sysconf(_SC_PAGE_SIZE);
off_t len = fdlength(fd);
unsigned int pages = (len/pagesize)-1, *swap = (unsigned int *)toybuf;
+ char *label = (char *)(swap+7), *uuid = (char *)(swap+3);
// Write header. Note that older kernel versions checked signature
// on disk (not in cache) during swapon, so sync after writing.
@@ -27,6 +33,8 @@ void mkswap_main(void)
swap[0] = 1;
swap[1] = pages;
xlseek(fd, 1024, SEEK_SET);
+ create_uuid(uuid);
+ if (TT.L) strncpy(label, TT.L, 15);
xwrite(fd, swap, 129*sizeof(unsigned int));
xlseek(fd, pagesize-10, SEEK_SET);
xwrite(fd, "SWAPSPACE2", 10);
@@ -34,5 +42,9 @@ void mkswap_main(void)
if (CFG_TOYBOX_FREE) close(fd);
- printf("Swapspace size: %luk\n", pages*(unsigned long)(pagesize/1024));
+ if (TT.L) sprintf(toybuf, ", LABEL=%s", label);
+ else *toybuf = 0;
+ printf("Swapspace size: %luk%s, UUID=%s\n",
+ pages*(unsigned long)(pagesize/1024),
+ toybuf, show_uuid(uuid));
}