PatchworkOS  10941b4
A non-POSIX operating system.
Loading...
Searching...
No Matches
netfs.c File Reference
#include <kernel/fs/ctl.h>
#include <kernel/fs/dentry.h>
#include <kernel/fs/devfs.h>
#include <kernel/fs/filesystem.h>
#include <kernel/fs/mount.h>
#include <kernel/fs/netfs.h>
#include <kernel/fs/path.h>
#include <kernel/fs/vfs.h>
#include <kernel/log/log.h>
#include <kernel/log/panic.h>
#include <kernel/module/module.h>
#include <kernel/proc/process.h>
#include <kernel/sched/sched.h>
#include <kernel/sync/rwmutex.h>
#include <sys/io.h>
#include <sys/list.h>
Include dependency graph for netfs.c:

Go to the source code of this file.

Data Structures

struct  socket_file_t
 
struct  netfs_family_file_t
 
struct  netfs_family_file_ctx_t
 

Functions

static void socket_free (socket_t *socket)
 
static socket_tsocket_new (netfs_family_t *family, socket_type_t type)
 
static uint64_t netfs_data_open (file_t *file)
 
static void netfs_data_close (file_t *file)
 
static size_t netfs_data_read (file_t *file, void *buf, size_t count, size_t *offset)
 
static size_t netfs_data_write (file_t *file, const void *buf, size_t count, size_t *offset)
 
static wait_queue_tnetfs_data_poll (file_t *file, poll_events_t *revents)
 
static uint64_t netfs_accept_open (file_t *file)
 
static uint64_t netfs_ctl_bind (file_t *file, uint64_t argc, const char **argv)
 
static uint64_t netfs_ctl_listen (file_t *file, uint64_t argc, const char **argv)
 
static uint64_t netfs_ctl_connect (file_t *file, uint64_t argc, const char **argv)
 
 CTL_STANDARD_OPS_DEFINE (ctlOps, { {"bind", netfs_ctl_bind, 2, 2}, {"listen", netfs_ctl_listen, 1, 2}, {"connect", netfs_ctl_connect, 2, 2}, {0}, })
 
static uint64_t netfs_socket_lookup (inode_t *dir, dentry_t *dentry)
 
static void netfs_socket_cleanup (inode_t *inode)
 
static uint64_t netfs_socket_iterate (dentry_t *dentry, dir_ctx_t *ctx)
 
static void socket_weak_ptr_callback (void *arg)
 
static uint64_t netfs_factory_open (file_t *file)
 
static void netfs_factory_close (file_t *file)
 
static size_t netfs_factory_read (file_t *file, void *buffer, size_t count, size_t *offset)
 
static size_t netfs_addrs_read (file_t *file, void *buffer, size_t count, size_t *offset)
 
static void netfs_file_cleanup (inode_t *inode)
 
static uint64_t netfs_family_lookup (inode_t *dir, dentry_t *dentry)
 
static uint64_t netfs_family_iterate (dentry_t *dentry, dir_ctx_t *ctx)
 
static uint64_t netfs_lookup (inode_t *dir, dentry_t *dentry)
 
static uint64_t netfs_iterate (dentry_t *dentry, dir_ctx_t *ctx)
 
static dentry_tnetfs_mount (filesystem_t *fs, block_device_t *device, void *private)
 
void netfs_init (void)
 Initialize the networking filesystem.
 
uint64_t netfs_family_register (netfs_family_t *family)
 Register a network family.
 
void netfs_family_unregister (netfs_family_t *family)
 Unregister a network family.
 

Variables

static list_t families = LIST_CREATE(families)
 
static rwmutex_t familiesMutex = RWMUTEX_CREATE(familiesMutex)
 
static file_ops_t dataOps
 
static file_ops_t acceptOps
 
static socket_file_t socketFiles []
 
static inode_ops_t socketInodeOps
 
static dentry_ops_t socketDentryOps
 
static file_ops_t factoryFileOps
 
static file_ops_t addrsFileOps
 
static netfs_family_file_t familyFiles []
 
static inode_ops_t familyFileInodeOps
 
static inode_ops_t familyInodeOps
 
static dentry_ops_t familyDentryOps
 
static inode_ops_t netInodeOps
 
static dentry_ops_t netDentryOps
 
static filesystem_t netfs
 

Function Documentation

◆ socket_free()

static void socket_free ( socket_t socket)
static

Definition at line 22 of file netfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ socket_new()

static socket_t * socket_new ( netfs_family_t family,
socket_type_t  type 
)
static

Definition at line 40 of file netfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ netfs_data_open()

static uint64_t netfs_data_open ( file_t file)
static

Definition at line 76 of file netfs.c.

◆ netfs_data_close()

static void netfs_data_close ( file_t file)
static

Definition at line 85 of file netfs.c.

◆ netfs_data_read()

static size_t netfs_data_read ( file_t file,
void buf,
size_t  count,
size_t offset 
)
static

Definition at line 96 of file netfs.c.

◆ netfs_data_write()

static size_t netfs_data_write ( file_t file,
const void buf,
size_t  count,
size_t offset 
)
static

