153 return sock->family->poll(
sock, revents);
227 sock->address[
sizeof(
sock->address) - 1] =
'\0';
245 if (
sscanf(argv[1],
"%llu", &backlog) != 1)
306 sock->address[
sizeof(
sock->address) - 1] =
'\0';
327 {.name =
"accept", .fileOps = &
acceptOps},
328 {.name =
"ctl", .fileOps = &
ctlOps},
774 if (superblock ==
NULL)
796 superblock->
root = dentry;
797 return superblock->
root;
809 panic(
NULL,
"Failed to register netfs filesystem");
#define MAX_PATH
Maximum length of filepaths.
#define assert(expression)
#define CTL_STANDARD_OPS_DEFINE(name,...)
Helper macro to define a standard ctl file operations structure.
void dentry_make_positive(dentry_t *dentry, inode_t *inode)
Make a dentry positive by associating it with an inode.
dentry_t * dentry_new(superblock_t *superblock, dentry_t *parent, const char *name)
Create a new dentry.
bool dentry_iterate_dots(dentry_t *dentry, dir_ctx_t *ctx)
Helper function to iterate over the special entries "." and "..".
uint64_t filesystem_register(filesystem_t *fs)
Registers a filesystem.
inode_t * inode_new(superblock_t *superblock, ino_t number, itype_t type, const inode_ops_t *ops, const file_ops_t *fileOps)
Create a new inode.
ino_t ino_gen(ino_t parentNumber, const char *name)
Helper to generate a consistent inode number for an entry in a directory.
#define NETFS_NAME
The name of the networking filesystem.
#define NETFS_BACKLOG_DEFAULT
The default backlog size for listening sockets.
socket_type_t
Socket types.
uint64_t netfs_family_register(netfs_family_t *family)
Register a network family.
void netfs_init(void)
Initialize the networking filesystem.
void netfs_family_unregister(netfs_family_t *family)
Unregister a network family.
@ SOCKET_RDM
A reliable datagram layer that does not guarantee ordering.
@ SOCKET_STREAM
A sequenced, reliable, two-way connection-based byte stream.
@ SOCKET_SEQPACKET
A sequenced, reliable, two-way connection-based packet stream.
@ SOCKET_DGRAM
A connectionless, unreliable datagram service.
@ SOCKET_RAW
Provides raw network protocol access.
superblock_t * superblock_new(filesystem_t *fs, block_device_t *device, const superblock_ops_t *ops, const dentry_ops_t *dentryOps)
Create a new superblock.
NORETURN void panic(const interrupt_frame_t *frame, const char *format,...)
Panic the kernel, printing a message and halting.
namespace_t * process_get_ns(process_t *process)
Gets the namespace of a process.
process_t * sched_process(void)
Retrieves the process of the currently running thread.
void mutex_init(mutex_t *mtx)
Initializes a mutex.
#define MUTEX_SCOPE(mutex)
Acquires a mutex for the reminder of the current scope.
void rwmutex_write_acquire(rwmutex_t *mtx)
Acquires a rwmutex for writing, blocking until it is available.
void rwmutex_init(rwmutex_t *mtx)
Initializes a rwmutex.
#define RWMUTEX_READ_SCOPE(mutex)
Acquires a rwmutex for reading for the reminder of the current scope.
#define RWMUTEX_CREATE(name)
Create a rwmutex initializer.
void rwmutex_deinit(rwmutex_t *mtx)
Deinitializes a rwmutex.
void rwmutex_write_release(rwmutex_t *mtx)
Releases a rwmutex from writing.
static void weak_ptr_set(weak_ptr_t *wp, ref_t *ref, void(*callback)(void *), void *arg)
Set a weak pointer.
#define UNREF_DEFER(ptr)
RAII-style cleanup for scoped references.
static void * weak_ptr_get(weak_ptr_t *wp)
Upgrade a weak pointer to a strong pointer.
#define REF(ptr)
Increment reference count.
static void ref_init(ref_t *ref, void *callback)
Initialize a reference counter.
#define UNREF(ptr)
Decrement reference count.
#define BUFFER_READ(buffer, count, offset, src, size)
Helper macros for implementing file operations dealing with simple buffers.
#define EINVAL
Invalid argument.
#define ENOSYS
Function not implemented.
#define ENOMEM
Out of memory.
#define errno
Error number variable.
#define ENOTCONN
Transport endpoint is not connected.
#define ARRAY_SIZE(x)
Get the number of elements in a static array.
#define UNUSED(x)
Mark a variable as unused.
poll_events_t
Poll events type.
@ INODE_DIR
Is a directory.
#define LIST_FOR_EACH(elem, list, member)
Iterates over a list.
static uint64_t list_length(list_t *list)
Gets the length of the list.
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 void list_remove(list_t *list, list_entry_t *entry)
Removes a list entry from its current list.
static bool list_is_empty(list_t *list)
Checks if a list is empty.
static void list_entry_init(list_entry_t *entry)
Initializes a list entry.
static bool list_contains_entry(list_t *list, list_entry_t *entry)
Check if an entry belongs to a specific list.
static void list_init(list_t *list)
Initializes a list.
#define NULL
Pointer error value.
#define ERR
Integer error value.
EFI_PHYSICAL_ADDRESS buffer
static void netfs_socket_cleanup(inode_t *inode)
static file_ops_t acceptOps
static dentry_ops_t familyDentryOps
static uint64_t netfs_ctl_listen(file_t *file, uint64_t argc, const char **argv)
static void socket_weak_ptr_callback(void *arg)
static netfs_family_file_t familyFiles[]
static uint64_t netfs_ctl_bind(file_t *file, uint64_t argc, const char **argv)
static uint64_t netfs_ctl_connect(file_t *file, uint64_t argc, const char **argv)
static size_t netfs_addrs_read(file_t *file, void *buffer, size_t count, size_t *offset)
static rwmutex_t familiesMutex
static dentry_ops_t socketDentryOps
static uint64_t netfs_factory_open(file_t *file)
static socket_file_t socketFiles[]
static wait_queue_t * netfs_data_poll(file_t *file, poll_events_t *revents)
static inode_ops_t socketInodeOps
static uint64_t netfs_socket_iterate(dentry_t *dentry, dir_ctx_t *ctx)
static socket_t * socket_new(netfs_family_t *family, socket_type_t type)
static size_t netfs_data_read(file_t *file, void *buf, size_t count, size_t *offset)
static uint64_t netfs_data_open(file_t *file)
static inode_ops_t familyFileInodeOps
static uint64_t netfs_iterate(dentry_t *dentry, dir_ctx_t *ctx)
static file_ops_t dataOps
static size_t netfs_data_write(file_t *file, const void *buf, size_t count, size_t *offset)
static dentry_t * netfs_mount(filesystem_t *fs, block_device_t *device, void *private)
static uint64_t netfs_family_lookup(inode_t *dir, dentry_t *dentry)
static filesystem_t netfs
static void netfs_file_cleanup(inode_t *inode)
static size_t netfs_factory_read(file_t *file, void *buffer, size_t count, size_t *offset)
static uint64_t netfs_accept_open(file_t *file)
static inode_ops_t familyInodeOps
static dentry_ops_t netDentryOps
static uint64_t netfs_lookup(inode_t *dir, dentry_t *dentry)
static file_ops_t addrsFileOps
static uint64_t netfs_family_iterate(dentry_t *dentry, dir_ctx_t *ctx)
static uint64_t netfs_socket_lookup(inode_t *dir, dentry_t *dentry)
static void socket_free(socket_t *socket)
static file_ops_t factoryFileOps
static inode_ops_t netInodeOps
static void netfs_data_close(file_t *file)
static void netfs_factory_close(file_t *file)
#define atomic_fetch_add_explicit(object, operand, order)
#define ATOMIC_VAR_INIT(value)
_PUBLIC int sscanf(const char *_RESTRICT s, const char *_RESTRICT format,...)
_PUBLIC int snprintf(char *_RESTRICT s, size_t n, const char *_RESTRICT format,...)
_PUBLIC void * malloc(size_t size)
_PUBLIC void free(void *ptr)
_PUBLIC char * strncpy(char *_RESTRICT s1, const char *_RESTRICT s2, size_t n)
_PUBLIC size_t strlen(const char *s)
_PUBLIC int strcmp(const char *s1, const char *s2)
Dentry operations structure.
uint64_t(* iterate)(dentry_t *dentry, dir_ctx_t *ctx)
Iterate over the entries in a directory dentry.
Directory entry structure.
inode_t * inode
Will be NULL if the dentry is negative, once positive it will never be modified.
char name[MAX_NAME]
Constant after creation.
superblock_t * superblock
Directory context used to iterate over directory entries.
size_t index
An index that the filesystem can use for its own purposes.
bool(* emit)(dir_ctx_t *ctx, const char *name, ino_t number, itype_t type)
Emit function.
size_t pos
The current position in the directory, can be used to skip entries.
File operations structure.
size_t(* read)(file_t *file, void *buffer, size_t count, size_t *offset)
uint64_t(* open)(file_t *file)
Filesystem structure, represents a filesystem type, e.g. fat32, tmpfs, devfs, etc.
Inode operations structure.
void(* cleanup)(inode_t *inode)
Cleanup function called when the inode is being freed.
uint64_t(* lookup)(inode_t *dir, dentry_t *target)
Look up a dentry in a directory inode.
superblock_t * superblock
netfs_family_file_t * fileInfo
uint64_t(* init)(socket_t *sock)
Initialize a socket.
void(* deinit)(socket_t *sock)
Deinitialize a socket.
Read-Write Mutex structure.
dentry_t * root
Root dentry of the filesystem, should not take a reference.
The primitive that threads block on.