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)
142 if (
f->buf_head_offset == 0)
144 if (!
f->item->show(
f))
160 if (offset >=
f->buf_head_offset)
163 const char *
const buf_va = (
char *)
phyframe_va(
f->buf_page);
164 const size_t begin = offset;
165 const size_t end = std::min(offset +
size, (
size_t)
f->buf_head_offset);
167 memcpy((
char *) buf, buf_va + begin, end - begin);
176 return f->item->store(
f, (
const char *) buf,
size, offset);
198 return f->buf_head_offset;
209 return f->item->mem.mmap(
f, vmap, offset);
216 if (offset >
f->buf_head_offset)
228 return f->item->mem.munmap(
f, vmap, unmapped);
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);
289 MOS_ASSERT_X(sysfs_dir || dir ==
sysfs_sb->root->inode,
"invalid sysfs entry, possibly a VFS bug");
310 MOS_ASSERT_X(sysfs_dir || dir ==
sysfs_sb->root->inode,
"invalid sysfs entry, possibly a VFS bug");
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);
371 for (
size_t i = 0; i < sysfs_dir->
num_items; i++)
414 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 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)
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)
static ssize_t sysfs_fops_write(const FsBaseFile *file, const void *buf, size_t size, off_t offset)
void sysfs_file_set_data(sysfs_file_t *file, void *data)
static const file_perm_t sysfs_dir_perm
static off_t sysfs_fops_seek(FsBaseFile *file, off_t offset, io_seek_whence_t whence)
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)
inode_t * sysfs_create_inode(file_type_t type, void *data)
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_read(const FsBaseFile *file, void *buf, size_t size, off_t offset)
static __nodiscard bool sysfs_file_ensure_ready(const FsBaseFile *file)
static PtrResult< dentry_t > sysfs_fsop_mount(filesystem_t *fs, const char *dev, const char *options)
bool sysfs_fops_mmap(FsBaseFile *file, vmap_t *vmap, off_t offset)
static void sysfs_iops_iterate_dir(dentry_t *dentry, vfs_listdir_state_t *state, dentry_iterator_op add_record)
bool sysfs_fops_munmap(FsBaseFile *file, vmap_t *vmap, bool *unmapped)
static bool sysfs_fops_open(inode_t *inode, FsBaseFile *file, bool created)
static superblock_t * sysfs_sb
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 void sysfs_fops_release(FsBaseFile *file)
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.