Remove building with NOCRYPTO option
[minix3.git] / tests / fs / ptyfs / t_nullpts.c
blob9265f32ffa0a1d622610bffdedd472140efb1d03
1 /* $NetBSD: t_nullpts.c,v 1.5 2011/01/10 11:11:04 hannken Exp $ */
3 #include <sys/types.h>
4 #include <sys/mount.h>
5 #include <sys/ioctl.h>
7 #include <atf-c.h>
8 #include <err.h>
9 #include <errno.h>
10 #include <fcntl.h>
11 #include <stdio.h>
12 #include <unistd.h>
13 #include <string.h>
14 #include <stdlib.h>
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"
24 static void
25 mountptyfs(const char *mp, int flags)
27 struct ptyfs_args args;
29 if (rump_sys_mkdir(mp, 0777) == -1) {
30 if (errno != EEXIST)
31 atf_tc_fail_errno("null create %s", mp);
33 memset(&args, 0, sizeof(args));
34 args.version = PTYFS_ARGSVERSION;
35 args.mode = 0777;
36 if (rump_sys_mount(MOUNT_PTYFS, mp, flags, &args, sizeof(args)) == -1)
37 atf_tc_fail_errno("could not mount ptyfs");
40 static void
41 mountnull(const char *what, const char *mp, int flags)
43 struct null_args nargs;
45 if (rump_sys_mkdir(what, 0777) == -1) {
46 if (errno != EEXIST)
47 atf_tc_fail_errno("null create %s", what);
49 if (rump_sys_mkdir(mp, 0777) == -1) {
50 if (errno != EEXIST)
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");
59 ATF_TC(nullrevoke);
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];
68 struct ptmget ptg;
69 int ptm;
71 rump_init();
74 * mount /dev/pts
76 mountptyfs("/dev/pts", 0);
79 * null mount /dev/pts to /null/dev/pts
81 if (rump_sys_mkdir("/null", 0777) == -1) {
82 if (errno != EEXIST)
83 atf_tc_fail_errno("null create /null");
85 if (rump_sys_mkdir("/null/dev", 0777) == -1) {
86 if (errno != EEXIST)
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);
119 /* done */
122 ATF_TP_ADD_TCS(tp)
125 ATF_TP_ADD_TC(tp, nullrevoke);
127 return atf_no_error();