- if (device_name && !PAGES) {
- PAGES = get_size(device_name) / PAGE_SIZE;
- }
- if (!device_name || PAGES<10) {
- fprintf(stderr,
- "%s: error: swap area needs to be at least %ldkB\n",
- program_name, 10 * PAGE_SIZE / 1024);
- /* usage(mkswap_usage); */
- exit(1);
- }
- if (PAGES > 8 * (PAGE_SIZE - 10)) {
- PAGES = 8 * (PAGE_SIZE - 10);
- fprintf(stderr, "%s: warning: truncating swap area to %ldkB\n",
- program_name, PAGES * PAGE_SIZE / 1024);
- }
- DEV = open(device_name,O_RDWR);
- if (DEV < 0 || fstat(DEV, &statbuf) < 0) {
- perror(device_name);
- exit(1);
- }
- if (!S_ISBLK(statbuf.st_mode))
- do_check=0;
- else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340)
- die("Will not try to make swapdevice on '%s'");
- check_blocks(signature_page);
- if (!bit_test_and_clear(signature_page,0))
- die("fatal: first page unreadable");
- goodpages = PAGES - badpages - 1;
- if (goodpages <= 0)
- die("Unable to set up swap-space: unreadable");
- printf("Setting up swapspace, size = %ld bytes\n",goodpages*PAGE_SIZE);
- strncpy((char*)signature_page+PAGE_SIZE-10,"SWAP-SPACE",10);
- if (lseek(DEV, 0, SEEK_SET))
- die("unable to rewind swap-device");
- if (PAGE_SIZE != write(DEV, signature_page, PAGE_SIZE))
- die("unable to write signature page");
-
- close(DEV);
- return 0;
-}