xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/rename/rename13.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() does nothing and returns a success status when
12*49cdfc7eSAndroid Build Coastguard Worker  * oldpath and newpath are existing hard links referring to the same file.
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_FILE1 MNT_POINT"/tmpfile1"
20*49cdfc7eSAndroid Build Coastguard Worker #define TEMP_FILE2 MNT_POINT"/tmpfile2"
21*49cdfc7eSAndroid Build Coastguard Worker 
22*49cdfc7eSAndroid Build Coastguard Worker static struct stat buf1, buf2;
23*49cdfc7eSAndroid Build Coastguard Worker 
setup(void)24*49cdfc7eSAndroid Build Coastguard Worker static void setup(void)
25*49cdfc7eSAndroid Build Coastguard Worker {
26*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_TOUCH(TEMP_FILE1, 0700, NULL);
27*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_STAT(TEMP_FILE1, &buf1);
28*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_LINK(TEMP_FILE1, TEMP_FILE2);
29*49cdfc7eSAndroid Build Coastguard Worker }
30*49cdfc7eSAndroid Build Coastguard Worker 
run(void)31*49cdfc7eSAndroid Build Coastguard Worker static void run(void)
32*49cdfc7eSAndroid Build Coastguard Worker {
33*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_PASS(rename(TEMP_FILE1, TEMP_FILE1));
34*49cdfc7eSAndroid Build Coastguard Worker 	if (TST_RET != 0)
35*49cdfc7eSAndroid Build Coastguard Worker 		return;
36*49cdfc7eSAndroid Build Coastguard Worker 
37*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_STAT(TEMP_FILE2, &buf2);
38*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_EQ_LU(buf1.st_dev, buf2.st_dev);
39*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_EQ_LU(buf1.st_ino, buf2.st_ino);
40*49cdfc7eSAndroid Build Coastguard Worker }
41*49cdfc7eSAndroid Build Coastguard Worker 
42*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
43*49cdfc7eSAndroid Build Coastguard Worker 	.setup = setup,
44*49cdfc7eSAndroid Build Coastguard Worker 	.test_all = run,
45*49cdfc7eSAndroid Build Coastguard Worker 	.needs_root = 1,
46*49cdfc7eSAndroid Build Coastguard Worker 	.mntpoint = MNT_POINT,
47*49cdfc7eSAndroid Build Coastguard Worker 	.mount_device = 1,
48*49cdfc7eSAndroid Build Coastguard Worker 	.all_filesystems = 1,
49*49cdfc7eSAndroid Build Coastguard Worker 	.skip_filesystems = (const char *const[]){
50*49cdfc7eSAndroid Build Coastguard Worker 		"exfat",
51*49cdfc7eSAndroid Build Coastguard Worker 		"vfat",
52*49cdfc7eSAndroid Build Coastguard Worker 		NULL
53*49cdfc7eSAndroid Build Coastguard Worker 	},
54*49cdfc7eSAndroid Build Coastguard Worker };
55