CS350 COS
COS
Loading...
Searching...
No Matches
vfsuio.c File Reference
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <sys/kassert.h>
#include <sys/kdebug.h>
#include <sys/spinlock.h>
#include <sys/disk.h>
#include <sys/vfs.h>
#include <sys/handle.h>
#include <sys/vfsuio.h>
Include dependency graph for vfsuio.c:

Go to the source code of this file.

Functions

static int VFSUIO_Read (Handle *handle, void *buf, uint64_t len, uint64_t off)
 
static int VFSUIO_Write (Handle *handle, void *buf, uint64_t len, uint64_t off)
 
static int VFSUIO_Flush (Handle *handle)
 
static int VFSUIO_Close (Handle *handle)
 
int VFSUIO_Open (const char *path, Handle **handle)
 

Function Documentation

◆ VFSUIO_Close()

static int VFSUIO_Close ( Handle handle)
static

Definition at line 43 of file vfsuio.c.

44{
45 int status;
46
47 ASSERT(handle->type == HANDLE_TYPE_FILE);
48
49 status = VFS_Close(handle->vnode);
50 Handle_Free(handle);
51
52 return status;
53}
#define HANDLE_TYPE_FILE
Definition: handle.h:12
#define ASSERT(_x)
Definition: kassert.h:8
uint64_t type
Definition: handle.h:19
VNode * vnode
Definition: handle.h:21
int VFS_Close(VNode *fn)
Definition: vfs.c:162
Here is the call graph for this function:
Here is the caller graph for this function:

◆ VFSUIO_Flush()

static int VFSUIO_Flush ( Handle handle)
static

Definition at line 36 of file vfsuio.c.

37{
38 ASSERT(handle->type == HANDLE_TYPE_FILE);
39 return -EINVAL;
40}
#define EINVAL
Definition: errno.h:12
Here is the caller graph for this function:

◆ VFSUIO_Open()

int VFSUIO_Open ( const char *  path,
Handle **  handle 
)

Definition at line 56 of file vfsuio.c.

57{
58 int status;
59
60 Handle *hdl = Handle_Alloc();
61 if (!hdl) {
62 return -ENOMEM;
63 }
64
65 VNode *vn = VFS_Lookup(path);
66 if (!vn) {
67 Handle_Free(hdl);
68 return -ENOENT;
69 }
70
71 status = VFS_Open(vn);
72 if (status != 0) {
73 // XXX: Release VNode
74 Handle_Free(hdl);
75 return status;
76 }
77
78 hdl->vnode = vn;
80 hdl->read = VFSUIO_Read;
81 hdl->write = VFSUIO_Write;
82 hdl->flush = VFSUIO_Flush;
83 hdl->close = VFSUIO_Close;
84
85 *handle = hdl;
86
87 return 0;
88}
#define ENOENT
Definition: errno.h:15
#define ENOMEM
Definition: errno.h:14
Definition: handle.h:17
int(* close)(Handle *)
Definition: handle.h:26
int(* write)(Handle *, void *, uint64_t, uint64_t)
Definition: handle.h:24
int(* read)(Handle *, void *, uint64_t, uint64_t)
Definition: handle.h:23
int(* flush)(Handle *)
Definition: handle.h:25
VNode * VFS_Lookup(const char *path)
Definition: vfs.c:63
int VFS_Open(VNode *fn)
Definition: vfs.c:147
Definition: vfs.h:24
static int VFSUIO_Write(Handle *handle, void *buf, uint64_t len, uint64_t off)
Definition: vfsuio.c:26
static int VFSUIO_Read(Handle *handle, void *buf, uint64_t len, uint64_t off)
Definition: vfsuio.c:16
static int VFSUIO_Flush(Handle *handle)
Definition: vfsuio.c:36
static int VFSUIO_Close(Handle *handle)
Definition: vfsuio.c:43
Here is the call graph for this function:
Here is the caller graph for this function:

◆ VFSUIO_Read()

static int VFSUIO_Read ( Handle handle,
void *  buf,
uint64_t  len,
uint64_t  off 
)
static

Definition at line 16 of file vfsuio.c.

17{
18 ASSERT(handle->type == HANDLE_TYPE_FILE);
19
20 // XXX: Need to pin memory
21
22 return VFS_Read(handle->vnode, buf, len, off);
23}
static char buf[4096]
Definition: ethdump.c:10
uint64_t len
Definition: multiboot.h:2
int VFS_Read(VNode *fn, void *buf, uint64_t off, uint64_t len)
Definition: vfs.c:180
Here is the call graph for this function:
Here is the caller graph for this function:

◆ VFSUIO_Write()

static int VFSUIO_Write ( Handle handle,
void *  buf,
uint64_t  len,
uint64_t  off 
)
static

Definition at line 26 of file vfsuio.c.

27{
28 ASSERT(handle->type == HANDLE_TYPE_FILE);
29
30 // XXX: Need to pin memory
31
32 return VFS_Write(handle->vnode, buf, len, off);
33}
int VFS_Write(VNode *fn, void *buf, uint64_t off, uint64_t len)
Definition: vfs.c:198
Here is the call graph for this function:
Here is the caller graph for this function: