VFS: Add a 'type' flag to Nodes, implement EISDIR

This commit is contained in:
apio 2022-10-11 17:48:11 +02:00
parent 7a097f16ea
commit 1278cec065
6 changed files with 16 additions and 1 deletions

View File

@ -4,6 +4,7 @@
#define ENOENT 2
#define EBADF 9
#define ENOMEM 12
#define EISDIR 21
#define EINVAL 22
#define EMFILE 24
#define ENOSYS 38

View File

@ -4,6 +4,9 @@
typedef long ssize_t;
#define VFS_FILE 0x0
#define VFS_DIRECTORY 0x1
namespace VFS
{
struct Node;
@ -16,6 +19,7 @@ namespace VFS
char name[64];
uint64_t inode;
uint64_t length;
int type;
node_read read_func;
node_finddir find_func;
};

View File

@ -1,6 +1,7 @@
#define MODULE "vfs"
#include "fs/VFS.h"
#include "errno.h"
#include "log/Log.h"
#include "std/stdlib.h"
#include "std/string.h"
@ -14,6 +15,11 @@ ssize_t VFS::read(Node* node, size_t offset, size_t length, char* buffer)
kwarnln("read() failed: trying to read from nullptr");
return -1;
}
if (node->type == VFS_DIRECTORY)
{
kwarnln("read() failed: is a directory");
return -EISDIR;
}
if (!node->read_func)
{
kwarnln("read() failed: the chosen node doesn't support reading");

View File

@ -8,7 +8,7 @@
#include "memory/MemoryManager.h"
#include "misc/utils.h"
#include "std/stdlib.h"
#include <string.h>
#include "std/string.h"
extern BOOTBOOT bootboot;
@ -227,6 +227,7 @@ static bool initrd_register_dir(InitRD::Directory& dir, uint64_t inode)
node.inode = inode;
node.find_func = initrd_scan_dir;
node.length = 0;
node.type = VFS_DIRECTORY;
strncpy(node.name, buffer, sizeof(node.name));
strncpy(dir.name, buffer, sizeof(dir.name));
@ -284,6 +285,7 @@ static bool initrd_register_file(InitRD::File& f, uint64_t inode)
node.inode = inode;
node.read_func = initrd_read;
node.length = f.size;
node.type = VFS_FILE;
strncpy(node.name, buffer, sizeof(node.name));
strncpy(f.name, buffer, sizeof(f.name));

View File

@ -7,6 +7,7 @@ extern int errno;
#define ENOENT 2
#define EBADF 9
#define ENOMEM 12
#define EISDIR 21
#define EINVAL 22
#define EMFILE 24
#define ENOSYS 38

View File

@ -124,6 +124,7 @@ extern "C"
case ENOENT: return "No such file or directory";
case EBADF: return "Bad file descriptor";
case EMFILE: return "Too many open files";
case EISDIR: return "Is a directory";
case 0: return "Success";
default: return (char*)(unsigned long int)errnum;
}