File: sysfs.h

package info (click to toggle)
ndctl 82-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,460 kB
  • sloc: ansic: 42,027; sh: 3,974; makefile: 28
file content (46 lines) | stat: -rw-r--r-- 1,749 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* SPDX-License-Identifier: LGPL-2.1 */
/* Copyright (C) 2014-2020, Intel Corporation. All rights reserved. */
#ifndef __UTIL_SYSFS_H__
#define __UTIL_SYSFS_H__

#include <string.h>

typedef void *(*add_dev_fn)(void *parent, int id, const char *dev_path);

#define SYSFS_ATTR_SIZE 1024

struct log_ctx;
int __sysfs_read_attr(struct log_ctx *ctx, const char *path, char *buf);
int __sysfs_write_attr(struct log_ctx *ctx, const char *path, const char *buf);
int __sysfs_write_attr_quiet(struct log_ctx *ctx, const char *path,
		const char *buf);
int __sysfs_device_parse(struct log_ctx *ctx, const char *base_path,
		const char *dev_name, void *parent, add_dev_fn add_dev);

#define sysfs_read_attr(c, p, b) __sysfs_read_attr(&(c)->ctx, (p), (b))
#define sysfs_write_attr(c, p, b) __sysfs_write_attr(&(c)->ctx, (p), (b))
#define sysfs_write_attr_quiet(c, p, b) __sysfs_write_attr_quiet(&(c)->ctx, (p), (b))
#define sysfs_device_parse(c, b, d, p, fn) __sysfs_device_parse(&(c)->ctx, \
		(b), (d), (p), (fn))

static inline const char *devpath_to_devname(const char *devpath)
{
	return strrchr(devpath, '/') + 1;
}

struct kmod_ctx;
struct kmod_module;
struct kmod_module *__util_modalias_to_module(struct kmod_ctx *kmod_ctx,
					      const char *alias,
					      struct log_ctx *log);
#define util_modalias_to_module(ctx, buf)                                      \
	__util_modalias_to_module((ctx)->kmod_ctx, buf, &(ctx)->ctx)

int __util_bind(const char *devname, struct kmod_module *module, const char *bus,
	      struct log_ctx *ctx);
#define util_bind(n, m, b, c) __util_bind(n, m, b, &(c)->ctx)

int __util_unbind(const char *devpath, struct log_ctx *ctx);
#define util_unbind(p, c) __util_unbind(p, &(c)->ctx)

#endif /* __UTIL_SYSFS_H__ */