Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/util-linux/fdisk_sgi.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/util-linux/fdisk_sgi.c
r1765 r2725 1 #if ENABLE_FEATURE_SGI_LABEL2 3 1 /* 4 2 * Copyright (C) Andreas Neuper, Sep 1998. 5 * This file may be modified and redistributed under6 * the terms of the GNU Public License.3 * 4 * Licensed under GPLv2, see file LICENSE in this source tree. 7 5 */ 6 7 #if ENABLE_FEATURE_SGI_LABEL 8 9 #define SGI_DEBUG 0 8 10 9 11 #define SGI_VOLHDR 0x00 … … 35 37 unsigned short bytes; 36 38 unsigned short ilfact; 37 unsigned int flags; 39 unsigned int flags; /* controller flags */ 38 40 unsigned int datarate; 39 41 unsigned int retries_on_error; … … 69 71 unsigned int vol_file_size; /* number of bytes */ 70 72 } directory[15]; 71 struct sgi_partinfo { /* 16 * 12 bytes */73 struct sgi_partinfo { /* 16 * 12 bytes */ 72 74 unsigned int num_sectors; /* number of blocks */ 73 75 unsigned int start_sector; /* must be cylinder aligned */ … … 118 120 119 121 120 static int sgi_other_endian; 121 static int debug; 122 static short sgi_volumes = 1; 122 static smallint sgi_other_endian; /* bool */ 123 static smallint sgi_volumes = 1; /* max 15 */ 123 124 124 125 /* … … 235 236 && sgilabel->magic != SGI_LABEL_MAGIC_SWAPPED 236 237 ) { 237 current_label_type = label_dos;238 current_label_type = LABEL_DOS; 238 239 return 0; 239 240 } … … 248 249 } 249 250 update_units(); 250 current_label_type = label_sgi;251 partitions = 16;251 current_label_type = LABEL_SGI; 252 g_partitions = 16; 252 253 sgi_volumes = 15; 253 254 return 1; … … 291 292 292 293 if (xtra) { 293 printf("\nDisk %s (SGI disk label): % d heads, %dsectors\n"294 "% d cylinders, %dphysical cylinders\n"295 "% d extra sects/cyl, interleave %d:1\n"294 printf("\nDisk %s (SGI disk label): %u heads, %u sectors\n" 295 "%u cylinders, %u physical cylinders\n" 296 "%u extra sects/cyl, interleave %u:1\n" 296 297 "%s\n" 297 "Units = %s of % d* 512 bytes\n\n",298 disk_device, heads, sectors,cylinders,298 "Units = %s of %u * 512 bytes\n\n", 299 disk_device, g_heads, g_sectors, g_cylinders, 299 300 SGI_SSWAP16(sgiparam.pcylcount), 300 301 SGI_SSWAP16(sgiparam.sparecyl), … … 304 305 } else { 305 306 printf("\nDisk %s (SGI disk label): " 306 "% d heads, %d sectors, %dcylinders\n"307 "Units = %s of % d* 512 bytes\n\n",308 disk_device, heads, sectors,cylinders,307 "%u heads, %u sectors, %u cylinders\n" 308 "Units = %s of %u * 512 bytes\n\n", 309 disk_device, g_heads, g_sectors, g_cylinders, 309 310 str_units(PLURAL), units_per_sector ); 310 311 } … … 318 319 "Pt# %*s Info Start End Sectors Id System\n", 319 320 w + 2, "Device"); 320 for (i = 0; i < partitions; i++) {321 if (sgi_get_num_sectors(i) || debug) {321 for (i = 0; i < g_partitions; i++) { 322 if (sgi_get_num_sectors(i) || SGI_DEBUG) { 322 323 uint32_t start = sgi_get_start_sector(i); 323 324 uint32_t len = sgi_get_num_sectors(i); 324 325 kpi++; /* only count nonempty partitions */ 325 326 printf( 326 "%2 d: %s %4s %9ld %9ld %9ld%2x %s\n",327 "%2u: %s %4s %9lu %9lu %9lu %2x %s\n", 327 328 /* fdisk part number */ i+1, 328 329 /* device */ partname(disk_device, kpi, w+3), … … 345 346 unsigned char *name = sgilabel->directory[i].vol_file_name; 346 347 347 printf("%2 d: %-10s sector%5u size%8u\n",348 printf("%2u: %-10s sector%5u size%8u\n", 348 349 i, (char*)name, (unsigned int) start, (unsigned int) len); 349 350 } … … 360 361 sgi_get_lastblock(void) 361 362 { 362 return heads * sectors *cylinders;363 return g_heads * g_sectors * g_cylinders; 363 364 } 364 365 … … 439 440 (unsigned int*)sgilabel, sizeof(*sgilabel)) == 0); 440 441 441 if (lseek(fd, 0, SEEK_SET) < 0) 442 fdisk_fatal(unable_to_seek); 443 if (write(fd, sgilabel, SECTOR_SIZE) != SECTOR_SIZE) 444 fdisk_fatal(unable_to_write); 442 write_sector(0, sgilabel); 445 443 if (!strncmp((char*)sgilabel->directory[0].vol_file_name, "sgilabel", 8)) { 446 444 /* … … 450 448 sgiinfo *info = fill_sgiinfo(); 451 449 int infostartblock = SGI_SSWAP32(sgilabel->directory[0].vol_file_start); 452 if (lseek(fd, infostartblock*SECTOR_SIZE, SEEK_SET) < 0) 453 fdisk_fatal(unable_to_seek); 454 if (write(fd, info, SECTOR_SIZE) != SECTOR_SIZE) 455 fdisk_fatal(unable_to_write); 450 write_sector(infostartblock, info); 456 451 free(info); 457 452 } … … 513 508 printf("The entire disk partition should start " 514 509 "at block 0,\n" 515 "not at diskblock % d\n",510 "not at diskblock %u\n", 516 511 sgi_get_start_sector(Index[0])); 517 if ( debug) /* I do not understand how some disks fulfil it */512 if (SGI_DEBUG) /* I do not understand how some disks fulfil it */ 518 513 if ((sgi_get_num_sectors(Index[0]) != lastblock) && verbose) 519 printf("The entire disk partition is only % ddiskblock large,\n"520 "but the disk is % ddiskblocks long\n",514 printf("The entire disk partition is only %u diskblock large,\n" 515 "but the disk is %u diskblocks long\n", 521 516 sgi_get_num_sectors(Index[0]), lastblock); 522 517 lastblock = sgi_get_num_sectors(Index[0]); … … 524 519 if (verbose) 525 520 printf("One Partition (#11) should cover the entire disk\n"); 526 if ( debug> 2)527 printf("sysid=% d\tpartition=%d\n",521 if (SGI_DEBUG > 2) 522 printf("sysid=%u\tpartition=%u\n", 528 523 sgi_get_sysid(Index[0]), Index[0]+1); 529 524 } … … 532 527 533 528 if ((sgi_get_start_sector(Index[i]) % cylsize) != 0) { 534 if ( debug) /* I do not understand how some disks fulfil it */529 if (SGI_DEBUG) /* I do not understand how some disks fulfil it */ 535 530 if (verbose) 536 printf("Partition % ddoes not start on cylinder boundary\n",531 printf("Partition %u does not start on cylinder boundary\n", 537 532 Index[i]+1); 538 533 } 539 534 if (sgi_get_num_sectors(Index[i]) % cylsize != 0) { 540 if ( debug) /* I do not understand how some disks fulfil it */535 if (SGI_DEBUG) /* I do not understand how some disks fulfil it */ 541 536 if (verbose) 542 printf("Partition % ddoes not end on cylinder boundary\n",537 printf("Partition %u does not end on cylinder boundary\n", 543 538 Index[i]+1); 544 539 } … … 547 542 if (start > sgi_get_start_sector(Index[i])) { 548 543 if (verbose) 549 printf("Partitions % d and %d overlap by %dsectors\n",544 printf("Partitions %u and %u overlap by %u sectors\n", 550 545 Index[i-1]+1, Index[i]+1, 551 546 start - sgi_get_start_sector(Index[i])); … … 555 550 if (start < sgi_get_start_sector(Index[i])) { 556 551 if (verbose) 557 printf("Unused gap of % 8u sectors - sectors %8u-%8u\n",552 printf("Unused gap of %u sectors - sectors %u-%u\n", 558 553 sgi_get_start_sector(Index[i]) - start, 559 554 start, sgi_get_start_sector(Index[i])-1); … … 563 558 start = sgi_get_start_sector(Index[i]) 564 559 + sgi_get_num_sectors(Index[i]); 565 if ( debug> 1) {560 if (SGI_DEBUG > 1) { 566 561 if (verbose) 567 printf("%2 d:%12d\t%12d\t%12d\n", Index[i],562 printf("%2u:%12u\t%12u\t%12u\n", Index[i], 568 563 sgi_get_start_sector(Index[i]), 569 564 sgi_get_num_sectors(Index[i]), … … 573 568 if (start < lastblock) { 574 569 if (verbose) 575 printf("Unused gap of % 8u sectors - sectors %8u-%8u\n",570 printf("Unused gap of %u sectors - sectors %u-%u\n", 576 571 lastblock - start, start, lastblock-1); 577 572 gap += lastblock - start; … … 661 656 int n; 662 657 663 for (n = 10; n < partitions; n++) {658 for (n = 10; n < g_partitions; n++) { 664 659 if (!sgi_get_num_sectors(n) ) { 665 660 sgi_set_partition(n, 0, sgi_get_lastblock(), SGI_VOLUME); … … 674 669 int n; 675 670 676 for (n = 8; n < partitions; n++) {671 for (n = 8; n < g_partitions; n++) { 677 672 if (!sgi_get_num_sectors(n)) { 678 673 /* … … 682 677 * sectors. 683 678 */ 684 if ( heads *sectors * 5 < sgi_get_lastblock())685 sgi_set_partition(n, 0, heads *sectors * 5, SGI_VOLHDR);679 if (g_heads * g_sectors * 5 < sgi_get_lastblock()) 680 sgi_set_partition(n, 0, g_heads * g_sectors * 5, SGI_VOLHDR); 686 681 break; 687 682 } … … 781 776 printf(msg_building_new_label, "SGI disklabel"); 782 777 783 sgi_other_endian = (BYTE_ORDER == LITTLE_ENDIAN);784 res = ioctl( fd, BLKGETSIZE, &longsectors);785 if (!ioctl( fd, HDIO_GETGEO, &geometry)) {786 heads = geometry.heads;787 sectors = geometry.sectors;778 sgi_other_endian = BB_LITTLE_ENDIAN; 779 res = ioctl(dev_fd, BLKGETSIZE, &longsectors); 780 if (!ioctl(dev_fd, HDIO_GETGEO, &geometry)) { 781 g_heads = geometry.heads; 782 g_sectors = geometry.sectors; 788 783 if (res == 0) { 789 784 /* the get device size ioctl was successful */ 790 cylinders = longsectors / (heads *sectors);791 cylinders /= sec_fac;785 g_cylinders = longsectors / (g_heads * g_sectors); 786 g_cylinders /= sec_fac; 792 787 } else { 793 788 /* otherwise print error and use truncated version */ 794 cylinders = geometry.cylinders;789 g_cylinders = geometry.cylinders; 795 790 printf( 796 "Warning: BLKGETSIZE ioctl failed on %s. Using geometry cylinder value of % d.\n"797 "This value may be truncated for devices > 33.8 GB.\n", disk_device, cylinders);791 "Warning: BLKGETSIZE ioctl failed on %s. Using geometry cylinder value of %u.\n" 792 "This value may be truncated for devices > 33.8 GB.\n", disk_device, g_cylinders); 798 793 } 799 794 } … … 805 800 old[i].start = get_start_sect(get_part_table(i)); 806 801 old[i].nsect = get_nr_sects(get_part_table(i)); 807 printf("Trying to keep parameters of partition % d\n", i);808 if ( debug)809 printf("ID=%02x\tSTART=% d\tLENGTH=%d\n",802 printf("Trying to keep parameters of partition %u\n", i); 803 if (SGI_DEBUG) 804 printf("ID=%02x\tSTART=%u\tLENGTH=%u\n", 810 805 old[i].sysid, old[i].start, old[i].nsect); 811 806 } … … 851 846 //memset( &(sgilabel->directory), 0, sizeof(struct volume_directory)*15 ); 852 847 //memset( &(sgilabel->partitions), 0, sizeof(struct sgi_partinfo)*16 ); 853 current_label_type = label_sgi;854 partitions = 16;848 current_label_type = LABEL_SGI; 849 g_partitions = 16; 855 850 sgi_volumes = 15; 856 851 sgi_set_entire();
Note:
See TracChangeset
for help on using the changeset viewer.