Definition at line 118 of file netfs.c.

◆ netfs_data_poll()

static wait_queue_t * netfs_data_poll ( file_t file,
poll_events_t revents 
)
static

Definition at line 140 of file netfs.c.

◆ netfs_accept_open()

static uint64_t netfs_accept_open ( file_t file)
static

Definition at line 164 of file netfs.c.

Here is the call graph for this function:

◆ netfs_ctl_bind()

static uint64_t netfs_ctl_bind ( file_t file,
uint64_t  argc,
const char **  argv 
)
static

Definition at line 205 of file netfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ netfs_ctl_listen()

static uint64_t netfs_ctl_listen ( file_t file,
uint64_t  argc,
const char **  argv 
)
static

Definition at line 238 of file netfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ netfs_ctl_connect()

static uint64_t netfs_ctl_connect ( file_t file,
uint64_t  argc,
const char **  argv 
)
static

Definition at line 284 of file netfs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CTL_STANDARD_OPS_DEFINE()

CTL_STANDARD_OPS_DEFINE ( ctlOps  ,
{ {"bind", netfs_ctl_bind, 2, 2}, {"listen", netfs_ctl_listen, 1, 2}, {"connect", netfs_ctl_connect, 2, 2}, {0}, }   
)
Here is the call graph for this function:

◆ netfs_socket_lookup()

static uint64_t netfs_socket_lookup ( inode_t dir,
dentry_t dentry 
)
static

Definition at line 331 of file netfs.c.

Here is the call graph for this function:

◆ netfs_socket_cleanup()

static void netfs_socket_cleanup ( inode_t inode)
static

Definition at line 356 of file netfs.c.

◆ netfs_socket_iterate()

static uint64_t netfs_socket_iterate ( dentry_t dentry,
dir_ctx_t ctx 
)
static

Definition at line 367 of file netfs.c.

Here is the call graph for this function:

◆ socket_weak_ptr_callback()

static void socket_weak_ptr_callback ( void arg)
static

Definition at line 412 of file netfs.c.

Here is the caller graph for this function:

◆ netfs_factory_open()

static uint64_t netfs_factory_open ( file_t file)
static

Definition at line 418 of file netfs.c.

Here is the call graph for this function:

◆ netfs_factory_close()

static void netfs_factory_close ( file_t file)
static

Definition at line 449 of file netfs.c.

◆ netfs_factory_read()

static size_t netfs_factory_read ( file_t file,
void buffer,
size_t  count,
size_t offset 
)
static

Definition at line 460 of file netfs.c.

Here is the call graph for this function:

◆ netfs_addrs_read()

static size_t netfs_addrs_read ( file_t file,
void buffer,
size_t  count,
size_t offset 
)
static

Definition at line 477 of file netfs.c.

Here is the call graph for this function:

◆ netfs_file_cleanup()

static void netfs_file_cleanup ( inode_t inode)
static

Definition at line 531 of file netfs.c.

Here is the call graph for this function:

◆ netfs_family_lookup()

static uint64_t netfs_family_lookup ( inode_t dir,
dentry_t dentry 
)
static

Definition at line 547 of file netfs.c.

Here is the call graph for this function:

◆ netfs_family_iterate()

static uint64_t netfs_family_iterate ( dentry_t dentry,
dir_ctx_t ctx 
)
static

Definition at line 631 of file netfs.c.

Here is the call graph for this function:

◆ netfs_lookup()

static uint64_t netfs_lookup ( inode_t dir,
dentry_t dentry 
)
static

Definition at line 705 of file netfs.c.

Here is the call graph for this function:

◆ netfs_iterate()

static uint64_t netfs_iterate ( dentry_t dentry,
dir_ctx_t ctx 
)
static

Definition at line 735 of file netfs.c.

Here is the call graph for this function:

◆ netfs_mount()

static dentry_t * netfs_mount ( filesystem_t fs,
block_device_t device,
void private 
)
static

Definition at line 769 of file netfs.c.

Here is the call graph for this function:

Variable Documentation

◆ families

list_t families = LIST_CREATE(families)
static

Definition at line 19 of file netfs.c.

◆ familiesMutex

rwmutex_t familiesMutex = RWMUTEX_CREATE(familiesMutex)
static

Definition at line 20 of file netfs.c.

◆ dataOps

file_ops_t dataOps
static
Initial value:
= {
.open = netfs_data_open,
.close = netfs_data_close,
.read = netfs_data_read,
.write = netfs_data_write,
.poll = netfs_data_poll,
}
static wait_queue_t * netfs_data_poll(file_t *file, poll_events_t *revents)
Definition netfs.c:140
static size_t netfs_data_read(file_t *file, void *buf, size_t count, size_t *offset)
Definition netfs.c:96
static uint64_t netfs_data_open(file_t *file)
Definition netfs.c:76
static size_t netfs_data_write(file_t *file, const void *buf, size_t count, size_t *offset)
Definition netfs.c:118
static void netfs_data_close(file_t *file)
Definition netfs.c:85

Definition at line 156 of file netfs.c.

◆ acceptOps

