1
/* sun.c - Read SUN style partition tables. */
3
* GRUB -- GRand Unified Bootloader
4
* Copyright (C) 2002, 2005 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 2 of the License, or
9
* (at your option) any later version.
11
* This program 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, write to the Free Software
18
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
#include <grub/partition.h>
22
#include <grub/disk.h>
24
#include <grub/misc.h>
26
#include <grub/symbol.h>
27
#include <grub/types.h>
30
#define GRUB_PARTMAP_SUN_MAGIC 0xDABE
31
#define GRUB_PARTMAP_SUN_MAX_PARTS 8
32
#define GRUB_PARTMAP_SUN_WHOLE_DISK_ID 0x05
34
struct grub_sun_partition_info
40
} __attribute__ ((packed));
42
struct grub_sun_partition_descriptor
44
grub_uint32_t start_cylinder;
45
grub_uint32_t num_sectors;
46
} __attribute__ ((packed));
50
grub_uint8_t info[128]; /* Informative text string. */
51
grub_uint8_t spare0[14];
52
struct grub_sun_partition_info infos[8];
53
grub_uint8_t spare1[246]; /* Boot information etc. */
54
grub_uint16_t rspeed; /* Disk rotational speed. */
55
grub_uint16_t pcylcount; /* Physical cylinder count. */
56
grub_uint16_t sparecyl; /* extra sects per cylinder. */
57
grub_uint8_t spare2[4]; /* More magic... */
58
grub_uint16_t ilfact; /* Interleave factor. */
59
grub_uint16_t ncyl; /* Data cylinder count. */
60
grub_uint16_t nacyl; /* Alt. cylinder count. */
61
grub_uint16_t ntrks; /* Tracks per cylinder. */
62
grub_uint16_t nsect; /* Sectors per track. */
63
grub_uint8_t spare3[4]; /* Even more magic... */
64
struct grub_sun_partition_descriptor partitions[8];
65
grub_uint16_t magic; /* Magic number. */
66
grub_uint16_t csum; /* Label xor'd checksum. */
67
} __attribute__ ((packed));
69
static struct grub_partition_map grub_sun_partition_map;
72
static grub_dl_t my_mod;
75
/* Verify checksum (true=ok). */
77
grub_sun_is_valid (struct grub_sun_block *label)
80
grub_uint16_t sum = 0;
81
for (pos = (grub_uint16_t *) label; pos < (grub_uint16_t *) (label + 1); pos++)
87
sun_partition_map_iterate (grub_disk_t disk,
88
int (*hook) (grub_disk_t disk,
89
const grub_partition_t partition))
91
struct grub_partition *p;
93
struct grub_sun_block block;
97
p = (struct grub_partition *) grub_malloc (sizeof (struct grub_partition));
103
p->partmap = &grub_sun_partition_map;
104
if (grub_disk_read (&raw, 0, 0, sizeof (struct grub_sun_block),
105
(char *) &block) == GRUB_ERR_NONE)
107
if (GRUB_PARTMAP_SUN_MAGIC != grub_be_to_cpu16 (block.magic))
108
grub_error (GRUB_ERR_BAD_PART_TABLE, "not a sun partiton table");
109
if (!grub_sun_is_valid (&block))
110
grub_error (GRUB_ERR_BAD_PART_TABLE, "invalid checksum");
111
/* Maybe another error value would be better, because partition
112
table _is_ recognised but invalid. */
113
for (partnum = 0; partnum < GRUB_PARTMAP_SUN_MAX_PARTS; partnum++)
115
if (block.infos[partnum].id == 0 ||
116
block.infos[partnum].id == GRUB_PARTMAP_SUN_WHOLE_DISK_ID)
118
p->start = grub_be_to_cpu32
119
(block.partitions[partnum].start_cylinder)
120
* grub_be_to_cpu16 (block.ntrks)
121
* grub_be_to_cpu16 (block.nsect);
122
p->len = grub_be_to_cpu32 (block.partitions[partnum].num_sectors);
127
partnum = GRUB_PARTMAP_SUN_MAX_PARTS;
136
static grub_partition_t
137
sun_partition_map_probe (grub_disk_t disk, const char *str)
139
grub_partition_t p = 0;
141
char *s = (char *) str;
143
auto int find_func (grub_disk_t d, const grub_partition_t partition);
145
int find_func (grub_disk_t d __attribute__ ((unused)),
146
const grub_partition_t partition)
148
if (partnum == partition->index)
150
p = (grub_partition_t) grub_malloc (sizeof (*p));
152
grub_memcpy (p, partition, sizeof (*p));
158
grub_errno = GRUB_ERR_NONE;
159
partnum = grub_strtoul (s, 0, 10);
160
if (grub_errno == GRUB_ERR_NONE)
162
if (sun_partition_map_iterate (disk, find_func))
170
grub_error (GRUB_ERR_BAD_FILENAME, "invalid partition");
177
sun_partition_map_get_name (const grub_partition_t p)
180
name = grub_malloc (13);
182
grub_sprintf (name, "%d", p->index);
186
/* Partition map type. */
187
static struct grub_partition_map grub_sun_partition_map =
189
.name = "sun_partition_map",
190
.iterate = sun_partition_map_iterate,
191
.probe = sun_partition_map_probe,
192
.get_name = sun_partition_map_get_name
195
GRUB_MOD_INIT(sun_partition_map)
197
grub_partition_map_register (&grub_sun_partition_map);
203
GRUB_MOD_FINI(sun_partition_map)
205
grub_partition_map_unregister (&grub_sun_partition_map);