Boot-to-ramdisk image generation scripts
[minix3.git] / tests / fs / vfs / t_vfsops.c
blob1bcee89e573d384fd6cdc41b21887b8692090c09
1 /* $NetBSD: t_vfsops.c,v 1.11 2011/04/04 19:16:58 hannken Exp $ */
3 /*-
4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/stat.h>
30 #include <sys/statvfs.h>
32 #include <atf-c.h>
33 #include <dirent.h>
34 #include <fcntl.h>
35 #include <stdlib.h>
36 #include <unistd.h>
38 #include <rump/rump_syscalls.h>
39 #include <rump/rump.h>
41 #include "../common/h_fsmacros.h"
42 #include "../../h_macros.h"
44 static void
45 tmount(const atf_tc_t *tc, const char *path)
48 return;
51 static void
52 tstatvfs(const atf_tc_t *tc, const char *path)
54 const char *fstype = atf_tc_get_md_var(tc, "X-fs.mntname");
55 struct statvfs svb;
57 if (rump_sys_statvfs1(path, &svb, ST_WAIT) == -1)
58 atf_tc_fail_errno("statvfs");
60 ATF_REQUIRE(svb.f_namemax > 0 && svb.f_namemax <= MAXNAMLEN);
61 if (!(FSTYPE_PUFFS(tc) || FSTYPE_P2K_FFS(tc)))
62 ATF_REQUIRE_STREQ(svb.f_fstypename, fstype);
63 ATF_REQUIRE_STREQ(svb.f_mntonname, path);
66 static void
67 tsync(const atf_tc_t *tc, const char *path)
70 rump_sys_sync();
73 #define MAGICSTR "just a string, I like A"
74 static void
75 tfilehandle(const atf_tc_t *tc, const char *path)
77 char fpath[MAXPATHLEN];
78 char buf[sizeof(MAGICSTR)];
79 size_t fhsize;
80 void *fhp;
81 int fd;
83 sprintf(fpath, "%s/file", path);
84 fd = rump_sys_open(fpath, O_RDWR | O_CREAT, 0777);
85 if (fd == -1)
86 atf_tc_fail_errno("open");
88 if (rump_sys_write(fd, MAGICSTR, sizeof(MAGICSTR)) != sizeof(MAGICSTR))
89 atf_tc_fail("write to file");
90 rump_sys_close(fd);
93 * Get file handle size.
94 * This also weeds out unsupported file systems.
96 fhsize = 0;
97 if (rump_sys_getfh(fpath, NULL, &fhsize) == -1) {
98 if (errno == EOPNOTSUPP) {
99 atf_tc_skip("file handles not supported");
100 } else if (errno != E2BIG) {
101 atf_tc_fail_errno("getfh size");
105 fhp = malloc(fhsize);
106 if (rump_sys_getfh(fpath, fhp, &fhsize) == -1)
107 atf_tc_fail_errno("getfh");
109 /* open file based on file handle */
110 fd = rump_sys_fhopen(fhp, fhsize, O_RDONLY);
111 if (fd == -1) {
112 atf_tc_fail_errno("fhopen");
115 /* check that we got the same file */
116 if (rump_sys_read(fd, buf, sizeof(buf)) != sizeof(MAGICSTR))
117 atf_tc_fail("read fhopened file");
119 ATF_REQUIRE_STREQ(buf, MAGICSTR);
121 rump_sys_close(fd);
124 #define FNAME "a_file"
125 static void
126 tfhremove(const atf_tc_t *tc, const char *path)
128 size_t fhsize;
129 void *fhp;
130 int fd;
132 RL(rump_sys_chdir(path));
133 RL(fd = rump_sys_open(FNAME, O_RDWR | O_CREAT, 0777));
134 RL(rump_sys_close(fd));
136 fhsize = 0;
137 if (rump_sys_getfh(FNAME, NULL, &fhsize) == -1) {
138 if (errno == EOPNOTSUPP) {
139 atf_tc_skip("file handles not supported");
140 } else if (errno != E2BIG) {
141 atf_tc_fail_errno("getfh size");
145 fhp = malloc(fhsize);
146 RL(rump_sys_getfh(FNAME, fhp, &fhsize));
147 RL(rump_sys_unlink(FNAME));
149 if (FSTYPE_LFS(tc))
150 atf_tc_expect_fail("fhopen() for removed file succeeds "
151 "(PR kern/43745)");
152 ATF_REQUIRE_ERRNO(ESTALE, rump_sys_fhopen(fhp, fhsize, O_RDONLY) == -1);
153 atf_tc_expect_pass();
155 RL(rump_sys_chdir("/"));
157 #undef FNAME
160 * This test only checks the file system doesn't crash. We *might*
161 * try a valid file handle.
163 static void
164 tfhinval(const atf_tc_t *tc, const char *path)
166 size_t fhsize;
167 void *fhp;
168 unsigned long seed;
169 int fd;
171 srandom(seed = time(NULL));
172 printf("RNG seed %lu\n", seed);
174 RL(rump_sys_chdir(path));
175 fhsize = 0;
176 if (rump_sys_getfh(".", NULL, &fhsize) == -1) {
177 if (errno == EOPNOTSUPP) {
178 atf_tc_skip("file handles not supported");
179 } else if (errno != E2BIG) {
180 atf_tc_fail_errno("getfh size");
184 fhp = malloc(fhsize);
185 tests_makegarbage(fhp, fhsize);
186 fd = rump_sys_fhopen(fhp, fhsize, O_RDWR);
187 if (fd != -1)
188 rump_sys_close(fd);
190 RL(rump_sys_chdir("/"));
193 ATF_TC_FSAPPLY(tmount, "mount/unmount");
194 ATF_TC_FSAPPLY(tstatvfs, "statvfs");
195 ATF_TC_FSAPPLY(tsync, "sync");
196 ATF_TC_FSAPPLY(tfilehandle, "file handles");
197 ATF_TC_FSAPPLY(tfhremove, "fhtovp for removed file");
198 ATF_TC_FSAPPLY(tfhinval, "fhopen invalid filehandle");
200 ATF_TP_ADD_TCS(tp)
203 ATF_TP_FSAPPLY(tmount);
204 ATF_TP_FSAPPLY(tstatvfs);
205 ATF_TP_FSAPPLY(tsync);
206 ATF_TP_FSAPPLY(tfilehandle);
207 ATF_TP_FSAPPLY(tfhremove);
208 ATF_TP_FSAPPLY(tfhinval);
210 return atf_no_error();