diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-02-01 23:48:27 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-02-01 23:48:27 +0100 |
commit | 40e7d25aca1abbe080e00e2bed64b444a5ec7858 (patch) | |
tree | 05cda08f66542aeb94d1ebb906a0f04b04a41d62 /util-linux | |
parent | 4875e7148b0512ee3c255526a484503da984935a (diff) | |
download | busybox-w32-40e7d25aca1abbe080e00e2bed64b444a5ec7858.tar.gz busybox-w32-40e7d25aca1abbe080e00e2bed64b444a5ec7858.tar.bz2 busybox-w32-40e7d25aca1abbe080e00e2bed64b444a5ec7858.zip |
mkXXXX: unify [KBYTES] parameter handling (added it to mkswap)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux')
-rw-r--r-- | util-linux/mkfs_ext2.c | 14 | ||||
-rw-r--r-- | util-linux/mkfs_reiser.c | 15 | ||||
-rw-r--r-- | util-linux/mkfs_vfat.c | 14 | ||||
-rw-r--r-- | util-linux/mkswap.c | 16 |
4 files changed, 11 insertions, 48 deletions
diff --git a/util-linux/mkfs_ext2.c b/util-linux/mkfs_ext2.c index 19c3c673e..44fb40250 100644 --- a/util-linux/mkfs_ext2.c +++ b/util-linux/mkfs_ext2.c | |||
@@ -230,19 +230,7 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv) | |||
230 | bb_error_msg_and_die("can't format mounted filesystem"); | 230 | bb_error_msg_and_die("can't format mounted filesystem"); |
231 | 231 | ||
232 | // open the device, get size in kbytes | 232 | // open the device, get size in kbytes |
233 | if (argv[1]) { | 233 | kilobytes = get_volume_size_in_bytes(fd, argv[1], 1024, /*extend:*/ !(option_mask32 & OPT_n)) / 1024; |
234 | kilobytes = xatoull(argv[1]); | ||
235 | // seek past end fails on block devices but works on files | ||
236 | if (lseek(fd, kilobytes * 1024 - 1, SEEK_SET) != (off_t)-1) { | ||
237 | if (!(option_mask32 & OPT_n)) | ||
238 | xwrite(fd, "", 1); // file grows if needed | ||
239 | } | ||
240 | //else { | ||
241 | // bb_error_msg("warning, block device is smaller"); | ||
242 | //} | ||
243 | } else { | ||
244 | kilobytes = (uoff_t)xlseek(fd, 0, SEEK_END) / 1024; | ||
245 | } | ||
246 | 234 | ||
247 | bytes_per_inode = 16384; | 235 | bytes_per_inode = 16384; |
248 | if (kilobytes < 512*1024) | 236 | if (kilobytes < 512*1024) |
diff --git a/util-linux/mkfs_reiser.c b/util-linux/mkfs_reiser.c index 7f37eb845..eb2c94d02 100644 --- a/util-linux/mkfs_reiser.c +++ b/util-linux/mkfs_reiser.c | |||
@@ -175,23 +175,12 @@ int mkfs_reiser_main(int argc UNUSED_PARAM, char **argv) | |||
175 | 175 | ||
176 | // check if it is mounted | 176 | // check if it is mounted |
177 | // N.B. what if we format a file? find_mount_point will return false negative since | 177 | // N.B. what if we format a file? find_mount_point will return false negative since |
178 | // it is loop block device which mounted! | 178 | // it is loop block device which is mounted! |
179 | if (find_mount_point(argv[0], 0)) | 179 | if (find_mount_point(argv[0], 0)) |
180 | bb_error_msg_and_die("can't format mounted filesystem"); | 180 | bb_error_msg_and_die("can't format mounted filesystem"); |
181 | 181 | ||
182 | // open the device, get size in blocks | 182 | // open the device, get size in blocks |
183 | if (argv[1]) { | 183 | blocks = get_volume_size_in_bytes(fd, argv[1], blocksize, /*extend:*/ 1) / blocksize; |
184 | blocks = xatoull(argv[1]); | ||
185 | // seek past end fails on block devices but works on files | ||
186 | if (lseek(fd, blocks * blocksize - 1, SEEK_SET) != (off_t)-1) { | ||
187 | xwrite(fd, "", 1); // file grows if needed | ||
188 | } | ||
189 | //else { | ||
190 | // bb_error_msg("warning, block device is smaller"); | ||
191 | //} | ||
192 | } else { | ||
193 | blocks = (uoff_t)xlseek(fd, 0, SEEK_END) / blocksize; | ||
194 | } | ||
195 | 184 | ||
196 | // block number sanity check | 185 | // block number sanity check |
197 | // we have a limit: skipped area, super block, journal and root block | 186 | // we have a limit: skipped area, super block, journal and root block |
diff --git a/util-linux/mkfs_vfat.c b/util-linux/mkfs_vfat.c index a9a65aa07..1363612f2 100644 --- a/util-linux/mkfs_vfat.c +++ b/util-linux/mkfs_vfat.c | |||
@@ -244,7 +244,7 @@ int mkfs_vfat_main(int argc UNUSED_PARAM, char **argv) | |||
244 | // default volume ID = creation time | 244 | // default volume ID = creation time |
245 | volume_id = time(NULL); | 245 | volume_id = time(NULL); |
246 | 246 | ||
247 | dev = xopen(device_name, O_EXCL | O_RDWR); | 247 | dev = xopen(device_name, O_RDWR); |
248 | if (fstat(dev, &st) < 0) | 248 | if (fstat(dev, &st) < 0) |
249 | bb_simple_perror_msg_and_die(device_name); | 249 | bb_simple_perror_msg_and_die(device_name); |
250 | 250 | ||
@@ -252,7 +252,6 @@ int mkfs_vfat_main(int argc UNUSED_PARAM, char **argv) | |||
252 | // Get image size and sector size | 252 | // Get image size and sector size |
253 | // | 253 | // |
254 | bytes_per_sect = SECTOR_SIZE; | 254 | bytes_per_sect = SECTOR_SIZE; |
255 | volume_size_bytes = st.st_size; | ||
256 | if (!S_ISBLK(st.st_mode)) { | 255 | if (!S_ISBLK(st.st_mode)) { |
257 | if (!S_ISREG(st.st_mode)) { | 256 | if (!S_ISREG(st.st_mode)) { |
258 | if (!argv[1]) | 257 | if (!argv[1]) |
@@ -262,10 +261,6 @@ int mkfs_vfat_main(int argc UNUSED_PARAM, char **argv) | |||
262 | opts &= ~OPT_c; | 261 | opts &= ~OPT_c; |
263 | } else { | 262 | } else { |
264 | int min_bytes_per_sect; | 263 | int min_bytes_per_sect; |
265 | |||
266 | // more portable than BLKGETSIZE[64] | ||
267 | volume_size_bytes = xlseek(dev, 0, SEEK_END); | ||
268 | xlseek(dev, 0, SEEK_SET); | ||
269 | #if 0 | 264 | #if 0 |
270 | unsigned device_num; | 265 | unsigned device_num; |
271 | // for true block devices we do check sanity | 266 | // for true block devices we do check sanity |
@@ -290,12 +285,7 @@ int mkfs_vfat_main(int argc UNUSED_PARAM, char **argv) | |||
290 | bb_error_msg("for this device sector size is %u", min_bytes_per_sect); | 285 | bb_error_msg("for this device sector size is %u", min_bytes_per_sect); |
291 | } | 286 | } |
292 | } | 287 | } |
293 | if (argv[1]) { | 288 | volume_size_bytes = get_volume_size_in_bytes(dev, argv[1], 1024, /*extend:*/ 1); |
294 | volume_size_bytes = XATOOFF(argv[1]); | ||
295 | if (volume_size_bytes >= MAXINT(off_t) / 1024) | ||
296 | bb_error_msg_and_die("image size is too big"); | ||
297 | volume_size_bytes *= 1024; | ||
298 | } | ||
299 | volume_size_sect = volume_size_bytes / bytes_per_sect; | 289 | volume_size_sect = volume_size_bytes / bytes_per_sect; |
300 | 290 | ||
301 | // | 291 | // |
diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c index 289692da3..949c71a78 100644 --- a/util-linux/mkswap.c +++ b/util-linux/mkswap.c | |||
@@ -86,23 +86,19 @@ int mkswap_main(int argc UNUSED_PARAM, char **argv) | |||
86 | off_t len; | 86 | off_t len; |
87 | const char *label = ""; | 87 | const char *label = ""; |
88 | 88 | ||
89 | opt_complementary = "=1"; | 89 | opt_complementary = "-1"; /* at least one param */ |
90 | /* TODO: -p PAGESZ, -U UUID, | 90 | /* TODO: -p PAGESZ, -U UUID */ |
91 | * optional SIZE_IN_KB 2nd param | ||
92 | */ | ||
93 | getopt32(argv, "L:", &label); | 91 | getopt32(argv, "L:", &label); |
94 | argv += optind; | 92 | argv += optind; |
95 | 93 | ||
96 | fd = xopen(argv[0], O_WRONLY); | 94 | fd = xopen(argv[0], O_WRONLY); |
97 | 95 | ||
98 | /* Figure out how big the device is and announce our intentions */ | 96 | /* Figure out how big the device is */ |
99 | /* fdlength was reported to be unreliable - use seek */ | 97 | len = get_volume_size_in_bytes(fd, argv[1], 1024, /*extend:*/ 1); |
100 | len = xlseek(fd, 0, SEEK_END); | ||
101 | if (ENABLE_SELINUX) | ||
102 | xlseek(fd, 0, SEEK_SET); | ||
103 | |||
104 | pagesize = getpagesize(); | 98 | pagesize = getpagesize(); |
105 | len -= pagesize; | 99 | len -= pagesize; |
100 | |||
101 | /* Announce our intentions */ | ||
106 | printf("Setting up swapspace version 1, size = %"OFF_FMT"u bytes\n", len); | 102 | printf("Setting up swapspace version 1, size = %"OFF_FMT"u bytes\n", len); |
107 | mkswap_selinux_setcontext(fd, argv[0]); | 103 | mkswap_selinux_setcontext(fd, argv[0]); |
108 | 104 | ||