~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to libblkid/src/topology/ioctl.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2011-11-03 15:38:23 UTC
  • mto: (4.5.5 sid) (1.6.4)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-10sx16jprzxlhkqf
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 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
 
 
40
static 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;
 
62
nothing:
 
63
        return 1;
 
64
err:
 
65
        return -1;
 
66
}
 
67
 
 
68
const struct blkid_idinfo ioctl_tp_idinfo =
 
69
{
 
70
        .name           = "ioctl",
 
71
        .probefunc      = probe_ioctl_tp,
 
72
        .magics         = BLKID_NONE_MAGIC
 
73
};
 
74