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() fails with EEXIST or ENOTEMPTY when
12*49cdfc7eSAndroid Build Coastguard Worker * newpath is a non-empty 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 DIR1 "dir1"
20*49cdfc7eSAndroid Build Coastguard Worker #define DIR2 "dir2"
21*49cdfc7eSAndroid Build Coastguard Worker #define TEMP_FILE DIR2"/tmpfile"
22*49cdfc7eSAndroid Build Coastguard Worker
setup(void)23*49cdfc7eSAndroid Build Coastguard Worker static void setup(void)
24*49cdfc7eSAndroid Build Coastguard Worker {
25*49cdfc7eSAndroid Build Coastguard Worker SAFE_CHDIR(MNT_POINT);
26*49cdfc7eSAndroid Build Coastguard Worker SAFE_MKDIR(DIR1, 00770);
27*49cdfc7eSAndroid Build Coastguard Worker SAFE_MKDIR(DIR2, 00770);
28*49cdfc7eSAndroid Build Coastguard Worker SAFE_TOUCH(TEMP_FILE, 0700, NULL);
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 TEST(rename(DIR1, DIR2));
34*49cdfc7eSAndroid Build Coastguard Worker
35*49cdfc7eSAndroid Build Coastguard Worker if (TST_RET == -1 && (TST_ERR == ENOTEMPTY || TST_ERR == EEXIST))
36*49cdfc7eSAndroid Build Coastguard Worker tst_res(TPASS | TTERRNO, "rename() failed as expected");
37*49cdfc7eSAndroid Build Coastguard Worker else if (TST_RET == 0)
38*49cdfc7eSAndroid Build Coastguard Worker tst_res(TFAIL, "rename() succeeded unexpectedly");
39*49cdfc7eSAndroid Build Coastguard Worker else
40*49cdfc7eSAndroid Build Coastguard Worker tst_res(TFAIL | TTERRNO, "rename() failed, but not with expected errno");
41*49cdfc7eSAndroid Build Coastguard Worker }
42*49cdfc7eSAndroid Build Coastguard Worker
43*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
44*49cdfc7eSAndroid Build Coastguard Worker .setup = setup,
45*49cdfc7eSAndroid Build Coastguard Worker .test_all = run,
46*49cdfc7eSAndroid Build Coastguard Worker .needs_root = 1,
47*49cdfc7eSAndroid Build Coastguard Worker .mntpoint = MNT_POINT,
48*49cdfc7eSAndroid Build Coastguard Worker .mount_device = 1,
49*49cdfc7eSAndroid Build Coastguard Worker .all_filesystems = 1
50*49cdfc7eSAndroid Build Coastguard Worker };
51