2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2019 The FreeBSD Foundation
6 * This software was developed by BFF Storage Systems, LLC under sponsorship
7 * from the FreeBSD Foundation.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/param.h>
33 #include <sys/mount.h>
39 using namespace testing;
41 class Statfs: public FuseTest {};
45 struct statfs statbuf;
47 EXPECT_CALL(*m_mock, process(
48 ResultOf([](auto in) {
49 return (in->header.opcode == FUSE_STATFS);
52 ).WillOnce(Invoke(ReturnErrno(EIO)));
54 ASSERT_NE(0, statfs("mountpoint", &statbuf));
55 ASSERT_EQ(EIO, errno);
59 * When the daemon is dead but the filesystem is still mounted, fuse(4) fakes
60 * the statfs(2) response, which is necessary for unmounting.
62 TEST_F(Statfs, enotconn)
64 struct statfs statbuf;
67 m_mock->kill_daemon();
69 ASSERT_NE(NULL, getcwd(mp, PATH_MAX)) << strerror(errno);
70 strlcat(mp, "/mountpoint", PATH_MAX);
71 ASSERT_EQ(0, statfs("mountpoint", &statbuf)) << strerror(errno);
73 EXPECT_EQ(getuid(), statbuf.f_owner);
74 EXPECT_EQ(0, strcmp("fusefs", statbuf.f_fstypename));
75 EXPECT_EQ(0, strcmp("/dev/fuse", statbuf.f_mntfromname));
76 EXPECT_EQ(0, strcmp(mp, statbuf.f_mntonname));
81 struct statfs statbuf;
84 EXPECT_CALL(*m_mock, process(
85 ResultOf([](auto in) {
86 return (in->header.opcode == FUSE_STATFS);
89 ).WillOnce(Invoke(ReturnImmediate([=](auto in __unused, auto out) {
90 SET_OUT_HEADER_LEN(out, statfs);
91 out->body.statfs.st.blocks = 1000;
92 out->body.statfs.st.bfree = 100;
93 out->body.statfs.st.bavail = 200;
94 out->body.statfs.st.files = 5;
95 out->body.statfs.st.ffree = 6;
96 out->body.statfs.st.namelen = 128;
97 out->body.statfs.st.frsize = 1024;
100 ASSERT_NE(NULL, getcwd(mp, PATH_MAX)) << strerror(errno);
101 strlcat(mp, "/mountpoint", PATH_MAX);
102 ASSERT_EQ(0, statfs("mountpoint", &statbuf)) << strerror(errno);
103 EXPECT_EQ(1024ul, statbuf.f_bsize);
105 * fuse(4) ignores the filesystem's reported optimal transfer size, and
106 * chooses a size that works well with the rest of the system instead
108 EXPECT_EQ(1000ul, statbuf.f_blocks);
109 EXPECT_EQ(100ul, statbuf.f_bfree);
110 EXPECT_EQ(200l, statbuf.f_bavail);
111 EXPECT_EQ(5ul, statbuf.f_files);
112 EXPECT_EQ(6l, statbuf.f_ffree);
113 EXPECT_EQ(128u, statbuf.f_namemax);
114 EXPECT_EQ(getuid(), statbuf.f_owner);
115 EXPECT_EQ(0, strcmp("fusefs", statbuf.f_fstypename));
116 EXPECT_EQ(0, strcmp("/dev/fuse", statbuf.f_mntfromname));
117 EXPECT_EQ(0, strcmp(mp, statbuf.f_mntonname));