3#define pr_fmt(fmt) "sysfs: " fmt
24typedef struct _sysfs_file
60 const size_t oldbuf_npages =
buffer->buf_npages;
63 buffer->buf_npages = new_npages;
83 if (should_write >= spaces_left)
97 if (count > spaces_left)
164 const size_t begin = offset;
167 memcpy((
char *) buf, buf_va + begin, end - begin);
255 MOS_ASSERT_X(dir,
"invalid sysfs entry, possibly a VFS bug");
264 for (
size_t j = 0; j < dir->
num_items; j++)
277 dynitem->
dyn.
iterate(dynitem, dentry, state, add_record);
321 if (dynitem->
dyn.
create(dir, dentry, type, perm))
337 if (
strcmp(dev,
"none") != 0)
343 if (options &&
strlen(options) != 0 &&
strcmp(options,
"defaults") != 0)
345 mos_warn(
"options '%s' not supported", options);
372 for (
size_t i = 0; i < sysfs_dir->
num_items; i++)
415 pr_warn(
"no name specified for sysfs entry '%s'", sysfs_dir ? sysfs_dir->
name :
"/");
418 MOS_ASSERT_X(target_dentry,
"registering sysfs entry '%s' failed", item->
name);
#define MOS_ASSERT_X(cond, msg,...)
#define MOS_UNREACHABLE()
#define mos_warn(fmt,...)
void dentry_attach(dentry_t *d, inode_t *inode)
Attach an inode to a dentry.
should_inline dentry_t * dentry_parent(const dentry_t *dentry)
MOSAPI s32 strcmp(const char *str1, const char *str2)
MOSAPI int vsnprintf(char *__restrict buf, size_t size, const char *__restrict format, va_list args)
MOSAPI void linked_list_init(list_node_t *head_node)
Initialise a circular double linked list.
#define LIST_HEAD_INIT(container)
MOSAPI void list_node_append(list_node_t *head, list_node_t *item)
#define list_node(element)
Get the ‘list_node’ of a list element. This is exactly the reverse of ‘list_entry’ above.
#define list_node_foreach(v, h)
list_node_t list_head
A linked list head.
MOSAPI bool list_is_empty(const list_node_t *head)
#define phyframe_va(frame)
#define mm_free_pages(frame, npages)
phyframe_t * mm_get_free_pages(size_t npages)
void vfs_register_filesystem(filesystem_t *fs)
inode_t * inode_create(superblock_t *sb, u64 ino, file_type_t type)
#define container_of(ptr, type, member)
static void * memcpy(void *s1, const void *s2, size_t n)
static size_t strlen(const char *s)
#define pr_dinfo2(feat, fmt,...)
#define MOS_INIT(_comp, _fn)
const file_ops_t * file_ops
sysfs_item_t *const items
list_head _dynamic_items
for internal use only
dentry_t * _dentry
for internal use only
struct sysfs_item_t::@8::@11 dyn
size_t(* store)(sysfs_file_t *file, const char *buf, size_t count, off_t offset)
bool(* mmap)(sysfs_file_t *file, vmap_t *vmap, off_t offset)
bool(* lookup)(inode_t *parent_dir, dentry_t *dentry)
bool(* create)(inode_t *parent_dir, dentry_t *dentry, file_type_t type, file_perm_t perm)
bool(* munmap)(sysfs_file_t *file, vmap_t *vmap, bool *unmapped)
struct sysfs_item_t::@8::@10 mem
void(* iterate)(struct _sysfs_item *item, dentry_t *dentry, vfs_listdir_state_t *iterator_state, dentry_iterator_op op)
bool(* show)(sysfs_file_t *file)
static __nodiscard bool sysfs_file_ensure_ready(const file_t *file)
void sysfs_file_set_data(sysfs_file_t *file, void *data)
static const file_perm_t sysfs_dir_perm
void sysfs_register(sysfs_dir_t *dir)
Register a sysfs directory.
void sysfs_register_file(sysfs_dir_t *sysfs_dir, sysfs_item_t *item)
Register an entry in a sysfs directory.
static list_head sysfs_dirs
ssize_t sysfs_printf(sysfs_file_t *file, const char *fmt,...)
static void sysfs_expand_buffer(sysfs_file_t *buffer, size_t new_npages)
static off_t sysfs_fops_seek(file_t *file, off_t offset, io_seek_whence_t whence)
inode_t * sysfs_create_inode(file_type_t type, void *data)
bool sysfs_fops_munmap(file_t *file, vmap_t *vmap, bool *unmapped)
static const inode_ops_t sysfs_dir_i_ops
ssize_t sysfs_put_data(sysfs_file_t *file, const void *data, size_t count)
static ssize_t sysfs_fops_write(const file_t *file, const void *buf, size_t size, off_t offset)
static void sysfs_fops_release(file_t *file)
static filesystem_t fs_sysfs
static bool sysfs_fops_open(inode_t *inode, file_t *file, bool created)
static void sysfs_iops_iterate_dir(dentry_t *dentry, vfs_listdir_state_t *state, dentry_iterator_op add_record)
static superblock_t * sysfs_sb
bool sysfs_fops_mmap(file_t *file, vmap_t *vmap, off_t offset)
static const file_ops_t sysfs_dir_file_ops
static const file_ops_t sysfs_file_ops
static bool sysfs_iops_create(inode_t *dir, dentry_t *dentry, file_type_t type, file_perm_t perm)
sysfs_item_t * sysfs_file_get_item(sysfs_file_t *file)
static u64 sysfs_get_ino(void)
void * sysfs_file_get_data(sysfs_file_t *file)
static dentry_t * sysfs_fsop_mount(filesystem_t *fs, const char *dev, const char *options)
static void sysfs_do_register(sysfs_dir_t *sysfs_dir)
static ssize_t sysfs_fops_read(const file_t *file, void *buf, size_t size, off_t offset)
static bool sysfs_iops_lookup(inode_t *dir, dentry_t *dentry)
@ SYSFS_MEM
memory-backed file
@ SYSFS_DYN
dynamic directory items
struct _sysfs_file sysfs_file_t
slab_t * superblock_cache
void dentry_iterator_op(vfs_listdir_state_t *state, u64 ino, const char *name, size_t name_len, file_type_t type)
void vfs_generic_iterate_dir(const dentry_t *dir, vfs_listdir_state_t *state, dentry_iterator_op add_record)
dentry_t * dentry_get_from_parent(superblock_t *sb, dentry_t *parent, const char *name)
Create a new dentry with the given name and parent.