Add ext2 VFS implementation
diff --git a/include/kernel/dri/fs/ext2/ext2.h b/include/kernel/dri/fs/ext2/ext2.h
index 5b587c9..9b6d5ba 100644
--- a/include/kernel/dri/fs/ext2/ext2.h
+++ b/include/kernel/dri/fs/ext2/ext2.h
@@ -264,6 +264,11 @@
EXT2_FT_SYMLINK,
};
+inline uint ext2_block_size(struct ext2_superblock *sb)
+{
+ return 1024 << sb->block_size_shift;
+}
+
/// Read a file system block (0-indexed), if necessary multiple disk
/// blocks will be read automatically
void ext2_read_block(struct ext2_superblock *sb, void *buffer,
@@ -300,9 +305,19 @@
struct ext2_inode *inode);
/// Load a block group descriptor for a certain block group
-struct ext2_block_group_descriptor ext2_load_block_group_descriptor(
+struct ext2_block_group_descriptor ext2_load_bgd(
struct ext2_superblock *sb, uint block_group);
+/// Write a block group descriptor for a certain block group
+void ext2_write_bgd(struct ext2_superblock *sb, uint block_group,
+ struct ext2_block_group_descriptor *d);
+
+/// Load or write a BGD
+void ext2_load_or_write_bgd(struct ext2_superblock *sb,
+ uint block_group,
+ struct ext2_block_group_descriptor *d,
+ bool set);
+
/// List the contents of a directory dir. Calls `cb` for each item. If
/// `dir` is not a directory, returns false. Otherwise returns true.
/// if cb returns true, ls will continue. Otherwise it will stop.
@@ -324,7 +339,9 @@
bool ext2_write_inode_block(struct ext2_superblock *sb, struct ext2_inode *dir,
void *buffer, uint block);
-ssize_t ext2_read_inode(struct ext2_superblock *sb, struct ext2_inode *inode, void *buffer, ssize_t size);
+ssize_t ext2_read_inode(struct ext2_superblock *sb,
+ struct ext2_inode *inode, void *buffer,
+ ssize_t size);
/**
* @brief Set a block in a bitmap
diff --git a/include/kernel/dri/fs/ext2/ext2_vfs.h b/include/kernel/dri/fs/ext2/ext2_vfs.h
new file mode 100644
index 0000000..856e9e2
--- /dev/null
+++ b/include/kernel/dri/fs/ext2/ext2_vfs.h
@@ -0,0 +1,10 @@
+#pragma once
+
+#include "ext2.h"
+#include <vfs.h>
+
+// VFS specific EXT2 functions
+
+/// ext2 inode -> vfs node
+struct fs_node *ext2_inode2vfs(struct ext2_superblock *sb, uint inode,
+ char *name, uint name_len);
diff --git a/include/kernel/vfs.h b/include/kernel/vfs.h
index e7cf8d9..d9f36a6 100644
--- a/include/kernel/vfs.h
+++ b/include/kernel/vfs.h
@@ -4,8 +4,12 @@
struct fs_vtable;
+#define FS_MAX_NAME_LEN 128
+
struct fs_node
{
+ /** length of file name */
+ uint name_len;
/** file name */
char name[128];
/** identifier */
@@ -21,7 +25,11 @@
/** size in bytes */
size_t size;
/** reserved for driver */
- uint dri_res;
+ union
+ {
+ uint dri_res_i;
+ void *dri_res_p;
+ };
struct fs_vtable *vtable;
@@ -33,6 +41,7 @@
{
// EXT2 supports up to 256 byte file names, so we will do the same
char name[256];
+ uint name_len;
uint inode;
};
@@ -42,7 +51,7 @@
typedef void (*fs_close_t)(struct fs_node *node);
typedef bool (*fs_readdir_t)(struct fs_node *node, uint index, struct fs_dirent *dirent);
-typedef struct fs_node *(*fs_finddir_t)(struct fs_node *node, char *name);
+typedef struct fs_node *(*fs_finddir_t)(struct fs_node *node, char *name, uint name_len);
struct fs_vtable
{
@@ -78,7 +87,7 @@
void fs_close(struct fs_node *node);
bool fs_readdir(struct fs_node *node, uint index, struct fs_dirent *out);
-struct fs_node *fs_finddir(struct fs_node *node, char *name);
+struct fs_node *fs_finddir(struct fs_node *node, char *name, uint name_len);
/* Returns the following error codes:
* 0: success