xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/rename/rename13.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  *   Copyright (c) International Business Machines  Corp., 2001
4  *		07/2001 Ported by Wayne Boyer
5  *   Copyright (c) 2022 SUSE LLC Avinesh Kumar <[email protected]>
6  */
7 
8 /*\
9  * [Description]
10  *
11  * Verify that rename() does nothing and returns a success status when
12  * oldpath and newpath are existing hard links referring to the same file.
13  */
14 
15 #include <stdio.h>
16 #include "tst_test.h"
17 
18 #define MNT_POINT "mntpoint"
19 #define TEMP_FILE1 MNT_POINT"/tmpfile1"
20 #define TEMP_FILE2 MNT_POINT"/tmpfile2"
21 
22 static struct stat buf1, buf2;
23 
setup(void)24 static void setup(void)
25 {
26 	SAFE_TOUCH(TEMP_FILE1, 0700, NULL);
27 	SAFE_STAT(TEMP_FILE1, &buf1);
28 	SAFE_LINK(TEMP_FILE1, TEMP_FILE2);
29 }
30 
run(void)31 static void run(void)
32 {
33 	TST_EXP_PASS(rename(TEMP_FILE1, TEMP_FILE1));
34 	if (TST_RET != 0)
35 		return;
36 
37 	SAFE_STAT(TEMP_FILE2, &buf2);
38 	TST_EXP_EQ_LU(buf1.st_dev, buf2.st_dev);
39 	TST_EXP_EQ_LU(buf1.st_ino, buf2.st_ino);
40 }
41 
42 static struct tst_test test = {
43 	.setup = setup,
44 	.test_all = run,
45 	.needs_root = 1,
46 	.mntpoint = MNT_POINT,
47 	.mount_device = 1,
48 	.all_filesystems = 1,
49 	.skip_filesystems = (const char *const[]){
50 		"exfat",
51 		"vfat",
52 		NULL
53 	},
54 };
55