xv6-cs450/userfs.c

60 lines
1.1 KiB
C
Raw Normal View History

#include "user.h"
2006-08-08 20:07:37 +02:00
#include "types.h"
#include "fs.h"
2006-07-10 18:27:15 +02:00
// file system tests
char buf[1024];
char *echo_args[] = { "echo", "hello", "goodbye", 0 };
char *cat_args[] = { "cat", "README", 0 };
2006-07-10 18:27:15 +02:00
int
2006-07-17 03:25:22 +02:00
main(void)
2006-07-10 18:27:15 +02:00
{
2006-07-29 11:35:02 +02:00
int fd;
2006-07-11 03:07:40 +02:00
puts("userfs running\n");
2006-07-10 18:27:15 +02:00
block();
2006-08-08 20:07:37 +02:00
if (mknod ("console", T_DEV, 1, 1) < 0)
puts ("mknod failed\n");
else
puts ("made a node\n");
fd = open("console", O_WRONLY);
if(fd >= 0){
puts("open console ok\n");
} else {
puts("open console failed!\n");
}
if (write (fd, "hello\n", 6) != 6) {
puts ("write to console failed\n");
}
close (fd);
2006-08-08 20:07:37 +02:00
2006-07-29 11:35:02 +02:00
fd = open("echo", 0);
if(fd >= 0){
puts("open echo ok\n");
close(fd);
} else {
puts("open echo failed!\n");
}
fd = open("doesnotexist", 0);
if(fd >= 0){
puts("open doesnotexist succeeded!\n");
close(fd);
} else {
puts("open doesnotexist failed\n");
}
fd = open("doesnotexist", O_CREATE|O_RDWR);
if(fd >= 0){
puts("creat doesnotexist succeeded\n");
} else {
puts("error: creat doesnotexist failed!\n");
}
close(fd);
//exec("echo", echo_args);
exec("cat", cat_args);
return 0;
2006-07-10 18:27:15 +02:00
}