#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>
Go to the source code of this file.
|
VFS * | O2FS_Mount (Disk *root) |
|
| DEFINE_SLAB (VFS, &vfsSlab) |
|
| DEFINE_SLAB (VNode, &vnodeSlab) |
|
int | VFS_MountRoot (Disk *rootDisk) |
|
VNode * | VFS_Lookup (const char *path) |
|
int | VFS_Stat (const char *path, struct stat *sb) |
|
int | VFS_Open (VNode *fn) |
|
int | VFS_Close (VNode *fn) |
|
int | VFS_Read (VNode *fn, void *buf, uint64_t off, uint64_t len) |
|
int | VFS_Write (VNode *fn, void *buf, uint64_t off, uint64_t len) |
|
int | VFS_ReadDir (VNode *fn, void *buf, uint64_t len, uint64_t *off) |
|
◆ DEFINE_SLAB() [1/2]
DEFINE_SLAB |
( |
VFS |
, |
|
|
& |
vfsSlab |
|
) |
| |
◆ DEFINE_SLAB() [2/2]
DEFINE_SLAB |
( |
VNode |
, |
|
|
& |
vnodeSlab |
|
) |
| |
◆ O2FS_Mount()
Definition at line 42 of file o2fs.c.
43{
44 int status;
45 VFS *fs = VFS_Alloc();
48
50
51 if (!fs)
53
55 if (status < 0) {
56 Alert(o2fs,
"Disk cache read failed\n");
58 }
59
60
63 Alert(o2fs,
"Invalid file system\n");
66 }
69 Alert(o2fs,
"Unsupported file system version\n");
72 }
73
74
77
80
82 Alert(o2fs,
"Bitmap read failed\n");
83 for (i = 0; i < 16; i++)
87 }
88
90 }
91
92 DLOG(o2fs,
"File system mounted\n");
94
98
99
105
107 if (status < 0) {
108 Alert(o2fs,
"Mount failed");
111 }
112
113 return fs;
114}
int BufCache_Read(Disk *disk, uint64_t diskOffset, BufCacheEntry **entry)
void BufCache_Release(BufCacheEntry *entry)
#define DLOG(_module, _format,...)
#define Alert(_module, _format,...)
static VFSOp O2FSOperations
int O2FS_GetRoot(VFS *fs, VNode **dn)
#define O2FS_VERSION_MINOR
#define O2FS_VERSION_MAJOR
#define SPINLOCK_TYPE_NORMAL
void Spinlock_Init(Spinlock *lock, const char *name, uint64_t type)
int memcmp(const void *b1, const void *b2, size_t len)
◆ VFS_Close()
int VFS_Close |
( |
VNode * |
fn | ) |
|
VFS_Close –
Close a vnode.
- Parameters
-
- Returns
- Return status
Definition at line 162 of file vfs.c.
◆ VFS_Lookup()
VNode * VFS_Lookup |
( |
const char * |
path | ) |
|
VFS_Lookup –
Lookup a VNode by a path. This function recursively searches the directory heirarchy until the given path is found otherwise returns NULL if not found.
Definition at line 63 of file vfs.c.
64{
65 int status;
66 const char *start = path + 1;
67 const char *end = path + 1;
71 char curName[256];
72
73 if (path[0] != '/')
75
77 if (status < 0)
78 Panic(
"Failed to get root VNode\n");
79
80 while (1) {
81 while (*end != '\0' && *end != '/')
82 end++;
83
86
87 return curNode;
88 }
90
92 }
93
96
97 oldNode = curNode;
99 status = oldNode->
op->
lookup(oldNode, &curNode, curName);
100 if (status < 0) {
101
103 }
104
105
106
107 if (*end == '\0') {
108 Log(vfs,
"%s %lx\n", path, curNode);
109 return curNode;
110 }
111
112 start = end + 1;
113 end = end + 1;
114 }
115}
#define Log(_module, _format,...)
void * memcpy(void *dst, const void *src, size_t len)
int(* getroot)(VFS *fs, VNode **dn)
int(* lookup)(VNode *dn, VNode **fn, const char *name)
void Panic(const char *str)
◆ VFS_MountRoot()
int VFS_MountRoot |
( |
Disk * |
rootDisk | ) |
|
VFS_MountRoot –
Mount the root file system from a specific disk.
Definition at line 36 of file vfs.c.
37{
38 int status;
39
41
44
47 return -1;
48
50 if (status < 0)
51 Panic(
"Failed to get root VNode\n");
52
53 return 0;
54}
void Slab_Init(Slab *slab, const char *name, uintptr_t objsz, uintptr_t align)
VFS * O2FS_Mount(Disk *root)
◆ VFS_Open()
int VFS_Open |
( |
VNode * |
fn | ) |
|
VFS_Open –
Open a vnode for reading and writing.
- Parameters
-
- Returns
- Return status
Definition at line 147 of file vfs.c.
◆ VFS_Read()
VFS_Read –
Read from a vnode.
- Parameters
-
[in] | fn | VNode to read from. |
[in] | buf | Buffer to write the data to. |
[in] | off | File offset in bytes. |
[in] | len | Length to read in bytes. |
- Returns
- Return status
Definition at line 180 of file vfs.c.
181{
183}
int(* read)(VNode *fn, void *buf, uint64_t off, uint64_t len)
◆ VFS_ReadDir()
VFS_ReadDir –
Read a directory entry from a vnode.
- Parameters
-
[in] | fn | VNode to read from. |
[in] | buf | Buffer to write the data to. |
[in] | off | Directory offset in bytes. |
[in] | len | Length to read in bytes. |
- Returns
- Return status
Definition at line 216 of file vfs.c.
217{
219}
int(* readdir)(VNode *fn, void *buf, uint64_t len, uint64_t *off)
◆ VFS_Stat()
int VFS_Stat |
( |
const char * |
path, |
|
|
struct stat * |
sb |
|
) |
| |
VFS_Stat –
Return the struct stat that contains the file and directory information for a given VNode.
Definition at line 124 of file vfs.c.
125{
129
131
132
133
134 return 0;
135}
int(* stat)(VNode *fn, struct stat *sb)
VNode * VFS_Lookup(const char *path)
◆ VFS_Write()
VFS_Write –
Write from a vnode.
- Parameters
-
[in] | fn | VNode to write to. |
[in] | buf | Buffer to read the data from. |
[in] | off | File offset in bytes. |
[in] | len | Length to read in bytes. |
- Returns
- Return status
Definition at line 198 of file vfs.c.
199{
201}
int(* write)(VNode *fn, void *buf, uint64_t off, uint64_t len)
◆ rootFS
Definition at line 21 of file vfs.c.
◆ rootNode
Definition at line 22 of file vfs.c.
◆ vfsLock
Definition at line 20 of file vfs.c.
◆ vfsSlab
Definition at line 24 of file vfs.c.
◆ vnodeSlab
Definition at line 25 of file vfs.c.