summaryrefslogtreecommitdiff
path: root/userfs.c
blob: 56be4fc5b57470c05d1fd74be3245bd032611f32 (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
#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", 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);

  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;
}