]>
Commit | Line | Data |
---|---|---|
7fe16fda | 1 | /* |
faeb1b64 KZ |
2 | * No copyright is claimed. This code is in the public domain; do with |
3 | * it what you wish. | |
4 | * | |
7fe16fda KZ |
5 | * Copyright (C) 2011 Karel Zak <kzak@redhat.com> |
6 | */ | |
7 | #ifndef UTIL_LINUX_SYSFS_H | |
8 | #define UTIL_LINUX_SYSFS_H | |
9 | ||
10 | ||
11 | #include <stdio.h> | |
12 | #include <stdlib.h> | |
13 | #include <unistd.h> | |
14 | #include <stdint.h> | |
15 | #include <sys/types.h> | |
16 | #include <sys/stat.h> | |
7fe16fda KZ |
17 | #include <fcntl.h> |
18 | #include <string.h> | |
19 | #include <inttypes.h> | |
7fe16fda KZ |
20 | #include <dirent.h> |
21 | ||
5387c015 | 22 | #include "path.h" |
d0f7e5b4 | 23 | |
d0dc6c17 | 24 | /** |
6c62abc4 | 25 | * sysfs_devname_sys_to_dev: |
d0dc6c17 SB |
26 | * @name: devname to be converted in place |
27 | * | |
28 | * Linux kernel linux/drivers/base/core.c: device_get_devnode() | |
29 | * defines a replacement of '!' in the /sys device name by '/' in the | |
9e930041 | 30 | * /dev device name. This helper replaces all occurrences of '!' in |
759b120d | 31 | * @name by '/' to convert from /sys to /dev. |
d0dc6c17 | 32 | */ |
6c62abc4 | 33 | static inline void sysfs_devname_sys_to_dev(char *name) |
d0dc6c17 SB |
34 | { |
35 | char *c; | |
36 | ||
37 | if (name) | |
38 | while ((c = strchr(name, '!'))) | |
39 | c[0] = '/'; | |
40 | } | |
41 | ||
759b120d | 42 | /** |
6c62abc4 | 43 | * sysfs_devname_dev_to_sys: |
759b120d SB |
44 | * @name: devname to be converted in place |
45 | * | |
6c62abc4 | 46 | * See sysfs_devname_sys_to_dev(). |
759b120d | 47 | */ |
6c62abc4 | 48 | static inline void sysfs_devname_dev_to_sys(char *name) |
759b120d SB |
49 | { |
50 | char *c; | |
51 | ||
52 | if (name) | |
53 | while ((c = strchr(name, '/'))) | |
54 | c[0] = '!'; | |
55 | } | |
56 | ||
5387c015 KZ |
57 | struct sysfs_blkdev { |
58 | dev_t devno; | |
59 | struct path_cxt *parent; | |
60 | ||
61 | unsigned int scsi_host, | |
62 | scsi_channel, | |
63 | scsi_target, | |
64 | scsi_lun; | |
65 | ||
66 | unsigned int has_hctl : 1, | |
67 | hctl_error : 1 ; | |
68 | }; | |
69 | ||
bcf445fd KZ |
70 | void ul_sysfs_init_debug(void); |
71 | ||
83029ea5 | 72 | struct path_cxt *ul_new_sysfs_path(dev_t devno, struct path_cxt *parent, const char *prefix); |
5387c015 | 73 | int sysfs_blkdev_init_path(struct path_cxt *pc, dev_t devno, struct path_cxt *parent); |
8c3d9cad | 74 | |
5387c015 | 75 | int sysfs_blkdev_set_parent(struct path_cxt *pc, struct path_cxt *parent); |
8c3d9cad | 76 | struct path_cxt *sysfs_blkdev_get_parent(struct path_cxt *pc); |
5387c015 KZ |
77 | |
78 | char *sysfs_blkdev_get_name(struct path_cxt *pc, char *buf, size_t bufsiz); | |
79 | int sysfs_blkdev_is_partition_dirent(DIR *dir, struct dirent *d, const char *parent_name); | |
80 | int sysfs_blkdev_count_partitions(struct path_cxt *pc, const char *devname); | |
81 | dev_t sysfs_blkdev_partno_to_devno(struct path_cxt *pc, int partno); | |
82 | char *sysfs_blkdev_get_slave(struct path_cxt *pc); | |
83 | char *sysfs_blkdev_get_path(struct path_cxt *pc, char *buf, size_t bufsiz); | |
84 | dev_t sysfs_blkdev_get_devno(struct path_cxt *pc); | |
85 | ||
86 | char *sysfs_blkdev_get_devchain(struct path_cxt *pc, char *buf, size_t bufsz); | |
87 | int sysfs_blkdev_next_subsystem(struct path_cxt *pc __attribute__((unused)), char *devchain, char **subsys); | |
88 | ||
89 | int sysfs_blkdev_is_hotpluggable(struct path_cxt *pc); | |
216d8b05 | 90 | int sysfs_blkdev_is_removable(struct path_cxt *pc); |
5387c015 KZ |
91 | int sysfs_blkdev_get_wholedisk( struct path_cxt *pc, |
92 | char *diskname, | |
93 | size_t len, | |
94 | dev_t *diskdevno); | |
95 | ||
96 | int sysfs_devno_to_wholedisk(dev_t dev, char *diskname, | |
97 | size_t len, dev_t *diskdevno); | |
98 | int sysfs_devno_is_dm_private(dev_t devno, char **uuid); | |
99 | int sysfs_devno_is_wholedisk(dev_t devno); | |
c8487d85 | 100 | |
5387c015 | 101 | dev_t sysfs_devname_to_devno(const char *name); |
ab628c7c | 102 | dev_t __sysfs_devname_to_devno(const char *prefix, const char *name, const char *parent); |
c8487d85 RS |
103 | int sysfs_devname_is_hidden(const char *prefix, const char *name); |
104 | ||
5387c015 KZ |
105 | char *sysfs_devno_to_devpath(dev_t devno, char *buf, size_t bufsiz); |
106 | char *sysfs_devno_to_devname(dev_t devno, char *buf, size_t bufsiz); | |
93c687d8 | 107 | int sysfs_devno_count_partitions(dev_t devno); |
5387c015 KZ |
108 | |
109 | int sysfs_blkdev_scsi_get_hctl(struct path_cxt *pc, int *h, int *c, int *t, int *l); | |
110 | char *sysfs_blkdev_scsi_host_strdup_attribute(struct path_cxt *pc, | |
111 | const char *type, const char *attr); | |
112 | int sysfs_blkdev_scsi_host_is(struct path_cxt *pc, const char *type); | |
ab628c7c KZ |
113 | int sysfs_blkdev_scsi_has_attribute(struct path_cxt *pc, const char *attr); |
114 | int sysfs_blkdev_scsi_path_contains(struct path_cxt *pc, const char *pattern); | |
5387c015 | 115 | |
ab5304a7 KZ |
116 | char *sysfs_chrdev_devno_to_devname(dev_t devno, char *buf, size_t bufsiz); |
117 | ||
3672d2be TW |
118 | enum sysfs_byteorder { |
119 | SYSFS_BYTEORDER_LITTLE, | |
120 | SYSFS_BYTEORDER_BIG, | |
121 | }; | |
122 | ||
7578e03f | 123 | extern enum sysfs_byteorder sysfs_get_byteorder(struct path_cxt *pc); |
74c9e0d8 | 124 | extern int sysfs_get_address_bits(struct path_cxt *pc); |
5387c015 | 125 | |
7fe16fda | 126 | #endif /* UTIL_LINUX_SYSFS_H */ |