summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2009-06-18 21:55:47 +0200
committerDenys Vlasenko2009-06-18 21:55:47 +0200
commitc9f280cc469daccfc0eba20bca6a1341070230b6 (patch)
tree415796a27592ed93b140aa0b8b895aa59da797fd
parent2207cd6e148309a00b4ee6a4b1461e7cd4818075 (diff)
downloadbusybox-c9f280cc469daccfc0eba20bca6a1341070230b6.zip
busybox-c9f280cc469daccfc0eba20bca6a1341070230b6.tar.gz
mkswap: generate UUID if CONFIG_DESKTOP=y. +110 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--util-linux/mkswap.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c
index 11c411b..167b9ee 100644
--- a/util-linux/mkswap.c
+++ b/util-linux/mkswap.c
@@ -5,7 +5,6 @@
*
* Licensed under GPL version 2, see file LICENSE in this tarball for details.
*/
-
#include "libbb.h"
#if ENABLE_SELINUX
@@ -48,7 +47,33 @@ static void mkswap_selinux_setcontext(int fd, const char *path)
bb_perror_msg_and_die("SELinux relabeling failed");
}
#else
-#define mkswap_selinux_setcontext(fd, path) ((void)0)
+# define mkswap_selinux_setcontext(fd, path) ((void)0)
+#endif
+
+#if ENABLE_DESKTOP
+static void mkswap_generate_uuid(uint8_t *buf)
+{
+ unsigned i;
+ char uuid_string[32];
+
+ /* rand() is guaranteed to generate at least [0, 2^15) range,
+ * but lowest bits in some libc are not so "random". */
+ srand((unsigned)monotonic_us() + getpid());
+ for (i = 0; i < 16; i++)
+ buf[i] = rand() >> 5;
+
+ bin2hex(uuid_string, (void*) buf, 16);
+ /* f.e. UUID=dfd9c173-be52-4d27-99a5-c34c6c2ff55f */
+ printf("UUID=%.8s" "-%.4s-%.4s-%.4s-%.12s\n",
+ uuid_string,
+ uuid_string+8,
+ uuid_string+8+4,
+ uuid_string+8+4+4,
+ uuid_string+8+4+4+4
+ );
+}
+#else
+# define mkswap_generate_uuid(buf) ((void)0)
#endif
#if 0 /* from Linux 2.6.23 */
@@ -113,10 +138,10 @@ int mkswap_main(int argc, char **argv)
// Make a header. hdr is zero-filled so far...
hdr[0] = 1;
hdr[1] = (len / pagesize) - 1;
+ mkswap_generate_uuid((void*) &hdr[3]);
// Write the header. Sync to disk because some kernel versions check
// signature on disk (not in cache) during swapon.
-
xlseek(fd, 1024, SEEK_SET);
xwrite(fd, hdr, NWORDS * 4);
xlseek(fd, pagesize - 10, SEEK_SET);