1 /*
2 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * You should have received a copy of the GNU General Public License along
13 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15 *
16 * AUTHOR : Nirmala Devi Dhanasekar <nirmala.devi@wipro.com>
17 *
18 * DESCRIPTION
19 * This is a Phase I test for the umount(2) system call.
20 * It is intended to provide a limited exposure of the system call.
21 *****************************************************************************/
22
23 #include <errno.h>
24 #include <sys/mount.h>
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include "test.h"
28
29 static void setup(void);
30 static void cleanup(void);
31
32 char *TCID = "umount01";
33 int TST_TOTAL = 1;
34
35 #define DEFAULT_FSTYPE "ext2"
36 #define DIR_MODE S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH
37
38 static const char *mntpoint = "mntpoint";
39 static const char *fs_type;
40 static const char *device;
41
main(int ac,char ** av)42 int main(int ac, char **av)
43 {
44 int lc;
45
46 tst_parse_opts(ac, av, NULL, NULL);
47
48 setup();
49
50 for (lc = 0; TEST_LOOPING(lc); lc++) {
51 tst_count = 0;
52
53 TEST(mount(device, mntpoint, fs_type, 0, NULL));
54
55 if (TEST_RETURN != 0) {
56 tst_brkm(TBROK, cleanup, "mount(2) Failed errno = %d :"
57 "%s ", TEST_ERRNO, strerror(TEST_ERRNO));
58 } else {
59 TEST(umount(mntpoint));
60
61 if (TEST_RETURN != 0 && TEST_ERRNO == EBUSY) {
62 tst_resm(TINFO, "umount() failed with EBUSY "
63 "possibly some daemon (gvfsd-trash) "
64 "is probing newly mounted dirs");
65 }
66
67 if (TEST_RETURN != 0) {
68 tst_brkm(TFAIL, NULL, "umount(2) Failed while "
69 " unmounting %s errno = %d : %s",
70 mntpoint, TEST_ERRNO,
71 strerror(TEST_ERRNO));
72 } else {
73 tst_resm(TPASS, "umount(2) Passed ");
74 }
75 }
76 }
77
78 cleanup();
79 tst_exit();
80 }
81
setup(void)82 static void setup(void)
83 {
84 tst_sig(NOFORK, DEF_HANDLER, cleanup);
85
86 tst_require_root();
87
88 tst_tmpdir();
89
90 fs_type = tst_dev_fs_type();
91 device = tst_acquire_device(cleanup);
92
93 if (!device)
94 tst_brkm(TCONF, cleanup, "Failed to obtain block device");
95
96 tst_mkfs(cleanup, device, fs_type, NULL, NULL);
97
98 if (mkdir(mntpoint, DIR_MODE) < 0) {
99 tst_brkm(TBROK, cleanup, "mkdir(%s, %#o) failed; "
100 "errno = %d: %s", mntpoint, DIR_MODE, errno,
101 strerror(errno));
102 }
103
104 TEST_PAUSE;
105 }
106
cleanup(void)107 static void cleanup(void)
108 {
109 if (device)
110 tst_release_device(device);
111
112 tst_rmdir();
113 }
114