xv6/userfs.c

77 lines
1.7 KiB
C
Raw Normal View History

#include "user.h"
2006-08-08 18:07:37 +00:00
#include "types.h"
#include "fs.h"
#include "fcntl.h"
2006-07-10 16:27:15 +00:00
// file system tests
char buf[2000];
char *echo_args[] = { "echo", "hello", "goodbye", 0 };
char *cat_args[] = { "cat", "README", 0 };
2006-07-10 16:27:15 +00:00
int
2006-07-17 01:25:22 +00:00
main(void)
2006-07-10 16:27:15 +00:00
{
2006-07-29 09:35:02 +00:00
int fd;
int i;
int stdout;
2006-07-29 09:35:02 +00:00
// printf(stdout, "userfs running\n");
2006-08-08 18:07:37 +00:00
if (mknod ("console", T_DEV, 1, 1) < 0)
puts ("mknod failed\n");
else
puts ("made a node\n");
stdout = open("console", O_WRONLY);
printf(stdout, "userfs is running\n");
block();
2006-08-08 18:07:37 +00:00
2006-07-29 09:35:02 +00:00
fd = open("echo", 0);
if(fd >= 0){
printf(stdout, "open echo ok\n");
2006-07-29 09:35:02 +00:00
close(fd);
} else {
printf(stdout, "open echo failed!\n");
2006-07-29 09:35:02 +00:00
}
fd = open("doesnotexist", 0);
if(fd >= 0){
printf(stdout, "open doesnotexist succeeded!\n");
2006-07-29 09:35:02 +00:00
close(fd);
} else {
printf(stdout, "open doesnotexist failed\n");
2006-07-29 09:35:02 +00:00
}
fd = open("doesnotexist", O_CREATE|O_RDWR);
if(fd >= 0){
printf(stdout, "creat doesnotexist succeeded\n");
} else {
printf(stdout, "error: creat doesnotexist failed!\n");
}
for (i = 0; i < 100; i++) {
if (write (fd, "aaaaaaaaaa", 10) != 10) {
printf(stdout, "error: write new file failed\n");
}
if (write (fd, "bbbbbbbbbb", 10) != 10) {
printf(stdout, "error: write new file failed\n");
}
}
printf(stdout, "writes done\n");
close(fd);
fd = open("doesnotexist", O_RDONLY);
if(fd >= 0){
printf(stdout, "open doesnotexist succeeded\n");
} else {
printf(stdout, "error: open doesnotexist failed!\n");
}
i = read(fd, buf, 10000);
if (i == 2000) {
printf(stdout, "read succeeded\\n");
} else {
printf(stdout, "read failed\n");
}
close(fd);
//exec("echo", echo_args);
printf(stdout, "about to do exec\n");
exec("cat", cat_args);
return 0;
2006-07-10 16:27:15 +00:00
}