user/forphan.c
39 lines
1#include "kernel/types.h"2#include "kernel/stat.h"3#include "kernel/fcntl.h"4#include "user/user.h"56// Create an orphaned file and check if test-xv6.py recovers it.78#define BUFSZ 500910char buf[BUFSZ];1112int13main(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 killed38 for(;;) pause(1000);39}40