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