diff options
author | Manuel Novoa III <mjn3@codepoet.org> | 2003-03-19 09:13:01 +0000 |
---|---|---|
committer | Manuel Novoa III <mjn3@codepoet.org> | 2003-03-19 09:13:01 +0000 |
commit | cad5364599eb5062d59e0c397ed638ddd61a8d5d (patch) | |
tree | a318d0f03aa076c74b576ea45dc543a5669e8e91 /util-linux/mkswap.c | |
parent | e01f9662a5bd5d91be4f6b3941b57fff73cd5af1 (diff) | |
download | busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.gz busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.bz2 busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.zip |
Major coreutils update.
Diffstat (limited to 'util-linux/mkswap.c')
-rw-r--r-- | util-linux/mkswap.c | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c index de10ba71f..15db392d2 100644 --- a/util-linux/mkswap.c +++ b/util-linux/mkswap.c | |||
@@ -87,7 +87,7 @@ static inline void init_signature_page(void) | |||
87 | 87 | ||
88 | #ifdef PAGE_SIZE | 88 | #ifdef PAGE_SIZE |
89 | if (pagesize != PAGE_SIZE) | 89 | if (pagesize != PAGE_SIZE) |
90 | error_msg("Assuming pages of size %d", pagesize); | 90 | bb_error_msg("Assuming pages of size %d", pagesize); |
91 | #endif | 91 | #endif |
92 | signature_page = (int *) xmalloc(pagesize); | 92 | signature_page = (int *) xmalloc(pagesize); |
93 | memset(signature_page, 0, pagesize); | 93 | memset(signature_page, 0, pagesize); |
@@ -185,7 +185,7 @@ static inline void page_bad(int page) | |||
185 | bit_test_and_clear(signature_page, page); | 185 | bit_test_and_clear(signature_page, page); |
186 | else { | 186 | else { |
187 | if (badpages == MAX_BADPAGES) | 187 | if (badpages == MAX_BADPAGES) |
188 | error_msg_and_die("too many bad pages"); | 188 | bb_error_msg_and_die("too many bad pages"); |
189 | p->badpages[badpages] = page; | 189 | p->badpages[badpages] = page; |
190 | } | 190 | } |
191 | badpages++; | 191 | badpages++; |
@@ -206,7 +206,7 @@ static void check_blocks(void) | |||
206 | } | 206 | } |
207 | if (do_seek && lseek(DEV, current_page * pagesize, SEEK_SET) != | 207 | if (do_seek && lseek(DEV, current_page * pagesize, SEEK_SET) != |
208 | current_page * pagesize) | 208 | current_page * pagesize) |
209 | error_msg_and_die("seek failed in check_blocks"); | 209 | bb_error_msg_and_die("seek failed in check_blocks"); |
210 | if ((do_seek = (pagesize != read(DEV, buffer, pagesize)))) { | 210 | if ((do_seek = (pagesize != read(DEV, buffer, pagesize)))) { |
211 | page_bad(current_page++); | 211 | page_bad(current_page++); |
212 | continue; | 212 | continue; |
@@ -255,7 +255,7 @@ static long get_size(const char *file) | |||
255 | long size; | 255 | long size; |
256 | 256 | ||
257 | if ((fd = open(file, O_RDONLY)) < 0) | 257 | if ((fd = open(file, O_RDONLY)) < 0) |
258 | perror_msg_and_die("%s", file); | 258 | bb_perror_msg_and_die("%s", file); |
259 | if (ioctl(fd, BLKGETSIZE, &size) >= 0) { | 259 | if (ioctl(fd, BLKGETSIZE, &size) >= 0) { |
260 | int sectors_per_page = pagesize / 512; | 260 | int sectors_per_page = pagesize / 512; |
261 | 261 | ||
@@ -287,7 +287,7 @@ int mkswap_main(int argc, char **argv) | |||
287 | 287 | ||
288 | PAGES = strtol(argv[0], &tmp, 0) / blocks_per_page; | 288 | PAGES = strtol(argv[0], &tmp, 0) / blocks_per_page; |
289 | if (*tmp) | 289 | if (*tmp) |
290 | show_usage(); | 290 | bb_show_usage(); |
291 | } else | 291 | } else |
292 | device_name = argv[0]; | 292 | device_name = argv[0]; |
293 | } else { | 293 | } else { |
@@ -302,19 +302,19 @@ int mkswap_main(int argc, char **argv) | |||
302 | version = atoi(argv[0] + 2); | 302 | version = atoi(argv[0] + 2); |
303 | break; | 303 | break; |
304 | default: | 304 | default: |
305 | show_usage(); | 305 | bb_show_usage(); |
306 | } | 306 | } |
307 | } | 307 | } |
308 | } | 308 | } |
309 | if (!device_name) { | 309 | if (!device_name) { |
310 | error_msg("error: Nowhere to set up swap on?"); | 310 | bb_error_msg("error: Nowhere to set up swap on?"); |
311 | show_usage(); | 311 | bb_show_usage(); |
312 | } | 312 | } |
313 | sz = get_size(device_name); | 313 | sz = get_size(device_name); |
314 | if (!PAGES) { | 314 | if (!PAGES) { |
315 | PAGES = sz; | 315 | PAGES = sz; |
316 | } else if (PAGES > sz && !force) { | 316 | } else if (PAGES > sz && !force) { |
317 | error_msg("error: size %ld is larger than device size %d", | 317 | bb_error_msg("error: size %ld is larger than device size %d", |
318 | PAGES * (pagesize / 1024), sz * (pagesize / 1024)); | 318 | PAGES * (pagesize / 1024), sz * (pagesize / 1024)); |
319 | return EXIT_FAILURE; | 319 | return EXIT_FAILURE; |
320 | } | 320 | } |
@@ -330,13 +330,13 @@ int mkswap_main(int argc, char **argv) | |||
330 | version = 1; | 330 | version = 1; |
331 | } | 331 | } |
332 | if (version != 0 && version != 1) { | 332 | if (version != 0 && version != 1) { |
333 | error_msg("error: unknown version %d", version); | 333 | bb_error_msg("error: unknown version %d", version); |
334 | show_usage(); | 334 | bb_show_usage(); |
335 | } | 335 | } |
336 | if (PAGES < 10) { | 336 | if (PAGES < 10) { |
337 | error_msg("error: swap area needs to be at least %ldkB", | 337 | bb_error_msg("error: swap area needs to be at least %ldkB", |
338 | (long) (10 * pagesize / 1024)); | 338 | (long) (10 * pagesize / 1024)); |
339 | show_usage(); | 339 | bb_show_usage(); |
340 | } | 340 | } |
341 | #if 0 | 341 | #if 0 |
342 | maxpages = ((version == 0) ? V0_MAX_PAGES : V1_MAX_PAGES); | 342 | maxpages = ((version == 0) ? V0_MAX_PAGES : V1_MAX_PAGES); |
@@ -353,17 +353,17 @@ int mkswap_main(int argc, char **argv) | |||
353 | #endif | 353 | #endif |
354 | if (PAGES > maxpages) { | 354 | if (PAGES > maxpages) { |
355 | PAGES = maxpages; | 355 | PAGES = maxpages; |
356 | error_msg("warning: truncating swap area to %ldkB", | 356 | bb_error_msg("warning: truncating swap area to %ldkB", |
357 | PAGES * pagesize / 1024); | 357 | PAGES * pagesize / 1024); |
358 | } | 358 | } |
359 | 359 | ||
360 | DEV = open(device_name, O_RDWR); | 360 | DEV = open(device_name, O_RDWR); |
361 | if (DEV < 0 || fstat(DEV, &statbuf) < 0) | 361 | if (DEV < 0 || fstat(DEV, &statbuf) < 0) |
362 | perror_msg_and_die("%s", device_name); | 362 | bb_perror_msg_and_die("%s", device_name); |
363 | if (!S_ISBLK(statbuf.st_mode)) | 363 | if (!S_ISBLK(statbuf.st_mode)) |
364 | check = 0; | 364 | check = 0; |
365 | else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) | 365 | else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) |
366 | error_msg_and_die("Will not try to make swapdevice on '%s'", device_name); | 366 | bb_error_msg_and_die("Will not try to make swapdevice on '%s'", device_name); |
367 | 367 | ||
368 | #ifdef __sparc__ | 368 | #ifdef __sparc__ |
369 | if (!force && version == 0) { | 369 | if (!force && version == 0) { |
@@ -372,13 +372,13 @@ int mkswap_main(int argc, char **argv) | |||
372 | unsigned short *q, sum; | 372 | unsigned short *q, sum; |
373 | 373 | ||
374 | if (read(DEV, buffer, 512) != 512) | 374 | if (read(DEV, buffer, 512) != 512) |
375 | error_msg_and_die("fatal: first page unreadable"); | 375 | bb_error_msg_and_die("fatal: first page unreadable"); |
376 | if (buffer[508] == 0xDA && buffer[509] == 0xBE) { | 376 | if (buffer[508] == 0xDA && buffer[509] == 0xBE) { |
377 | q = (unsigned short *) (buffer + 510); | 377 | q = (unsigned short *) (buffer + 510); |
378 | for (sum = 0; q >= (unsigned short *) buffer;) | 378 | for (sum = 0; q >= (unsigned short *) buffer;) |
379 | sum ^= *q--; | 379 | sum ^= *q--; |
380 | if (!sum) { | 380 | if (!sum) { |
381 | error_msg("Device '%s' contains a valid Sun disklabel.\n" | 381 | bb_error_msg("Device '%s' contains a valid Sun disklabel.\n" |
382 | "This probably means creating v0 swap would destroy your partition table\n" | 382 | "This probably means creating v0 swap would destroy your partition table\n" |
383 | "No swap created. If you really want to create swap v0 on that device, use\n" | 383 | "No swap created. If you really want to create swap v0 on that device, use\n" |
384 | "the -f option to force it.", device_name); | 384 | "the -f option to force it.", device_name); |
@@ -391,7 +391,7 @@ int mkswap_main(int argc, char **argv) | |||
391 | if (version == 0 || check) | 391 | if (version == 0 || check) |
392 | check_blocks(); | 392 | check_blocks(); |
393 | if (version == 0 && !bit_test_and_clear(signature_page, 0)) | 393 | if (version == 0 && !bit_test_and_clear(signature_page, 0)) |
394 | error_msg_and_die("fatal: first page unreadable"); | 394 | bb_error_msg_and_die("fatal: first page unreadable"); |
395 | if (version == 1) { | 395 | if (version == 1) { |
396 | p->version = version; | 396 | p->version = version; |
397 | p->last_page = PAGES - 1; | 397 | p->last_page = PAGES - 1; |
@@ -400,23 +400,23 @@ int mkswap_main(int argc, char **argv) | |||
400 | 400 | ||
401 | goodpages = PAGES - badpages - 1; | 401 | goodpages = PAGES - badpages - 1; |
402 | if (goodpages <= 0) | 402 | if (goodpages <= 0) |
403 | error_msg_and_die("Unable to set up swap-space: unreadable"); | 403 | bb_error_msg_and_die("Unable to set up swap-space: unreadable"); |
404 | printf("Setting up swapspace version %d, size = %ld bytes\n", | 404 | printf("Setting up swapspace version %d, size = %ld bytes\n", |
405 | version, (long) (goodpages * pagesize)); | 405 | version, (long) (goodpages * pagesize)); |
406 | write_signature((version == 0) ? "SWAP-SPACE" : "SWAPSPACE2"); | 406 | write_signature((version == 0) ? "SWAP-SPACE" : "SWAPSPACE2"); |
407 | 407 | ||
408 | offset = ((version == 0) ? 0 : 1024); | 408 | offset = ((version == 0) ? 0 : 1024); |
409 | if (lseek(DEV, offset, SEEK_SET) != offset) | 409 | if (lseek(DEV, offset, SEEK_SET) != offset) |
410 | error_msg_and_die("unable to rewind swap-device"); | 410 | bb_error_msg_and_die("unable to rewind swap-device"); |
411 | if (write(DEV, (char *) signature_page + offset, pagesize - offset) | 411 | if (write(DEV, (char *) signature_page + offset, pagesize - offset) |
412 | != pagesize - offset) | 412 | != pagesize - offset) |
413 | error_msg_and_die("unable to write signature page"); | 413 | bb_error_msg_and_die("unable to write signature page"); |
414 | 414 | ||
415 | /* | 415 | /* |
416 | * A subsequent swapon() will fail if the signature | 416 | * A subsequent swapon() will fail if the signature |
417 | * is not actually on disk. (This is a kernel bug.) | 417 | * is not actually on disk. (This is a kernel bug.) |
418 | */ | 418 | */ |
419 | if (fsync(DEV)) | 419 | if (fsync(DEV)) |
420 | error_msg_and_die("fsync failed"); | 420 | bb_error_msg_and_die("fsync failed"); |
421 | return EXIT_SUCCESS; | 421 | return EXIT_SUCCESS; |
422 | } | 422 | } |