]> git.ipfire.org Git - thirdparty/util-linux.git/blob - include/sysfs.h
include: add indirect monotonic clock id specifier
[thirdparty/util-linux.git] / include / sysfs.h
1 /*
2 * Copyright (C) 2011 Karel Zak <kzak@redhat.com>
3 */
4 #ifndef UTIL_LINUX_SYSFS_H
5 #define UTIL_LINUX_SYSFS_H
6
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <stdint.h>
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 #include <fcntl.h>
15 #include <string.h>
16 #include <inttypes.h>
17 #include <dirent.h>
18
19 #include "path.h"
20
21 /**
22 * sysfs_devname_sys_to_dev:
23 * @name: devname to be converted in place
24 *
25 * Linux kernel linux/drivers/base/core.c: device_get_devnode()
26 * defines a replacement of '!' in the /sys device name by '/' in the
27 * /dev device name. This helper replaces all occurrences of '!' in
28 * @name by '/' to convert from /sys to /dev.
29 */
30 static inline void sysfs_devname_sys_to_dev(char *name)
31 {
32 char *c;
33
34 if (name)
35 while ((c = strchr(name, '!')))
36 c[0] = '/';
37 }
38
39 /**
40 * sysfs_devname_dev_to_sys:
41 * @name: devname to be converted in place
42 *
43 * See sysfs_devname_sys_to_dev().
44 */
45 static inline void sysfs_devname_dev_to_sys(char *name)
46 {
47 char *c;
48
49 if (name)
50 while ((c = strchr(name, '/')))
51 c[0] = '!';
52 }
53
54 struct sysfs_blkdev {
55 dev_t devno;
56 struct path_cxt *parent;
57
58 unsigned int scsi_host,
59 scsi_channel,
60 scsi_target,
61 scsi_lun;
62
63 unsigned int has_hctl : 1,
64 hctl_error : 1 ;
65 };
66
67 void ul_sysfs_init_debug(void);
68
69 struct path_cxt *ul_new_sysfs_path(dev_t devno, struct path_cxt *parent, const char *prefix);
70 int sysfs_blkdev_init_path(struct path_cxt *pc, dev_t devno, struct path_cxt *parent);
71
72 int sysfs_blkdev_set_parent(struct path_cxt *pc, struct path_cxt *parent);
73 struct path_cxt *sysfs_blkdev_get_parent(struct path_cxt *pc);
74
75 char *sysfs_blkdev_get_name(struct path_cxt *pc, char *buf, size_t bufsiz);
76 int sysfs_blkdev_is_partition_dirent(DIR *dir, struct dirent *d, const char *parent_name);
77 int sysfs_blkdev_count_partitions(struct path_cxt *pc, const char *devname);
78 dev_t sysfs_blkdev_partno_to_devno(struct path_cxt *pc, int partno);
79 char *sysfs_blkdev_get_slave(struct path_cxt *pc);
80 char *sysfs_blkdev_get_path(struct path_cxt *pc, char *buf, size_t bufsiz);
81 dev_t sysfs_blkdev_get_devno(struct path_cxt *pc);
82
83 char *sysfs_blkdev_get_devchain(struct path_cxt *pc, char *buf, size_t bufsz);
84 int sysfs_blkdev_next_subsystem(struct path_cxt *pc __attribute__((unused)), char *devchain, char **subsys);
85
86 int sysfs_blkdev_is_hotpluggable(struct path_cxt *pc);
87 int sysfs_blkdev_get_wholedisk( struct path_cxt *pc,
88 char *diskname,
89 size_t len,
90 dev_t *diskdevno);
91
92 int sysfs_devno_to_wholedisk(dev_t dev, char *diskname,
93 size_t len, dev_t *diskdevno);
94 int sysfs_devno_is_dm_private(dev_t devno, char **uuid);
95 int sysfs_devno_is_wholedisk(dev_t devno);
96 dev_t sysfs_devname_to_devno(const char *name);
97 dev_t __sysfs_devname_to_devno(const char *prefix, const char *name, const char *parent);
98 char *sysfs_devno_to_devpath(dev_t devno, char *buf, size_t bufsiz);
99 char *sysfs_devno_to_devname(dev_t devno, char *buf, size_t bufsiz);
100 int sysfs_devno_count_partitions(dev_t devno);
101
102 int sysfs_blkdev_scsi_get_hctl(struct path_cxt *pc, int *h, int *c, int *t, int *l);
103 char *sysfs_blkdev_scsi_host_strdup_attribute(struct path_cxt *pc,
104 const char *type, const char *attr);
105 int sysfs_blkdev_scsi_host_is(struct path_cxt *pc, const char *type);
106 int sysfs_blkdev_scsi_has_attribute(struct path_cxt *pc, const char *attr);
107 int sysfs_blkdev_scsi_path_contains(struct path_cxt *pc, const char *pattern);
108
109
110 #endif /* UTIL_LINUX_SYSFS_H */