BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / 648c56b1573240b17ce0a6ab62746ab30e41e126 / vfs / ext2fs / file.c

// Related

Nucleus

Barry Read-only Ext2 file system driver 648c56b (3 years, 2 months ago)
diff --git a/vfs/ext2fs/file.c b/vfs/ext2fs/file.c
new file mode 100644
index 0000000..d19df72
--- /dev/null
+++ b/vfs/ext2fs/file.c
@@ -0,0 +1,55 @@
+#include <string.h>
+#include <nucleus/vfs.h>
+#include "ext2fs.h"
+
+size_t ext2fs_read(File *file, char *buf, size_t size, off_t offset);
+int ext2fs_readdir(File *file, DirEntry *de, off_t index);
+int ext2fs_open(File *file);
+
+FileOps ext2fsFileOps = {
+	.read = ext2fs_read,
+//	.readdir = ext2fs_readdir,
+	.open = ext2fs_open,
+};
+
+/* Read an ext2fs file */
+size_t
+ext2fs_read(File *file, char *buf, size_t size, off_t offset)
+{
+	SuperBlock *sb = file->inode->super;
+	struct Ext2Inode inode;
+	uint16_t min, indent = offset % PAGE_SIZE;
+	size_t count = 0, i = offset / PAGE_SIZE;
+	uint32_t blk;
+	char ebuf[PAGE_SIZE];
+	ext2fs_read_inode(sb, file->inode->ino, &inode);
+	if (offset > inode.lsize)
+		return 0;
+	if (size + offset > inode.lsize)
+		size = inode.lsize - offset;
+	while (size) {
+		min = (size > PAGE_SIZE) ? PAGE_SIZE : size;
+		blk = ext2fs_get_data_addr(sb, &inode, i);
+		ext2fs_read_block(sb, blk, ebuf);
+		memcpy(buf + count, ebuf + indent, min);
+		size -= min;
+		count += min;
+		indent = 0;
+		i++;
+	}
+	return count;
+}
+
+/* Read an ext2fs directory entry */
+int
+ext2fs_readdir(File *file, DirEntry *de, off_t index)
+{
+	return 0;
+}
+
+/* Open an ext2fs file */
+int
+ext2fs_open(File *file)
+{
+	return 0;
+}