t_vfsops.c revision 1.2 1 /* $NetBSD: t_vfsops.c,v 1.2 2010/07/13 11:53:47 pooka Exp $ */
2
3 /*-
4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
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.
15 *
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.
27 */
28
29 #include <sys/stat.h>
30 #include <sys/statvfs.h>
31
32 #include <atf-c.h>
33 #include <fcntl.h>
34 #include <unistd.h>
35
36 #include <rump/rump_syscalls.h>
37 #include <rump/rump.h>
38
39 #include "../common/h_fsmacros.h"
40 #include "../../h_macros.h"
41
42 static void
43 tmount(const atf_tc_t *tc, const char *path)
44 {
45
46 return;
47 }
48
49 static void
50 tstatvfs(const atf_tc_t *tc, const char *path)
51 {
52 struct statvfs svb;
53
54 if (rump_sys_statvfs1(path, &svb, ST_WAIT) == -1)
55 atf_tc_fail_errno("statvfs");
56 }
57
58 static void
59 tsync(const atf_tc_t *tc, const char *path)
60 {
61
62 rump_sys_sync();
63 }
64
65 #define MAGICSTR "just a string, I like A"
66 static void
67 tfilehandle(const atf_tc_t *tc, const char *path)
68 {
69 char fpath[MAXPATHLEN];
70 char buf[sizeof(MAGICSTR)];
71 size_t fhsize;
72 void *fhp;
73 int fd;
74
75 sprintf(fpath, "%s/file", path);
76 fd = rump_sys_open(fpath, O_RDWR | O_CREAT, 0777);
77 if (fd == -1)
78 atf_tc_fail_errno("open");
79
80 if (rump_sys_write(fd, MAGICSTR, sizeof(MAGICSTR)) != sizeof(MAGICSTR))
81 atf_tc_fail("write to file");
82 rump_sys_close(fd);
83
84 /*
85 * Get file handle size.
86 * This also weeds out unsupported file systems.
87 */
88 fhsize = 0;
89 if (rump_sys_getfh(fpath, NULL, &fhsize) == -1) {
90 if (errno == EOPNOTSUPP) {
91 atf_tc_skip("file handles not supported");
92 } else if (errno != E2BIG) {
93 atf_tc_fail_errno("getfh size");
94 }
95 }
96
97 fhp = malloc(fhsize);
98 if (rump_sys_getfh(fpath, fhp, &fhsize) == -1)
99 atf_tc_fail_errno("getfh");
100
101 /* open file based on file handle */
102 fd = rump_sys_fhopen(fhp, fhsize, O_RDONLY);
103 if (FSTYPE_TMPFS(tc)) {
104 atf_tc_expect_fail("PR kern/43605");
105 if (fd != -1 || errno != EINVAL)
106 atf_tc_expect_pass();
107 }
108 if (fd == -1) {
109 atf_tc_fail_errno("fhopen");
110 }
111
112 /* check that we got the same file */
113 if (rump_sys_read(fd, buf, sizeof(buf)) != sizeof(MAGICSTR))
114 atf_tc_fail("read fhopened file");
115
116 ATF_REQUIRE_STREQ(buf, MAGICSTR);
117
118 rump_sys_close(fd);
119 }
120
121 ATF_TC_FSAPPLY(tmount, "mount/unmount");
122 ATF_TC_FSAPPLY(tstatvfs, "statvfs");
123 ATF_TC_FSAPPLY(tsync, "sync");
124 ATF_TC_FSAPPLY(tfilehandle, "file handles");
125
126 ATF_TP_ADD_TCS(tp)
127 {
128
129 ATF_TP_FSAPPLY(tmount);
130 ATF_TP_FSAPPLY(tstatvfs);
131 ATF_TP_FSAPPLY(tsync);
132 ATF_TP_FSAPPLY(tfilehandle);
133
134 return atf_no_error();
135 }
136