summaryrefslogtreecommitdiff
path: root/userfs.c
blob: e6dd1726cd7662985553b257e08d0cf82f7a1737 (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
#include "user.h"
#include "types.h"
#include "fs.h"

// file system tests

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

int
main(void)
{
  int fd;

  puts("userfs running\n");
  block();

  if (mknod ("console", T_DEV, 1, 1) < 0)
    puts ("mknod failed\n");
  else
    puts ("made a node\n");
  fd = open("console", 1);
  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);

  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");
  }
  //exec("echo", echo_args);
  exec("cat", cat_args);
  return 0;
}