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-08-24 19:28:01 +02:00
|
|
|
// simple file system tests
|
2006-07-10 18:27:15 +02:00
|
|
|
|
2006-08-12 03:25:45 +02:00
|
|
|
char buf[2000];
|
2006-08-13 07:28:04 +02:00
|
|
|
char name[3];
|
2006-08-08 21:58:06 +02:00
|
|
|
char *echo_args[] = { "echo", "hello", "goodbye", 0 };
|
2006-08-14 23:22:13 +02:00
|
|
|
char *cat_args[] = { "cat", "readme", 0 };
|
2006-08-24 19:28:01 +02:00
|
|
|
int stdout = 1;
|
2006-07-10 18:27:15 +02:00
|
|
|
|
2006-08-24 19:28:01 +02:00
|
|
|
void
|
|
|
|
opentest(void)
|
2006-07-10 18:27:15 +02:00
|
|
|
{
|
2006-07-29 11:35:02 +02:00
|
|
|
int fd;
|
2006-08-23 03:09:24 +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-08-24 19:28:01 +02:00
|
|
|
exit();
|
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-08-24 19:28:01 +02:00
|
|
|
exit();
|
2006-07-29 11:35:02 +02:00
|
|
|
} 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-24 19:28:01 +02:00
|
|
|
}
|
|
|
|
|
2006-09-06 19:27:19 +02:00
|
|
|
void
|
2006-08-24 19:28:01 +02:00
|
|
|
writetest(void)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
fd = open("small", O_CREATE|O_RDWR);
|
2006-08-09 21:25:20 +02:00
|
|
|
if(fd >= 0){
|
2006-08-24 19:28:01 +02:00
|
|
|
printf(stdout, "creat small succeeded\n");
|
2006-08-10 03:28:57 +02:00
|
|
|
} else {
|
2006-08-24 19:28:01 +02:00
|
|
|
printf(stdout, "error: creat small failed!\n");
|
|
|
|
exit();
|
2006-08-10 03:28:57 +02:00
|
|
|
}
|
2006-09-06 19:27:19 +02:00
|
|
|
for(i = 0; i < 100; i++) {
|
|
|
|
if(write(fd, "aaaaaaaaaa", 10) != 10) {
|
2006-08-24 04:44:41 +02:00
|
|
|
printf(stdout, "error: write aa %d new file failed\n", i);
|
2006-08-24 19:28:01 +02:00
|
|
|
exit();
|
2006-08-10 03:28:57 +02:00
|
|
|
}
|
2006-09-06 19:27:19 +02:00
|
|
|
if(write(fd, "bbbbbbbbbb", 10) != 10) {
|
2006-08-24 04:44:41 +02:00
|
|
|
printf(stdout, "error: write bb %d new file failed\n", i);
|
2006-08-24 19:28:01 +02:00
|
|
|
exit();
|
2006-08-10 03:28:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
printf(stdout, "writes done\n");
|
|
|
|
close(fd);
|
2006-08-24 19:28:01 +02:00
|
|
|
fd = open("small", O_RDONLY);
|
2006-08-10 03:28:57 +02:00
|
|
|
if(fd >= 0){
|
2006-08-24 19:28:01 +02:00
|
|
|
printf(stdout, "open small succeeded\n");
|
2006-08-10 03:28:57 +02:00
|
|
|
} else {
|
2006-08-24 19:28:01 +02:00
|
|
|
printf(stdout, "error: open small failed!\n");
|
|
|
|
exit();
|
2006-08-10 03:28:57 +02:00
|
|
|
}
|
2006-08-11 20:18:38 +02:00
|
|
|
i = read(fd, buf, 2000);
|
2006-09-06 19:27:19 +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-24 19:28:01 +02:00
|
|
|
exit();
|
2006-08-09 21:25:20 +02:00
|
|
|
}
|
|
|
|
close(fd);
|
2006-08-14 05:00:13 +02:00
|
|
|
|
2006-09-06 19:27:19 +02:00
|
|
|
if(unlink("small") < 0) {
|
2006-08-24 19:28:01 +02:00
|
|
|
printf(stdout, "unlink small failed\n");
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-06 19:27:19 +02:00
|
|
|
void
|
2006-08-24 19:28:01 +02:00
|
|
|
writetest1(void)
|
|
|
|
{
|
|
|
|
int i, fd, n;
|
|
|
|
|
|
|
|
printf(stdout, "big files\n");
|
|
|
|
|
|
|
|
fd = open("big", O_CREATE|O_RDWR);
|
|
|
|
if(fd < 0){
|
|
|
|
printf(stdout, "error: creat big failed!\n");
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2006-09-06 19:27:19 +02:00
|
|
|
for(i = 0; i < MAXFILE; i++) {
|
|
|
|
((int*) buf)[0] = i;
|
|
|
|
if(write(fd, buf, 512) != 512) {
|
2006-08-24 19:28:01 +02:00
|
|
|
printf(stdout, "error: write big file failed\n", i);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
fd = open("big", O_RDONLY);
|
|
|
|
if(fd < 0){
|
|
|
|
printf(stdout, "error: open big failed!\n");
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
n = 0;
|
2006-09-06 20:47:48 +02:00
|
|
|
for(;;) {
|
2006-08-24 19:28:01 +02:00
|
|
|
i = read(fd, buf, 512);
|
2006-09-06 19:27:19 +02:00
|
|
|
if(i == 0) {
|
|
|
|
if(n == MAXFILE - 1) {
|
2006-09-06 19:04:06 +02:00
|
|
|
printf(stdout, "read only %d blocks from big", n);
|
|
|
|
exit();
|
2006-08-24 19:28:01 +02:00
|
|
|
}
|
|
|
|
break;
|
2006-09-06 19:27:19 +02:00
|
|
|
} else if(i != 512) {
|
2006-08-24 19:28:01 +02:00
|
|
|
printf(stdout, "read failed %d\n", i);
|
|
|
|
exit();
|
|
|
|
}
|
2006-09-06 19:27:19 +02:00
|
|
|
if(((int*)buf)[0] != n) {
|
2006-09-06 21:08:14 +02:00
|
|
|
printf(stdout, "read content of block %d is %d\n",
|
|
|
|
n, ((int*)buf)[0]);
|
2006-08-24 19:28:01 +02:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
close(fd);
|
2006-09-06 19:27:19 +02:00
|
|
|
if(unlink("big") < 0) {
|
2006-08-24 19:28:01 +02:00
|
|
|
printf(stdout, "unlink big failed\n");
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
2006-08-14 05:00:13 +02:00
|
|
|
|
2006-08-24 19:28:01 +02:00
|
|
|
void
|
|
|
|
createtest(void)
|
|
|
|
{
|
|
|
|
int i, fd;
|
2006-08-14 05:00:13 +02:00
|
|
|
|
|
|
|
printf(stdout, "many creates, followed by unlink\n");
|
|
|
|
|
2006-08-13 07:28:04 +02:00
|
|
|
name[0] = 'a';
|
|
|
|
name[2] = '\0';
|
2006-09-06 19:27:19 +02:00
|
|
|
for(i = 0; i < 52; i++) {
|
2006-08-13 07:28:04 +02:00
|
|
|
name[1] = '0' + i;
|
|
|
|
fd = open(name, O_CREATE|O_RDWR);
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
name[0] = 'a';
|
|
|
|
name[2] = '\0';
|
2006-09-06 19:27:19 +02:00
|
|
|
for(i = 0; i < 52; i++) {
|
2006-08-13 07:28:04 +02:00
|
|
|
name[1] = '0' + i;
|
|
|
|
unlink(name);
|
|
|
|
}
|
2006-08-24 19:28:01 +02:00
|
|
|
}
|
2006-08-13 07:28:04 +02:00
|
|
|
|
2006-08-24 19:28:01 +02:00
|
|
|
void dirtest(void)
|
|
|
|
{
|
2006-08-14 05:00:13 +02:00
|
|
|
printf(stdout, "mkdir\n");
|
|
|
|
|
2006-09-06 20:47:48 +02:00
|
|
|
if(mkdir("dir0") < 0) {
|
2006-08-14 05:00:13 +02:00
|
|
|
printf(stdout, "mkdir failed\n");
|
2006-08-24 19:28:01 +02:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2006-09-06 20:47:48 +02:00
|
|
|
if(chdir("dir0") < 0) {
|
2006-08-24 19:28:01 +02:00
|
|
|
printf(stdout, "chdir dir0 failed\n");
|
|
|
|
exit();
|
|
|
|
}
|
2006-08-14 05:00:13 +02:00
|
|
|
|
2006-09-06 20:47:48 +02:00
|
|
|
if(chdir("..") < 0) {
|
2006-08-24 19:28:01 +02:00
|
|
|
printf(stdout, "chdir .. failed\n");
|
2006-09-06 19:27:19 +02:00
|
|
|
exit();
|
2006-08-24 19:28:01 +02:00
|
|
|
}
|
2006-09-06 19:27:19 +02:00
|
|
|
|
|
|
|
if(unlink("dir0") < 0) {
|
2006-08-24 19:28:01 +02:00
|
|
|
printf(stdout, "unlink dir0 failed\n");
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
exectest(void)
|
|
|
|
{
|
2006-09-06 19:27:19 +02:00
|
|
|
if(exec("echo", echo_args) < 0) {
|
2006-08-24 19:28:01 +02:00
|
|
|
printf(stdout, "exec echo failed\n");
|
|
|
|
exit();
|
|
|
|
}
|
2006-09-06 19:27:19 +02:00
|
|
|
if(exec("cat", cat_args) < 0) {
|
2006-08-24 19:28:01 +02:00
|
|
|
printf(stdout, "exec cat failed\n");
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
printf(stdout, "userfs is running\n");
|
|
|
|
opentest();
|
|
|
|
writetest();
|
|
|
|
writetest1();
|
|
|
|
createtest();
|
|
|
|
exectest();
|
2006-07-16 17:36:31 +02:00
|
|
|
return 0;
|
2006-07-10 18:27:15 +02:00
|
|
|
}
|