Skip to content

Commit 7ed570b

Browse files
author
Jean-Pierre André
committed
Added support for testing mknod(2)
This is an adaptation of code from another branch by the same author
1 parent 8af5670 commit 7ed570b

File tree

2 files changed

+128
-1
lines changed

2 files changed

+128
-1
lines changed

fstest.c

+72-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*-
2-
* Copyright (c) 2006-2007 Pawel Jakub Dawidek <[email protected]>
2+
* Copyright (c) 2006-2010 Pawel Jakub Dawidek <[email protected]>
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -41,6 +41,8 @@
4141
#include <errno.h>
4242
#include <assert.h>
4343
#include <sys/types.h>
44+
#include <sys/socket.h>
45+
#include <sys/un.h>
4446
#include <utime.h>
4547
#ifdef HAS_ACL
4648
#include <sys/acl.h>
@@ -84,6 +86,9 @@ enum action {
8486
ACTION_STAT,
8587
ACTION_LSTAT,
8688
ACTION_UTIME,
89+
ACTION_BIND,
90+
ACTION_MKNOD,
91+
ACTION_MKNODAT,
8792
#ifdef HAS_ACL
8893
ACTION_GETFACL,
8994
ACTION_SETFACL,
@@ -93,6 +98,7 @@ enum action {
9398
#define TYPE_NONE 0x0000
9499
#define TYPE_STRING 0x0001
95100
#define TYPE_NUMBER 0x0002
101+
#define TYPE_DESCRIPTOR 0x0003
96102

97103
#define TYPE_OPTIONAL 0x0100
98104

@@ -114,6 +120,9 @@ static struct syscall_desc syscalls[] = {
114120
{ "symlink", ACTION_SYMLINK, { TYPE_STRING, TYPE_STRING, TYPE_NONE } },
115121
{ "rename", ACTION_RENAME, { TYPE_STRING, TYPE_STRING, TYPE_NONE } },
116122
{ "mkfifo", ACTION_MKFIFO, { TYPE_STRING, TYPE_NUMBER, TYPE_NONE } },
123+
{ "bind", ACTION_BIND, { TYPE_STRING, TYPE_NONE } },
124+
{ "mknod", ACTION_MKNOD, { TYPE_STRING, TYPE_STRING, TYPE_NUMBER, TYPE_NUMBER, TYPE_NUMBER, TYPE_NONE} },
125+
{ "mknodat", ACTION_MKNODAT, { TYPE_DESCRIPTOR, TYPE_STRING, TYPE_STRING, TYPE_NUMBER, TYPE_NUMBER, TYPE_NUMBER, TYPE_NONE} },
117126
{ "chmod", ACTION_CHMOD, { TYPE_STRING, TYPE_NUMBER, TYPE_NONE } },
118127
#ifdef HAS_LCHMOD
119128
{ "lchmod", ACTION_LCHMOD, { TYPE_STRING, TYPE_NUMBER, TYPE_NONE } },
@@ -320,6 +329,10 @@ show_stat(struct stat64 *sp, const char *what)
320329
printf("%lld", (long long)sp->st_mtime);
321330
else if (strcmp(what, "ctime") == 0)
322331
printf("%lld", (long long)sp->st_ctime);
332+
else if (strcmp(what, "major") == 0)
333+
printf("%u", (unsigned int)major(sp->st_rdev));
334+
else if (strcmp(what, "minor") == 0)
335+
printf("%u", (unsigned int)minor(sp->st_rdev));
323336
#ifdef HAS_CHFLAGS
324337
else if (strcmp(what, "flags") == 0)
325338
printf("%s", flags2str(chflags_flags, sp->st_flags));
@@ -670,6 +683,64 @@ call_syscall(struct syscall_desc *scall, char *argv[])
670683
exit(1);
671684
}
672685
break;
686+
case ACTION_BIND:
687+
{
688+
struct sockaddr_un sunx;
689+
690+
sunx.sun_family = AF_UNIX;
691+
strncpy(sunx.sun_path, STR(0), sizeof(sunx.sun_path) - 1);
692+
sunx.sun_path[sizeof(sunx.sun_path) - 1] = '\0';
693+
rval = socket(AF_UNIX, SOCK_STREAM, 0);
694+
if (rval < 0)
695+
break;
696+
rval = bind(rval, (struct sockaddr *)&sunx, sizeof(sunx));
697+
break;
698+
}
699+
case ACTION_MKNOD:
700+
case ACTION_MKNODAT:
701+
{
702+
mode_t ntype;
703+
dev_t dev;
704+
int fa;
705+
706+
switch (scall->sd_action) {
707+
case ACTION_MKNOD:
708+
fa = 0;
709+
break;
710+
case ACTION_MKNODAT:
711+
fa = 1;
712+
break;
713+
default:
714+
abort();
715+
}
716+
717+
dev = makedev(NUM(fa + 3), NUM(fa + 4));
718+
if (strcmp(STR(fa + 1), "c") == 0) /* character device */
719+
ntype = S_IFCHR;
720+
else if (strcmp(STR(fa + 1), "b") == 0) /* block device */
721+
ntype = S_IFBLK;
722+
else if (strcmp(STR(fa + 1), "f") == 0) /* fifo special */
723+
ntype = S_IFIFO;
724+
else if (strcmp(STR(fa + 1), "d") == 0) /* directory */
725+
ntype = S_IFDIR;
726+
else if (strcmp(STR(fa + 1), "o") == 0) /* regular file */
727+
ntype = S_IFREG;
728+
else {
729+
fprintf(stderr, "wrong argument 1\n");
730+
exit(1);
731+
}
732+
switch (scall->sd_action) {
733+
case ACTION_MKNOD:
734+
rval = mknod(STR(0), ntype | NUM(2), dev);
735+
break;
736+
case ACTION_MKNODAT:
737+
rval = mknodat(NUM(0), STR(1), ntype | NUM(3), dev);
738+
break;
739+
default:
740+
abort();
741+
}
742+
break;
743+
}
673744
#ifdef HAS_ACL
674745
case ACTION_GETFACL :
675746
rval = do_getfacl(STR(0), STR(1));

tests/misc.sh

100644100755
+56
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,59 @@ require()
141141
fi
142142
quick_exit
143143
}
144+
145+
# POSIX:
146+
# {NAME_MAX}
147+
# Maximum number of bytes in a filename (not including terminating null).
148+
namegen_max()
149+
{
150+
echo ${name_max}
151+
}
152+
153+
# POSIX:
154+
# {PATH_MAX}
155+
# Maximum number of bytes in a pathname, including the terminating null character.
156+
dirgen_max()
157+
{
158+
echo ${too_long} | cut -b -$((path_max_val-1))
159+
}
160+
161+
create_file() {
162+
type="${1}"
163+
name="${2}"
164+
165+
case "${type}" in
166+
none)
167+
return
168+
;;
169+
regular)
170+
expect 0 create ${name} 0644
171+
;;
172+
dir)
173+
expect 0 mkdir ${name} 0755
174+
;;
175+
fifo)
176+
expect 0 mkfifo ${name} 0644
177+
;;
178+
block)
179+
expect 0 mknod ${name} b 0644 1 2
180+
;;
181+
char)
182+
expect 0 mknod ${name} c 0644 1 2
183+
;;
184+
socket)
185+
expect 0 bind ${name}
186+
;;
187+
symlink)
188+
expect 0 symlink test ${name}
189+
;;
190+
esac
191+
if [ -n "${3}" -a -n "${4}" -a -n "${5}" ]; then
192+
expect 0 lchmod ${name} ${3}
193+
expect 0 lchown ${name} ${4} ${5}
194+
elif [ -n "${3}" -a -n "${4}" ]; then
195+
expect 0 lchown ${name} ${3} ${4}
196+
elif [ -n "${3}" ]; then
197+
expect 0 lchmod ${name} ${3}
198+
fi
199+
}

0 commit comments

Comments
 (0)