summaryrefslogtreecommitdiffstats
path: root/libblkid/src/topology/ioctl.c
blob: 7b15c9e9a74d54ca4481c5a7dad526d9972a9a24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * ioctl based topology -- gathers topology information
 *
 * Copyright (C) 2009 Karel Zak <kzak@redhat.com>
 *
 * This file may be redistributed under the terms of the
 * GNU Lesser General Public License.
 *
 */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>

#include "topology.h"

static int probe_ioctl_tp(blkid_probe pr,
		const struct blkid_idmag *mag __attribute__((__unused__)))
{
	uint64_t u64;
	int s32;

	if (ioctl(pr->fd, BLKALIGNOFF, &s32) == -1)
		return 1;
	if (blkid_topology_set_alignment_offset(pr, s32))
		return -1;

	if (ioctl(pr->fd, BLKIOMIN, &s32) == -1)
		return 1;
	if (blkid_topology_set_minimum_io_size(pr, s32))
		return -1;

	if (ioctl(pr->fd, BLKIOOPT, &s32) == -1)
		return 1;
	if (blkid_topology_set_optimal_io_size(pr, s32))
		return -1;

	if (ioctl(pr->fd, BLKPBSZGET, &s32) == -1)
		return 1;
	if (blkid_topology_set_physical_sector_size(pr, s32))
		return -1;

	if (ioctl(pr->fd, BLKGETDISKSEQ, &u64) == -1)
		return 1;
	if (blkid_topology_set_physical_sector_size(pr, u64))
		return -1;

	return 0;
}

const struct blkid_idinfo ioctl_tp_idinfo =
{
	.name		= "ioctl",
	.probefunc	= probe_ioctl_tp,
	.magics		= BLKID_NONE_MAGIC
};