summaryrefslogtreecommitdiffstats
path: root/include/sysfs.h
blob: dcd2a148d98666deaf757668a039b192a7f1366c (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * Copyright (C) 2011 Karel Zak <kzak@redhat.com>
 */
#ifndef UTIL_LINUX_SYSFS_H
#define UTIL_LINUX_SYSFS_H


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <inttypes.h>
#include <dirent.h>

#include "path.h"

/**
 * sysfs_devname_sys_to_dev:
 * @name: devname to be converted in place
 *
 * Linux kernel linux/drivers/base/core.c: device_get_devnode()
 * defines a replacement of '!' in the /sys device name by '/' in the
 * /dev device name. This helper replaces all occurrences of '!' in
 * @name by '/' to convert from /sys to /dev.
 */
static inline void sysfs_devname_sys_to_dev(char *name)
{
	char *c;

	if (name)
		while ((c = strchr(name, '!')))
			c[0] = '/';
}

/**
 * sysfs_devname_dev_to_sys:
 * @name: devname to be converted in place
 *
 * See sysfs_devname_sys_to_dev().
 */
static inline void sysfs_devname_dev_to_sys(char *name)
{
	char *c;

	if (name)
		while ((c = strchr(name, '/')))
			c[0] = '!';
}

struct sysfs_blkdev {
	dev_t	devno;
	struct path_cxt *parent;

	unsigned int	scsi_host,
			scsi_channel,
			scsi_target,
			scsi_lun;

	unsigned int	has_hctl   : 1,
			hctl_error : 1 ;
};

void ul_sysfs_init_debug(void);

struct path_cxt *ul_new_sysfs_path(dev_t devno, struct path_cxt *parent, const char *prefix);
int sysfs_blkdev_init_path(struct path_cxt *pc, dev_t devno, struct path_cxt *parent);

int sysfs_blkdev_set_parent(struct path_cxt *pc, struct path_cxt *parent);
struct path_cxt *sysfs_blkdev_get_parent(struct path_cxt *pc);

char *sysfs_blkdev_get_name(struct path_cxt *pc, char *buf, size_t bufsiz);
int sysfs_blkdev_is_partition_dirent(DIR *dir, struct dirent *d, const char *parent_name);
int sysfs_blkdev_count_partitions(struct path_cxt *pc, const char *devname);
dev_t sysfs_blkdev_partno_to_devno(struct path_cxt *pc, int partno);
char *sysfs_blkdev_get_slave(struct path_cxt *pc);
char *sysfs_blkdev_get_path(struct path_cxt *pc, char *buf, size_t bufsiz);
dev_t sysfs_blkdev_get_devno(struct path_cxt *pc);

char *sysfs_blkdev_get_devchain(struct path_cxt *pc, char *buf, size_t bufsz);
int sysfs_blkdev_next_subsystem(struct path_cxt *pc __attribute__((unused)), char *devchain, char **subsys);

int sysfs_blkdev_is_hotpluggable(struct path_cxt *pc);
int sysfs_blkdev_get_wholedisk( struct path_cxt *pc,
                                char *diskname,
                                size_t len,
                                dev_t *diskdevno);

int sysfs_devno_to_wholedisk(dev_t dev, char *diskname,
                             size_t len, dev_t *diskdevno);
int sysfs_devno_is_dm_private(dev_t devno, char **uuid);
int sysfs_devno_is_wholedisk(dev_t devno);

dev_t sysfs_devname_to_devno(const char *name);
dev_t __sysfs_devname_to_devno(const char *prefix, const char *name, const char *parent);
int sysfs_devname_is_hidden(const char *prefix, const char *name);

char *sysfs_devno_to_devpath(dev_t devno, char *buf, size_t bufsiz);
char *sysfs_devno_to_devname(dev_t devno, char *buf, size_t bufsiz);
int sysfs_devno_count_partitions(dev_t devno);

int sysfs_blkdev_scsi_get_hctl(struct path_cxt *pc, int *h, int *c, int *t, int *l);
char *sysfs_blkdev_scsi_host_strdup_attribute(struct path_cxt *pc,
                        const char *type, const char *attr);
int sysfs_blkdev_scsi_host_is(struct path_cxt *pc, const char *type);
int sysfs_blkdev_scsi_has_attribute(struct path_cxt *pc, const char *attr);
int sysfs_blkdev_scsi_path_contains(struct path_cxt *pc, const char *pattern);


#endif /* UTIL_LINUX_SYSFS_H */