blob: 739f9de127090b416e943093c4d1b3495833255a [file] [log] [blame]
bigbiff bigbiffe60683a2013-02-22 20:55:50 -05001/*
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
19struct sysfs_cxt {
20 dev_t devno;
21 int dir_fd; /* /sys/block/<name> */
22 char *dir_path;
23 struct sysfs_cxt *parent;
24
25 unsigned int scsi_host,
26 scsi_channel,
27 scsi_target,
28 scsi_lun;
29
30 unsigned int has_hctl : 1;
31};
32
33#define UL_SYSFSCXT_EMPTY { 0, -1, NULL, NULL, 0, 0, 0, 0, 0 }
34
35extern char *sysfs_devno_attribute_path(dev_t devno, char *buf,
36 size_t bufsiz, const char *attr);
37extern int sysfs_devno_has_attribute(dev_t devno, const char *attr);
38extern char *sysfs_devno_path(dev_t devno, char *buf, size_t bufsiz);
39extern char *sysfs_devno_to_devpath(dev_t devno, char *buf, size_t bufsiz);
40extern dev_t sysfs_devname_to_devno(const char *name, const char *parent);
41
42extern int sysfs_init(struct sysfs_cxt *cxt, dev_t devno, struct sysfs_cxt *parent)
43 __attribute__ ((warn_unused_result));
44extern void sysfs_deinit(struct sysfs_cxt *cxt);
45
46extern DIR *sysfs_opendir(struct sysfs_cxt *cxt, const char *attr);
47
48extern int sysfs_stat(struct sysfs_cxt *cxt, const char *attr, struct stat *st);
49extern ssize_t sysfs_readlink(struct sysfs_cxt *cxt, const char *attr,
50 char *buf, size_t bufsiz);
51extern int sysfs_has_attribute(struct sysfs_cxt *cxt, const char *attr);
52
53extern int sysfs_scanf(struct sysfs_cxt *cxt, const char *attr,
54 const char *fmt, ...)
55 __attribute__ ((format (scanf, 3, 4)));
56
57extern int sysfs_read_s64(struct sysfs_cxt *cxt, const char *attr, int64_t *res);
58extern int sysfs_read_u64(struct sysfs_cxt *cxt, const char *attr, uint64_t *res);
59extern int sysfs_read_int(struct sysfs_cxt *cxt, const char *attr, int *res);
60
61extern char *sysfs_get_devname(struct sysfs_cxt *cxt, char *buf, size_t bufsiz);
62
63extern char *sysfs_strdup(struct sysfs_cxt *cxt, const char *attr);
64
65extern int sysfs_count_dirents(struct sysfs_cxt *cxt, const char *attr);
66extern int sysfs_count_partitions(struct sysfs_cxt *cxt, const char *devname);
67extern dev_t sysfs_partno_to_devno(struct sysfs_cxt *cxt, int partno);
68extern char *sysfs_get_slave(struct sysfs_cxt *cxt);
69
70extern int sysfs_is_partition_dirent(DIR *dir, struct dirent *d,
71 const char *parent_name);
72
73extern int sysfs_devno_to_wholedisk(dev_t dev, char *diskname,
74 size_t len, dev_t *diskdevno);
75
76extern int sysfs_scsi_get_hctl(struct sysfs_cxt *cxt, int *h,
77 int *c, int *t, int *l);
78extern char *sysfs_scsi_host_strdup_attribute(struct sysfs_cxt *cxt,
79 const char *type, const char *attr);
80extern int sysfs_scsi_host_is(struct sysfs_cxt *cxt, const char *type);
81extern int sysfs_scsi_has_attribute(struct sysfs_cxt *cxt, const char *attr);
82extern int sysfs_scsi_path_contains(struct sysfs_cxt *cxt, const char *pattern);
83
84#endif /* UTIL_LINUX_SYSFS_H */