58 if (superblock ==
NULL)
60 panic(
NULL,
"Failed to create sysfs superblock");
67 panic(
NULL,
"Failed to create sysfs root vnode");
74 panic(
NULL,
"Failed to create sysfs root dentry");
78 superblock->
root = dentry;
87 panic(
NULL,
"Failed to get process namespace");
97 panic(
NULL,
"Failed to init pathname for /sys");
111 LOG_INFO(
"sysfs mounted to '/sys'\n");
#define assert(expression)
path_t cwd_get(cwd_t *cwd, namespace_t *ns)
Get the current working directory.
dentry_t * dentry_new(superblock_t *superblock, dentry_t *parent, const char *name)
Create a new dentry.
uint64_t dentry_generic_iterate(dentry_t *dentry, dir_ctx_t *ctx)
Helper function for a basic iterate.
void dentry_make_positive(dentry_t *dentry, vnode_t *vnode)
Make a dentry positive by associating it with an vnode.
uint64_t filesystem_register(filesystem_t *fs)
Registers a filesystem.
mount_t * namespace_mount(namespace_t *ns, path_t *target, filesystem_t *fs, const char *options, mode_t mode, void *data)
Mount a filesystem in a namespace.
#define PATH_DEFER(path)
Defer path put.
uint64_t path_walk(path_t *path, const pathname_t *pathname, namespace_t *ns)
Walk a pathname to a path.
uint64_t pathname_init(pathname_t *pathname, const char *string)
Initialize a pathname.
superblock_t * superblock_new(filesystem_t *fs, const superblock_ops_t *ops, const dentry_ops_t *dentryOps)
Create a new superblock.
dentry_t * sysfs_symlink_new(dentry_t *parent, const char *name, const vnode_ops_t *vnodeOps, void *data)
Create a new symbolic link inside a mounted sysfs instance.
uint64_t sysfs_files_new(list_t *out, dentry_t *parent, const sysfs_file_desc_t *descs)
Create multiple files in a sysfs directory.
#define SYSFS_NAME
The name of the system filesystem.
void sysfs_files_free(list_t *files)
Free all files in a list created by sysfs_files_new().
void sysfs_init(void)
Initializes the sysfs and mount an instance at /sys.
dentry_t * sysfs_file_new(dentry_t *parent, const char *name, const vnode_ops_t *vnodeOps, const file_ops_t *fileOps, void *data)
Create a new file inside a mounted sysfs instance.
dentry_t * sysfs_dir_new(dentry_t *parent, const char *name, const vnode_ops_t *vnodeOps, void *data)
Create a new directory inside a mounted sysfs instance.
vnode_t * vnode_new(superblock_t *superblock, vtype_t type, const vnode_ops_t *ops, const file_ops_t *fileOps)
Create a new vnode.
NORETURN void panic(const interrupt_frame_t *frame, const char *format,...)
Panic the kernel, printing a message and halting.
#define LOG_INFO(format,...)
static process_t * process_current(void)
Retrieves the process of the currently running thread.
namespace_t * process_get_ns(process_t *process)
Gets the namespace of a process.
#define UNREF_DEFER(ptr)
RAII-style cleanup for scoped references.
#define REF(ptr)
Increment reference count.
#define UNREF(ptr)
Decrement reference count.
#define EINVAL
Invalid argument.
#define EXDEV
Cross-device link.
#define errno
Error number variable.
#define UNUSED(x)
Mark a variable as unused.
@ VSYMLINK
Is a symbolic link.
static void list_push_back(list_t *list, list_entry_t *entry)
Pushes an entry to the end of the list.
#define LIST_CREATE(name)
Creates a list initializer.
static bool list_is_empty(list_t *list)
Checks if a list is empty.
static list_entry_t * list_pop_back(list_t *list)
Pops the last entry from the list.
static list_entry_t * list_pop_front(list_t *list)
Pops the first entry from the list.
#define NULL
Pointer error value.
#define ERR
Integer error value.
#define CONTAINER_OF_SAFE(ptr, type, member)
Safe container of macro.
Dentry operations structure.
uint64_t(* iterate)(dentry_t *dentry, dir_ctx_t *ctx)
Iterate over the entries in a directory dentry.
Directory entry structure.
char name[MAX_NAME]
The name of the dentry, immutable after creation.
list_entry_t otherEntry
Made available for use by any other subsystems for convenience.
superblock_t * superblock
File operations structure.
Filesystem structure, represents a filesystem type, e.g. fat32, tmpfs, devfs, etc.
dentry_t * root
Root dentry of the filesystem, should not take a reference.
Descriptor for batch file creation.
const char * name
Name of the file, NULL marks end of array.
vnode operations structure.
void * data
Filesystem defined data.
static dentry_ops_t dentryOps
static filesystem_t sysfs
static dentry_t * sysfs_mount(filesystem_t *fs, const char *options, void *data)
static vnode_ops_t vnodeOps
static file_ops_t fileOps