Whamcloud - gitweb
file loop-sync-2.4.21-suse.patch was initially added on branch b1_2_smallfix.
[fs/lustre-release.git] / lustre / tests / openfilleddirunlink.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  */
4
5 /* for O_DIRECTORY */
6 #define _GNU_SOURCE
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <errno.h>
12 #include <fcntl.h>
13 #include <sys/types.h>
14 #include <sys/stat.h>
15 #include <dirent.h>
16 #include <string.h>
17
18 char fname[1024];
19
20
21 int main(int argc, char **argv)
22 {
23         char *dname1;
24         int fddir1, rc;
25         int fd;
26
27         if (argc != 2) {
28                 fprintf(stderr, "usage: %s dirname1\n", argv[0]);
29                 exit(1);
30         }
31
32         dname1 = argv[1];
33
34         //create the directory
35         fprintf(stderr, "creating directory %s\n", dname1);
36         rc = mkdir(dname1, 0744);
37         if (rc == -1) {
38                 fprintf(stderr, "creating %s fails: %s\n",
39                         dname1, strerror(errno));
40                 exit(1);
41         }
42
43         sprintf(fname, "%s/0", dname1);
44         fprintf(stderr, "creating file %s\n", fname);
45         fd = creat(fname, 0666);
46         if (fd < 0) {
47                 fprintf(stderr, "creation %s fails: %s\n",
48                         fname, strerror(errno));
49                 exit(1);
50         }
51         close(fd);
52
53         // open the dir again
54         fprintf(stderr, "opening directory\n");
55         fddir1 = open(dname1, O_RDONLY | O_DIRECTORY);
56         if (fddir1 == -1) {
57                 fprintf(stderr, "open %s fails: %s\n",
58                         dname1, strerror(errno));
59                 exit(1);
60         }
61
62         // delete the dir
63         fprintf(stderr, "unlinking %s\n", dname1);
64         rc = rmdir(dname1);
65         if (rc == 0) {
66                 fprintf(stderr, "unlinked non-empty %s successfully\n",
67                         dname1);
68                 exit(1);
69         }
70
71         if (access(dname1, F_OK) != 0){
72                 fprintf(stderr, "can't access %s: %s\n",
73                         dname1, strerror(errno));
74                 exit(1);
75         }
76
77         fprintf(stderr, "Ok, everything goes well.\n");
78         return 0;
79 }