Virtual File System #10
@ -1,11 +1,14 @@
|
||||
#pragma once
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef long ssize_t;
|
||||
|
||||
namespace VFS
|
||||
{
|
||||
struct Node;
|
||||
|
||||
typedef int32_t (*node_read)(Node*, uint32_t, uint32_t, char*);
|
||||
typedef ssize_t (*node_read)(Node*, size_t, size_t, char*);
|
||||
typedef Node* (*node_finddir)(Node*, const char*);
|
||||
|
||||
struct Node
|
||||
@ -17,7 +20,7 @@ namespace VFS
|
||||
node_finddir find_func;
|
||||
};
|
||||
|
||||
int32_t read(Node* node, uint32_t offset, uint32_t length, char* buffer);
|
||||
ssize_t read(Node* node, size_t offset, size_t length, char* buffer);
|
||||
Node* open(const char* filename);
|
||||
|
||||
void mount_root(Node* root);
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
static VFS::Node* vfs_root;
|
||||
|
||||
int32_t VFS::read(Node* node, uint32_t offset, uint32_t length, char* buffer)
|
||||
ssize_t VFS::read(Node* node, size_t offset, size_t length, char* buffer)
|
||||
{
|
||||
if (!node)
|
||||
{
|
||||
@ -19,7 +19,7 @@ int32_t VFS::read(Node* node, uint32_t offset, uint32_t length, char* buffer)
|
||||
return -1;
|
||||
}
|
||||
|
||||
kdbgln("read(): node %s (inode %ld), offset %d, %d bytes, into %p", node->name, node->inode, offset, length,
|
||||
kdbgln("read(): node %s (inode %ld), offset %zd, %zd bytes, into %p", node->name, node->inode, offset, length,
|
||||
(void*)buffer);
|
||||
|
||||
return node->read_func(node, offset, length, buffer);
|
||||
|
@ -120,15 +120,15 @@ static uint32_t total_files = 0;
|
||||
|
||||
static VFS::Node nodes[32];
|
||||
|
||||
int32_t initrd_read(VFS::Node* node, uint32_t offset, uint32_t length, char* buffer)
|
||||
ssize_t initrd_read(VFS::Node* node, size_t offset, size_t length, char* buffer)
|
||||
{
|
||||
if (!node) return -1;
|
||||
if (node->inode >= total_files) return -1;
|
||||
InitRD::File& file = files[node->inode];
|
||||
if (offset > file.size) return -1;
|
||||
if (offset + length > file.size) { length = (uint32_t)file.size - offset; }
|
||||
memcpy(buffer, (void*)((uint64_t)file.addr + offset), length);
|
||||
return (int32_t)length;
|
||||
if (offset + length > file.size) { length = file.size - offset; }
|
||||
memcpy(buffer, (void*)((uintptr_t)file.addr + offset), length);
|
||||
return length;
|
||||
}
|
||||
|
||||
VFS::Node* initrd_scan_root(VFS::Node*, const char* filename)
|
||||
@ -169,8 +169,6 @@ void InitRD::init()
|
||||
strncpy(initrd_root.name, "initrd", 7);
|
||||
initrd_root.find_func = initrd_scan_root;
|
||||
VFS::mount_root(&initrd_root);
|
||||
VFS::mount_root(0);
|
||||
VFS::mount_root(&initrd_root);
|
||||
kdbgln("mounted initrd at VFS root, total files: %d", total_files);
|
||||
initrd_initialized = true;
|
||||
}
|
@ -169,8 +169,8 @@ extern "C" void _start()
|
||||
kinfoln("Found '%s'", node->name);
|
||||
char* buffer = (char*)kmalloc(node->length + 1);
|
||||
buffer[node->length] = 0;
|
||||
int nread = VFS::read(node, 0, (uint32_t)node->length, buffer);
|
||||
kdbgln("Read %d bytes", nread);
|
||||
ssize_t nread = VFS::read(node, 0, node->length, buffer);
|
||||
kdbgln("Read %zd bytes", nread);
|
||||
kinfoln("Read: %s", buffer);
|
||||
kfree(buffer);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user