wip
This commit is contained in:
parent
1dd7d6191e
commit
dff2cce035
@ -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 */
|
||||
|
14
core/fs.c
14
core/fs.c
@ -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;
|
||||
};
|
||||
|
151
core/fs.h
151
core/fs.h
@ -1,7 +1,154 @@
|
||||
#pragma once
|
||||
#include "fsEntry.h"
|
||||
#include "process.h"
|
||||
#include "stdint.h"
|
||||
#include "types.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 {
|
||||
};
|
||||
|
||||
/**
|
||||
* Represent a file on the disk
|
||||
*/
|
||||
struct inode {
|
||||
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 (*newOpenedFile)(struct inode *this, const struct process *owner, uint32_t openFlags,
|
||||
struct file **result);
|
||||
int (*closeOpenedFile)(struct inode *this, struct file *of);
|
||||
void *custom;
|
||||
|
||||
struct inode *prevDirty, *nextDirty;
|
||||
};
|
||||
|
||||
struct file_system_instance_ops { // super_operations
|
||||
// From the inode location, instantiace a struct inode
|
||||
int (*getInodeFromDevice)(struct file_system_instance *this, uint64_t storageLocation,
|
||||
struct inode **result);
|
||||
|
||||
int (*allocateNewInode)(struct file_system_instance *this, fs_inode_type_t type,
|
||||
const struct process *creator, uint32_t accessRights,
|
||||
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 fs_entry *root; // root fs_entry for this fs instance
|
||||
struct inode *dirtyNodes; // list of inodes that are out of sync
|
||||
void *custom; // custom
|
||||
const struct file_system_instance_ops *ops;
|
||||
|
||||
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 **mountedFs);
|
||||
|
||||
int (*umount)(struct file_system *this, struct file_system_instance *mountedFs);
|
||||
|
||||
struct file_system *prev, *next;
|
||||
};
|
||||
|
||||
typedef enum { SEEK_SET, SEEK_CUR, SEEK_END } seek_mode_t;
|
||||
|
||||
struct file_operations {
|
||||
loff_t (*llseek)(struct file *this, loff_t offset, seek_mode_t whence);
|
||||
ssize_t (*read)(struct file *this, char *buf, size_t size, loff_t *offset);
|
||||
ssize_t (*write)(struct file *this, const char *buf, size_t size, loff_t *offset);
|
||||
int (*mmap)(struct file *this, uaddr_t *uaddr, size_t size,
|
||||
int32_t access_rights, int32_t flags, loff_t offset);
|
||||
|
||||
int (*open)(struct inode *, struct file *);
|
||||
int (*flush)(struct file *);
|
||||
int (*release)(struct inode *, struct file *);
|
||||
};
|
||||
|
||||
/**
|
||||
* A opened file by a process
|
||||
*/
|
||||
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 *owner, struct file **result);
|
||||
|
||||
void *custom;
|
||||
};
|
||||
|
||||
int fsRegister(struct file_system *fs);
|
||||
|
||||
struct inode {//TODO
|
||||
};
|
||||
int fsInodeUnref(struct inode *inode);
|
||||
int fsInodeRef(struct inode *inode);
|
||||
|
@ -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;
|
||||
|
@ -9,3 +9,6 @@ typedef unsigned long paddr_t;
|
||||
|
||||
// Userspace vaddr
|
||||
typedef unsigned long uaddr_t;
|
||||
|
||||
// Offset
|
||||
typedef long long loff_t;
|
||||
|
Loading…
Reference in New Issue
Block a user