bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Solaris x86 partition parsing code |
| 3 | * |
| 4 | * Copyright (C) 2009 Karel Zak <kzak@redhat.com> |
| 5 | * |
| 6 | * This file may be redistributed under the terms of the |
| 7 | * GNU Lesser General Public License. |
| 8 | */ |
| 9 | #include <stdio.h> |
| 10 | #include <string.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <stdint.h> |
| 13 | |
| 14 | #include "partitions.h" |
| 15 | |
| 16 | /* |
| 17 | * Solaris-x86 is always within primary dos partition (nested PT table). The |
| 18 | * solaris-x86 vtoc allows to split the entire partition to "slices". The |
| 19 | * offset (start) of the slice is always relatively to the primary dos |
| 20 | * partition. |
| 21 | * |
| 22 | * Note that Solaris-SPARC uses entire disk with a different partitionning |
| 23 | * scheme. |
| 24 | */ |
| 25 | |
| 26 | /* some other implementation than Linux kernel assume 8 partitions only */ |
| 27 | #define SOLARIS_MAXPARTITIONS 16 |
| 28 | |
| 29 | /* disklabel (vtoc) location */ |
| 30 | #define SOLARIS_SECTOR 1 /* in 512-sectors */ |
| 31 | #define SOLARIS_OFFSET (SOLARIS_SECTOR << 9) /* in bytes */ |
| 32 | #define SOLARIS_MAGICOFFSET (SOLARIS_OFFSET + 12) /* v_sanity offset in bytes */ |
| 33 | |
| 34 | /* slice tags */ |
| 35 | #define SOLARIS_TAG_WHOLEDISK 5 |
| 36 | |
| 37 | struct solaris_slice { |
| 38 | uint16_t s_tag; /* ID tag of partition */ |
| 39 | uint16_t s_flag; /* permission flags */ |
| 40 | uint32_t s_start; /* start sector no of partition */ |
| 41 | uint32_t s_size; /* # of blocks in partition */ |
| 42 | } __attribute__((packed)); |
| 43 | |
| 44 | struct solaris_vtoc { |
| 45 | unsigned int v_bootinfo[3]; /* info needed by mboot (unsupported) */ |
| 46 | |
| 47 | uint32_t v_sanity; /* to verify vtoc sanity */ |
| 48 | uint32_t v_version; /* layout version */ |
| 49 | char v_volume[8]; /* volume name */ |
| 50 | uint16_t v_sectorsz; /* sector size in bytes */ |
| 51 | uint16_t v_nparts; /* number of partitions */ |
| 52 | unsigned int v_reserved[10]; /* free space */ |
| 53 | |
| 54 | struct solaris_slice v_slice[SOLARIS_MAXPARTITIONS]; /* slices */ |
| 55 | |
| 56 | unsigned int timestamp[SOLARIS_MAXPARTITIONS]; /* timestamp (unsupported) */ |
| 57 | char v_asciilabel[128]; /* for compatibility */ |
| 58 | } __attribute__((packed)); |
| 59 | |
| 60 | static int probe_solaris_pt(blkid_probe pr, |
| 61 | const struct blkid_idmag *mag __attribute__((__unused__))) |
| 62 | { |
| 63 | struct solaris_vtoc *l; /* disk label */ |
| 64 | struct solaris_slice *p; /* partitsion */ |
| 65 | blkid_parttable tab = NULL; |
| 66 | blkid_partition parent; |
| 67 | blkid_partlist ls; |
| 68 | int i; |
| 69 | uint16_t nparts; |
| 70 | |
| 71 | l = (struct solaris_vtoc *) blkid_probe_get_sector(pr, SOLARIS_SECTOR); |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 72 | if (!l) { |
| 73 | if (errno) |
| 74 | return -errno; |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 75 | goto nothing; |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 76 | } |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 77 | |
| 78 | if (le32_to_cpu(l->v_version) != 1) { |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 79 | DBG(LOWPROBE, ul_debug( |
| 80 | "WARNING: unsupported solaris x86 version %d, ignore", |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 81 | le32_to_cpu(l->v_version))); |
| 82 | goto nothing; |
| 83 | } |
| 84 | |
| 85 | if (blkid_partitions_need_typeonly(pr)) |
| 86 | /* caller does not ask for details about partitions */ |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 87 | return BLKID_PROBE_OK; |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 88 | |
| 89 | ls = blkid_probe_get_partlist(pr); |
| 90 | if (!ls) |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 91 | goto nothing; |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 92 | |
| 93 | parent = blkid_partlist_get_parent(ls); |
| 94 | |
| 95 | tab = blkid_partlist_new_parttable(ls, "solaris", SOLARIS_OFFSET); |
| 96 | if (!tab) |
| 97 | goto err; |
| 98 | |
| 99 | nparts = le16_to_cpu(l->v_nparts); |
| 100 | if (nparts > SOLARIS_MAXPARTITIONS) |
| 101 | nparts = SOLARIS_MAXPARTITIONS; |
| 102 | |
| 103 | for (i = 1, p = &l->v_slice[0]; i < nparts; i++, p++) { |
| 104 | |
| 105 | uint32_t start = le32_to_cpu(p->s_start); |
| 106 | uint32_t size = le32_to_cpu(p->s_size); |
| 107 | blkid_partition par; |
| 108 | |
| 109 | if (size == 0 || le16_to_cpu(p->s_tag) == SOLARIS_TAG_WHOLEDISK) |
| 110 | continue; |
| 111 | |
| 112 | if (parent) |
| 113 | /* Solaris slices are relative to the parent (primary |
| 114 | * DOS partition) */ |
| 115 | start += blkid_partition_get_start(parent); |
| 116 | |
| 117 | if (parent && !blkid_is_nested_dimension(parent, start, size)) { |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 118 | DBG(LOWPROBE, ul_debug( |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 119 | "WARNING: solaris partition (%d) overflow " |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 120 | "detected, ignore", i)); |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 121 | continue; |
| 122 | } |
| 123 | |
| 124 | par = blkid_partlist_add_partition(ls, tab, start, size); |
| 125 | if (!par) |
| 126 | goto err; |
| 127 | |
| 128 | blkid_partition_set_type(par, le16_to_cpu(p->s_tag)); |
| 129 | blkid_partition_set_flags(par, le16_to_cpu(p->s_flag)); |
| 130 | } |
| 131 | |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 132 | return BLKID_PROBE_OK; |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 133 | |
| 134 | nothing: |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 135 | return BLKID_PROBE_NONE; |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 136 | err: |
bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 137 | return -ENOMEM; |
bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | const struct blkid_idinfo solaris_x86_pt_idinfo = |
| 141 | { |
| 142 | .name = "solaris", |
| 143 | .probefunc = probe_solaris_pt, |
| 144 | .magics = |
| 145 | { |
| 146 | { |
| 147 | .magic = "\xEE\xDE\x0D\x60", /* little-endian magic string */ |
| 148 | .len = 4, /* v_sanity size in bytes */ |
| 149 | .sboff = SOLARIS_MAGICOFFSET /* offset of v_sanity */ |
| 150 | }, |
| 151 | { NULL } |
| 152 | } |
| 153 | }; |
| 154 | |