xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/rename/rename05.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) International Business Machines  Corp., 2001
4*49cdfc7eSAndroid Build Coastguard Worker  *  07/2001 Ported by Wayne Boyer
5*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 2022 SUSE LLC Avinesh Kumar <[email protected]>
6*49cdfc7eSAndroid Build Coastguard Worker  */
7*49cdfc7eSAndroid Build Coastguard Worker 
8*49cdfc7eSAndroid Build Coastguard Worker /*\
9*49cdfc7eSAndroid Build Coastguard Worker  * [Description]
10*49cdfc7eSAndroid Build Coastguard Worker  *
11*49cdfc7eSAndroid Build Coastguard Worker  * Verify that rename(2) fails with EISDIR when
12*49cdfc7eSAndroid Build Coastguard Worker  * oldpath is not a directory and newpath is an existing directory.
13*49cdfc7eSAndroid Build Coastguard Worker  */
14*49cdfc7eSAndroid Build Coastguard Worker 
15*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
16*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
17*49cdfc7eSAndroid Build Coastguard Worker 
18*49cdfc7eSAndroid Build Coastguard Worker #define MNT_POINT "mntpoint"
19*49cdfc7eSAndroid Build Coastguard Worker #define TEMP_FILE "tmpfile"
20*49cdfc7eSAndroid Build Coastguard Worker #define TEMP_DIR "tmpdir"
21*49cdfc7eSAndroid Build Coastguard Worker 
setup(void)22*49cdfc7eSAndroid Build Coastguard Worker static void setup(void)
23*49cdfc7eSAndroid Build Coastguard Worker {
24*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_CHDIR(MNT_POINT);
25*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_TOUCH(TEMP_FILE, 0700, NULL);
26*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_MKDIR(TEMP_DIR, 00770);
27*49cdfc7eSAndroid Build Coastguard Worker }
28*49cdfc7eSAndroid Build Coastguard Worker 
run(void)29*49cdfc7eSAndroid Build Coastguard Worker static void run(void)
30*49cdfc7eSAndroid Build Coastguard Worker {
31*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_FAIL(rename(TEMP_FILE, TEMP_DIR),
32*49cdfc7eSAndroid Build Coastguard Worker 				EISDIR);
33*49cdfc7eSAndroid Build Coastguard Worker }
34*49cdfc7eSAndroid Build Coastguard Worker 
35*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
36*49cdfc7eSAndroid Build Coastguard Worker 	.setup = setup,
37*49cdfc7eSAndroid Build Coastguard Worker 	.test_all = run,
38*49cdfc7eSAndroid Build Coastguard Worker 	.needs_root = 1,
39*49cdfc7eSAndroid Build Coastguard Worker 	.mount_device = 1,
40*49cdfc7eSAndroid Build Coastguard Worker 	.mntpoint = MNT_POINT,
41*49cdfc7eSAndroid Build Coastguard Worker 	.all_filesystems = 1
42*49cdfc7eSAndroid Build Coastguard Worker };
43