]> git.ipfire.org Git - thirdparty/util-linux.git/blame - include/sysfs.h
include: add indirect monotonic clock id specifier
[thirdparty/util-linux.git] / include / sysfs.h
CommitLineData
7fe16fda
KZ
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>
7fe16fda
KZ
14#include <fcntl.h>
15#include <string.h>
16#include <inttypes.h>
7fe16fda
KZ
17#include <dirent.h>
18
5387c015 19#include "path.h"
d0f7e5b4 20
d0dc6c17 21/**
6c62abc4 22 * sysfs_devname_sys_to_dev:
d0dc6c17
SB
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
9e930041 27 * /dev device name. This helper replaces all occurrences of '!' in
759b120d 28 * @name by '/' to convert from /sys to /dev.
d0dc6c17 29 */
6c62abc4 30static inline void sysfs_devname_sys_to_dev(char *name)
d0dc6c17
SB
31{
32 char *c;
33
34 if (name)
35 while ((c = strchr(name, '!')))
36 c[0] = '/';
37}
38
759b120d 39/**
6c62abc4 40 * sysfs_devname_dev_to_sys:
759b120d
SB
41 * @name: devname to be converted in place
42 *
6c62abc4 43 * See sysfs_devname_sys_to_dev().
759b120d 44 */
6c62abc4 45static inline void sysfs_devname_dev_to_sys(char *name)
759b120d
SB
46{
47 char *c;
48
49 if (name)
50 while ((c = strchr(name, '/')))
51 c[0] = '!';
52}
53
5387c015
KZ
54struct 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
bcf445fd
KZ
67void ul_sysfs_init_debug(void);
68
83029ea5 69struct path_cxt *ul_new_sysfs_path(dev_t devno, struct path_cxt *parent, const char *prefix);
5387c015 70int sysfs_blkdev_init_path(struct path_cxt *pc, dev_t devno, struct path_cxt *parent);
8c3d9cad 71
5387c015 72int sysfs_blkdev_set_parent(struct path_cxt *pc, struct path_cxt *parent);
8c3d9cad 73struct path_cxt *sysfs_blkdev_get_parent(struct path_cxt *pc);
5387c015
KZ
74
75char *sysfs_blkdev_get_name(struct path_cxt *pc, char *buf, size_t bufsiz);
76int sysfs_blkdev_is_partition_dirent(DIR *dir, struct dirent *d, const char *parent_name);
77int sysfs_blkdev_count_partitions(struct path_cxt *pc, const char *devname);
78dev_t sysfs_blkdev_partno_to_devno(struct path_cxt *pc, int partno);
79char *sysfs_blkdev_get_slave(struct path_cxt *pc);
80char *sysfs_blkdev_get_path(struct path_cxt *pc, char *buf, size_t bufsiz);
81dev_t sysfs_blkdev_get_devno(struct path_cxt *pc);
82
83char *sysfs_blkdev_get_devchain(struct path_cxt *pc, char *buf, size_t bufsz);
84int sysfs_blkdev_next_subsystem(struct path_cxt *pc __attribute__((unused)), char *devchain, char **subsys);
85
86int sysfs_blkdev_is_hotpluggable(struct path_cxt *pc);
87int sysfs_blkdev_get_wholedisk( struct path_cxt *pc,
88 char *diskname,
89 size_t len,
90 dev_t *diskdevno);
91
92int sysfs_devno_to_wholedisk(dev_t dev, char *diskname,
93 size_t len, dev_t *diskdevno);
94int sysfs_devno_is_dm_private(dev_t devno, char **uuid);
95int sysfs_devno_is_wholedisk(dev_t devno);
96dev_t sysfs_devname_to_devno(const char *name);
ab628c7c 97dev_t __sysfs_devname_to_devno(const char *prefix, const char *name, const char *parent);
5387c015
KZ
98char *sysfs_devno_to_devpath(dev_t devno, char *buf, size_t bufsiz);
99char *sysfs_devno_to_devname(dev_t devno, char *buf, size_t bufsiz);
93c687d8 100int sysfs_devno_count_partitions(dev_t devno);
5387c015
KZ
101
102int sysfs_blkdev_scsi_get_hctl(struct path_cxt *pc, int *h, int *c, int *t, int *l);
103char *sysfs_blkdev_scsi_host_strdup_attribute(struct path_cxt *pc,
104 const char *type, const char *attr);
105int sysfs_blkdev_scsi_host_is(struct path_cxt *pc, const char *type);
ab628c7c
KZ
106int sysfs_blkdev_scsi_has_attribute(struct path_cxt *pc, const char *attr);
107int sysfs_blkdev_scsi_path_contains(struct path_cxt *pc, const char *pattern);
5387c015
KZ
108
109
7fe16fda 110#endif /* UTIL_LINUX_SYSFS_H */