file_ops_t acceptOps
static
Initial value:
= {
}
static uint64_t netfs_accept_open(file_t *file)
Definition netfs.c:164

Definition at line 201 of file netfs.c.

◆ socketFiles

socket_file_t socketFiles[]
static
Initial value:
= {
{.name = "data", .fileOps = &dataOps},
{.name = "accept", .fileOps = &acceptOps},
{.name = "ctl", .fileOps = &ctlOps},
}
int64_t y
Definition main.c:153
static file_ops_t acceptOps
Definition netfs.c:201
static file_ops_t dataOps
Definition netfs.c:156

Definition at line 325 of file netfs.c.

◆ socketInodeOps

inode_ops_t socketInodeOps
static
Initial value:
= {
}
static void netfs_socket_cleanup(inode_t *inode)
Definition netfs.c:356
static uint64_t netfs_socket_lookup(inode_t *dir, dentry_t *dentry)
Definition netfs.c:331

Definition at line 390 of file netfs.c.

◆ socketDentryOps

dentry_ops_t socketDentryOps
static
Initial value:
= {
}
static uint64_t netfs_socket_iterate(dentry_t *dentry, dir_ctx_t *ctx)
Definition netfs.c:367

Definition at line 395 of file netfs.c.

◆ factoryFileOps

file_ops_t factoryFileOps
static
Initial value:
= {
}
static uint64_t netfs_factory_open(file_t *file)
Definition netfs.c:418
static size_t netfs_factory_read(file_t *file, void *buffer, size_t count, size_t *offset)
Definition netfs.c:460
static void netfs_factory_close(file_t *file)
Definition netfs.c:449

Definition at line 471 of file netfs.c.

◆ addrsFileOps

file_ops_t addrsFileOps
static
Initial value:
= {
}
static size_t netfs_addrs_read(file_t *file, void *buffer, size_t count, size_t *offset)
Definition netfs.c:477

Definition at line 518 of file netfs.c.

◆ familyFiles

netfs_family_file_t familyFiles[]
static
Initial value:
= {
{.name = "stream", .type = SOCKET_STREAM, .fileOps = &factoryFileOps},
{.name = "dgram", .type = SOCKET_DGRAM, .fileOps = &factoryFileOps},
{.name = "seqpacket", .type = SOCKET_SEQPACKET, .fileOps = &factoryFileOps},
{.name = "raw", .type = SOCKET_RAW, .fileOps = &factoryFileOps},
{.name = "rdm", .type = SOCKET_RDM, .fileOps = &factoryFileOps},
{.name = "addrs", .type = 0, .fileOps = &addrsFileOps},
}
@ SOCKET_RDM
A reliable datagram layer that does not guarantee ordering.
Definition netfs.h:102
@ SOCKET_STREAM
A sequenced, reliable, two-way connection-based byte stream.
Definition netfs.h:98
@ SOCKET_SEQPACKET
A sequenced, reliable, two-way connection-based packet stream.
Definition netfs.h:100
@ SOCKET_DGRAM
A connectionless, unreliable datagram service.
Definition netfs.h:99
@ SOCKET_RAW
Provides raw network protocol access.
Definition netfs.h:101
static file_ops_t addrsFileOps
Definition netfs.c:518
static file_ops_t factoryFileOps
Definition netfs.c:471

Definition at line 522 of file netfs.c.

◆ familyFileInodeOps

inode_ops_t familyFileInodeOps
static
Initial value:
= {
.cleanup = netfs_file_cleanup,
}
static void netfs_file_cleanup(inode_t *inode)
Definition netfs.c:531

Definition at line 543 of file netfs.c.

◆ familyInodeOps

inode_ops_t familyInodeOps
static
Initial value:
= {
}
static uint64_t netfs_family_lookup(inode_t *dir, dentry_t *dentry)
Definition netfs.c:547

Definition at line 697 of file netfs.c.

◆ familyDentryOps

dentry_ops_t familyDentryOps
static
Initial value:
= {
}
static uint64_t netfs_family_iterate(dentry_t *dentry, dir_ctx_t *ctx)
Definition netfs.c:631

Definition at line 701 of file netfs.c.

◆ netInodeOps

inode_ops_t netInodeOps
static
Initial value:
= {
.lookup = netfs_lookup,
}
static uint64_t netfs_lookup(inode_t *dir, dentry_t *dentry)
Definition netfs.c:705

Definition at line 761 of file netfs.c.

◆ netDentryOps

dentry_ops_t netDentryOps
static
Initial value:
= {
.iterate = netfs_iterate,
}
static uint64_t netfs_iterate(dentry_t *dentry, dir_ctx_t *ctx)
Definition netfs.c:735

Definition at line 765 of file netfs.c.

◆ netfs

filesystem_t netfs
static
Initial value:
= {
.name = NETFS_NAME,
.mount = netfs_mount,
}
#define NETFS_NAME
The name of the networking filesystem.
Definition netfs.h:85
static dentry_t * netfs_mount(filesystem_t *fs, block_device_t *device, void *private)
Definition netfs.c:769

Definition at line 800 of file netfs.c.