20typedef struct _sysfs_item
48#define SYSFS_RO_ITEM(_name, _show_fn) { .name = _name, .type = SYSFS_RO, .show = _show_fn }
49#define SYSFS_RW_ITEM(_name, _show_fn, _store_fn) { .name = _name, .type = SYSFS_RW, .show = _show_fn, .store = _store_fn }
50#define SYSFS_WO_ITEM(_name, _store_fn) { .name = _name, .type = SYSFS_WO, .store = _store_fn }
51#define SYSFS_MEM_ITEM(_name, _mmap_fn, _munmap_fn) { .name = _name, .type = SYSFS_MEM, .mem.mmap = _mmap_fn, .mem.munmap = _munmap_fn }
52#define SYSFS_DYN_ITEMS(_name, _iterate_fn, _lookup_fn) { .type = SYSFS_DYN, .dyn.iterate = _iterate_fn, .dyn.lookup = _lookup_fn }
53#define SYSFS_DYN_DIR(_name, _iterate_fn, _lookup_fn, _create_fn) { .type = SYSFS_DYN, .dyn.iterate = _iterate_fn, .dyn.lookup = _lookup_fn, .dyn.create = _create_fn }
56#define SYSFS_ITEM_RO_PRINTF(name, fmt, ...) \
57 static bool name(sysfs_file_t *file) \
59 sysfs_printf(file, fmt, ##__VA_ARGS__); \
63#define SYSFS_ITEM_RO_STRING(name, value) SYSFS_ITEM_RO_PRINTF(name, "%s\n", value)
65#define SYSFS_DEFINE_DIR(sysfs_name, sysfs_items) \
66 static sysfs_dir_t __sysfs_##sysfs_name = { \
67 .list_node = LIST_NODE_INIT(__sysfs_##sysfs_name), \
68 .name = #sysfs_name, \
69 .items = sysfs_items, \
70 .num_items = MOS_ARRAY_SIZE(sysfs_items), \
72 ._dynamic_items = LIST_HEAD_INIT(__sysfs_##sysfs_name._dynamic_items), \
MOSAPI void(1, 2) fatal_abort(const char *fmt
list_node_t list_head
A linked list head.
bool munmap(ptr_t addr, size_t size)
Unmap a page from the current process's address space.
sysfs_item_t *const items
list_head _dynamic_items
for internal use only
dentry_t * _dentry
for internal use only
should_inline void sysfs_register_root_file(sysfs_item_t *item)
Register an entry in the sysfs root directory.
void sysfs_register(sysfs_dir_t *entry)
Register a sysfs directory.
void sysfs_file_set_data(sysfs_file_t *file, void *data)
void sysfs_register_file(sysfs_dir_t *sysfs_dir, sysfs_item_t *item)
Register an entry in a sysfs directory.
ssize_t sysfs_printf(sysfs_file_t *file, const char *fmt,...)
inode_t * sysfs_create_inode(file_type_t type, void *data)
ssize_t sysfs_put_data(sysfs_file_t *file, const void *data, size_t count)
@ SYSFS_MEM
memory-backed file
@ SYSFS_DYN
dynamic directory items
sysfs_item_t * sysfs_file_get_item(sysfs_file_t *file)
void * sysfs_file_get_data(sysfs_file_t *file)
void dentry_iterator_op(vfs_listdir_state_t *state, u64 ino, const char *name, size_t name_len, file_type_t type)