Remove building with NOCRYPTO option
[minix.git] / tests / fs / umapfs / t_basic.c
blob259f6fe8c11bc266a91ff027d858ec697a4e01f2
1 /* $NetBSD: t_basic.c,v 1.4 2010/07/19 15:35:39 pooka Exp $ */
3 #include <sys/types.h>
4 #include <sys/param.h>
5 #include <sys/mount.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>
18 #include <rump/rumpvfs_if_pub.h>
20 #include <fs/tmpfs/tmpfs_args.h>
21 #include <miscfs/umapfs/umap.h>
23 #include "../../h_macros.h"
25 ATF_TC(basic);
26 ATF_TC_HEAD(basic, tc)
28 atf_tc_set_md_var(tc, "descr", "basic umapfs mapping");
31 static void
32 xtouch(const char *path)
34 int fd;
36 fd = rump_sys_open(path, O_CREAT | O_RDWR, 0777);
37 if (fd == -1)
38 atf_tc_fail_errno("create %s", path);
39 rump_sys_close(fd);
42 static void
43 xchown(const char *path, uid_t uid, gid_t gid)
46 if (rump_sys_chown(path, uid, gid) == -1)
47 atf_tc_fail_errno("chown %s failed", path);
50 static void
51 testuidgid(const char *path, uid_t uid, gid_t gid)
53 struct stat sb;
55 if (rump_sys_stat(path, &sb) == -1)
56 atf_tc_fail_errno("stat %s", path);
57 if (uid != (uid_t)-1) {
58 if (sb.st_uid != uid)
59 atf_tc_fail("%s: expected uid %d, got %d",
60 path, uid, sb.st_uid);
62 if (gid != (gid_t)-1) {
63 if (sb.st_gid != gid)
64 atf_tc_fail("%s: expected gid %d, got %d",
65 path, gid, sb.st_gid);
69 ATF_TC_BODY(basic, tc)
71 struct umap_args umargs;
72 struct tmpfs_args targs;
73 u_long umaps[2][2];
74 u_long gmaps[2][2];
76 rump_init();
77 if (rump_sys_mkdir("/td1", 0777) == -1)
78 atf_tc_fail_errno("mp1");
79 if (rump_sys_mkdir("/td2", 0777) == -1)
80 atf_tc_fail_errno("mp1");
82 /* use tmpfs because rumpfs doesn't support ownership */
83 memset(&targs, 0, sizeof(targs));
84 targs.ta_version = TMPFS_ARGS_VERSION;
85 targs.ta_root_mode = 0777;
86 if (rump_sys_mount(MOUNT_TMPFS, "/td1", 0, &targs, sizeof(targs)) == -1)
87 atf_tc_fail_errno("could not mount tmpfs td1");
89 memset(&umargs, 0, sizeof(umargs));
92 * Map td1 uid 555 to td2 uid 777 (yes, IMHO the umapfs
93 * mapping format is counter-intuitive).
95 umaps[0][0] = 777;
96 umaps[0][1] = 555;
97 umaps[1][0] = 0;
98 umaps[1][1] = 0;
99 gmaps[0][0] = 4321;
100 gmaps[0][1] = 1234;
101 gmaps[1][0] = 0;
102 gmaps[1][1] = 0;
104 umargs.umap_target = __UNCONST("/td1");
105 umargs.nentries = 2;
106 umargs.gnentries = 2;
107 umargs.mapdata = umaps;
108 umargs.gmapdata = gmaps;
110 if (rump_sys_mount(MOUNT_UMAP, "/td2", 0, &umargs,sizeof(umargs)) == -1)
111 atf_tc_fail_errno("could not mount umapfs");
113 xtouch("/td1/noch");
114 testuidgid("/td1/noch", 0, 0);
115 testuidgid("/td2/noch", 0, 0);
117 xtouch("/td1/nomap");
118 xchown("/td1/nomap", 1, 2);
119 testuidgid("/td1/nomap", 1, 2);
120 testuidgid("/td2/nomap", -1, -1);
122 xtouch("/td1/forwmap");
123 xchown("/td1/forwmap", 555, 1234);
124 testuidgid("/td1/forwmap", 555, 1234);
125 testuidgid("/td2/forwmap", 777, 4321);
128 * this *CANNOT* be correct???
130 xtouch("/td1/revmap");
132 * should be 777 / 4321 (?), but makes first test fail since
133 * it gets 777 / 4321, i.e. unmapped results.
135 xchown("/td2/revmap", 555, 1234);
136 testuidgid("/td1/revmap", 555, 1234);
137 testuidgid("/td2/revmap", 777, 4321);
141 ATF_TP_ADD_TCS(tp)
143 ATF_TP_ADD_TC(tp, basic);
144 return 0; /*XXX?*/