aboutsummaryrefslogtreecommitdiff
path: root/util-linux/mkswap.c
diff options
context:
space:
mode:
Diffstat (limited to 'util-linux/mkswap.c')
-rw-r--r--util-linux/mkswap.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c
index 7e32d91ed..53537fcd9 100644
--- a/util-linux/mkswap.c
+++ b/util-linux/mkswap.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright 2006 Rob Landley <rob@landley.net> 4 * Copyright 2006 Rob Landley <rob@landley.net>
5 * 5 *
6 * Licensed under GPL version 2, see file LICENSE in this tarball for details. 6 * Licensed under GPLv2, see file LICENSE in this source tree.
7 */ 7 */
8#include "libbb.h" 8#include "libbb.h"
9 9
@@ -15,8 +15,7 @@ static void mkswap_selinux_setcontext(int fd, const char *path)
15 if (!is_selinux_enabled()) 15 if (!is_selinux_enabled())
16 return; 16 return;
17 17
18 if (fstat(fd, &stbuf) < 0) 18 xfstat(fd, &stbuf, argv[0]);
19 bb_perror_msg_and_die("fstat failed");
20 if (S_ISREG(stbuf.st_mode)) { 19 if (S_ISREG(stbuf.st_mode)) {
21 security_context_t newcon; 20 security_context_t newcon;
22 security_context_t oldcon = NULL; 21 security_context_t oldcon = NULL;
@@ -102,7 +101,15 @@ int mkswap_main(int argc UNUSED_PARAM, char **argv)
102 printf("Setting up swapspace version 1, size = %"OFF_FMT"u bytes\n", len); 101 printf("Setting up swapspace version 1, size = %"OFF_FMT"u bytes\n", len);
103 mkswap_selinux_setcontext(fd, argv[0]); 102 mkswap_selinux_setcontext(fd, argv[0]);
104 103
105 /* Make a header. hdr is zero-filled so far... */ 104 /* hdr is zero-filled so far. Clear the first kbyte, or else
105 * mkswap-ing former FAT partition does NOT erase its signature.
106 *
107 * util-linux-ng 2.17.2 claims to erase it only if it does not see
108 * a partition table and is not run on whole disk. -f forces it.
109 */
110 xwrite(fd, hdr, 1024);
111
112 /* Fill the header. */
106 hdr->version = 1; 113 hdr->version = 1;
107 hdr->last_page = (uoff_t)len / pagesize; 114 hdr->last_page = (uoff_t)len / pagesize;
108 115
@@ -123,7 +130,6 @@ int mkswap_main(int argc UNUSED_PARAM, char **argv)
123 130
124 /* Write the header. Sync to disk because some kernel versions check 131 /* Write the header. Sync to disk because some kernel versions check
125 * signature on disk (not in cache) during swapon. */ 132 * signature on disk (not in cache) during swapon. */
126 xlseek(fd, 1024, SEEK_SET);
127 xwrite(fd, hdr, NWORDS * 4); 133 xwrite(fd, hdr, NWORDS * 4);
128 xlseek(fd, pagesize - 10, SEEK_SET); 134 xlseek(fd, pagesize - 10, SEEK_SET);
129 xwrite(fd, SWAPSPACE2, 10); 135 xwrite(fd, SWAPSPACE2, 10);