fdisk_sun.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. #ifdef CONFIG_FEATURE_SUN_LABEL
  2. #define SUN_LABEL_MAGIC 0xDABE
  3. #define SUN_LABEL_MAGIC_SWAPPED 0xBEDA
  4. #define SUN_SSWAP16(x) (sun_other_endian ? __swap16(x) : (uint16_t)(x))
  5. #define SUN_SSWAP32(x) (sun_other_endian ? __swap32(x) : (uint32_t)(x))
  6. /* Copied from linux/major.h */
  7. #define FLOPPY_MAJOR 2
  8. #define SCSI_IOCTL_GET_IDLUN 0x5382
  9. /*
  10. * fdisksunlabel.c
  11. *
  12. * I think this is mostly, or entirely, due to
  13. * Jakub Jelinek (jj@sunsite.mff.cuni.cz), July 1996
  14. *
  15. * Merged with fdisk for other architectures, aeb, June 1998.
  16. *
  17. * Sat Mar 20 EST 1999 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  18. * Internationalization
  19. */
  20. static int sun_other_endian;
  21. static int scsi_disk;
  22. static int floppy;
  23. #ifndef IDE0_MAJOR
  24. #define IDE0_MAJOR 3
  25. #endif
  26. #ifndef IDE1_MAJOR
  27. #define IDE1_MAJOR 22
  28. #endif
  29. static void
  30. guess_device_type(void)
  31. {
  32. struct stat bootstat;
  33. if (fstat(fd, &bootstat) < 0) {
  34. scsi_disk = 0;
  35. floppy = 0;
  36. } else if (S_ISBLK(bootstat.st_mode)
  37. && (major(bootstat.st_rdev) == IDE0_MAJOR ||
  38. major(bootstat.st_rdev) == IDE1_MAJOR)) {
  39. scsi_disk = 0;
  40. floppy = 0;
  41. } else if (S_ISBLK(bootstat.st_mode)
  42. && major(bootstat.st_rdev) == FLOPPY_MAJOR) {
  43. scsi_disk = 0;
  44. floppy = 1;
  45. } else {
  46. scsi_disk = 1;
  47. floppy = 0;
  48. }
  49. }
  50. static const struct systypes sun_sys_types[] = {
  51. { "\x00" "Empty" }, /* 0 */
  52. { "\x01" "Boot" }, /* 1 */
  53. { "\x02" "SunOS root" }, /* 2 */
  54. { "\x03" "SunOS swap" }, /* SUNOS_SWAP */
  55. { "\x04" "SunOS usr" }, /* 4 */
  56. { "\x05" "Whole disk" }, /* SUN_WHOLE_DISK */
  57. { "\x06" "SunOS stand" }, /* 6 */
  58. { "\x07" "SunOS var" }, /* 7 */
  59. { "\x08" "SunOS home" }, /* 8 */
  60. { "\x82" "Linux swap" }, /* LINUX_SWAP */
  61. { "\x83" "Linux native" }, /* LINUX_NATIVE */
  62. { "\x8e" "Linux LVM" }, /* 0x8e */
  63. /* New (2.2.x) raid partition with autodetect using persistent superblock */
  64. { "\xfd" "Linux raid autodetect" }, /* 0xfd */
  65. { NULL }
  66. };
  67. static void
  68. set_sun_partition(int i, uint start, uint stop, int sysid)
  69. {
  70. sunlabel->infos[i].id = sysid;
  71. sunlabel->partitions[i].start_cylinder =
  72. SUN_SSWAP32(start / (heads * sectors));
  73. sunlabel->partitions[i].num_sectors =
  74. SUN_SSWAP32(stop - start);
  75. set_changed(i);
  76. }
  77. static int
  78. check_sun_label(void)
  79. {
  80. unsigned short *ush;
  81. int csum;
  82. if (sunlabel->magic != SUN_LABEL_MAGIC
  83. && sunlabel->magic != SUN_LABEL_MAGIC_SWAPPED) {
  84. current_label_type = label_dos;
  85. sun_other_endian = 0;
  86. return 0;
  87. }
  88. sun_other_endian = (sunlabel->magic == SUN_LABEL_MAGIC_SWAPPED);
  89. ush = ((unsigned short *) (sunlabel + 1)) - 1;
  90. for (csum = 0; ush >= (unsigned short *)sunlabel;) csum ^= *ush--;
  91. if (csum) {
  92. fprintf(stderr,_("Detected sun disklabel with wrong checksum.\n"
  93. "Probably you'll have to set all the values,\n"
  94. "e.g. heads, sectors, cylinders and partitions\n"
  95. "or force a fresh label (s command in main menu)\n"));
  96. } else {
  97. heads = SUN_SSWAP16(sunlabel->ntrks);
  98. cylinders = SUN_SSWAP16(sunlabel->ncyl);
  99. sectors = SUN_SSWAP16(sunlabel->nsect);
  100. }
  101. update_units();
  102. current_label_type = label_sun;
  103. partitions = 8;
  104. return 1;
  105. }
  106. static const struct sun_predefined_drives {
  107. const char *vendor;
  108. const char *model;
  109. unsigned short sparecyl;
  110. unsigned short ncyl;
  111. unsigned short nacyl;
  112. unsigned short pcylcount;
  113. unsigned short ntrks;
  114. unsigned short nsect;
  115. unsigned short rspeed;
  116. } sun_drives[] = {
  117. { "Quantum","ProDrive 80S",1,832,2,834,6,34,3662},
  118. { "Quantum","ProDrive 105S",1,974,2,1019,6,35,3662},
  119. { "CDC","Wren IV 94171-344",3,1545,2,1549,9,46,3600},
  120. { "IBM","DPES-31080",0,4901,2,4903,4,108,5400},
  121. { "IBM","DORS-32160",0,1015,2,1017,67,62,5400},
  122. { "IBM","DNES-318350",0,11199,2,11474,10,320,7200},
  123. { "SEAGATE","ST34371",0,3880,2,3882,16,135,7228},
  124. { "","SUN0104",1,974,2,1019,6,35,3662},
  125. { "","SUN0207",4,1254,2,1272,9,36,3600},
  126. { "","SUN0327",3,1545,2,1549,9,46,3600},
  127. { "","SUN0340",0,1538,2,1544,6,72,4200},
  128. { "","SUN0424",2,1151,2,2500,9,80,4400},
  129. { "","SUN0535",0,1866,2,2500,7,80,5400},
  130. { "","SUN0669",5,1614,2,1632,15,54,3600},
  131. { "","SUN1.0G",5,1703,2,1931,15,80,3597},
  132. { "","SUN1.05",0,2036,2,2038,14,72,5400},
  133. { "","SUN1.3G",6,1965,2,3500,17,80,5400},
  134. { "","SUN2.1G",0,2733,2,3500,19,80,5400},
  135. { "IOMEGA","Jaz",0,1019,2,1021,64,32,5394},
  136. };
  137. static const struct sun_predefined_drives *
  138. sun_autoconfigure_scsi(void)
  139. {
  140. const struct sun_predefined_drives *p = NULL;
  141. #ifdef SCSI_IOCTL_GET_IDLUN
  142. unsigned int id[2];
  143. char buffer[2048];
  144. char buffer2[2048];
  145. FILE *pfd;
  146. char *vendor;
  147. char *model;
  148. char *q;
  149. int i;
  150. if (ioctl(fd, SCSI_IOCTL_GET_IDLUN, &id))
  151. return NULL;
  152. sprintf(buffer,
  153. "Host: scsi%d Channel: %02d Id: %02d Lun: %02d\n",
  154. /* This is very wrong (works only if you have one HBA),
  155. but I haven't found a way how to get hostno
  156. from the current kernel */
  157. 0,
  158. (id[0]>>16) & 0xff,
  159. id[0] & 0xff,
  160. (id[0]>>8) & 0xff
  161. );
  162. pfd = fopen("/proc/scsi/scsi", "r");
  163. if (!pfd) {
  164. return NULL;
  165. }
  166. while (fgets(buffer2, 2048, pfd)) {
  167. if (strcmp(buffer, buffer2))
  168. continue;
  169. if (!fgets(buffer2, 2048, pfd))
  170. break;
  171. q = strstr(buffer2, "Vendor: ");
  172. if (!q)
  173. break;
  174. q += 8;
  175. vendor = q;
  176. q = strstr(q, " ");
  177. *q++ = '\0'; /* truncate vendor name */
  178. q = strstr(q, "Model: ");
  179. if (!q)
  180. break;
  181. *q = '\0';
  182. q += 7;
  183. model = q;
  184. q = strstr(q, " Rev: ");
  185. if (!q)
  186. break;
  187. *q = '\0';
  188. for (i = 0; i < SIZE(sun_drives); i++) {
  189. if (*sun_drives[i].vendor && strcasecmp(sun_drives[i].vendor, vendor))
  190. continue;
  191. if (!strstr(model, sun_drives[i].model))
  192. continue;
  193. printf(_("Autoconfigure found a %s%s%s\n"),
  194. sun_drives[i].vendor,
  195. (*sun_drives[i].vendor) ? " " : "",
  196. sun_drives[i].model);
  197. p = sun_drives + i;
  198. break;
  199. }
  200. break;
  201. }
  202. fclose(pfd);
  203. #endif
  204. return p;
  205. }
  206. static void
  207. create_sunlabel(void)
  208. {
  209. struct hd_geometry geometry;
  210. unsigned int ndiv;
  211. int i;
  212. unsigned char c;
  213. const struct sun_predefined_drives *p = NULL;
  214. fprintf(stderr,
  215. _("Building a new sun disklabel. Changes will remain in memory only,\n"
  216. "until you decide to write them. After that, of course, the previous\n"
  217. "content won't be recoverable.\n\n"));
  218. sun_other_endian = BB_LITTLE_ENDIAN;
  219. memset(MBRbuffer, 0, sizeof(MBRbuffer));
  220. sunlabel->magic = SUN_SSWAP16(SUN_LABEL_MAGIC);
  221. if (!floppy) {
  222. puts(_("Drive type\n"
  223. " ? auto configure\n"
  224. " 0 custom (with hardware detected defaults)"));
  225. for (i = 0; i < SIZE(sun_drives); i++) {
  226. printf(" %c %s%s%s\n",
  227. i + 'a', sun_drives[i].vendor,
  228. (*sun_drives[i].vendor) ? " " : "",
  229. sun_drives[i].model);
  230. }
  231. while (1) {
  232. c = read_nonempty(_("Select type (? for auto, 0 for custom): "));
  233. if (c >= 'a' && c < 'a' + SIZE(sun_drives)) {
  234. p = sun_drives + c - 'a';
  235. break;
  236. } else if (c >= 'A' && c < 'A' + SIZE(sun_drives)) {
  237. p = sun_drives + c - 'A';
  238. break;
  239. } else if (c == '0') {
  240. break;
  241. } else if (c == '?' && scsi_disk) {
  242. p = sun_autoconfigure_scsi();
  243. if (!p)
  244. printf(_("Autoconfigure failed.\n"));
  245. else
  246. break;
  247. }
  248. }
  249. }
  250. if (!p || floppy) {
  251. if (!ioctl(fd, HDIO_GETGEO, &geometry)) {
  252. heads = geometry.heads;
  253. sectors = geometry.sectors;
  254. cylinders = geometry.cylinders;
  255. } else {
  256. heads = 0;
  257. sectors = 0;
  258. cylinders = 0;
  259. }
  260. if (floppy) {
  261. sunlabel->nacyl = 0;
  262. sunlabel->pcylcount = SUN_SSWAP16(cylinders);
  263. sunlabel->rspeed = SUN_SSWAP16(300);
  264. sunlabel->ilfact = SUN_SSWAP16(1);
  265. sunlabel->sparecyl = 0;
  266. } else {
  267. heads = read_int(1,heads,1024,0,_("Heads"));
  268. sectors = read_int(1,sectors,1024,0,_("Sectors/track"));
  269. if (cylinders)
  270. cylinders = read_int(1,cylinders-2,65535,0,_("Cylinders"));
  271. else
  272. cylinders = read_int(1,0,65535,0,_("Cylinders"));
  273. sunlabel->nacyl = SUN_SSWAP16(read_int(0,2,65535,0, _("Alternate cylinders")));
  274. sunlabel->pcylcount = SUN_SSWAP16(read_int(0,cylinders+SUN_SSWAP16(sunlabel->nacyl), 65535,0, _("Physical cylinders")));
  275. sunlabel->rspeed = SUN_SSWAP16(read_int(1,5400,100000,0, _("Rotation speed (rpm)")));
  276. sunlabel->ilfact = SUN_SSWAP16(read_int(1,1,32,0, _("Interleave factor")));
  277. sunlabel->sparecyl = SUN_SSWAP16(read_int(0,0,sectors,0, _("Extra sectors per cylinder")));
  278. }
  279. } else {
  280. sunlabel->sparecyl = SUN_SSWAP16(p->sparecyl);
  281. sunlabel->ncyl = SUN_SSWAP16(p->ncyl);
  282. sunlabel->nacyl = SUN_SSWAP16(p->nacyl);
  283. sunlabel->pcylcount = SUN_SSWAP16(p->pcylcount);
  284. sunlabel->ntrks = SUN_SSWAP16(p->ntrks);
  285. sunlabel->nsect = SUN_SSWAP16(p->nsect);
  286. sunlabel->rspeed = SUN_SSWAP16(p->rspeed);
  287. sunlabel->ilfact = SUN_SSWAP16(1);
  288. cylinders = p->ncyl;
  289. heads = p->ntrks;
  290. sectors = p->nsect;
  291. puts(_("You may change all the disk params from the x menu"));
  292. }
  293. snprintf((char *)(sunlabel->info), sizeof(sunlabel->info),
  294. "%s%s%s cyl %d alt %d hd %d sec %d",
  295. p ? p->vendor : "", (p && *p->vendor) ? " " : "",
  296. p ? p->model : (floppy ? _("3,5\" floppy") : _("Linux custom")),
  297. cylinders, SUN_SSWAP16(sunlabel->nacyl), heads, sectors);
  298. sunlabel->ntrks = SUN_SSWAP16(heads);
  299. sunlabel->nsect = SUN_SSWAP16(sectors);
  300. sunlabel->ncyl = SUN_SSWAP16(cylinders);
  301. if (floppy)
  302. set_sun_partition(0, 0, cylinders * heads * sectors, LINUX_NATIVE);
  303. else {
  304. if (cylinders * heads * sectors >= 150 * 2048) {
  305. ndiv = cylinders - (50 * 2048 / (heads * sectors)); /* 50M swap */
  306. } else
  307. ndiv = cylinders * 2 / 3;
  308. set_sun_partition(0, 0, ndiv * heads * sectors, LINUX_NATIVE);
  309. set_sun_partition(1, ndiv * heads * sectors, cylinders * heads * sectors, LINUX_SWAP);
  310. sunlabel->infos[1].flags |= 0x01; /* Not mountable */
  311. }
  312. set_sun_partition(2, 0, cylinders * heads * sectors, SUN_WHOLE_DISK);
  313. {
  314. unsigned short *ush = (unsigned short *)sunlabel;
  315. unsigned short csum = 0;
  316. while (ush < (unsigned short *)(&sunlabel->csum))
  317. csum ^= *ush++;
  318. sunlabel->csum = csum;
  319. }
  320. set_all_unchanged();
  321. set_changed(0);
  322. get_boot(create_empty_sun);
  323. }
  324. static void
  325. toggle_sunflags(int i, unsigned char mask)
  326. {
  327. if (sunlabel->infos[i].flags & mask)
  328. sunlabel->infos[i].flags &= ~mask;
  329. else
  330. sunlabel->infos[i].flags |= mask;
  331. set_changed(i);
  332. }
  333. static void
  334. fetch_sun(uint *starts, uint *lens, uint *start, uint *stop)
  335. {
  336. int i, continuous = 1;
  337. *start = 0;
  338. *stop = cylinders * heads * sectors;
  339. for (i = 0; i < partitions; i++) {
  340. if (sunlabel->partitions[i].num_sectors
  341. && sunlabel->infos[i].id
  342. && sunlabel->infos[i].id != SUN_WHOLE_DISK) {
  343. starts[i] = SUN_SSWAP32(sunlabel->partitions[i].start_cylinder) * heads * sectors;
  344. lens[i] = SUN_SSWAP32(sunlabel->partitions[i].num_sectors);
  345. if (continuous) {
  346. if (starts[i] == *start)
  347. *start += lens[i];
  348. else if (starts[i] + lens[i] >= *stop)
  349. *stop = starts[i];
  350. else
  351. continuous = 0;
  352. /* There will be probably more gaps
  353. than one, so lets check afterwards */
  354. }
  355. } else {
  356. starts[i] = 0;
  357. lens[i] = 0;
  358. }
  359. }
  360. }
  361. static uint *verify_sun_starts;
  362. static int
  363. verify_sun_cmp(int *a, int *b)
  364. {
  365. if (*a == -1) return 1;
  366. if (*b == -1) return -1;
  367. if (verify_sun_starts[*a] > verify_sun_starts[*b]) return 1;
  368. return -1;
  369. }
  370. static void
  371. verify_sun(void)
  372. {
  373. uint starts[8], lens[8], start, stop;
  374. int i,j,k,starto,endo;
  375. int array[8];
  376. verify_sun_starts = starts;
  377. fetch_sun(starts,lens,&start,&stop);
  378. for (k = 0; k < 7; k++) {
  379. for (i = 0; i < 8; i++) {
  380. if (k && (lens[i] % (heads * sectors))) {
  381. printf(_("Partition %d doesn't end on cylinder boundary\n"), i+1);
  382. }
  383. if (lens[i]) {
  384. for (j = 0; j < i; j++)
  385. if (lens[j]) {
  386. if (starts[j] == starts[i]+lens[i]) {
  387. starts[j] = starts[i]; lens[j] += lens[i];
  388. lens[i] = 0;
  389. } else if (starts[i] == starts[j]+lens[j]){
  390. lens[j] += lens[i];
  391. lens[i] = 0;
  392. } else if (!k) {
  393. if (starts[i] < starts[j]+lens[j]
  394. && starts[j] < starts[i]+lens[i]) {
  395. starto = starts[i];
  396. if (starts[j] > starto)
  397. starto = starts[j];
  398. endo = starts[i]+lens[i];
  399. if (starts[j]+lens[j] < endo)
  400. endo = starts[j]+lens[j];
  401. printf(_("Partition %d overlaps with others in "
  402. "sectors %d-%d\n"), i+1, starto, endo);
  403. }
  404. }
  405. }
  406. }
  407. }
  408. }
  409. for (i = 0; i < 8; i++) {
  410. if (lens[i])
  411. array[i] = i;
  412. else
  413. array[i] = -1;
  414. }
  415. qsort(array,SIZE(array),sizeof(array[0]),
  416. (int (*)(const void *,const void *)) verify_sun_cmp);
  417. if (array[0] == -1) {
  418. printf(_("No partitions defined\n"));
  419. return;
  420. }
  421. stop = cylinders * heads * sectors;
  422. if (starts[array[0]])
  423. printf(_("Unused gap - sectors 0-%d\n"),starts[array[0]]);
  424. for (i = 0; i < 7 && array[i+1] != -1; i++) {
  425. printf(_("Unused gap - sectors %d-%d\n"),starts[array[i]]+lens[array[i]],starts[array[i+1]]);
  426. }
  427. start = starts[array[i]] + lens[array[i]];
  428. if (start < stop)
  429. printf(_("Unused gap - sectors %d-%d\n"),start,stop);
  430. }
  431. static void
  432. add_sun_partition(int n, int sys)
  433. {
  434. uint start, stop, stop2;
  435. uint starts[8], lens[8];
  436. int whole_disk = 0;
  437. char mesg[256];
  438. int i, first, last;
  439. if (sunlabel->partitions[n].num_sectors && sunlabel->infos[n].id) {
  440. printf(_("Partition %d is already defined. Delete "
  441. "it before re-adding it.\n"), n + 1);
  442. return;
  443. }
  444. fetch_sun(starts,lens,&start,&stop);
  445. if (stop <= start) {
  446. if (n == 2)
  447. whole_disk = 1;
  448. else {
  449. printf(_("Other partitions already cover the whole disk.\nDelete "
  450. "some/shrink them before retry.\n"));
  451. return;
  452. }
  453. }
  454. snprintf(mesg, sizeof(mesg), _("First %s"), str_units(SINGULAR));
  455. while (1) {
  456. if (whole_disk)
  457. first = read_int(0, 0, 0, 0, mesg);
  458. else
  459. first = read_int(scround(start), scround(stop)+1,
  460. scround(stop), 0, mesg);
  461. if (display_in_cyl_units)
  462. first *= units_per_sector;
  463. else
  464. /* Starting sector has to be properly aligned */
  465. first = (first + heads * sectors - 1) / (heads * sectors);
  466. if (n == 2 && first != 0)
  467. printf("\
  468. It is highly recommended that the third partition covers the whole disk\n\
  469. and is of type `Whole disk'\n");
  470. /* ewt asks to add: "don't start a partition at cyl 0"
  471. However, edmundo@rano.demon.co.uk writes:
  472. "In addition to having a Sun partition table, to be able to
  473. boot from the disc, the first partition, /dev/sdX1, must
  474. start at cylinder 0. This means that /dev/sdX1 contains
  475. the partition table and the boot block, as these are the
  476. first two sectors of the disc. Therefore you must be
  477. careful what you use /dev/sdX1 for. In particular, you must
  478. not use a partition starting at cylinder 0 for Linux swap,
  479. as that would overwrite the partition table and the boot
  480. block. You may, however, use such a partition for a UFS
  481. or EXT2 file system, as these file systems leave the first
  482. 1024 bytes undisturbed. */
  483. /* On the other hand, one should not use partitions
  484. starting at block 0 in an md, or the label will
  485. be trashed. */
  486. for (i = 0; i < partitions; i++)
  487. if (lens[i] && starts[i] <= first && starts[i] + lens[i] > first)
  488. break;
  489. if (i < partitions && !whole_disk) {
  490. if (n == 2 && !first) {
  491. whole_disk = 1;
  492. break;
  493. }
  494. printf(_("Sector %d is already allocated\n"), first);
  495. } else
  496. break;
  497. }
  498. stop = cylinders * heads * sectors;
  499. stop2 = stop;
  500. for (i = 0; i < partitions; i++) {
  501. if (starts[i] > first && starts[i] < stop)
  502. stop = starts[i];
  503. }
  504. snprintf(mesg, sizeof(mesg),
  505. _("Last %s or +size or +sizeM or +sizeK"),
  506. str_units(SINGULAR));
  507. if (whole_disk)
  508. last = read_int(scround(stop2), scround(stop2), scround(stop2),
  509. 0, mesg);
  510. else if (n == 2 && !first)
  511. last = read_int(scround(first), scround(stop2), scround(stop2),
  512. scround(first), mesg);
  513. else
  514. last = read_int(scround(first), scround(stop), scround(stop),
  515. scround(first), mesg);
  516. if (display_in_cyl_units)
  517. last *= units_per_sector;
  518. if (n == 2 && !first) {
  519. if (last >= stop2) {
  520. whole_disk = 1;
  521. last = stop2;
  522. } else if (last > stop) {
  523. printf(_("You haven't covered the whole disk with "
  524. "the 3rd partition, but your value\n"
  525. "%d %s covers some other partition. "
  526. "Your entry has been changed\n"
  527. "to %d %s\n"),
  528. scround(last), str_units(SINGULAR),
  529. scround(stop), str_units(SINGULAR));
  530. last = stop;
  531. }
  532. } else if (!whole_disk && last > stop)
  533. last = stop;
  534. if (whole_disk)
  535. sys = SUN_WHOLE_DISK;
  536. set_sun_partition(n, first, last, sys);
  537. }
  538. static void
  539. sun_delete_partition(int i)
  540. {
  541. unsigned int nsec;
  542. if (i == 2
  543. && sunlabel->infos[i].id == SUN_WHOLE_DISK
  544. && !sunlabel->partitions[i].start_cylinder
  545. && (nsec = SUN_SSWAP32(sunlabel->partitions[i].num_sectors)) == heads * sectors * cylinders)
  546. printf(_("If you want to maintain SunOS/Solaris compatibility, "
  547. "consider leaving this\n"
  548. "partition as Whole disk (5), starting at 0, with %u "
  549. "sectors\n"), nsec);
  550. sunlabel->infos[i].id = 0;
  551. sunlabel->partitions[i].num_sectors = 0;
  552. }
  553. static void
  554. sun_change_sysid(int i, int sys)
  555. {
  556. if (sys == LINUX_SWAP && !sunlabel->partitions[i].start_cylinder) {
  557. read_maybe_empty(
  558. _("It is highly recommended that the partition at offset 0\n"
  559. "is UFS, EXT2FS filesystem or SunOS swap. Putting Linux swap\n"
  560. "there may destroy your partition table and bootblock.\n"
  561. "Type YES if you're very sure you would like that partition\n"
  562. "tagged with 82 (Linux swap): "));
  563. if (strcmp (line_ptr, _("YES\n")))
  564. return;
  565. }
  566. switch (sys) {
  567. case SUNOS_SWAP:
  568. case LINUX_SWAP:
  569. /* swaps are not mountable by default */
  570. sunlabel->infos[i].flags |= 0x01;
  571. break;
  572. default:
  573. /* assume other types are mountable;
  574. user can change it anyway */
  575. sunlabel->infos[i].flags &= ~0x01;
  576. break;
  577. }
  578. sunlabel->infos[i].id = sys;
  579. }
  580. static void
  581. sun_list_table(int xtra)
  582. {
  583. int i, w;
  584. w = strlen(disk_device);
  585. if (xtra)
  586. printf(
  587. _("\nDisk %s (Sun disk label): %d heads, %d sectors, %d rpm\n"
  588. "%d cylinders, %d alternate cylinders, %d physical cylinders\n"
  589. "%d extra sects/cyl, interleave %d:1\n"
  590. "%s\n"
  591. "Units = %s of %d * 512 bytes\n\n"),
  592. disk_device, heads, sectors, SUN_SSWAP16(sunlabel->rspeed),
  593. cylinders, SUN_SSWAP16(sunlabel->nacyl),
  594. SUN_SSWAP16(sunlabel->pcylcount),
  595. SUN_SSWAP16(sunlabel->sparecyl),
  596. SUN_SSWAP16(sunlabel->ilfact),
  597. (char *)sunlabel,
  598. str_units(PLURAL), units_per_sector);
  599. else
  600. printf(
  601. _("\nDisk %s (Sun disk label): %d heads, %d sectors, %d cylinders\n"
  602. "Units = %s of %d * 512 bytes\n\n"),
  603. disk_device, heads, sectors, cylinders,
  604. str_units(PLURAL), units_per_sector);
  605. printf(_("%*s Flag Start End Blocks Id System\n"),
  606. w + 1, _("Device"));
  607. for (i = 0 ; i < partitions; i++) {
  608. if (sunlabel->partitions[i].num_sectors) {
  609. uint32_t start = SUN_SSWAP32(sunlabel->partitions[i].start_cylinder) * heads * sectors;
  610. uint32_t len = SUN_SSWAP32(sunlabel->partitions[i].num_sectors);
  611. printf("%s %c%c %9ld %9ld %9ld%c %2x %s\n",
  612. partname(disk_device, i+1, w), /* device */
  613. (sunlabel->infos[i].flags & 0x01) ? 'u' : ' ', /* flags */
  614. (sunlabel->infos[i].flags & 0x10) ? 'r' : ' ',
  615. (long) scround(start), /* start */
  616. (long) scround(start+len), /* end */
  617. (long) len / 2, len & 1 ? '+' : ' ', /* odd flag on end */
  618. sunlabel->infos[i].id, /* type id */
  619. partition_type(sunlabel->infos[i].id)); /* type name */
  620. }
  621. }
  622. }
  623. #ifdef CONFIG_FEATURE_FDISK_ADVANCED
  624. static void
  625. sun_set_alt_cyl(void)
  626. {
  627. sunlabel->nacyl =
  628. SUN_SSWAP16(read_int(0,SUN_SSWAP16(sunlabel->nacyl), 65535, 0,
  629. _("Number of alternate cylinders")));
  630. }
  631. static void
  632. sun_set_ncyl(int cyl)
  633. {
  634. sunlabel->ncyl = SUN_SSWAP16(cyl);
  635. }
  636. static void
  637. sun_set_xcyl(void)
  638. {
  639. sunlabel->sparecyl =
  640. SUN_SSWAP16(read_int(0, SUN_SSWAP16(sunlabel->sparecyl), sectors, 0,
  641. _("Extra sectors per cylinder")));
  642. }
  643. static void
  644. sun_set_ilfact(void)
  645. {
  646. sunlabel->ilfact =
  647. SUN_SSWAP16(read_int(1, SUN_SSWAP16(sunlabel->ilfact), 32, 0,
  648. _("Interleave factor")));
  649. }
  650. static void
  651. sun_set_rspeed(void)
  652. {
  653. sunlabel->rspeed =
  654. SUN_SSWAP16(read_int(1, SUN_SSWAP16(sunlabel->rspeed), 100000, 0,
  655. _("Rotation speed (rpm)")));
  656. }
  657. static void
  658. sun_set_pcylcount(void)
  659. {
  660. sunlabel->pcylcount =
  661. SUN_SSWAP16(read_int(0, SUN_SSWAP16(sunlabel->pcylcount), 65535, 0,
  662. _("Number of physical cylinders")));
  663. }
  664. #endif /* CONFIG_FEATURE_FDISK_ADVANCED */
  665. static void
  666. sun_write_table(void)
  667. {
  668. unsigned short *ush = (unsigned short *)sunlabel;
  669. unsigned short csum = 0;
  670. while (ush < (unsigned short *)(&sunlabel->csum))
  671. csum ^= *ush++;
  672. sunlabel->csum = csum;
  673. if (lseek(fd, 0, SEEK_SET) < 0)
  674. fdisk_fatal(unable_to_seek);
  675. if (write(fd, sunlabel, SECTOR_SIZE) != SECTOR_SIZE)
  676. fdisk_fatal(unable_to_write);
  677. }
  678. #endif /* SUN_LABEL */