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

« back to all changes in this revision

Viewing changes to shlibs/blkid/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, const struct blkid_idmag *mag)
41
 
{
42
 
        int i;
43
 
 
44
 
        for (i = 0; i < ARRAY_SIZE(topology_vals); i++) {
45
 
                struct topology_val *val = &topology_vals[i];
46
 
                int rc = 1;
47
 
                unsigned int data;
48
 
 
49
 
                if (ioctl(pr->fd, val->ioc, &data) == -1)
50
 
                        goto nothing;
51
 
 
52
 
                if (val->set_int)
53
 
                        rc = val->set_int(pr, (int) data);
54
 
                else
55
 
                        rc = val->set_ulong(pr, (unsigned long) data);
56
 
                if (rc)
57
 
                        goto err;
58
 
        }
59
 
 
60
 
        return 0;
61
 
nothing:
62
 
        return 1;
63
 
err:
64
 
        return -1;
65
 
}
66
 
 
67
 
const struct blkid_idinfo ioctl_tp_idinfo =
68
 
{
69
 
        .name           = "ioctl",
70
 
        .probefunc      = probe_ioctl_tp,
71
 
        .magics         = BLKID_NONE_MAGIC
72
 
};
73