xref: /freebsd/tests/sys/fs/fusefs/access.cc (revision 140bb4927aff197ccec5174d00d7442887db1245)
19821f1d3SAlan Somers /*-
29821f1d3SAlan Somers  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
39821f1d3SAlan Somers  *
49821f1d3SAlan Somers  * Copyright (c) 2019 The FreeBSD Foundation
59821f1d3SAlan Somers  *
69821f1d3SAlan Somers  * This software was developed by BFF Storage Systems, LLC under sponsorship
79821f1d3SAlan Somers  * from the FreeBSD Foundation.
89821f1d3SAlan Somers  *
99821f1d3SAlan Somers  * Redistribution and use in source and binary forms, with or without
109821f1d3SAlan Somers  * modification, are permitted provided that the following conditions
119821f1d3SAlan Somers  * are met:
129821f1d3SAlan Somers  * 1. Redistributions of source code must retain the above copyright
139821f1d3SAlan Somers  *    notice, this list of conditions and the following disclaimer.
149821f1d3SAlan Somers  * 2. Redistributions in binary form must reproduce the above copyright
159821f1d3SAlan Somers  *    notice, this list of conditions and the following disclaimer in the
169821f1d3SAlan Somers  *    documentation and/or other materials provided with the distribution.
179821f1d3SAlan Somers  *
189821f1d3SAlan Somers  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
199821f1d3SAlan Somers  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
209821f1d3SAlan Somers  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
219821f1d3SAlan Somers  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
229821f1d3SAlan Somers  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
239821f1d3SAlan Somers  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
249821f1d3SAlan Somers  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
259821f1d3SAlan Somers  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
269821f1d3SAlan Somers  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
279821f1d3SAlan Somers  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
289821f1d3SAlan Somers  * SUCH DAMAGE.
299821f1d3SAlan Somers  */
309821f1d3SAlan Somers 
319821f1d3SAlan Somers extern "C" {
329821f1d3SAlan Somers #include <fcntl.h>
339821f1d3SAlan Somers #include <unistd.h>
349821f1d3SAlan Somers }
359821f1d3SAlan Somers 
369821f1d3SAlan Somers #include "mockfs.hh"
379821f1d3SAlan Somers #include "utils.hh"
389821f1d3SAlan Somers 
399821f1d3SAlan Somers using namespace testing;
409821f1d3SAlan Somers 
419821f1d3SAlan Somers class Access: public FuseTest {
429821f1d3SAlan Somers public:
439821f1d3SAlan Somers void expect_lookup(const char *relpath, uint64_t ino)
449821f1d3SAlan Somers {
459821f1d3SAlan Somers 	FuseTest::expect_lookup(relpath, ino, S_IFREG | 0644, 0, 1);
469821f1d3SAlan Somers }
479821f1d3SAlan Somers };
489821f1d3SAlan Somers 
49*140bb492SAlan Somers class RofsAccess: public Access {
50*140bb492SAlan Somers public:
51*140bb492SAlan Somers virtual void SetUp() {
52*140bb492SAlan Somers 	m_ro = true;
53*140bb492SAlan Somers 	Access::SetUp();
54*140bb492SAlan Somers }
55*140bb492SAlan Somers };
56*140bb492SAlan Somers 
579821f1d3SAlan Somers /* The error case of FUSE_ACCESS.  */
589821f1d3SAlan Somers /* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236291 */
599821f1d3SAlan Somers TEST_F(Access, DISABLED_eaccess)
609821f1d3SAlan Somers {
619821f1d3SAlan Somers 	const char FULLPATH[] = "mountpoint/some_file.txt";
629821f1d3SAlan Somers 	const char RELPATH[] = "some_file.txt";
639821f1d3SAlan Somers 	uint64_t ino = 42;
649821f1d3SAlan Somers 	mode_t	access_mode = X_OK;
659821f1d3SAlan Somers 
669821f1d3SAlan Somers 	expect_lookup(RELPATH, ino);
679821f1d3SAlan Somers 	expect_access(ino, access_mode, EACCES);
689821f1d3SAlan Somers 
699821f1d3SAlan Somers 	ASSERT_NE(0, access(FULLPATH, access_mode));
709821f1d3SAlan Somers 	ASSERT_EQ(EACCES, errno);
719821f1d3SAlan Somers }
729821f1d3SAlan Somers 
739821f1d3SAlan Somers /*
749821f1d3SAlan Somers  * If the filesystem returns ENOSYS, then it is treated as a permanent success,
759821f1d3SAlan Somers  * and subsequent VOP_ACCESS calls will succeed automatically without querying
769821f1d3SAlan Somers  * the daemon.
779821f1d3SAlan Somers  */
789821f1d3SAlan Somers /* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236557 */
799821f1d3SAlan Somers /* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236291 */
809821f1d3SAlan Somers TEST_F(Access, DISABLED_enosys)
819821f1d3SAlan Somers {
829821f1d3SAlan Somers 	const char FULLPATH[] = "mountpoint/some_file.txt";
839821f1d3SAlan Somers 	const char RELPATH[] = "some_file.txt";
849821f1d3SAlan Somers 	uint64_t ino = 42;
859821f1d3SAlan Somers 	mode_t	access_mode = R_OK;
869821f1d3SAlan Somers 
879821f1d3SAlan Somers 	expect_lookup(RELPATH, ino);
889821f1d3SAlan Somers 	expect_access(ino, access_mode, ENOSYS);
899821f1d3SAlan Somers 
909821f1d3SAlan Somers 	ASSERT_EQ(0, access(FULLPATH, access_mode)) << strerror(errno);
919821f1d3SAlan Somers 	ASSERT_EQ(0, access(FULLPATH, access_mode)) << strerror(errno);
929821f1d3SAlan Somers }
939821f1d3SAlan Somers 
94*140bb492SAlan Somers TEST_F(RofsAccess, erofs)
95*140bb492SAlan Somers {
96*140bb492SAlan Somers 	const char FULLPATH[] = "mountpoint/some_file.txt";
97*140bb492SAlan Somers 	const char RELPATH[] = "some_file.txt";
98*140bb492SAlan Somers 	uint64_t ino = 42;
99*140bb492SAlan Somers 	mode_t	access_mode = W_OK;
100*140bb492SAlan Somers 
101*140bb492SAlan Somers 	expect_lookup(RELPATH, ino);
102*140bb492SAlan Somers 
103*140bb492SAlan Somers 	ASSERT_NE(0, access(FULLPATH, access_mode));
104*140bb492SAlan Somers 	ASSERT_EQ(EROFS, errno);
105*140bb492SAlan Somers }
106*140bb492SAlan Somers 
1079821f1d3SAlan Somers /* The successful case of FUSE_ACCESS.  */
1089821f1d3SAlan Somers /* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236291 */
1099821f1d3SAlan Somers TEST_F(Access, DISABLED_ok)
1109821f1d3SAlan Somers {
1119821f1d3SAlan Somers 	const char FULLPATH[] = "mountpoint/some_file.txt";
1129821f1d3SAlan Somers 	const char RELPATH[] = "some_file.txt";
1139821f1d3SAlan Somers 	uint64_t ino = 42;
1149821f1d3SAlan Somers 	mode_t	access_mode = R_OK;
1159821f1d3SAlan Somers 
1169821f1d3SAlan Somers 	expect_lookup(RELPATH, ino);
1179821f1d3SAlan Somers 	expect_access(ino, access_mode, 0);
1189821f1d3SAlan Somers 
1199821f1d3SAlan Somers 	ASSERT_EQ(0, access(FULLPATH, access_mode)) << strerror(errno);
1209821f1d3SAlan Somers }
121