blob: 3aba09e4fc27e77e1d7458c0986a01691319d509 [file] [log] [blame]
bigbiff bigbiffe60683a2013-02-22 20:55:50 -05001/*
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 */
24static 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
32} topology_vals[] = {
33 { BLKALIGNOFF, NULL, blkid_topology_set_alignment_offset },
34 { BLKIOMIN, blkid_topology_set_minimum_io_size },
35 { BLKIOOPT, blkid_topology_set_optimal_io_size },
36 { BLKPBSZGET, blkid_topology_set_physical_sector_size }
37 /* we read BLKSSZGET in topology.c */
38};
39
40static int probe_ioctl_tp(blkid_probe pr,
41 const struct blkid_idmag *mag __attribute__((__unused__)))
42{
43 size_t i;
44
45 for (i = 0; i < ARRAY_SIZE(topology_vals); i++) {
46 struct topology_val *val = &topology_vals[i];
47 int rc = 1;
48 unsigned int data;
49
50 if (ioctl(pr->fd, val->ioc, &data) == -1)
51 goto nothing;
52
53 if (val->set_int)
54 rc = val->set_int(pr, (int) data);
55 else
56 rc = val->set_ulong(pr, (unsigned long) data);
57 if (rc)
58 goto err;
59 }
60
61 return 0;
62nothing:
63 return 1;
64err:
65 return -1;
66}
67
68const struct blkid_idinfo ioctl_tp_idinfo =
69{
70 .name = "ioctl",
71 .probefunc = probe_ioctl_tp,
72 .magics = BLKID_NONE_MAGIC
73};
74