diff options
Diffstat (limited to 'mkswap.c')
-rw-r--r-- | mkswap.c | 24 |
1 files changed, 9 insertions, 15 deletions
@@ -173,12 +173,6 @@ static int bit_test_and_clear(unsigned int *addr, unsigned int nr) | |||
173 | } | 173 | } |
174 | 174 | ||
175 | 175 | ||
176 | static void die(const char *str) | ||
177 | { | ||
178 | error_msg("%s\n", str); | ||
179 | exit(EXIT_FAILURE); | ||
180 | } | ||
181 | |||
182 | static void page_ok(int page) | 176 | static void page_ok(int page) |
183 | { | 177 | { |
184 | if (version == 0) | 178 | if (version == 0) |
@@ -191,7 +185,7 @@ static void page_bad(int page) | |||
191 | bit_test_and_clear(signature_page, page); | 185 | bit_test_and_clear(signature_page, page); |
192 | else { | 186 | else { |
193 | if (badpages == MAX_BADPAGES) | 187 | if (badpages == MAX_BADPAGES) |
194 | die("too many bad pages"); | 188 | error_msg_and_die("too many bad pages\n"); |
195 | p->badpages[badpages] = page; | 189 | p->badpages[badpages] = page; |
196 | } | 190 | } |
197 | badpages++; | 191 | badpages++; |
@@ -212,7 +206,7 @@ static void check_blocks(void) | |||
212 | } | 206 | } |
213 | if (do_seek && lseek(DEV, current_page * pagesize, SEEK_SET) != | 207 | if (do_seek && lseek(DEV, current_page * pagesize, SEEK_SET) != |
214 | current_page * pagesize) | 208 | current_page * pagesize) |
215 | die("seek failed in check_blocks"); | 209 | error_msg_and_die("seek failed in check_blocks\n"); |
216 | if ((do_seek = (pagesize != read(DEV, buffer, pagesize)))) { | 210 | if ((do_seek = (pagesize != read(DEV, buffer, pagesize)))) { |
217 | page_bad(current_page++); | 211 | page_bad(current_page++); |
218 | continue; | 212 | continue; |
@@ -369,7 +363,7 @@ int mkswap_main(int argc, char **argv) | |||
369 | if (!S_ISBLK(statbuf.st_mode)) | 363 | if (!S_ISBLK(statbuf.st_mode)) |
370 | check = 0; | 364 | check = 0; |
371 | else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) | 365 | else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) |
372 | die("Will not try to make swapdevice on '%s'"); | 366 | error_msg_and_die("Will not try to make swapdevice on '%s'\n", device_name); |
373 | 367 | ||
374 | #ifdef __sparc__ | 368 | #ifdef __sparc__ |
375 | if (!force && version == 0) { | 369 | if (!force && version == 0) { |
@@ -378,7 +372,7 @@ int mkswap_main(int argc, char **argv) | |||
378 | unsigned short *q, sum; | 372 | unsigned short *q, sum; |
379 | 373 | ||
380 | if (read(DEV, buffer, 512) != 512) | 374 | if (read(DEV, buffer, 512) != 512) |
381 | die("fatal: first page unreadable"); | 375 | error_msg_and_die("fatal: first page unreadable\n"); |
382 | if (buffer[508] == 0xDA && buffer[509] == 0xBE) { | 376 | if (buffer[508] == 0xDA && buffer[509] == 0xBE) { |
383 | q = (unsigned short *) (buffer + 510); | 377 | q = (unsigned short *) (buffer + 510); |
384 | for (sum = 0; q >= (unsigned short *) buffer;) | 378 | for (sum = 0; q >= (unsigned short *) buffer;) |
@@ -397,7 +391,7 @@ int mkswap_main(int argc, char **argv) | |||
397 | if (version == 0 || check) | 391 | if (version == 0 || check) |
398 | check_blocks(); | 392 | check_blocks(); |
399 | if (version == 0 && !bit_test_and_clear(signature_page, 0)) | 393 | if (version == 0 && !bit_test_and_clear(signature_page, 0)) |
400 | die("fatal: first page unreadable"); | 394 | error_msg_and_die("fatal: first page unreadable\n"); |
401 | if (version == 1) { | 395 | if (version == 1) { |
402 | p->version = version; | 396 | p->version = version; |
403 | p->last_page = PAGES - 1; | 397 | p->last_page = PAGES - 1; |
@@ -406,23 +400,23 @@ int mkswap_main(int argc, char **argv) | |||
406 | 400 | ||
407 | goodpages = PAGES - badpages - 1; | 401 | goodpages = PAGES - badpages - 1; |
408 | if (goodpages <= 0) | 402 | if (goodpages <= 0) |
409 | die("Unable to set up swap-space: unreadable"); | 403 | error_msg_and_die("Unable to set up swap-space: unreadable\n"); |
410 | printf("Setting up swapspace version %d, size = %ld bytes\n", | 404 | printf("Setting up swapspace version %d, size = %ld bytes\n", |
411 | version, (long) (goodpages * pagesize)); | 405 | version, (long) (goodpages * pagesize)); |
412 | write_signature((version == 0) ? "SWAP-SPACE" : "SWAPSPACE2"); | 406 | write_signature((version == 0) ? "SWAP-SPACE" : "SWAPSPACE2"); |
413 | 407 | ||
414 | offset = ((version == 0) ? 0 : 1024); | 408 | offset = ((version == 0) ? 0 : 1024); |
415 | if (lseek(DEV, offset, SEEK_SET) != offset) | 409 | if (lseek(DEV, offset, SEEK_SET) != offset) |
416 | die("unable to rewind swap-device"); | 410 | error_msg_and_die("unable to rewind swap-device\n"); |
417 | if (write(DEV, (char *) signature_page + offset, pagesize - offset) | 411 | if (write(DEV, (char *) signature_page + offset, pagesize - offset) |
418 | != pagesize - offset) | 412 | != pagesize - offset) |
419 | die("unable to write signature page"); | 413 | error_msg_and_die("unable to write signature page\n"); |
420 | 414 | ||
421 | /* | 415 | /* |
422 | * A subsequent swapon() will fail if the signature | 416 | * A subsequent swapon() will fail if the signature |
423 | * is not actually on disk. (This is a kernel bug.) | 417 | * is not actually on disk. (This is a kernel bug.) |
424 | */ | 418 | */ |
425 | if (fsync(DEV)) | 419 | if (fsync(DEV)) |
426 | die("fsync failed"); | 420 | error_msg_and_die("fsync failed\n"); |
427 | return EXIT_SUCCESS; | 421 | return EXIT_SUCCESS; |
428 | } | 422 | } |