diff options
-rw-r--r-- | util-linux/mkswap.c | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c index 11c411b6a..167b9ee03 100644 --- a/util-linux/mkswap.c +++ b/util-linux/mkswap.c | |||
@@ -5,7 +5,6 @@ | |||
5 | * | 5 | * |
6 | * Licensed under GPL version 2, see file LICENSE in this tarball for details. | 6 | * Licensed under GPL version 2, see file LICENSE in this tarball for details. |
7 | */ | 7 | */ |
8 | |||
9 | #include "libbb.h" | 8 | #include "libbb.h" |
10 | 9 | ||
11 | #if ENABLE_SELINUX | 10 | #if ENABLE_SELINUX |
@@ -48,7 +47,33 @@ static void mkswap_selinux_setcontext(int fd, const char *path) | |||
48 | bb_perror_msg_and_die("SELinux relabeling failed"); | 47 | bb_perror_msg_and_die("SELinux relabeling failed"); |
49 | } | 48 | } |
50 | #else | 49 | #else |
51 | #define mkswap_selinux_setcontext(fd, path) ((void)0) | 50 | # define mkswap_selinux_setcontext(fd, path) ((void)0) |
51 | #endif | ||
52 | |||
53 | #if ENABLE_DESKTOP | ||
54 | static void mkswap_generate_uuid(uint8_t *buf) | ||
55 | { | ||
56 | unsigned i; | ||
57 | char uuid_string[32]; | ||
58 | |||
59 | /* rand() is guaranteed to generate at least [0, 2^15) range, | ||
60 | * but lowest bits in some libc are not so "random". */ | ||
61 | srand((unsigned)monotonic_us() + getpid()); | ||
62 | for (i = 0; i < 16; i++) | ||
63 | buf[i] = rand() >> 5; | ||
64 | |||
65 | bin2hex(uuid_string, (void*) buf, 16); | ||
66 | /* f.e. UUID=dfd9c173-be52-4d27-99a5-c34c6c2ff55f */ | ||
67 | printf("UUID=%.8s" "-%.4s-%.4s-%.4s-%.12s\n", | ||
68 | uuid_string, | ||
69 | uuid_string+8, | ||
70 | uuid_string+8+4, | ||
71 | uuid_string+8+4+4, | ||
72 | uuid_string+8+4+4+4 | ||
73 | ); | ||
74 | } | ||
75 | #else | ||
76 | # define mkswap_generate_uuid(buf) ((void)0) | ||
52 | #endif | 77 | #endif |
53 | 78 | ||
54 | #if 0 /* from Linux 2.6.23 */ | 79 | #if 0 /* from Linux 2.6.23 */ |
@@ -113,10 +138,10 @@ int mkswap_main(int argc, char **argv) | |||
113 | // Make a header. hdr is zero-filled so far... | 138 | // Make a header. hdr is zero-filled so far... |
114 | hdr[0] = 1; | 139 | hdr[0] = 1; |
115 | hdr[1] = (len / pagesize) - 1; | 140 | hdr[1] = (len / pagesize) - 1; |
141 | mkswap_generate_uuid((void*) &hdr[3]); | ||
116 | 142 | ||
117 | // Write the header. Sync to disk because some kernel versions check | 143 | // Write the header. Sync to disk because some kernel versions check |
118 | // signature on disk (not in cache) during swapon. | 144 | // signature on disk (not in cache) during swapon. |
119 | |||
120 | xlseek(fd, 1024, SEEK_SET); | 145 | xlseek(fd, 1024, SEEK_SET); |
121 | xwrite(fd, hdr, NWORDS * 4); | 146 | xwrite(fd, hdr, NWORDS * 4); |
122 | xlseek(fd, pagesize - 10, SEEK_SET); | 147 | xlseek(fd, pagesize - 10, SEEK_SET); |