Some additions to the VFS

This commit is contained in:
Kevin Lange 2013-04-22 22:36:47 -07:00
parent 7c8d34d1b6
commit 6f096454cd
4 changed files with 50 additions and 15 deletions

View File

@ -20,6 +20,7 @@ static fs_node_t * procfs_generic_create(char * name, read_type_t read_func) {
strcpy(fnode->name, name);
fnode->uid = 0;
fnode->gid = 0;
fnode->mask = 0555;
fnode->flags = FS_FILE;
fnode->read = read_func;
fnode->write = NULL;
@ -278,8 +279,9 @@ fs_node_t * procfs_create() {
memset(fnode, 0x00, sizeof(fs_node_t));
fnode->inode = 0;
strcpy(fnode->name, "proc");
fnode->uid = 0;
fnode->gid = 0;
fnode->mask = 0555;
fnode->uid = 0;
fnode->gid = 0;
fnode->flags = FS_DIRECTORY;
fnode->read = NULL;
fnode->write = NULL;

View File

@ -16,6 +16,9 @@ struct tmpfs_file {
size_t pointers;
uint32_t flags;
char ** blocks;
int mask;
int uid;
int gid;
};
list_t * tmpfs_files = NULL;
@ -32,6 +35,9 @@ static struct tmpfs_file * tmpfs_file_new(char * name) {
t->pointers = 2;
t->block_count = 0;
t->flags = 0;
t->mask = 0;
t->uid = 0;
t->gid = 0;
t->blocks = malloc(t->pointers * sizeof(char *));
for (size_t i = 0; i < t->pointers; ++i) {
t->blocks[i] = NULL;
@ -152,9 +158,9 @@ static fs_node_t * tmpfs_from_file(struct tmpfs_file * t) {
fnode->inode = 0;
strcpy(fnode->name, t->name);
fnode->device = t;
fnode->mask = 0777;
fnode->uid = 0;
fnode->gid = 0;
fnode->mask = t->mask;
fnode->uid = t->uid;
fnode->gid = t->gid;
fnode->flags = FS_FILE;
fnode->read = read_tmpfs;
fnode->write = write_tmpfs;
@ -224,7 +230,9 @@ void create_tmpfs(fs_node_t *parent, char *name, uint16_t permission) {
debug_print(NOTICE, "... creating a new file.");
struct tmpfs_file * t = tmpfs_file_new(name);
t->flags = permission;
t->mask = permission;
t->uid = current_process->user;
t->gid = current_process->user;
list_insert(tmpfs_files, t);
}
@ -234,6 +242,7 @@ fs_node_t * tmpfs_create() {
memset(fnode, 0x00, sizeof(fs_node_t));
fnode->inode = 0;
strcpy(fnode->name, "tmp");
fnode->mask = 0777;
fnode->uid = 0;
fnode->gid = 0;
fnode->flags = FS_DIRECTORY;

View File

@ -664,6 +664,7 @@ fs_node_t *kopen(char *filename, uint32_t flags) {
/* We are still searching... */
path_offset += strlen(path_offset) + 1;
}
debug_print(INFO, "- Not found.");
/* We failed to find the requested file, but our loop terminated. */
free((void *)path);
return NULL;

View File

@ -155,16 +155,17 @@ static int wait(int child) {
static int open(const char * file, int flags, int mode) {
validate((void *)file);
debug_print(NOTICE, "open(%s) flags=0x%x; mode=0x%x", file, flags, mode);
fs_node_t * node = kopen((char *)file, 0);
debug_print(NOTICE, "Flags opening %s are 0x%x", file, flags);
if (!node && (flags & 0x600)) {
debug_print(NOTICE, "- file does not exist and create was requested.");
/* Um, make one */
if (!create_file_fs((char *)file, 0777)) {
debug_print(NOTICE, "[creat] Creating file!");
if (!create_file_fs((char *)file, mode)) {
node = kopen((char *)file, 0);
}
}
if (!node) {
debug_print(NOTICE, "File does not exist; someone should be setting errno?");
return -1;
}
node->offset = 0;
@ -175,7 +176,7 @@ static int open(const char * file, int flags, int mode) {
static int access(const char * file, int flags) {
validate((void *)file);
debug_print(INFO, "access(%s) from pid=%d", file, getpid());
debug_print(INFO, "access(%s, 0x%x) from pid=%d", file, flags, getpid());
fs_node_t * node = kopen((char *)file, 0);
if (!node) return -1;
close_fs(node);
@ -278,13 +279,13 @@ static int seek(int fd, int offset, int whence) {
return current_process->fds->entries[fd]->offset;
}
static int stat(int fd, uint32_t st) {
validate((void *)st);
if (fd >= (int)current_process->fds->length || fd < 0) {
static int stat_node(fs_node_t * fn, uintptr_t st) {
struct stat * f = (struct stat *)st;
if (!fn) {
memset(f, 0x00, sizeof(struct stat));
debug_print(INFO, "stat: This file doesn't exist");
return -1;
}
fs_node_t * fn = current_process->fds->entries[fd];
struct stat * f = (struct stat *)st;
f->st_dev = 0;
f->st_ino = fn->inode;
@ -314,6 +315,27 @@ static int stat(int fd, uint32_t st) {
return 0;
}
static int stat_file(char * file, uintptr_t st) {
int result;
validate((void *)file);
validate((void *)st);
fs_node_t * fn = kopen(file, 0);
result = stat_node(fn, st);
if (fn) {
close_fs(fn);
}
return result;
}
static int stat(int fd, uintptr_t st) {
validate((void *)st);
if (fd >= (int)current_process->fds->length || fd < 0) {
return -1;
}
fs_node_t * fn = current_process->fds->entries[fd];
return stat_node(fn, st);
}
static int setgraphicsoffset(int rows) {
bochs_set_y_offset(rows);
return 0;
@ -676,6 +698,7 @@ static uintptr_t syscalls[] = {
(uintptr_t)&sleep_rel,
(uintptr_t)&ioctl,
(uintptr_t)&access, /* 48 */
(uintptr_t)&stat_file,
0
};
uint32_t num_syscalls;