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