xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/umount/umount01.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
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) Wipro Technologies Ltd, 2002.  All Rights Reserved.
4*49cdfc7eSAndroid Build Coastguard Worker  * Author: Nirmala Devi Dhanasekar <[email protected]>
5*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) Linux Test Project, 2002-2023
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  * Check the basic functionality of the umount(2) system call.
12*49cdfc7eSAndroid Build Coastguard Worker  */
13*49cdfc7eSAndroid Build Coastguard Worker 
14*49cdfc7eSAndroid Build Coastguard Worker #include <sys/mount.h>
15*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
16*49cdfc7eSAndroid Build Coastguard Worker 
17*49cdfc7eSAndroid Build Coastguard Worker #define MNTPOINT	"mntpoint"
18*49cdfc7eSAndroid Build Coastguard Worker 
19*49cdfc7eSAndroid Build Coastguard Worker static int mount_flag;
20*49cdfc7eSAndroid Build Coastguard Worker 
verify_umount(void)21*49cdfc7eSAndroid Build Coastguard Worker static void verify_umount(void)
22*49cdfc7eSAndroid Build Coastguard Worker {
23*49cdfc7eSAndroid Build Coastguard Worker 	if (mount_flag != 1) {
24*49cdfc7eSAndroid Build Coastguard Worker 		SAFE_MOUNT(tst_device->dev, MNTPOINT,
25*49cdfc7eSAndroid Build Coastguard Worker 			tst_device->fs_type, 0, NULL);
26*49cdfc7eSAndroid Build Coastguard Worker 		mount_flag = 1;
27*49cdfc7eSAndroid Build Coastguard Worker 	}
28*49cdfc7eSAndroid Build Coastguard Worker 
29*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_PASS(umount(MNTPOINT));
30*49cdfc7eSAndroid Build Coastguard Worker 
31*49cdfc7eSAndroid Build Coastguard Worker 	if (TST_RET != 0 && TST_ERR == EBUSY) {
32*49cdfc7eSAndroid Build Coastguard Worker 		tst_res(TINFO, "umount() Failed with EBUSY "
33*49cdfc7eSAndroid Build Coastguard Worker 			"possibly some daemon (gvfsd-trash) "
34*49cdfc7eSAndroid Build Coastguard Worker 			"is probing newly mounted dirs");
35*49cdfc7eSAndroid Build Coastguard Worker 	}
36*49cdfc7eSAndroid Build Coastguard Worker 
37*49cdfc7eSAndroid Build Coastguard Worker 	mount_flag = 0;
38*49cdfc7eSAndroid Build Coastguard Worker }
39*49cdfc7eSAndroid Build Coastguard Worker 
setup(void)40*49cdfc7eSAndroid Build Coastguard Worker static void setup(void)
41*49cdfc7eSAndroid Build Coastguard Worker {
42*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_MKDIR(MNTPOINT, 0775);
43*49cdfc7eSAndroid Build Coastguard Worker }
44*49cdfc7eSAndroid Build Coastguard Worker 
cleanup(void)45*49cdfc7eSAndroid Build Coastguard Worker static void cleanup(void)
46*49cdfc7eSAndroid Build Coastguard Worker {
47*49cdfc7eSAndroid Build Coastguard Worker 	if (mount_flag)
48*49cdfc7eSAndroid Build Coastguard Worker 		tst_umount(MNTPOINT);
49*49cdfc7eSAndroid Build Coastguard Worker }
50*49cdfc7eSAndroid Build Coastguard Worker 
51*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
52*49cdfc7eSAndroid Build Coastguard Worker 	.needs_root = 1,
53*49cdfc7eSAndroid Build Coastguard Worker 	.format_device = 1,
54*49cdfc7eSAndroid Build Coastguard Worker 	.setup = setup,
55*49cdfc7eSAndroid Build Coastguard Worker 	.cleanup = cleanup,
56*49cdfc7eSAndroid Build Coastguard Worker 	.test_all = verify_umount,
57*49cdfc7eSAndroid Build Coastguard Worker };
58