From 515805652e2b3975c269eb7df9e16349fa63c634 Mon Sep 17 00:00:00 2001 From: Erez Zadok Date: Wed, 27 Apr 2011 05:54:42 -0400 Subject: [PATCH] Regression: add chdir-open and rmdir-open test programs Signed-off-by: Erez Zadok --- progs/Makefile | 3 +- progs/chdir-open.c | 69 ++++++++++++++++++++++++++ progs/rmdir-open.c | 117 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 progs/chdir-open.c create mode 100644 progs/rmdir-open.c diff --git a/progs/Makefile b/progs/Makefile index bfcb5c1..54dedb6 100644 --- a/progs/Makefile +++ b/progs/Makefile @@ -19,7 +19,8 @@ CFLAGS=-g -Wall # -Werror # -lefence MOUNTPOINT=. BINS=open-unlink flock-copyup fsync truncate bug418 rmdircheckinode \ - creat-open rename mapper queryfile mapper2 ftruncate-unlink + creat-open rename mapper queryfile mapper2 ftruncate-unlink \ + rmdir-open chdir-open all: $(BINS) diff --git a/progs/chdir-open.c b/progs/chdir-open.c new file mode 100644 index 0000000..a169440 --- /dev/null +++ b/progs/chdir-open.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2003-2007 Erez Zadok + * Copyright (c) 2003-2007 Stony Brook University + * Copyright (c) 2003-2007 The Research Foundation of SUNY + * + * For specific licensing information, see the COPYING file distributed with + * this package. + * + * This Copyright notice must be kept intact and distributed with all sources. + */ + +#include +#include +#include +#include +#include +#include +#include +//#include +#include +#include +#include +#define O_LARGEFILE 00100000 +#define O_DIRECTORY 0200000 + +/* open a open dir chdir'd into */ +int main(int argc, char *argv[]) +{ + char *dir = argv[1]; + char *what2open = argv[2]; + int fd, ret = 0; + + if (argc != 3) { + fprintf(stderr, "Usage: %s dir what2open\n", argv[0]); + exit(1); + } + +#if 1 + // NO OOPS if I skip the chdir and open(dir) directly + /* chdir into the dir */ + ret = chdir(dir); + if (ret < 0) { + fprintf(stderr, "%s(%s): %s\n", dir, "chdir", strerror(errno)); + exit(1); + } +#endif +#if 1 + /* open the dir */ + // NO OOPS if I skip the chdir and open(dir) directly +// fd = open(dir, O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY); +// fd = open(".", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY); + // NO OOPS if I open(dir), but oops if I open(".") -- WTF + fd = open(what2open, O_RDONLY|O_DIRECTORY); + if (fd < 0) { + fprintf(stderr, "%s(%s): %s\n", ".", "open", strerror(errno)); + exit(1); + } +#endif +#if 1 + /* close the dir */ + ret = close(fd); + if (ret < 0) { + fprintf(stderr, "%s(%s): %s\n", ".", "close", strerror(errno)); + exit(1); + } +#endif + /* all's well */ + exit(0); +} diff --git a/progs/rmdir-open.c b/progs/rmdir-open.c new file mode 100644 index 0000000..eb321f9 --- /dev/null +++ b/progs/rmdir-open.c @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2003-2007 Erez Zadok + * Copyright (c) 2003-2007 Stony Brook University + * Copyright (c) 2003-2007 The Research Foundation of SUNY + * + * For specific licensing information, see the COPYING file distributed with + * this package. + * + * This Copyright notice must be kept intact and distributed with all sources. + */ + +#include +#include +#include +#include +#include +#include +#include +//#include +#include +#include +#include +#define O_LARGEFILE 00100000 +#define O_DIRECTORY 0200000 + +/* rmdir an open dir, which we're chdir'd into */ +int main(int argc, char *argv[]) +{ + char *dir = argv[1]; + struct stat sbuf; + struct dirent dent; + int fd, ret = 0; + + if (argc != 2) { + fprintf(stderr, "Usage: %s dir2remove\n", argv[0]); + exit(1); + } + +#if 0 + // NO DIFFERENCE -- STILL PANIC + /* try to unlink first -- should fail */ + ret = unlink(dir); + if (ret < 0) { + fprintf(stderr, "%s(%s): %s\n", dir, "unlink", strerror(errno)); + // exit(1); /* don't exit */ + } +#endif +#if 0 + // NO DIFFERENCE -- STILL PANIC + /* stat the dir */ + ret = lstat(dir, &sbuf); + if (ret < 0) { + fprintf(stderr, "%s(%s): %s\n", dir, "lstat1", strerror(errno)); + exit(1); + } +#endif +#if 1 + // NO OOPS if I skip the chdir and open(dir) directly + /* chdir into the dir */ + ret = chdir(dir); + if (ret < 0) { + fprintf(stderr, "%s(%s): %s\n", dir, "chdir", strerror(errno)); + exit(1); + } +#endif +#if 0 + // NO DIFFERENCE -- STILL PANIC + /* stat the cwd dir */ + ret = lstat(".", &sbuf); + if (ret < 0) { + fprintf(stderr, "%s(%s): %s\n", ".", "lstat2", strerror(errno)); + exit(1); + } +#endif +#if 1 + /* open the dir */ + // NO OOPS if I skip the chdir and open(dir) directly +// fd = open(dir, O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY); +// fd = open(".", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY); + fd = open(".", O_RDONLY|O_DIRECTORY); + if (fd < 0) { + fprintf(stderr, "%s(%s): %s\n", ".", "open", strerror(errno)); + exit(1); + } +#endif +#if 0 + // NO DIFFERENCE -- STILL PANIC EVEN IF I DONT READ THE DIR + /* read the dir */ + do { + ret = syscall(__NR_getdents, fd, &dent, 32768); + if (ret < 0) { + fprintf(stderr, "%s(%s): %s\n", ".", "getdent", strerror(errno)); + exit(1); + } + } while (ret == 0); +#endif +#if 1 + /* close the dir */ + ret = close(fd); + if (ret < 0) { + fprintf(stderr, "%s(%s): %s\n", ".", "close", strerror(errno)); + exit(1); + } +#endif +#if 0 + // NO DIFFERENCE -- STILL PANIC + /* rmdir the dir */ + ret = rmdir(dir); + if (ret < 0) { + fprintf(stderr, "%s(%s): %s\n", dir, "rmdir", strerror(errno)); + exit(1); + } +#endif + /* all's well */ + fprintf(stderr, "%s: removed successfully\n", dir); + exit(0); +} -- 2.43.0