Coverage Report

Created: 2023-03-26 06:54

/src/util-linux/libblkid/src/topology/ioctl.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * ioctl based topology -- gathers topology information
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
 */
10
#include <stdio.h>
11
#include <string.h>
12
#include <stdlib.h>
13
#include <stdint.h>
14
#include <sys/types.h>
15
#include <sys/stat.h>
16
#include <unistd.h>
17
#include <errno.h>
18
19
#include "topology.h"
20
21
/*
22
 * ioctl topology values
23
 */
24
static const struct topology_val {
25
26
  long  ioc;
27
28
  /* functions to set probing result */
29
  int (*set_ulong)(blkid_probe, unsigned long);
30
  int (*set_int)(blkid_probe, int);
31
  int (*set_u64)(blkid_probe, uint64_t);
32
33
} topology_vals[] = {
34
  { BLKALIGNOFF, NULL, blkid_topology_set_alignment_offset },
35
  { BLKIOMIN, blkid_topology_set_minimum_io_size },
36
  { BLKIOOPT, blkid_topology_set_optimal_io_size },
37
  { BLKPBSZGET, blkid_topology_set_physical_sector_size },
38
  { BLKGETDISKSEQ, .set_u64 = blkid_topology_set_diskseq },
39
  /* we read BLKSSZGET in topology.c */
40
};
41
42
static int probe_ioctl_tp(blkid_probe pr,
43
    const struct blkid_idmag *mag __attribute__((__unused__)))
44
0
{
45
0
  size_t i;
46
47
0
  for (i = 0; i < ARRAY_SIZE(topology_vals); i++) {
48
0
    const struct topology_val *val = &topology_vals[i];
49
0
    int rc = 1;
50
0
    union {
51
0
      unsigned long ul;
52
0
      int i;
53
0
      uint64_t u64;
54
0
    } data;
55
56
0
    if (ioctl(pr->fd, val->ioc, &data) == -1)
57
0
      goto nothing;
58
59
0
    if (val->set_int)
60
0
      rc = val->set_int(pr, data.i);
61
0
    else if (val->set_ulong)
62
0
      rc = val->set_ulong(pr, data.ul);
63
0
    else
64
0
      rc = val->set_u64(pr, data.u64);
65
66
0
    if (rc)
67
0
      goto err;
68
0
  }
69
70
0
  return 0;
71
0
nothing:
72
0
  return 1;
73
0
err:
74
0
  return -1;
75
0
}
76
77
const struct blkid_idinfo ioctl_tp_idinfo =
78
{
79
  .name   = "ioctl",
80
  .probefunc  = probe_ioctl_tp,
81
  .magics   = BLKID_NONE_MAGIC
82
};
83