t_vfsops.c revision 1.3 1 1.3 njoly /* $NetBSD: t_vfsops.c,v 1.3 2010/07/16 17:49:38 njoly Exp $ */
2 1.1 pooka
3 1.1 pooka /*-
4 1.1 pooka * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 1.1 pooka * All rights reserved.
6 1.1 pooka *
7 1.1 pooka * Redistribution and use in source and binary forms, with or without
8 1.1 pooka * modification, are permitted provided that the following conditions
9 1.1 pooka * are met:
10 1.1 pooka * 1. Redistributions of source code must retain the above copyright
11 1.1 pooka * notice, this list of conditions and the following disclaimer.
12 1.1 pooka * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 pooka * notice, this list of conditions and the following disclaimer in the
14 1.1 pooka * documentation and/or other materials provided with the distribution.
15 1.1 pooka *
16 1.1 pooka * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.1 pooka * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.1 pooka * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.1 pooka * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.1 pooka * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.1 pooka * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.1 pooka * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.1 pooka * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.1 pooka * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.1 pooka * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 pooka * POSSIBILITY OF SUCH DAMAGE.
27 1.1 pooka */
28 1.1 pooka
29 1.1 pooka #include <sys/stat.h>
30 1.1 pooka #include <sys/statvfs.h>
31 1.1 pooka
32 1.1 pooka #include <atf-c.h>
33 1.2 pooka #include <fcntl.h>
34 1.1 pooka #include <unistd.h>
35 1.1 pooka
36 1.1 pooka #include <rump/rump_syscalls.h>
37 1.1 pooka #include <rump/rump.h>
38 1.1 pooka
39 1.1 pooka #include "../common/h_fsmacros.h"
40 1.1 pooka #include "../../h_macros.h"
41 1.1 pooka
42 1.1 pooka static void
43 1.1 pooka tmount(const atf_tc_t *tc, const char *path)
44 1.1 pooka {
45 1.1 pooka
46 1.1 pooka return;
47 1.1 pooka }
48 1.1 pooka
49 1.1 pooka static void
50 1.1 pooka tstatvfs(const atf_tc_t *tc, const char *path)
51 1.1 pooka {
52 1.3 njoly const char *fstype = atf_tc_get_md_var(tc, "X-fs.type");
53 1.1 pooka struct statvfs svb;
54 1.1 pooka
55 1.1 pooka if (rump_sys_statvfs1(path, &svb, ST_WAIT) == -1)
56 1.1 pooka atf_tc_fail_errno("statvfs");
57 1.3 njoly
58 1.3 njoly ATF_REQUIRE(svb.f_namemax > 0 && svb.f_namemax <= MAXNAMLEN);
59 1.3 njoly if (!FSTYPE_PUFFS(tc))
60 1.3 njoly ATF_REQUIRE_STREQ(svb.f_fstypename, fstype);
61 1.3 njoly ATF_REQUIRE_STREQ(svb.f_mntonname, path);
62 1.1 pooka }
63 1.1 pooka
64 1.1 pooka static void
65 1.1 pooka tsync(const atf_tc_t *tc, const char *path)
66 1.1 pooka {
67 1.1 pooka
68 1.1 pooka rump_sys_sync();
69 1.1 pooka }
70 1.1 pooka
71 1.1 pooka #define MAGICSTR "just a string, I like A"
72 1.1 pooka static void
73 1.1 pooka tfilehandle(const atf_tc_t *tc, const char *path)
74 1.1 pooka {
75 1.1 pooka char fpath[MAXPATHLEN];
76 1.1 pooka char buf[sizeof(MAGICSTR)];
77 1.1 pooka size_t fhsize;
78 1.1 pooka void *fhp;
79 1.1 pooka int fd;
80 1.1 pooka
81 1.1 pooka sprintf(fpath, "%s/file", path);
82 1.1 pooka fd = rump_sys_open(fpath, O_RDWR | O_CREAT, 0777);
83 1.1 pooka if (fd == -1)
84 1.1 pooka atf_tc_fail_errno("open");
85 1.1 pooka
86 1.1 pooka if (rump_sys_write(fd, MAGICSTR, sizeof(MAGICSTR)) != sizeof(MAGICSTR))
87 1.1 pooka atf_tc_fail("write to file");
88 1.1 pooka rump_sys_close(fd);
89 1.1 pooka
90 1.1 pooka /*
91 1.1 pooka * Get file handle size.
92 1.1 pooka * This also weeds out unsupported file systems.
93 1.1 pooka */
94 1.1 pooka fhsize = 0;
95 1.1 pooka if (rump_sys_getfh(fpath, NULL, &fhsize) == -1) {
96 1.1 pooka if (errno == EOPNOTSUPP) {
97 1.1 pooka atf_tc_skip("file handles not supported");
98 1.1 pooka } else if (errno != E2BIG) {
99 1.1 pooka atf_tc_fail_errno("getfh size");
100 1.1 pooka }
101 1.1 pooka }
102 1.1 pooka
103 1.1 pooka fhp = malloc(fhsize);
104 1.1 pooka if (rump_sys_getfh(fpath, fhp, &fhsize) == -1)
105 1.1 pooka atf_tc_fail_errno("getfh");
106 1.1 pooka
107 1.1 pooka /* open file based on file handle */
108 1.1 pooka fd = rump_sys_fhopen(fhp, fhsize, O_RDONLY);
109 1.1 pooka if (FSTYPE_TMPFS(tc)) {
110 1.1 pooka atf_tc_expect_fail("PR kern/43605");
111 1.1 pooka if (fd != -1 || errno != EINVAL)
112 1.1 pooka atf_tc_expect_pass();
113 1.1 pooka }
114 1.1 pooka if (fd == -1) {
115 1.1 pooka atf_tc_fail_errno("fhopen");
116 1.1 pooka }
117 1.1 pooka
118 1.1 pooka /* check that we got the same file */
119 1.1 pooka if (rump_sys_read(fd, buf, sizeof(buf)) != sizeof(MAGICSTR))
120 1.1 pooka atf_tc_fail("read fhopened file");
121 1.1 pooka
122 1.1 pooka ATF_REQUIRE_STREQ(buf, MAGICSTR);
123 1.1 pooka
124 1.1 pooka rump_sys_close(fd);
125 1.1 pooka }
126 1.1 pooka
127 1.1 pooka ATF_TC_FSAPPLY(tmount, "mount/unmount");
128 1.1 pooka ATF_TC_FSAPPLY(tstatvfs, "statvfs");
129 1.1 pooka ATF_TC_FSAPPLY(tsync, "sync");
130 1.1 pooka ATF_TC_FSAPPLY(tfilehandle, "file handles");
131 1.1 pooka
132 1.1 pooka ATF_TP_ADD_TCS(tp)
133 1.1 pooka {
134 1.1 pooka
135 1.1 pooka ATF_TP_FSAPPLY(tmount);
136 1.1 pooka ATF_TP_FSAPPLY(tstatvfs);
137 1.1 pooka ATF_TP_FSAPPLY(tsync);
138 1.1 pooka ATF_TP_FSAPPLY(tfilehandle);
139 1.1 pooka
140 1.1 pooka return atf_no_error();
141 1.1 pooka }
142