1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
4 * Use is subject to license terms.
7 * This file is part of Lustre, http://www.lustre.org/
20 #include <sys/types.h>
25 int main(int argc, char **argv)
27 char *dname1, *dname2;
28 int fddir1, fddir2, rc;
31 if (argc < 2 || argc > 3) {
32 fprintf(stderr, "usage: %s dirname1 [dirname2]\n", argv[0]);
42 /* create the directory */
43 fprintf(stderr, "creating directory %s\n", dname1);
44 rc = mkdir(dname1, 0744);
46 fprintf(stderr, "creating %s fails: %s\n",
47 dname1, strerror(errno));
51 /* open the dir again */
52 fprintf(stderr, "opening directory\n");
53 fddir1 = open(dname1, O_RDONLY | O_DIRECTORY);
55 fprintf(stderr, "open %s fails: %s\n",
56 dname1, strerror(errno));
60 /* doesn't matter if the two dirs are the same?? */
61 fddir2 = open(dname2, O_RDONLY | O_DIRECTORY);
63 fprintf(stderr, "open %s fails: %s\n",
64 dname2, strerror(errno));
69 fprintf(stderr, "unlinking %s\n", dname1);
72 fprintf(stderr, "unlink %s error: %s\n",
73 dname1, strerror(errno));
77 if (access(dname2, F_OK) == 0) {
78 fprintf(stderr, "%s still exists\n", dname2);
82 if (access(dname1, F_OK) == 0) {
83 fprintf(stderr, "%s still exists\n", dname1);
88 rc = fchmod(fddir1, 0777);
90 fprintf(stderr, "fchmod unlinked dir fails %s\n",
95 /* fstat two dirs to check if they are the same */
96 rc = fstat(fddir1, &st1);
98 fprintf(stderr, "fstat unlinked dir %s fails %s\n",
99 dname1, strerror(errno));
103 rc = fstat(fddir2, &st2);
105 fprintf(stderr, "fstat dir %s fails %s\n",
106 dname2, strerror(errno));
110 if (st1.st_mode != st2.st_mode) { /* can we do this? */
111 fprintf(stderr, "fstat different value on %s and %s\n",
116 fprintf(stderr, "Ok, everything goes well.\n");