1 /* $NetBSD: t_nullpts.c,v 1.5 2011/01/10 11:11:04 hannken Exp $ */
16 #include <rump/rump.h>
17 #include <rump/rump_syscalls.h>
19 #include <fs/ptyfs/ptyfs.h>
20 #include <miscfs/nullfs/null.h>
22 #include "../../h_macros.h"
25 mountptyfs(const char *mp
, int flags
)
27 struct ptyfs_args args
;
29 if (rump_sys_mkdir(mp
, 0777) == -1) {
31 atf_tc_fail_errno("null create %s", mp
);
33 memset(&args
, 0, sizeof(args
));
34 args
.version
= PTYFS_ARGSVERSION
;
36 if (rump_sys_mount(MOUNT_PTYFS
, mp
, flags
, &args
, sizeof(args
)) == -1)
37 atf_tc_fail_errno("could not mount ptyfs");
41 mountnull(const char *what
, const char *mp
, int flags
)
43 struct null_args nargs
;
45 if (rump_sys_mkdir(what
, 0777) == -1) {
47 atf_tc_fail_errno("null create %s", what
);
49 if (rump_sys_mkdir(mp
, 0777) == -1) {
51 atf_tc_fail_errno("null create %s", mp
);
53 memset(&nargs
, 0, sizeof(nargs
));
54 nargs
.nulla_target
= __UNCONST(what
);
55 if (rump_sys_mount(MOUNT_NULL
, mp
, flags
, &nargs
, sizeof(nargs
)) == -1)
56 atf_tc_fail_errno("could not mount nullfs");
60 ATF_TC_HEAD(nullrevoke
, tc
)
62 atf_tc_set_md_var(tc
, "descr", "null mount ptyfs and revoke");
65 ATF_TC_BODY(nullrevoke
, tc
)
67 char path
[MAXPATHLEN
];
76 mountptyfs("/dev/pts", 0);
79 * null mount /dev/pts to /null/dev/pts
81 if (rump_sys_mkdir("/null", 0777) == -1) {
83 atf_tc_fail_errno("null create /null");
85 if (rump_sys_mkdir("/null/dev", 0777) == -1) {
87 atf_tc_fail_errno("null create /null/dev");
90 mountnull("/dev/pts", "/null/dev/pts", 0);
93 * get slave/master pair.
95 ptm
= rump_sys_open("/dev/ptm", O_RDWR
);
96 if (rump_sys_ioctl(ptm
, TIOCPTMGET
, &ptg
) == -1)
97 atf_tc_fail_errno("get pty");
100 * Build nullfs path to slave.
102 strcpy(path
, "/null");
103 strcat(path
, ptg
.sn
);
106 * Open slave tty via nullfs.
108 if (rump_sys_open(path
, O_RDWR
) == -1)
109 atf_tc_fail_errno("slave null open");
112 * Close slave opened with /dev/ptm. Need purely non-null refs to it.
114 rump_sys_close(ptg
.sfd
);
116 /* revoke slave tty. */
117 rump_sys_revoke(path
);
125 ATF_TP_ADD_TC(tp
, nullrevoke
);
127 return atf_no_error();