xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/statfs/statfs03.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /*
4  *   Copyright (C) Bull S.A. 2001
5  *   Copyright (c) International Business Machines  Corp., 2001
6  *		05/2002 Ported by Jacky Malcles
7  *   Copyright (c) 2022 SUSE LLC Avinesh Kumar <[email protected]>
8  */
9 
10 /*\
11  * [Description]
12  *
13  * Verify that statfs(2) fails with errno EACCES when search permission
14  * is denied for a component of the path prefix of path.
15  */
16 
17 #include <pwd.h>
18 #include "tst_test.h"
19 
20 #define TEMP_DIR "testdir"
21 #define TEMP_DIR2 TEMP_DIR"/subdir"
22 
setup(void)23 static void setup(void)
24 {
25 	struct passwd *ltpuser;
26 
27 	SAFE_MKDIR(TEMP_DIR, 0444);
28 	SAFE_MKDIR(TEMP_DIR2, 0444);
29 
30 	ltpuser = SAFE_GETPWNAM("nobody");
31 	SAFE_SETEUID(ltpuser->pw_uid);
32 }
33 
run(void)34 static void run(void)
35 {
36 	struct statfs buf;
37 
38 	TST_EXP_FAIL(statfs(TEMP_DIR2, &buf), EACCES);
39 }
40 
41 static struct tst_test test = {
42 	.setup = setup,
43 	.test_all = run,
44 	.needs_tmpdir = 1,
45 	.needs_root = 1
46 };
47