bigbiff bigbiff | e60683a | 2013-02-22 20:55:50 -0500 | [diff] [blame] | 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 | struct 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 | |
| 35 | extern char *sysfs_devno_attribute_path(dev_t devno, char *buf, |
| 36 | size_t bufsiz, const char *attr); |
| 37 | extern int sysfs_devno_has_attribute(dev_t devno, const char *attr); |
| 38 | extern char *sysfs_devno_path(dev_t devno, char *buf, size_t bufsiz); |
| 39 | extern char *sysfs_devno_to_devpath(dev_t devno, char *buf, size_t bufsiz); |
| 40 | extern dev_t sysfs_devname_to_devno(const char *name, const char *parent); |
| 41 | |
| 42 | extern int sysfs_init(struct sysfs_cxt *cxt, dev_t devno, struct sysfs_cxt *parent) |
| 43 | __attribute__ ((warn_unused_result)); |
| 44 | extern void sysfs_deinit(struct sysfs_cxt *cxt); |
| 45 | |
| 46 | extern DIR *sysfs_opendir(struct sysfs_cxt *cxt, const char *attr); |
| 47 | |
| 48 | extern int sysfs_stat(struct sysfs_cxt *cxt, const char *attr, struct stat *st); |
| 49 | extern ssize_t sysfs_readlink(struct sysfs_cxt *cxt, const char *attr, |
| 50 | char *buf, size_t bufsiz); |
| 51 | extern int sysfs_has_attribute(struct sysfs_cxt *cxt, const char *attr); |
| 52 | |
| 53 | extern int sysfs_scanf(struct sysfs_cxt *cxt, const char *attr, |
| 54 | const char *fmt, ...) |
| 55 | __attribute__ ((format (scanf, 3, 4))); |
| 56 | |
| 57 | extern int sysfs_read_s64(struct sysfs_cxt *cxt, const char *attr, int64_t *res); |
| 58 | extern int sysfs_read_u64(struct sysfs_cxt *cxt, const char *attr, uint64_t *res); |
| 59 | extern int sysfs_read_int(struct sysfs_cxt *cxt, const char *attr, int *res); |
| 60 | |
| 61 | extern char *sysfs_get_devname(struct sysfs_cxt *cxt, char *buf, size_t bufsiz); |
| 62 | |
| 63 | extern char *sysfs_strdup(struct sysfs_cxt *cxt, const char *attr); |
| 64 | |
| 65 | extern int sysfs_count_dirents(struct sysfs_cxt *cxt, const char *attr); |
| 66 | extern int sysfs_count_partitions(struct sysfs_cxt *cxt, const char *devname); |
| 67 | extern dev_t sysfs_partno_to_devno(struct sysfs_cxt *cxt, int partno); |
| 68 | extern char *sysfs_get_slave(struct sysfs_cxt *cxt); |
| 69 | |
| 70 | extern int sysfs_is_partition_dirent(DIR *dir, struct dirent *d, |
| 71 | const char *parent_name); |
| 72 | |
| 73 | extern int sysfs_devno_to_wholedisk(dev_t dev, char *diskname, |
| 74 | size_t len, dev_t *diskdevno); |
| 75 | |
| 76 | extern int sysfs_scsi_get_hctl(struct sysfs_cxt *cxt, int *h, |
| 77 | int *c, int *t, int *l); |
| 78 | extern char *sysfs_scsi_host_strdup_attribute(struct sysfs_cxt *cxt, |
| 79 | const char *type, const char *attr); |
| 80 | extern int sysfs_scsi_host_is(struct sysfs_cxt *cxt, const char *type); |
| 81 | extern int sysfs_scsi_has_attribute(struct sysfs_cxt *cxt, const char *attr); |
| 82 | extern int sysfs_scsi_path_contains(struct sysfs_cxt *cxt, const char *pattern); |
| 83 | |
| 84 | #endif /* UTIL_LINUX_SYSFS_H */ |