Coverage Report

Created: 2026-06-09 06:33

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