From ce29a12f91f44ec315d5a136c7d616639d699ae0 Mon Sep 17 00:00:00 2001 From: Pawel Jakub Dawidek Date: Fri, 6 Aug 2010 20:48:10 +0000 Subject: [PATCH] Add mknod(2) support. Submitted by: Jan Senolt Submitted by: Milan Cermak --- tools/regression/fstest/fstest.c | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tools/regression/fstest/fstest.c b/tools/regression/fstest/fstest.c index 04ccbb34522a..976ad8b27d18 100644 --- a/tools/regression/fstest/fstest.c +++ b/tools/regression/fstest/fstest.c @@ -27,9 +27,13 @@ */ #include +#include #include #include #include +#ifndef makedev +#include +#endif #include #include @@ -66,6 +70,7 @@ enum action { ACTION_SYMLINK, ACTION_RENAME, ACTION_MKFIFO, + ACTION_MKNOD, ACTION_BIND, ACTION_CONNECT, ACTION_CHMOD, @@ -115,6 +120,7 @@ static struct syscall_desc syscalls[] = { { "symlink", ACTION_SYMLINK, { TYPE_STRING, TYPE_STRING, TYPE_NONE } }, { "rename", ACTION_RENAME, { TYPE_STRING, TYPE_STRING, TYPE_NONE } }, { "mkfifo", ACTION_MKFIFO, { TYPE_STRING, TYPE_NUMBER, TYPE_NONE } }, + { "mknod", ACTION_MKNOD, { TYPE_STRING, TYPE_STRING, TYPE_NUMBER, TYPE_NUMBER, TYPE_NUMBER, TYPE_NONE} }, { "bind", ACTION_BIND, { TYPE_STRING, TYPE_NONE } }, { "connect", ACTION_CONNECT, { TYPE_STRING, TYPE_NONE } }, { "chmod", ACTION_CHMOD, { TYPE_STRING, TYPE_NUMBER, TYPE_NONE } }, @@ -359,6 +365,10 @@ show_stat(struct stat64 *sp, const char *what) else if (strcmp(what, "flags") == 0) printf("%s", flags2str(chflags_flags, (long long)sp->st_flags)); #endif + else if (strcmp(what, "major") == 0) + printf("%u", (unsigned int)major(sp->st_rdev)); + else if (strcmp(what, "minor") == 0) + printf("%u", (unsigned int)minor(sp->st_rdev)); else if (strcmp(what, "type") == 0) { switch (sp->st_mode & S_IFMT) { case S_IFIFO: @@ -503,6 +513,29 @@ call_syscall(struct syscall_desc *scall, char *argv[]) case ACTION_MKFIFO: rval = mkfifo(STR(0), (mode_t)NUM(1)); break; + case ACTION_MKNOD: + { + mode_t ntype; + dev_t dev; + + dev = makedev(NUM(3), NUM(4)); + if (strcmp(STR(1), "c") == 0) /* character device */ + ntype = S_IFCHR; + else if (strcmp(STR(1), "b") == 0) /* block device */ + ntype = S_IFBLK; + else if (strcmp(STR(1), "f") == 0) /* fifo special */ + ntype = S_IFIFO; + else if (strcmp(STR(1), "d") == 0) /* directory */ + ntype = S_IFDIR; + else if (strcmp(STR(1), "o") == 0) /* regular file */ + ntype = S_IFREG; + else { + fprintf(stderr, "wrong argument 1\n"); + exit(1); + } + rval = mknod(STR(0), ntype | NUM(2), dev); + break; + } case ACTION_BIND: { struct sockaddr_un sun;