1 // SPDX-License-Identifier: GPL-2.0
5 * Code extracted from drivers/block/genhd.c
7 * Copyright (C) 1991-1998 Linus Torvalds
8 * Re-organised Feb 1998 Russell King
13 #define SUN_LABEL_MAGIC 0xDABE
14 #define SUN_VTOC_SANITY 0x600DDEEE
16 int sun_partition(struct parsed_partitions *state)
23 struct sun_disklabel {
24 unsigned char info[128]; /* Informative text string */
26 __be32 version; /* Layout version */
27 char volume[8]; /* Volume name */
28 __be16 nparts; /* Number of partitions */
29 struct sun_info { /* Partition hdrs, sec 2 */
33 __be16 padding; /* Alignment padding */
34 __be32 bootinfo[3]; /* Info needed by mboot */
35 __be32 sanity; /* To verify vtoc sanity */
36 __be32 reserved[10]; /* Free space */
37 __be32 timestamp[8]; /* Partition timestamp */
39 __be32 write_reinstruct; /* sectors to skip, writes */
40 __be32 read_reinstruct; /* sectors to skip, reads */
41 unsigned char spare[148]; /* Padding */
42 __be16 rspeed; /* Disk rotational speed */
43 __be16 pcylcount; /* Physical cylinder count */
44 __be16 sparecyl; /* extra sects per cylinder */
45 __be16 obs1; /* gap1 */
46 __be16 obs2; /* gap2 */
47 __be16 ilfact; /* Interleave factor */
48 __be16 ncyl; /* Data cylinder count */
49 __be16 nacyl; /* Alt. cylinder count */
50 __be16 ntrks; /* Tracks per cylinder */
51 __be16 nsect; /* Sectors per track */
52 __be16 obs3; /* bhead - Label head offset */
53 __be16 obs4; /* ppart - Physical Partition */
54 struct sun_partition {
55 __be32 start_cylinder;
58 __be16 magic; /* Magic number */
59 __be16 csum; /* Label xor'd checksum */
61 struct sun_partition *p;
63 char b[BDEVNAME_SIZE];
67 label = read_part_sector(state, 0, §);
71 p = label->partitions;
72 if (be16_to_cpu(label->magic) != SUN_LABEL_MAGIC) {
73 /* printk(KERN_INFO "Dev %s Sun disklabel: bad magic %04x\n",
74 bdevname(bdev, b), be16_to_cpu(label->magic)); */
78 /* Look at the checksum */
79 ush = ((__be16 *) (label+1)) - 1;
80 for (csum = 0; ush >= ((__be16 *) label);)
83 printk("Dev %s Sun disklabel: Csum bad, label corrupted\n",
84 bdevname(state->bdev, b));
89 /* Check to see if we can use the VTOC table */
90 use_vtoc = ((be32_to_cpu(label->vtoc.sanity) == SUN_VTOC_SANITY) &&
91 (be32_to_cpu(label->vtoc.version) == 1) &&
92 (be16_to_cpu(label->vtoc.nparts) <= 8));
94 /* Use 8 partition entries if not specified in validated VTOC */
95 nparts = (use_vtoc) ? be16_to_cpu(label->vtoc.nparts) : 8;
98 * So that old Linux-Sun partitions continue to work,
99 * alow the VTOC to be used under the additional condition ...
101 use_vtoc = use_vtoc || !(label->vtoc.sanity ||
102 label->vtoc.version || label->vtoc.nparts);
103 spc = be16_to_cpu(label->ntrks) * be16_to_cpu(label->nsect);
104 for (i = 0; i < nparts; i++, p++) {
105 unsigned long st_sector;
106 unsigned int num_sectors;
108 st_sector = be32_to_cpu(p->start_cylinder) * spc;
109 num_sectors = be32_to_cpu(p->num_sectors);
111 put_partition(state, slot, st_sector, num_sectors);
112 state->parts[slot].flags = 0;
114 if (be16_to_cpu(label->vtoc.infos[i].id) == LINUX_RAID_PARTITION)
115 state->parts[slot].flags |= ADDPART_FLAG_RAID;
116 else if (be16_to_cpu(label->vtoc.infos[i].id) == SUN_WHOLE_DISK)
117 state->parts[slot].flags |= ADDPART_FLAG_WHOLEDISK;
122 strlcat(state->pp_buf, "\n", PAGE_SIZE);
123 put_dev_sector(sect);