Coverage Report

Created: 2025-06-13 06:36

/src/util-linux/include/sysfs.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * No copyright is claimed.  This code is in the public domain; do with
3
 * it what you wish.
4
 *
5
 * Written by Karel Zak <kzak@redhat.com> [2011]
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>
17
#include <fcntl.h>
18
#include <string.h>
19
#include <inttypes.h>
20
#include <dirent.h>
21
22
#include "path.h"
23
24
/**
25
 * sysfs_devname_sys_to_dev:
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
30
 * /dev device name. This helper replaces all occurrences of '!' in
31
 * @name by '/' to convert from /sys to /dev.
32
 */
33
static inline void sysfs_devname_sys_to_dev(char *name)
34
0
{
35
0
  char *c;
36
37
0
  if (name)
38
0
    while ((c = strchr(name, '!')))
39
0
      c[0] = '/';
40
0
}
Unexecuted instantiation: probe.c:sysfs_devname_sys_to_dev
Unexecuted instantiation: verify.c:sysfs_devname_sys_to_dev
Unexecuted instantiation: partitions.c:sysfs_devname_sys_to_dev
Unexecuted instantiation: sysfs.c:sysfs_devname_sys_to_dev
Unexecuted instantiation: devname.c:sysfs_devname_sys_to_dev
Unexecuted instantiation: devno.c:sysfs_devname_sys_to_dev
41
42
/**
43
 * sysfs_devname_dev_to_sys:
44
 * @name: devname to be converted in place
45
 *
46
 * See sysfs_devname_sys_to_dev().
47
 */
48
static inline void sysfs_devname_dev_to_sys(char *name)
49
0
{
50
0
  char *c;
51
52
0
  if (name)
53
0
    while ((c = strchr(name, '/')))
54
0
      c[0] = '!';
55
0
}
Unexecuted instantiation: probe.c:sysfs_devname_dev_to_sys
Unexecuted instantiation: verify.c:sysfs_devname_dev_to_sys
Unexecuted instantiation: partitions.c:sysfs_devname_dev_to_sys
Unexecuted instantiation: sysfs.c:sysfs_devname_dev_to_sys
Unexecuted instantiation: devname.c:sysfs_devname_dev_to_sys
Unexecuted instantiation: devno.c:sysfs_devname_dev_to_sys
56
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
70
void ul_sysfs_init_debug(void);
71
72
struct path_cxt *ul_new_sysfs_path(dev_t devno, struct path_cxt *parent, const char *prefix);
73
int sysfs_blkdev_init_path(struct path_cxt *pc, dev_t devno, struct path_cxt *parent);
74
75
int sysfs_blkdev_set_parent(struct path_cxt *pc, struct path_cxt *parent);
76
struct path_cxt *sysfs_blkdev_get_parent(struct path_cxt *pc);
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);
90
int sysfs_blkdev_is_removable(struct path_cxt *pc);
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);
100
101
dev_t sysfs_devname_to_devno(const char *name);
102
dev_t __sysfs_devname_to_devno(const char *prefix, const char *name, const char *parent);
103
int sysfs_devname_is_hidden(const char *prefix, const char *name);
104
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);
107
int sysfs_devno_count_partitions(dev_t devno);
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);
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);
115
116
char *sysfs_chrdev_devno_to_devname(dev_t devno, char *buf, size_t bufsiz);
117
118
enum sysfs_byteorder {
119
  SYSFS_BYTEORDER_LITTLE,
120
  SYSFS_BYTEORDER_BIG,
121
};
122
123
extern enum sysfs_byteorder sysfs_get_byteorder(struct path_cxt *pc);
124
extern int sysfs_get_address_bits(struct path_cxt *pc);
125
126
#endif /* UTIL_LINUX_SYSFS_H */