root/user/forphan.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 #include "kernel/types.h"
   2 #include "kernel/stat.h"
   3 #include "kernel/fcntl.h"
   4 #include "user/user.h"
   5 
   6 // Create an orphaned file and check if test-xv6.py recovers it.
   7 
   8 #define BUFSZ 500
   9 
  10 char buf[BUFSZ];
  11 
  12 int
  13 main(int argc, char **argv)
  14 {
  15   int fd = 0;
  16   char *s = argv[0];
  17   struct stat st;
  18   char *ff = "file0";
  19   
  20   if ((fd = open(ff, O_CREATE|O_WRONLY)) < 0) {
  21     printf("%s: open failed\n", s);
  22     exit(1);
  23   }
  24   if(fstat(fd, &st) < 0){
  25     fprintf(2, "%s: cannot stat %s\n", s, "ff");
  26     exit(1);
  27   }
  28   if (unlink(ff) < 0) {
  29     printf("%s: unlink failed\n", s);
  30     exit(1);
  31   }
  32   if (open(ff, O_RDONLY) != -1) {
  33     printf("%s: open successed\n", s);
  34     exit(1);
  35   }
  36   printf("wait for kill and reclaim %d\n", st.ino);
  37   // sit around until killed
  38   for(;;) pause(1000);
  39 }

/* [<][>][^][v][top][bottom][index][help] */