Coverage Report

Created: 2025-10-12 06:56

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/util-linux/libblkid/src/partitions/minix.c
Line
Count
Source
1
/*
2
 * Minix 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
#include "minix.h"
16
17
static int probe_minix_pt(blkid_probe pr,
18
    const struct blkid_idmag *mag __attribute__((__unused__)))
19
679
{
20
679
  const struct dos_partition *p;
21
679
  blkid_parttable tab = NULL;
22
679
  blkid_partition parent;
23
679
  blkid_partlist ls;
24
679
  const unsigned char *data;
25
679
  int i;
26
27
679
  data = blkid_probe_get_sector(pr, 0);
28
679
  if (!data) {
29
0
    if (errno)
30
0
      return -errno;
31
0
    goto nothing;
32
0
  }
33
34
679
  ls = blkid_probe_get_partlist(pr);
35
679
  if (!ls)
36
679
    goto nothing;
37
38
  /* Parent is required, because Minix uses the same PT as DOS and
39
   * difference is only in primary partition (parent) type.
40
   */
41
0
  parent = blkid_partlist_get_parent(ls);
42
0
  if (!parent)
43
0
    goto nothing;
44
45
0
  if (blkid_partition_get_type(parent) != MBR_MINIX_PARTITION)
46
0
    goto nothing;
47
48
0
  if (blkid_partitions_need_typeonly(pr))
49
    /* caller does not ask for details about partitions */
50
0
    return BLKID_PROBE_OK;
51
52
0
  tab = blkid_partlist_new_parttable(ls, "minix", MBR_PT_OFFSET);
53
0
  if (!tab)
54
0
    goto err;
55
56
0
  for (i = 0, p = mbr_get_partition(data, 0);
57
0
      i < MINIX_MAXPARTITIONS; i++, p++) {
58
59
0
    uint32_t start, size;
60
0
    blkid_partition par;
61
62
0
    if (p->sys_ind != MBR_MINIX_PARTITION)
63
0
      continue;
64
65
0
    start = dos_partition_get_start(p);
66
0
    size = dos_partition_get_size(p);
67
68
0
    if (parent && !blkid_is_nested_dimension(parent, start, size)) {
69
0
      DBG(LOWPROBE, ul_debug(
70
0
        "WARNING: minix partition (%d) overflow "
71
0
        "detected, ignore", i));
72
0
      continue;
73
0
    }
74
75
0
    par = blkid_partlist_add_partition(ls, tab, start, size);
76
0
    if (!par)
77
0
      goto err;
78
79
0
    blkid_partition_set_type(par, p->sys_ind);
80
0
    blkid_partition_set_flags(par, p->boot_ind);
81
0
  }
82
83
0
  return BLKID_PROBE_OK;
84
85
679
nothing:
86
679
  return BLKID_PROBE_NONE;
87
0
err:
88
  return -ENOMEM;
89
0
}
90
91
/* same as DOS */
92
const struct blkid_idinfo minix_pt_idinfo =
93
{
94
  .name   = "minix",
95
  .probefunc  = probe_minix_pt,
96
  .magics   =
97
  {
98
    { .magic = "\x55\xAA", .len = 2, .sboff = 510 },
99
    { NULL }
100
  }
101
};
102