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