1 /* sun.c - Read SUN style partition tables. */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2002,2005,2006,2007 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #include <grub/partition.h>
21 #include <grub/disk.h>
23 #include <grub/misc.h>
25 #include <grub/symbol.h>
26 #include <grub/types.h>
29 GRUB_MOD_LICENSE ("GPLv3+");
31 #define GRUB_PARTMAP_SUN_MAGIC 0xDABE
32 #define GRUB_PARTMAP_SUN_MAX_PARTS 8
33 #define GRUB_PARTMAP_SUN_WHOLE_DISK_ID 0x05
35 struct grub_sun_partition_info
43 struct grub_sun_partition_descriptor
45 grub_uint32_t start_cylinder
;
46 grub_uint32_t num_sectors
;
51 grub_uint8_t info
[128]; /* Informative text string. */
52 grub_uint8_t spare0
[14];
53 struct grub_sun_partition_info infos
[8];
54 grub_uint8_t spare1
[246]; /* Boot information etc. */
55 grub_uint16_t rspeed
; /* Disk rotational speed. */
56 grub_uint16_t pcylcount
; /* Physical cylinder count. */
57 grub_uint16_t sparecyl
; /* extra sects per cylinder. */
58 grub_uint8_t spare2
[4]; /* More magic... */
59 grub_uint16_t ilfact
; /* Interleave factor. */
60 grub_uint16_t ncyl
; /* Data cylinder count. */
61 grub_uint16_t nacyl
; /* Alt. cylinder count. */
62 grub_uint16_t ntrks
; /* Tracks per cylinder. */
63 grub_uint16_t nsect
; /* Sectors per track. */
64 grub_uint8_t spare3
[4]; /* Even more magic... */
65 struct grub_sun_partition_descriptor partitions
[8];
66 grub_uint16_t magic
; /* Magic number. */
67 grub_uint16_t csum
; /* Label xor'd checksum. */
70 static struct grub_partition_map grub_sun_partition_map
;
72 /* Verify checksum (true=ok). */
74 grub_sun_is_valid (grub_uint16_t
*label
)
77 grub_uint16_t sum
= 0;
80 pos
< (label
+ sizeof (struct grub_sun_block
) / 2);
88 sun_partition_map_iterate (grub_disk_t disk
,
89 grub_partition_iterate_hook_t hook
, void *hook_data
)
91 struct grub_partition p
;
94 struct grub_sun_block sun
;
100 p
.partmap
= &grub_sun_partition_map
;
101 err
= grub_disk_read (disk
, 0, 0, sizeof (struct grub_sun_block
),
106 if (GRUB_PARTMAP_SUN_MAGIC
!= grub_be_to_cpu16 (block
.sun
.magic
))
107 return grub_error (GRUB_ERR_BAD_PART_TABLE
, "not a sun partition table");
109 if (! grub_sun_is_valid (block
.raw
))
110 return grub_error (GRUB_ERR_BAD_PART_TABLE
, "invalid checksum");
112 /* Maybe another error value would be better, because partition
113 table _is_ recognized but invalid. */
114 for (partnum
= 0; partnum
< GRUB_PARTMAP_SUN_MAX_PARTS
; partnum
++)
116 struct grub_sun_partition_descriptor
*desc
;
118 if (block
.sun
.infos
[partnum
].id
== 0
119 || block
.sun
.infos
[partnum
].id
== GRUB_PARTMAP_SUN_WHOLE_DISK_ID
)
122 desc
= &block
.sun
.partitions
[partnum
];
123 p
.start
= ((grub_uint64_t
) grub_be_to_cpu32 (desc
->start_cylinder
)
124 * grub_be_to_cpu16 (block
.sun
.ntrks
)
125 * grub_be_to_cpu16 (block
.sun
.nsect
));
126 p
.len
= grub_be_to_cpu32 (desc
->num_sectors
);
127 p
.number
= p
.index
= partnum
;
130 if (hook (disk
, &p
, hook_data
))
131 partnum
= GRUB_PARTMAP_SUN_MAX_PARTS
;
138 /* Partition map type. */
139 static struct grub_partition_map grub_sun_partition_map
=
142 .iterate
= sun_partition_map_iterate
,
145 GRUB_MOD_INIT(part_sun
)
147 grub_partition_map_register (&grub_sun_partition_map
);
150 GRUB_MOD_FINI(part_sun
)
152 grub_partition_map_unregister (&grub_sun_partition_map
);