3#define pr_fmt(fmt) "sysfs: " fmt
61 const size_t oldbuf_npages =
buffer->buf_npages;
64 buffer->buf_npages = new_npages;
84 if (should_write >= spaces_left)
98 if (count > spaces_left)
165 const size_t begin = offset;
168 memcpy((
char *) buf, buf_va + begin, end - begin);
256 MOS_ASSERT_X(dir,
"invalid sysfs entry, possibly a VFS bug");
265 for (
size_t j = 0; j < dir->
num_items; j++)
278 dynitem->
dyn_iterate(dynitem, dentry, state, add_record);
290 MOS_ASSERT_X(sysfs_dir || dir ==
sysfs_sb->root->inode,
"invalid sysfs entry, possibly a VFS bug");
311 MOS_ASSERT_X(sysfs_dir || dir ==
sysfs_sb->root->inode,
"invalid sysfs entry, possibly a VFS bug");
322 if (dynitem->
dyn_create(dir, dentry, type, perm))
338 if (
strcmp(dev,
"none") != 0)
344 if (options &&
strlen(options) != 0 &&
strcmp(options,
"defaults") != 0)
346 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.
c_str() :
"/");
#define MOS_ASSERT_X(cond, msg,...)
#define MOS_UNREACHABLE()
#define mos_warn(fmt,...)
const Char * c_str() const
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.
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)
T * create(Args &&...args)
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
void(* dyn_iterate)(struct _sysfs_item *item, dentry_t *dentry, vfs_listdir_state_t *iterator_state, dentry_iterator_op op)
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(* munmap)(sysfs_file_t *file, vmap_t *vmap, bool *unmapped)
struct sysfs_item_t::@153140136221376072256077077307321051166012334217 mem
bool(* dyn_create)(inode_t *parent_dir, dentry_t *dentry, file_type_t type, file_perm_t perm)
bool(* dyn_lookup)(inode_t *parent_dir, dentry_t *dentry)
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 PtrResult< dentry_t > sysfs_fsop_mount(filesystem_t *fs, const char *dev, const char *options)
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 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
#define container_of(ptr, type, member)
void dentry_iterator_op(vfs_listdir_state_t *state, u64 ino, mos::string_view name, 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, mos::string_view name)
Create a new dentry with the given name and parent.