mkdir and creat testing

This commit is contained in:
Kevin Lange 2012-02-05 16:04:41 -06:00
parent f7e554c409
commit c4e33117c0
5 changed files with 75 additions and 12 deletions

View File

@ -110,7 +110,7 @@ fs_node_t *finddir_fs(fs_node_t *node, char *name) {
* and a file, thus, the use of flag sets should suffice
*/
void create_file_fs(char *name, uint16_t permission) {
int create_file_fs(char *name, uint16_t permission) {
int32_t i = strlen(name);
char *dir_name = malloc(i + 1);
memcpy(dir_name, name, i);
@ -118,8 +118,7 @@ void create_file_fs(char *name, uint16_t permission) {
if (dir_name[i - 1] == '/')
dir_name[i - 1] = '\0';
if (strlen(dir_name) == 0) {
kprintf("mkdir: /: Is a directory\n");
return;
return 1;
}
for (i = strlen(dir_name) - 1; i >= 0; i--) {
if (dir_name[i] == '/') {
@ -138,9 +137,8 @@ void create_file_fs(char *name, uint16_t permission) {
}
if (node == NULL) {
kprintf("mkdir: Directory does not exist\n");
free(dir_name);
return;
return 2;
}
i++;
@ -150,9 +148,10 @@ void create_file_fs(char *name, uint16_t permission) {
free(node);
free(dir_name);
return 0;
}
void mkdir_fs(char *name, uint16_t permission) {
int mkdir_fs(char *name, uint16_t permission) {
int32_t i = strlen(name);
char *dir_name = malloc(i + 1);
memcpy(dir_name, name, i);
@ -160,8 +159,7 @@ void mkdir_fs(char *name, uint16_t permission) {
if (dir_name[i - 1] == '/')
dir_name[i - 1] = '\0';
if (strlen(dir_name) == 0) {
kprintf("mkdir: /: Is a directory\n");
return;
return 1;
}
for (i = strlen(dir_name) - 1; i >= 0; i--) {
if (dir_name[i] == '/') {
@ -181,7 +179,7 @@ void mkdir_fs(char *name, uint16_t permission) {
if (node == NULL) {
kprintf("mkdir: Directory does not exist\n");
free(dir_name);
return;
return 1;
}
i++;
@ -191,6 +189,8 @@ void mkdir_fs(char *name, uint16_t permission) {
free(node);
free(dir_name);
return 0;
}
fs_node_t *clone_fs(fs_node_t *source) {

View File

@ -82,8 +82,8 @@ void open_fs(fs_node_t *node, uint8_t read, uint8_t write);
void close_fs(fs_node_t *node);
struct dirent *readdir_fs(fs_node_t *node, uint32_t index);
fs_node_t *finddir_fs(fs_node_t *node, char *name);
void mkdir_fs(char *name, uint16_t permission);
void create_file_fs(char *name, uint16_t permission);
int mkdir_fs(char *name, uint16_t permission);
int create_file_fs(char *name, uint16_t permission);
fs_node_t *kopen(char *filename, uint32_t flags);
char *canonicalize_path(char *cwd, char *input);
fs_node_t *clone_fs(fs_node_t * source);

View File

@ -124,8 +124,12 @@ static int open(const char * file, int flags, int mode) {
validate((void *)file);
fs_node_t * node = kopen((char *)file, 0);
if (!node && (mode & 0x600)) {
if (!node && (flags & 0x600)) {
/* Um, make one */
if (!create_file_fs((char *)file, 0777)) {
kprintf("[debug] Created file %s\n", file);
node = kopen((char *)file, 0);
}
}
if (!node) {
return -1;
@ -375,6 +379,12 @@ static int mousedevice() {
return process_append_fd((process_t *)current_process, mouse_pipe);
}
extern int mkdir_fs(char *name, uint16_t permission);
static int sys_mkdir(char * path, uint32_t mode) {
return mkdir_fs(path, 0777);
}
/*
* System Call Internals
*/
@ -415,6 +425,7 @@ static uintptr_t syscalls[] = {
(uintptr_t)&sethostname,
(uintptr_t)&gethostname, /* 32 */
(uintptr_t)&mousedevice,
(uintptr_t)&sys_mkdir,
0
};
uint32_t num_syscalls;

32
userspace/edit.c Normal file
View File

@ -0,0 +1,32 @@
#include <stdio.h>
#include <string.h>
int main(int argc, char * argv[]) {
if (argc < 2) {
fprintf(stderr, "%s: argument expected\n", argv[0]);
return 1;
}
FILE * f = fopen(argv[1], "w");
if (!f) {
fprintf(stderr, "%s: Could not open %s\n", argv[0], argv[1]);
return 1;
}
while (1) {
char buf[1024];
fgets(buf, 1024, stdin);
buf[strlen(buf)-1] = '\0';
if (strlen(buf) < 2) {
break;
}
fprintf(f, "%s\n", buf);
}
fclose(f);
return 0;
}

20
userspace/mkdir.c Normal file
View File

@ -0,0 +1,20 @@
/* vim:tabstop=4 shiftwidth=4 noexpandtab
*
* Hello World!
*/
#include <stdio.h>
#include <syscall.h>
#include <stdint.h>
DEFN_SYSCALL2(mkdir, 34, char *, uint32_t)
int main(int argc, char ** argv) {
if (argc < 2) {
fprintf(stderr, "%s: expected argument\n", argv[0]);
return 1;
}
syscall_mkdir(argv[1], 0x00);
return 0;
}