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) 2013 Fujitsu Ltd. Dan Li <[email protected]>
4*49cdfc7eSAndroid Build Coastguard Worker * Copyright (C) 2023 SUSE LLC Andrea Cervesato <[email protected]>
5*49cdfc7eSAndroid Build Coastguard Worker */
6*49cdfc7eSAndroid Build Coastguard Worker
7*49cdfc7eSAndroid Build Coastguard Worker /*\
8*49cdfc7eSAndroid Build Coastguard Worker * [Description]
9*49cdfc7eSAndroid Build Coastguard Worker *
10*49cdfc7eSAndroid Build Coastguard Worker * Test for feature MS_MOVE of mount, which moves an existing mount point to
11*49cdfc7eSAndroid Build Coastguard Worker * a new location.
12*49cdfc7eSAndroid Build Coastguard Worker */
13*49cdfc7eSAndroid Build Coastguard Worker
14*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
15*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
16*49cdfc7eSAndroid Build Coastguard Worker #include <sys/mount.h>
17*49cdfc7eSAndroid Build Coastguard Worker
18*49cdfc7eSAndroid Build Coastguard Worker #ifndef MS_MOVE
19*49cdfc7eSAndroid Build Coastguard Worker #define MS_MOVE 8192
20*49cdfc7eSAndroid Build Coastguard Worker #endif
21*49cdfc7eSAndroid Build Coastguard Worker
22*49cdfc7eSAndroid Build Coastguard Worker #ifndef MS_PRIVATE
23*49cdfc7eSAndroid Build Coastguard Worker #define MS_PRIVATE (1 << 18)
24*49cdfc7eSAndroid Build Coastguard Worker #endif
25*49cdfc7eSAndroid Build Coastguard Worker
26*49cdfc7eSAndroid Build Coastguard Worker #define MNTPOINT_SRC "mntpoint1"
27*49cdfc7eSAndroid Build Coastguard Worker #define MNTPOINT_DST "mntpoint2"
28*49cdfc7eSAndroid Build Coastguard Worker
29*49cdfc7eSAndroid Build Coastguard Worker static char *tmppath;
30*49cdfc7eSAndroid Build Coastguard Worker static char mntpoint_src[PATH_MAX];
31*49cdfc7eSAndroid Build Coastguard Worker static char mntpoint_dst[PATH_MAX];
32*49cdfc7eSAndroid Build Coastguard Worker static char tstfiles_src[PATH_MAX];
33*49cdfc7eSAndroid Build Coastguard Worker static char tstfiles_dst[PATH_MAX];
34*49cdfc7eSAndroid Build Coastguard Worker
setup(void)35*49cdfc7eSAndroid Build Coastguard Worker static void setup(void)
36*49cdfc7eSAndroid Build Coastguard Worker {
37*49cdfc7eSAndroid Build Coastguard Worker tmppath = tst_get_tmpdir();
38*49cdfc7eSAndroid Build Coastguard Worker
39*49cdfc7eSAndroid Build Coastguard Worker /*
40*49cdfc7eSAndroid Build Coastguard Worker * Turn current dir into a private mount point being a parent
41*49cdfc7eSAndroid Build Coastguard Worker * mount which is required by move mount.
42*49cdfc7eSAndroid Build Coastguard Worker */
43*49cdfc7eSAndroid Build Coastguard Worker SAFE_MOUNT(tmppath, tmppath, "none", MS_BIND, NULL);
44*49cdfc7eSAndroid Build Coastguard Worker SAFE_MOUNT("none", tmppath, "none", MS_PRIVATE, NULL);
45*49cdfc7eSAndroid Build Coastguard Worker
46*49cdfc7eSAndroid Build Coastguard Worker snprintf(mntpoint_src, PATH_MAX, "%s/%s", tmppath, MNTPOINT_SRC);
47*49cdfc7eSAndroid Build Coastguard Worker snprintf(mntpoint_dst, PATH_MAX, "%s/%s", tmppath, MNTPOINT_DST);
48*49cdfc7eSAndroid Build Coastguard Worker
49*49cdfc7eSAndroid Build Coastguard Worker snprintf(tstfiles_src, PATH_MAX, "%s/%s/testfile", tmppath, MNTPOINT_SRC);
50*49cdfc7eSAndroid Build Coastguard Worker snprintf(tstfiles_dst, PATH_MAX, "%s/%s/testfile", tmppath, MNTPOINT_DST);
51*49cdfc7eSAndroid Build Coastguard Worker
52*49cdfc7eSAndroid Build Coastguard Worker SAFE_MKDIR(mntpoint_dst, 0750);
53*49cdfc7eSAndroid Build Coastguard Worker }
54*49cdfc7eSAndroid Build Coastguard Worker
cleanup(void)55*49cdfc7eSAndroid Build Coastguard Worker static void cleanup(void)
56*49cdfc7eSAndroid Build Coastguard Worker {
57*49cdfc7eSAndroid Build Coastguard Worker if (tst_is_mounted(mntpoint_src))
58*49cdfc7eSAndroid Build Coastguard Worker SAFE_UMOUNT(mntpoint_src);
59*49cdfc7eSAndroid Build Coastguard Worker
60*49cdfc7eSAndroid Build Coastguard Worker if (tst_is_mounted(mntpoint_dst))
61*49cdfc7eSAndroid Build Coastguard Worker SAFE_UMOUNT(mntpoint_dst);
62*49cdfc7eSAndroid Build Coastguard Worker
63*49cdfc7eSAndroid Build Coastguard Worker if (tst_is_mounted(tmppath))
64*49cdfc7eSAndroid Build Coastguard Worker SAFE_UMOUNT(tmppath);
65*49cdfc7eSAndroid Build Coastguard Worker
66*49cdfc7eSAndroid Build Coastguard Worker SAFE_RMDIR(mntpoint_dst);
67*49cdfc7eSAndroid Build Coastguard Worker }
68*49cdfc7eSAndroid Build Coastguard Worker
run(void)69*49cdfc7eSAndroid Build Coastguard Worker static void run(void)
70*49cdfc7eSAndroid Build Coastguard Worker {
71*49cdfc7eSAndroid Build Coastguard Worker SAFE_MOUNT(tst_device->dev, mntpoint_src, tst_device->fs_type, 0, NULL);
72*49cdfc7eSAndroid Build Coastguard Worker SAFE_FILE_PRINTF(tstfiles_src, "LTP TEST FILE");
73*49cdfc7eSAndroid Build Coastguard Worker
74*49cdfc7eSAndroid Build Coastguard Worker SAFE_MOUNT(mntpoint_src, mntpoint_dst, tst_device->fs_type, MS_MOVE, NULL);
75*49cdfc7eSAndroid Build Coastguard Worker
76*49cdfc7eSAndroid Build Coastguard Worker TST_EXP_FAIL(
77*49cdfc7eSAndroid Build Coastguard Worker access(tstfiles_src, F_OK),
78*49cdfc7eSAndroid Build Coastguard Worker ENOENT,
79*49cdfc7eSAndroid Build Coastguard Worker "File %s doesn't exist",
80*49cdfc7eSAndroid Build Coastguard Worker tstfiles_src);
81*49cdfc7eSAndroid Build Coastguard Worker
82*49cdfc7eSAndroid Build Coastguard Worker TST_EXP_PASS(
83*49cdfc7eSAndroid Build Coastguard Worker access(tstfiles_dst, F_OK),
84*49cdfc7eSAndroid Build Coastguard Worker "File %s exists :",
85*49cdfc7eSAndroid Build Coastguard Worker tstfiles_dst);
86*49cdfc7eSAndroid Build Coastguard Worker
87*49cdfc7eSAndroid Build Coastguard Worker if (tst_is_mounted(mntpoint_src))
88*49cdfc7eSAndroid Build Coastguard Worker SAFE_UMOUNT(mntpoint_src);
89*49cdfc7eSAndroid Build Coastguard Worker
90*49cdfc7eSAndroid Build Coastguard Worker if (tst_is_mounted(mntpoint_dst))
91*49cdfc7eSAndroid Build Coastguard Worker SAFE_UMOUNT(mntpoint_dst);
92*49cdfc7eSAndroid Build Coastguard Worker }
93*49cdfc7eSAndroid Build Coastguard Worker
94*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
95*49cdfc7eSAndroid Build Coastguard Worker .setup = setup,
96*49cdfc7eSAndroid Build Coastguard Worker .cleanup = cleanup,
97*49cdfc7eSAndroid Build Coastguard Worker .test_all = run,
98*49cdfc7eSAndroid Build Coastguard Worker .needs_root = 1,
99*49cdfc7eSAndroid Build Coastguard Worker .format_device = 1,
100*49cdfc7eSAndroid Build Coastguard Worker .mntpoint = MNTPOINT_SRC,
101*49cdfc7eSAndroid Build Coastguard Worker .all_filesystems = 1,
102*49cdfc7eSAndroid Build Coastguard Worker .skip_filesystems = (const char *const []){
103*49cdfc7eSAndroid Build Coastguard Worker "exfat",
104*49cdfc7eSAndroid Build Coastguard Worker "vfat",
105*49cdfc7eSAndroid Build Coastguard Worker "ntfs",
106*49cdfc7eSAndroid Build Coastguard Worker NULL
107*49cdfc7eSAndroid Build Coastguard Worker },
108*49cdfc7eSAndroid Build Coastguard Worker };
109