This commit is contained in:
Mathieu Maret 2024-07-19 14:13:09 +02:00
parent 1dd7d6191e
commit b4299be161
4 changed files with 150 additions and 7 deletions

View File

@ -17,7 +17,7 @@
uaddr_t loadElfProg(const char *prog, struct process *proc)
{
int i;
uaddr_t lastUserAddr = 0;
uaddr_t lastUserAddr = 0;
struct uAddrSpace *as = processGetAddrSpace(proc);
/* e_ident value */

View File

@ -1,13 +1,27 @@
#include "fs.h"
#include "list.h"
#include "stddef.h"
// List of all fs supported (e.g. EXT4, FAT32 ...)
struct file_system *fsList = NULL;
int fsRegister(struct file_system *fs){
list_add_tail(fsList, fs);
return 0;
}
int fsInodeUnref(struct inode *inode)
{
//TODO
(void)inode;
return 0;
};
int fsInodeRef(struct inode *inode)
{
//TODO
(void)inode;
return 0;
};

136
core/fs.h
View File

@ -1,7 +1,139 @@
#pragma once
#include "fsEntry.h"
#include "process.h"
#include "stdint.h"
#include <stddef.h>
#include <stdint.h>
#define FS_NAME_MAXLEN 32
// Forward declaration
struct file_system;
struct file_system_instance;
struct fs_stat;
struct file;
typedef enum {
FS_INODE_REGULAR_FILE = 0x01,
FS_INODE_DIRECTORY = 0x02,
FS_INODE_SYMLINK = 0x04,
FS_INODE_DEVICE_CHAR = 0x08,
FS_INODE_DEVICE_BLOCK = 0x10
} fs_inode_type_t;
struct inode_operation {
};
struct inode { // inode_operation
struct file_system_instance *fs;
uint64_t location;
size_t ondiskRef;
size_t inmemRef;
fs_inode_type_t type;
#define FS_READABLE 00400
#define FS_WRITABLE 00200
#define FS_EXECUTABLE 00100
uint32_t mode;
bool_t dirty;
struct inode_operation *ops;
union {
struct inode_dir_ops *opsDir;
struct inode_dir_symlink *opsSymlink;
};
int (*destructor)(struct inode *this);
int (*new_opened_file)(struct inode *this, const struct process *owner,
uint32_t open_flags, struct file **result_of);
int (*close_opened_file)(struct inode *this, struct file *of);
void *custom;
struct inode *prev_dirty, *next_dirty;
};
struct file_system_instance_ops { // super_operations
// From the inode location, instantiace a struct inode
int (*getInodeFromDevice)(struct file_system_instance *this, uint64_t storage_location,
struct inode **result);
int (*allocateNewInode)(struct file_system_instance *this, fs_inode_type_t type,
const struct process *creator, uint32_t access_rights,
uint32_t open_creat_flags, struct inode **result);
int (*statfs)(struct file_system_instance *this, struct fs_stat *result);
};
struct file_system_instance {
struct file_system *fsType; // this instance is of this type of file_system
struct inode *device; // device (like block one) could have a disk associated
#define FS_MOUNT_SYNC (1 << 0)
#define FS_MOUNT_READONLY (1 << 1)
#define FS_MOUNT_NOEXEC (1 << 2)
uint32_t flags;
struct fsEntry *root; // root fsEntry for this fs instance
struct indoe *dirtyNodes; // list of inodes that are out of sync
void *custom; // custom
const struct file_system_instance_ops *ops;
struct inode {//TODO
};
struct file_system_instance *prev, *next;
};
struct file_system {
char name[FS_NAME_MAXLEN];
struct file_system_instance *instances;
void *custom;
int (*mount)(struct file_system *this, struct inode *device, const char *args,
struct file_system_instance **mounted_fs);
int (*umount)(struct file_system *this, struct file_system_instance *mounted_fs);
struct file_system *prev, *next;
};
struct file_operations{
};
struct file {
const struct process *owner;
struct fs_entry *direntry;
uint ref;
int64_t position;
#define O_ACCMODE 0003
#define O_RDONLY 00
#define O_WRONLY 01
#define O_RDWR 02
#define O_CREAT 0100 /* Not fcntl. */
#define O_EXCL 0200 /* Not fcntl. */
#define O_NOCTTY 0400 /* Not fcntl. */
#define O_TRUNC 01000 /* Not fcntl. */
#define O_APPEND 02000
#define O_DIRECTORY 0200000 /* Must be a directory. */
#define O_NOFOLLOW 0400000 /* Do not follow links. */
#define O_SYNC 04010000
#define O_CLOEXEC 02000000 /* Set close_on_exec. */
uint32_t flags;
const struct file_operations *ops;
int (*duplicate)(struct file *this, const struct process *for_owner,
struct file **result);
void *custom;
};
int fsRegister(struct file_system *fs);
int fsInodeUnref(struct inode *inode);
int fsInodeRef(struct inode *inode);

View File

@ -7,7 +7,6 @@
#include "gdt.h"
#include "idt.h"
#include "interrupt.h"
#include "io.h"
#include "irq.h"
#include "kernel.h"
#include "keyboard.h"
@ -20,7 +19,6 @@
#include "process.h"
#include "serial.h"
#include "stack.h"
#include "stdarg.h"
#include "swintr.h"
#include "thread.h"
#ifdef RUN_TEST
@ -42,7 +40,6 @@ void idleThread(void *arg)
}
}
#define FILE_HEADER_SIZE 16
#define FILE_MAX_SIZE 64 // In nb of sectors
void loadUserSpace()
@ -54,7 +51,7 @@ void loadUserSpace()
return;
}
char *buf = malloc(FILE_MAX_SIZE * DISK_SECTOR_SIZE);
char *buf = (char *)malloc(FILE_MAX_SIZE * DISK_SECTOR_SIZE);
if (buf == NULL) {
printf("ENOMEM\n");
return;