2006-08-08 20:07:37 +02:00
|
|
|
#include "types.h"
|
2006-08-12 06:33:50 +02:00
|
|
|
#include "stat.h"
|
|
|
|
#include "user.h"
|
2006-08-08 20:07:37 +02:00
|
|
|
#include "fs.h"
|
2006-08-10 04:07:10 +02:00
|
|
|
#include "fcntl.h"
|
2006-07-16 17:36:31 +02:00
|
|
|
|
2006-07-10 18:27:15 +02:00
|
|
|
// file system tests
|
|
|
|
|
2006-08-12 03:25:45 +02:00
|
|
|
char buf[2000];
|
2006-08-08 21:58:06 +02:00
|
|
|
char *echo_args[] = { "echo", "hello", "goodbye", 0 };
|
|
|
|
char *cat_args[] = { "cat", "README", 0 };
|
2006-07-10 18:27:15 +02:00
|
|
|
|
2006-07-16 17:36:31 +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-08-10 03:28:57 +02:00
|
|
|
int i;
|
2006-08-12 03:25:45 +02:00
|
|
|
int stdout = 1;
|
2006-07-29 11:35:02 +02:00
|
|
|
|
2006-08-10 03:28:57 +02:00
|
|
|
printf(stdout, "userfs is running\n");
|
|
|
|
|
|
|
|
block();
|
2006-08-08 20:07:37 +02:00
|
|
|
|
2006-07-29 11:35:02 +02:00
|
|
|
fd = open("echo", 0);
|
|
|
|
if(fd >= 0){
|
2006-08-10 03:28:57 +02:00
|
|
|
printf(stdout, "open echo ok\n");
|
2006-07-29 11:35:02 +02:00
|
|
|
close(fd);
|
|
|
|
} else {
|
2006-08-10 03:28:57 +02:00
|
|
|
printf(stdout, "open echo failed!\n");
|
2006-07-29 11:35:02 +02:00
|
|
|
}
|
|
|
|
fd = open("doesnotexist", 0);
|
|
|
|
if(fd >= 0){
|
2006-08-10 03:28:57 +02:00
|
|
|
printf(stdout, "open doesnotexist succeeded!\n");
|
2006-07-29 11:35:02 +02:00
|
|
|
close(fd);
|
|
|
|
} else {
|
2006-08-10 03:28:57 +02:00
|
|
|
printf(stdout, "open doesnotexist failed\n");
|
2006-07-29 11:35:02 +02:00
|
|
|
}
|
2006-08-09 21:25:20 +02:00
|
|
|
fd = open("doesnotexist", O_CREATE|O_RDWR);
|
|
|
|
if(fd >= 0){
|
2006-08-10 03:28:57 +02:00
|
|
|
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");
|
|
|
|
}
|
2006-08-11 20:18:38 +02:00
|
|
|
i = read(fd, buf, 2000);
|
2006-08-10 03:28:57 +02:00
|
|
|
if (i == 2000) {
|
2006-08-11 20:18:38 +02:00
|
|
|
printf(stdout, "read succeeded\n");
|
2006-08-09 21:25:20 +02:00
|
|
|
} else {
|
2006-08-10 03:28:57 +02:00
|
|
|
printf(stdout, "read failed\n");
|
2006-08-09 21:25:20 +02:00
|
|
|
}
|
|
|
|
close(fd);
|
2006-08-11 20:18:38 +02:00
|
|
|
unlink("doesnotexist");
|
2006-08-08 21:58:06 +02:00
|
|
|
//exec("echo", echo_args);
|
2006-08-10 03:28:57 +02:00
|
|
|
printf(stdout, "about to do exec\n");
|
2006-08-08 21:58:06 +02:00
|
|
|
exec("cat", cat_args);
|
2006-07-16 17:36:31 +02:00
|
|
|
return 0;
|
2006-07-10 18:27:15 +02:00
|
|
|
}
|