summaryrefslogtreecommitdiff
path: root/userfs.c
blob: 516a7c90d66241e11283c10d0d70eb492c09f14f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "user.h"
#include "types.h"
#include "fs.h"

// file system tests

char buf[2000];
char *echo_args[] = { "echo", "hello", "goodbye", 0 };
char *cat_args[] = { "cat", "README", 0 };

int
main(void)
{
  int fd;
  int i;
  int stdout;

  //  printf(stdout, "userfs running\n");
  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();

  fd = open("echo", 0);
  if(fd >= 0){
    printf(stdout, "open echo ok\n");
    close(fd);
  } else {
    printf(stdout, "open echo failed!\n");
  }
  fd = open("doesnotexist", 0);
  if(fd >= 0){
    printf(stdout, "open doesnotexist succeeded!\n");
    close(fd);
  } else {
    printf(stdout, "open doesnotexist failed\n");
  }
  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;
}