Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/util-linux/fdisk_sun.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_sun.c
r1765 r2725 1 #if ENABLE_FEATURE_SUN_LABEL2 3 #define SUNOS_SWAP 34 #define SUN_WHOLE_DISK 55 6 #define SUN_LABEL_MAGIC 0xDABE7 #define SUN_LABEL_MAGIC_SWAPPED 0xBEDA8 #define SUN_SSWAP16(x) (sun_other_endian ? fdisk_swap16(x) : (uint16_t)(x))9 #define SUN_SSWAP32(x) (sun_other_endian ? fdisk_swap32(x) : (uint32_t)(x))10 11 /* Copied from linux/major.h */12 #define FLOPPY_MAJOR 213 14 #define SCSI_IOCTL_GET_IDLUN 0x538215 16 1 /* 17 * fdisk sunlabel.c2 * fdisk_sun.c 18 3 * 19 4 * I think this is mostly, or entirely, due to … … 24 9 * Sat Mar 20 EST 1999 Arnaldo Carvalho de Melo <acme@conectiva.com.br> 25 10 * Internationalization 11 * 12 * Licensed under GPLv2, see file LICENSE in this source tree. 26 13 */ 27 14 28 29 static int sun_other_endian; 30 static int scsi_disk; 31 static int floppy; 15 #if ENABLE_FEATURE_SUN_LABEL 16 17 #define SUNOS_SWAP 3 18 #define SUN_WHOLE_DISK 5 19 20 #define SUN_LABEL_MAGIC 0xDABE 21 #define SUN_LABEL_MAGIC_SWAPPED 0xBEDA 22 #define SUN_SSWAP16(x) (sun_other_endian ? fdisk_swap16(x) : (uint16_t)(x)) 23 #define SUN_SSWAP32(x) (sun_other_endian ? fdisk_swap32(x) : (uint32_t)(x)) 24 25 /* Copied from linux/major.h */ 26 #define FLOPPY_MAJOR 2 27 28 #define SCSI_IOCTL_GET_IDLUN 0x5382 29 30 static smallint sun_other_endian; 31 static smallint scsi_disk; 32 static smallint floppy; 32 33 33 34 #ifndef IDE0_MAJOR … … 43 44 struct stat bootstat; 44 45 45 if (fstat( fd, &bootstat) < 0) {46 if (fstat(dev_fd, &bootstat) < 0) { 46 47 scsi_disk = 0; 47 48 floppy = 0; … … 81 82 82 83 static void 83 set_sun_partition(int i, u int start, uintstop, int sysid)84 set_sun_partition(int i, unsigned start, unsigned stop, int sysid) 84 85 { 85 86 sunlabel->infos[i].id = sysid; 86 87 sunlabel->partitions[i].start_cylinder = 87 SUN_SSWAP32(start / ( heads *sectors));88 SUN_SSWAP32(start / (g_heads * g_sectors)); 88 89 sunlabel->partitions[i].num_sectors = 89 90 SUN_SSWAP32(stop - start); … … 98 99 99 100 if (sunlabel->magic != SUN_LABEL_MAGIC 100 && sunlabel->magic != SUN_LABEL_MAGIC_SWAPPED) { 101 current_label_type = label_dos; 101 && sunlabel->magic != SUN_LABEL_MAGIC_SWAPPED 102 ) { 103 current_label_type = LABEL_DOS; 102 104 sun_other_endian = 0; 103 105 return 0; … … 112 114 "or force a fresh label (s command in main menu)\n"); 113 115 } else { 114 heads = SUN_SSWAP16(sunlabel->ntrks);115 cylinders = SUN_SSWAP16(sunlabel->ncyl);116 sectors = SUN_SSWAP16(sunlabel->nsect);116 g_heads = SUN_SSWAP16(sunlabel->ntrks); 117 g_cylinders = SUN_SSWAP16(sunlabel->ncyl); 118 g_sectors = SUN_SSWAP16(sunlabel->nsect); 117 119 } 118 120 update_units(); 119 current_label_type = label_sun;120 partitions = 8;121 current_label_type = LABEL_SUN; 122 g_partitions = 8; 121 123 return 1; 122 124 } … … 169 171 int i; 170 172 171 if (ioctl( fd, SCSI_IOCTL_GET_IDLUN, &id))173 if (ioctl(dev_fd, SCSI_IOCTL_GET_IDLUN, &id)) 172 174 return NULL; 173 175 174 176 sprintf(buffer, 175 "Host: scsi% d Channel: %02d Id: %02d Lun: %02d\n",177 "Host: scsi%u Channel: %02u Id: %02u Lun: %02u\n", 176 178 /* This is very wrong (works only if you have one HBA), 177 179 but I haven't found a way how to get hostno … … 182 184 (id[0]>>8) & 0xff 183 185 ); 184 pfd = fopen ("/proc/scsi/scsi", "r");186 pfd = fopen_for_read("/proc/scsi/scsi"); 185 187 if (!pfd) { 186 188 return NULL; … … 231 233 { 232 234 struct hd_geometry geometry; 233 unsigned int ndiv; 234 int i; 235 unsigned ndiv; 235 236 unsigned char c; 236 237 const struct sun_predefined_drives *p = NULL; … … 242 243 sunlabel->magic = SUN_SSWAP16(SUN_LABEL_MAGIC); 243 244 if (!floppy) { 245 unsigned i; 244 246 puts("Drive type\n" 245 247 " ? auto configure\n" … … 273 275 } 274 276 if (!p || floppy) { 275 if (!ioctl( fd, HDIO_GETGEO, &geometry)) {276 heads = geometry.heads;277 sectors = geometry.sectors;278 cylinders = geometry.cylinders;277 if (!ioctl(dev_fd, HDIO_GETGEO, &geometry)) { 278 g_heads = geometry.heads; 279 g_sectors = geometry.sectors; 280 g_cylinders = geometry.cylinders; 279 281 } else { 280 heads = 0;281 sectors = 0;282 cylinders = 0;282 g_heads = 0; 283 g_sectors = 0; 284 g_cylinders = 0; 283 285 } 284 286 if (floppy) { 285 287 sunlabel->nacyl = 0; 286 sunlabel->pcylcount = SUN_SSWAP16( cylinders);288 sunlabel->pcylcount = SUN_SSWAP16(g_cylinders); 287 289 sunlabel->rspeed = SUN_SSWAP16(300); 288 290 sunlabel->ilfact = SUN_SSWAP16(1); 289 291 sunlabel->sparecyl = 0; 290 292 } else { 291 heads = read_int(1,heads, 1024, 0, "Heads");292 sectors = read_int(1,sectors, 1024, 0, "Sectors/track");293 if ( cylinders)294 cylinders = read_int(1, cylinders-2, 65535, 0, "Cylinders");293 g_heads = read_int(1, g_heads, 1024, 0, "Heads"); 294 g_sectors = read_int(1, g_sectors, 1024, 0, "Sectors/track"); 295 if (g_cylinders) 296 g_cylinders = read_int(1, g_cylinders - 2, 65535, 0, "Cylinders"); 295 297 else 296 cylinders = read_int(1, 0, 65535, 0, "Cylinders");298 g_cylinders = read_int(1, 0, 65535, 0, "Cylinders"); 297 299 sunlabel->nacyl = SUN_SSWAP16(read_int(0, 2, 65535, 0, "Alternate cylinders")); 298 sunlabel->pcylcount = SUN_SSWAP16(read_int(0, cylinders+SUN_SSWAP16(sunlabel->nacyl), 65535, 0, "Physical cylinders"));300 sunlabel->pcylcount = SUN_SSWAP16(read_int(0, g_cylinders + SUN_SSWAP16(sunlabel->nacyl), 65535, 0, "Physical cylinders")); 299 301 sunlabel->rspeed = SUN_SSWAP16(read_int(1, 5400, 100000, 0, "Rotation speed (rpm)")); 300 302 sunlabel->ilfact = SUN_SSWAP16(read_int(1, 1, 32, 0, "Interleave factor")); 301 sunlabel->sparecyl = SUN_SSWAP16(read_int(0, 0, sectors, 0, "Extra sectors per cylinder"));303 sunlabel->sparecyl = SUN_SSWAP16(read_int(0, 0, g_sectors, 0, "Extra sectors per cylinder")); 302 304 } 303 305 } else { … … 310 312 sunlabel->rspeed = SUN_SSWAP16(p->rspeed); 311 313 sunlabel->ilfact = SUN_SSWAP16(1); 312 cylinders = p->ncyl;313 heads = p->ntrks;314 sectors = p->nsect;314 g_cylinders = p->ncyl; 315 g_heads = p->ntrks; 316 g_sectors = p->nsect; 315 317 puts("You may change all the disk params from the x menu"); 316 318 } 317 319 318 320 snprintf((char *)(sunlabel->info), sizeof(sunlabel->info), 319 "%s%s%s cyl % d alt %d hd %d sec %d",321 "%s%s%s cyl %u alt %u hd %u sec %u", 320 322 p ? p->vendor : "", (p && *p->vendor) ? " " : "", 321 323 p ? p->model : (floppy ? "3,5\" floppy" : "Linux custom"), 322 cylinders, SUN_SSWAP16(sunlabel->nacyl), heads,sectors);323 324 sunlabel->ntrks = SUN_SSWAP16( heads);325 sunlabel->nsect = SUN_SSWAP16( sectors);326 sunlabel->ncyl = SUN_SSWAP16( cylinders);324 g_cylinders, SUN_SSWAP16(sunlabel->nacyl), g_heads, g_sectors); 325 326 sunlabel->ntrks = SUN_SSWAP16(g_heads); 327 sunlabel->nsect = SUN_SSWAP16(g_sectors); 328 sunlabel->ncyl = SUN_SSWAP16(g_cylinders); 327 329 if (floppy) 328 set_sun_partition(0, 0, cylinders * heads *sectors, LINUX_NATIVE);330 set_sun_partition(0, 0, g_cylinders * g_heads * g_sectors, LINUX_NATIVE); 329 331 else { 330 if ( cylinders * heads *sectors >= 150 * 2048) {331 ndiv = cylinders - (50 * 2048 / (heads *sectors)); /* 50M swap */332 if (g_cylinders * g_heads * g_sectors >= 150 * 2048) { 333 ndiv = g_cylinders - (50 * 2048 / (g_heads * g_sectors)); /* 50M swap */ 332 334 } else 333 ndiv = cylinders * 2 / 3;334 set_sun_partition(0, 0, ndiv * heads *sectors, LINUX_NATIVE);335 set_sun_partition(1, ndiv * heads * sectors, cylinders * heads *sectors, LINUX_SWAP);335 ndiv = g_cylinders * 2 / 3; 336 set_sun_partition(0, 0, ndiv * g_heads * g_sectors, LINUX_NATIVE); 337 set_sun_partition(1, ndiv * g_heads * g_sectors, g_cylinders * g_heads * g_sectors, LINUX_SWAP); 336 338 sunlabel->infos[1].flags |= 0x01; /* Not mountable */ 337 339 } 338 set_sun_partition(2, 0, cylinders * heads *sectors, SUN_WHOLE_DISK);340 set_sun_partition(2, 0, g_cylinders * g_heads * g_sectors, SUN_WHOLE_DISK); 339 341 { 340 342 unsigned short *ush = (unsigned short *)sunlabel; … … 347 349 set_all_unchanged(); 348 350 set_changed(0); 349 get_boot( create_empty_sun);351 get_boot(CREATE_EMPTY_SUN); 350 352 } 351 353 … … 361 363 362 364 static void 363 fetch_sun(u int *starts, uint *lens, uint *start, uint*stop)365 fetch_sun(unsigned *starts, unsigned *lens, unsigned *start, unsigned *stop) 364 366 { 365 367 int i, continuous = 1; 366 368 367 369 *start = 0; 368 *stop = cylinders * heads *sectors;369 for (i = 0; i < partitions; i++) {370 *stop = g_cylinders * g_heads * g_sectors; 371 for (i = 0; i < g_partitions; i++) { 370 372 if (sunlabel->partitions[i].num_sectors 371 373 && sunlabel->infos[i].id 372 374 && sunlabel->infos[i].id != SUN_WHOLE_DISK) { 373 starts[i] = SUN_SSWAP32(sunlabel->partitions[i].start_cylinder) * heads *sectors;375 starts[i] = SUN_SSWAP32(sunlabel->partitions[i].start_cylinder) * g_heads * g_sectors; 374 376 lens[i] = SUN_SSWAP32(sunlabel->partitions[i].num_sectors); 375 377 if (continuous) { … … 390 392 } 391 393 392 static u int*verify_sun_starts;394 static unsigned *verify_sun_starts; 393 395 394 396 static int … … 404 406 verify_sun(void) 405 407 { 406 u intstarts[8], lens[8], start, stop;408 unsigned starts[8], lens[8], start, stop; 407 409 int i,j,k,starto,endo; 408 410 int array[8]; 409 411 410 412 verify_sun_starts = starts; 411 fetch_sun(starts, lens,&start,&stop);413 fetch_sun(starts, lens, &start, &stop); 412 414 for (k = 0; k < 7; k++) { 413 415 for (i = 0; i < 8; i++) { 414 if (k && (lens[i] % ( heads *sectors))) {415 printf("Partition % ddoesn't end on cylinder boundary\n", i+1);416 if (k && (lens[i] % (g_heads * g_sectors))) { 417 printf("Partition %u doesn't end on cylinder boundary\n", i+1); 416 418 } 417 419 if (lens[i]) { … … 433 435 if (starts[j]+lens[j] < endo) 434 436 endo = starts[j]+lens[j]; 435 printf("Partition % doverlaps with others in "436 "sectors % d-%d\n", i+1, starto, endo);437 printf("Partition %u overlaps with others in " 438 "sectors %u-%u\n", i+1, starto, endo); 437 439 } 438 440 } … … 453 455 return; 454 456 } 455 stop = cylinders * heads *sectors;457 stop = g_cylinders * g_heads * g_sectors; 456 458 if (starts[array[0]]) 457 printf("Unused gap - sectors 0-%d\n", starts[array[0]]);459 printf("Unused gap - sectors %u-%u\n", 0, starts[array[0]]); 458 460 for (i = 0; i < 7 && array[i+1] != -1; i++) { 459 printf("Unused gap - sectors % d-%d\n", starts[array[i]]+lens[array[i]], starts[array[i+1]]);461 printf("Unused gap - sectors %u-%u\n", starts[array[i]]+lens[array[i]], starts[array[i+1]]); 460 462 } 461 463 start = starts[array[i]] + lens[array[i]]; 462 464 if (start < stop) 463 printf("Unused gap - sectors % d-%d\n", start, stop);465 printf("Unused gap - sectors %u-%u\n", start, stop); 464 466 } 465 467 … … 467 469 add_sun_partition(int n, int sys) 468 470 { 469 u intstart, stop, stop2;470 u intstarts[8], lens[8];471 unsigned start, stop, stop2; 472 unsigned starts[8], lens[8]; 471 473 int whole_disk = 0; 472 474 … … 479 481 } 480 482 481 fetch_sun(starts, lens,&start,&stop);483 fetch_sun(starts, lens, &start, &stop); 482 484 if (stop <= start) { 483 485 if (n == 2) … … 500 502 else 501 503 /* Starting sector has to be properly aligned */ 502 first = (first + heads * sectors - 1) / (heads *sectors);504 first = (first + g_heads * g_sectors - 1) / (g_heads * g_sectors); 503 505 if (n == 2 && first != 0) 504 506 printf("\ … … 521 523 starting at block 0 in an md, or the label will 522 524 be trashed. */ 523 for (i = 0; i < partitions; i++)525 for (i = 0; i < g_partitions; i++) 524 526 if (lens[i] && starts[i] <= first && starts[i] + lens[i] > first) 525 527 break; 526 if (i < partitions && !whole_disk) {528 if (i < g_partitions && !whole_disk) { 527 529 if (n == 2 && !first) { 528 530 whole_disk = 1; 529 531 break; 530 532 } 531 printf("Sector % dis already allocated\n", first);533 printf("Sector %u is already allocated\n", first); 532 534 } else 533 535 break; 534 536 } 535 stop = cylinders * heads *sectors;537 stop = g_cylinders * g_heads * g_sectors; 536 538 stop2 = stop; 537 for (i = 0; i < partitions; i++) {539 for (i = 0; i < g_partitions; i++) { 538 540 if (starts[i] > first && starts[i] < stop) 539 541 stop = starts[i]; … … 560 562 printf( 561 563 "You haven't covered the whole disk with the 3rd partition,\n" 562 "but your value % d%s covers some other partition.\n"563 "Your entry has been changed to % d%s\n",564 "but your value %u %s covers some other partition.\n" 565 "Your entry has been changed to %u %s\n", 564 566 scround(last), str_units(SINGULAR), 565 567 scround(stop), str_units(SINGULAR)); … … 582 584 && sunlabel->infos[i].id == SUN_WHOLE_DISK 583 585 && !sunlabel->partitions[i].start_cylinder 584 && (nsec = SUN_SSWAP32(sunlabel->partitions[i].num_sectors)) == heads * sectors *cylinders)586 && (nsec = SUN_SSWAP32(sunlabel->partitions[i].num_sectors)) == g_heads * g_sectors * g_cylinders) 585 587 printf("If you want to maintain SunOS/Solaris compatibility, " 586 588 "consider leaving this\n" … … 627 629 if (xtra) 628 630 printf( 629 "\nDisk %s (Sun disk label): % d heads, %d sectors, %drpm\n"630 "% d cylinders, %d alternate cylinders, %dphysical cylinders\n"631 "% d extra sects/cyl, interleave %d:1\n"631 "\nDisk %s (Sun disk label): %u heads, %u sectors, %u rpm\n" 632 "%u cylinders, %u alternate cylinders, %u physical cylinders\n" 633 "%u extra sects/cyl, interleave %u:1\n" 632 634 "%s\n" 633 "Units = %s of % d* 512 bytes\n\n",634 disk_device, heads,sectors, SUN_SSWAP16(sunlabel->rspeed),635 cylinders, SUN_SSWAP16(sunlabel->nacyl),635 "Units = %s of %u * 512 bytes\n\n", 636 disk_device, g_heads, g_sectors, SUN_SSWAP16(sunlabel->rspeed), 637 g_cylinders, SUN_SSWAP16(sunlabel->nacyl), 636 638 SUN_SSWAP16(sunlabel->pcylcount), 637 639 SUN_SSWAP16(sunlabel->sparecyl), … … 641 643 else 642 644 printf( 643 "\nDisk %s (Sun disk label): % d heads, %d sectors, %dcylinders\n"644 "Units = %s of % d* 512 bytes\n\n",645 disk_device, heads, sectors,cylinders,645 "\nDisk %s (Sun disk label): %u heads, %u sectors, %u cylinders\n" 646 "Units = %s of %u * 512 bytes\n\n", 647 disk_device, g_heads, g_sectors, g_cylinders, 646 648 str_units(PLURAL), units_per_sector); 647 649 648 650 printf("%*s Flag Start End Blocks Id System\n", 649 651 w + 1, "Device"); 650 for (i = 0; i < partitions; i++) {652 for (i = 0; i < g_partitions; i++) { 651 653 if (sunlabel->partitions[i].num_sectors) { 652 uint32_t start = SUN_SSWAP32(sunlabel->partitions[i].start_cylinder) * heads *sectors;654 uint32_t start = SUN_SSWAP32(sunlabel->partitions[i].start_cylinder) * g_heads * g_sectors; 653 655 uint32_t len = SUN_SSWAP32(sunlabel->partitions[i].num_sectors); 654 printf("%s %c%c %9l d %9ld %9ld%c %2x %s\n",655 partname(disk_device, i+1, w), 656 printf("%s %c%c %9lu %9lu %9lu%c %2x %s\n", 657 partname(disk_device, i+1, w), /* device */ 656 658 (sunlabel->infos[i].flags & 0x01) ? 'u' : ' ', /* flags */ 657 659 (sunlabel->infos[i].flags & 0x10) ? 'r' : ' ', … … 685 687 { 686 688 sunlabel->sparecyl = 687 SUN_SSWAP16(read_int(0, SUN_SSWAP16(sunlabel->sparecyl), sectors, 0,689 SUN_SSWAP16(read_int(0, SUN_SSWAP16(sunlabel->sparecyl), g_sectors, 0, 688 690 "Extra sectors per cylinder")); 689 691 } … … 723 725 csum ^= *ush++; 724 726 sunlabel->csum = csum; 725 if (lseek(fd, 0, SEEK_SET) < 0) 726 fdisk_fatal(unable_to_seek); 727 if (write(fd, sunlabel, SECTOR_SIZE) != SECTOR_SIZE) 728 fdisk_fatal(unable_to_write); 727 write_sector(0, sunlabel); 729 728 } 730 729 #endif /* SUN_LABEL */
Note:
See TracChangeset
for help on using the changeset viewer.