VFS: Use 64-bit numbers in read()
There is no need for any kind of 32-bit compatibility.
This commit is contained in:
parent
8158ddc94f
commit
2be70d0bc1
@ -1,11 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
typedef long ssize_t;
|
||||||
|
|
||||||
namespace VFS
|
namespace VFS
|
||||||
{
|
{
|
||||||
struct Node;
|
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*);
|
typedef Node* (*node_finddir)(Node*, const char*);
|
||||||
|
|
||||||
struct Node
|
struct Node
|
||||||
@ -17,7 +20,7 @@ namespace VFS
|
|||||||
node_finddir find_func;
|
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);
|
Node* open(const char* filename);
|
||||||
|
|
||||||
void mount_root(Node* root);
|
void mount_root(Node* root);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
static VFS::Node* vfs_root;
|
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)
|
if (!node)
|
||||||
{
|
{
|
||||||
@ -19,7 +19,7 @@ int32_t VFS::read(Node* node, uint32_t offset, uint32_t length, char* buffer)
|
|||||||
return -1;
|
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);
|
(void*)buffer);
|
||||||
|
|
||||||
return node->read_func(node, offset, length, buffer);
|
return node->read_func(node, offset, length, buffer);
|
||||||
|
@ -120,15 +120,15 @@ static uint32_t total_files = 0;
|
|||||||
|
|
||||||
static VFS::Node nodes[32];
|
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) return -1;
|
||||||
if (node->inode >= total_files) return -1;
|
if (node->inode >= total_files) return -1;
|
||||||
InitRD::File& file = files[node->inode];
|
InitRD::File& file = files[node->inode];
|
||||||
if (offset > file.size) return -1;
|
if (offset > file.size) return -1;
|
||||||
if (offset + length > file.size) { length = (uint32_t)file.size - offset; }
|
if (offset + length > file.size) { length = file.size - offset; }
|
||||||
memcpy(buffer, (void*)((uint64_t)file.addr + offset), length);
|
memcpy(buffer, (void*)((uintptr_t)file.addr + offset), length);
|
||||||
return (int32_t)length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
VFS::Node* initrd_scan_root(VFS::Node*, const char* filename)
|
VFS::Node* initrd_scan_root(VFS::Node*, const char* filename)
|
||||||
@ -169,8 +169,6 @@ void InitRD::init()
|
|||||||
strncpy(initrd_root.name, "initrd", 7);
|
strncpy(initrd_root.name, "initrd", 7);
|
||||||
initrd_root.find_func = initrd_scan_root;
|
initrd_root.find_func = initrd_scan_root;
|
||||||
VFS::mount_root(&initrd_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);
|
kdbgln("mounted initrd at VFS root, total files: %d", total_files);
|
||||||
initrd_initialized = true;
|
initrd_initialized = true;
|
||||||
}
|
}
|
@ -169,8 +169,8 @@ extern "C" void _start()
|
|||||||
kinfoln("Found '%s'", node->name);
|
kinfoln("Found '%s'", node->name);
|
||||||
char* buffer = (char*)kmalloc(node->length + 1);
|
char* buffer = (char*)kmalloc(node->length + 1);
|
||||||
buffer[node->length] = 0;
|
buffer[node->length] = 0;
|
||||||
int nread = VFS::read(node, 0, (uint32_t)node->length, buffer);
|
ssize_t nread = VFS::read(node, 0, node->length, buffer);
|
||||||
kdbgln("Read %d bytes", nread);
|
kdbgln("Read %zd bytes", nread);
|
||||||
kinfoln("Read: %s", buffer);
|
kinfoln("Read: %s", buffer);
|
||||||
kfree(buffer);
|
kfree(buffer);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user