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
39 using namespace testing;
41 class Opendir: public FuseTest {
43 void expect_lookup(const char *relpath, uint64_t ino)
45 FuseTest::expect_lookup(relpath, ino, S_IFDIR | 0755, 0, 1);
51 * The fuse daemon fails the request with enoent. This usually indicates a
52 * race condition: some other FUSE client removed the file in between when the
53 * kernel checked for it with lookup and tried to open it
55 TEST_F(Opendir, enoent)
57 const char FULLPATH[] = "mountpoint/some_dir";
58 const char RELPATH[] = "some_dir";
61 expect_lookup(RELPATH, ino);
63 EXPECT_CALL(*m_mock, process(
64 ResultOf([=](auto in) {
65 return (in->header.opcode == FUSE_OPENDIR &&
66 in->header.nodeid == ino);
69 ).WillOnce(Invoke(ReturnErrno(ENOENT)));
70 EXPECT_NE(0, open(FULLPATH, O_DIRECTORY));
71 EXPECT_EQ(ENOENT, errno);
75 * The daemon is responsible for checking file permissions (unless the
76 * default_permissions mount option was used)
78 TEST_F(Opendir, eperm)
80 const char FULLPATH[] = "mountpoint/some_dir";
81 const char RELPATH[] = "some_dir";
84 expect_lookup(RELPATH, ino);
86 EXPECT_CALL(*m_mock, process(
87 ResultOf([=](auto in) {
88 return (in->header.opcode == FUSE_OPENDIR &&
89 in->header.nodeid == ino);
92 ).WillOnce(Invoke(ReturnErrno(EPERM)));
94 EXPECT_NE(0, open(FULLPATH, O_DIRECTORY));
95 EXPECT_EQ(EPERM, errno);
100 const char FULLPATH[] = "mountpoint/some_dir";
101 const char RELPATH[] = "some_dir";
104 expect_lookup(RELPATH, ino);
106 EXPECT_CALL(*m_mock, process(
107 ResultOf([=](auto in) {
108 return (in->header.opcode == FUSE_OPENDIR &&
109 in->header.nodeid == ino);
112 ).WillOnce(Invoke(ReturnImmediate([=](auto in __unused, auto out) {
113 SET_OUT_HEADER_LEN(out, open);
116 EXPECT_LE(0, open(FULLPATH, O_DIRECTORY)) << strerror(errno);
119 TEST_F(Opendir, opendir)
121 const char FULLPATH[] = "mountpoint/some_dir";
122 const char RELPATH[] = "some_dir";
125 expect_lookup(RELPATH, ino);
126 EXPECT_CALL(*m_mock, process(
127 ResultOf([](auto in) {
128 return (in->header.opcode == FUSE_STATFS);
131 ).WillOnce(Invoke(ReturnImmediate([=](auto in __unused, auto out) {
132 SET_OUT_HEADER_LEN(out, statfs);
135 EXPECT_CALL(*m_mock, process(
136 ResultOf([=](auto in) {
137 return (in->header.opcode == FUSE_OPENDIR &&
138 in->header.nodeid == ino);
141 ).WillOnce(Invoke(ReturnImmediate([=](auto in __unused, auto out) {
142 SET_OUT_HEADER_LEN(out, open);
146 EXPECT_NE(NULL, opendir(FULLPATH)) << strerror(errno);