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(2) fails with EINVAL when
12 * an attempt is made to make a directory a subdirectory of itself.
13 */
14
15 #include <stdio.h>
16 #include "tst_test.h"
17
18 #define MNT_POINT "mntpoint"
19 #define DIR1 "dir1"
20 #define DIR2 DIR1"/dir2"
21
setup(void)22 static void setup(void)
23 {
24 SAFE_CHDIR(MNT_POINT);
25 SAFE_MKDIR(DIR1, 00770);
26 SAFE_MKDIR(DIR2, 00770);
27 }
28
run(void)29 static void run(void)
30 {
31 TST_EXP_FAIL(rename(DIR1, DIR2),
32 EINVAL);
33 }
34
35 static struct tst_test test = {
36 .setup = setup,
37 .test_all = run,
38 .needs_root = 1,
39 .mount_device = 1,
40 .mntpoint = MNT_POINT,
41 .all_filesystems = 1
42 };
43