blob: cc677b7e567f08a6f08b90da49511ff7f1651cf0 [file] [log] [blame]
vapierd13d74b2006-02-11 07:24:00 +00001/*
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
Wanlong Gaofed96412012-10-24 10:10:29 +080013 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
vapierd13d74b2006-02-11 07:24:00 +000015 *
Cyril Hrubis7224b782013-08-08 18:03:54 +020016 * AUTHOR : Nirmala Devi Dhanasekar <nirmala.devi@wipro.com>
subrata_modak4bb656a2009-02-26 12:02:09 +000017 *
Cyril Hrubis7224b782013-08-08 18:03:54 +020018 * DESCRIPTION
vapierd13d74b2006-02-11 07:24:00 +000019 * 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.
vapierd13d74b2006-02-11 07:24:00 +000021 *****************************************************************************/
22
23#include <errno.h>
24#include <sys/mount.h>
25#include <sys/types.h>
26#include <sys/stat.h>
27#include "test.h"
vapierd13d74b2006-02-11 07:24:00 +000028
vapierd13d74b2006-02-11 07:24:00 +000029static void setup(void);
30static void cleanup(void);
31
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020032char *TCID = "umount01";
33int TST_TOTAL = 1;
vapierd13d74b2006-02-11 07:24:00 +000034
35#define DEFAULT_FSTYPE "ext2"
36#define DIR_MODE S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH
37
Cyril Hrubisafe13b32014-08-14 10:26:45 +020038static const char *mntpoint = "mntpoint";
39static const char *fs_type;
40static const char *device;
vapierd13d74b2006-02-11 07:24:00 +000041
subrata_modak56207ce2009-03-23 13:35:39 +000042int main(int ac, char **av)
vapierd13d74b2006-02-11 07:24:00 +000043{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020044 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020045 const char *msg;
vapierd13d74b2006-02-11 07:24:00 +000046
Cyril Hrubisafe13b32014-08-14 10:26:45 +020047 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
vapierd13d74b2006-02-11 07:24:00 +000048 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
vapierd13d74b2006-02-11 07:24:00 +000049
vapierd13d74b2006-02-11 07:24:00 +000050 setup();
51
vapierd13d74b2006-02-11 07:24:00 +000052 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080053 tst_count = 0;
vapierd13d74b2006-02-11 07:24:00 +000054
Cyril Hrubisafe13b32014-08-14 10:26:45 +020055 TEST(mount(device, mntpoint, fs_type, 0, NULL));
vapierd13d74b2006-02-11 07:24:00 +000056
vapierd13d74b2006-02-11 07:24:00 +000057 if (TEST_RETURN != 0) {
vapierd13d74b2006-02-11 07:24:00 +000058 tst_brkm(TBROK, cleanup, "mount(2) Failed errno = %d :"
59 "%s ", TEST_ERRNO, strerror(TEST_ERRNO));
60 } else {
61 TEST(umount(mntpoint));
Cyril Hrubis10b61172015-01-29 16:51:36 +010062
63 if (TEST_RETURN != 0 && TEST_ERRNO == EBUSY) {
64 tst_resm(TINFO, "umount() failed with EBUSY "
65 "possibly some daemon (gvfsd-trash) "
66 "is probing newly mounted dirs");
67 }
68
vapierd13d74b2006-02-11 07:24:00 +000069 if (TEST_RETURN != 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +010070 tst_brkm(TFAIL, NULL, "umount(2) Failed while "
vapierd13d74b2006-02-11 07:24:00 +000071 " unmounting %s errno = %d : %s",
72 mntpoint, TEST_ERRNO,
73 strerror(TEST_ERRNO));
vapierd13d74b2006-02-11 07:24:00 +000074 } else {
75 tst_resm(TPASS, "umount(2) Passed ");
76 }
77 }
Garrett Cooper2c282152010-12-16 00:55:50 -080078 }
vapierd13d74b2006-02-11 07:24:00 +000079
vapierd13d74b2006-02-11 07:24:00 +000080 cleanup();
Garrett Cooper53740502010-12-16 00:04:01 -080081 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -080082}
vapierd13d74b2006-02-11 07:24:00 +000083
Cyril Hrubis7224b782013-08-08 18:03:54 +020084static void setup(void)
vapierd13d74b2006-02-11 07:24:00 +000085{
vapierd13d74b2006-02-11 07:24:00 +000086 tst_sig(NOFORK, DEF_HANDLER, cleanup);
87
Cyril Hrubis7224b782013-08-08 18:03:54 +020088 tst_require_root(NULL);
vapierd13d74b2006-02-11 07:24:00 +000089
vapierd13d74b2006-02-11 07:24:00 +000090 tst_tmpdir();
91
Cyril Hrubisafe13b32014-08-14 10:26:45 +020092 fs_type = tst_dev_fs_type();
93 device = tst_acquire_device(cleanup);
94
95 if (!device)
96 tst_brkm(TCONF, cleanup, "Failed to obtain block device");
97
98 tst_mkfs(cleanup, device, fs_type, NULL);
99
vapierd13d74b2006-02-11 07:24:00 +0000100 if (mkdir(mntpoint, DIR_MODE) < 0) {
101 tst_brkm(TBROK, cleanup, "mkdir(%s, %#o) failed; "
102 "errno = %d: %s", mntpoint, DIR_MODE, errno,
subrata_modak56207ce2009-03-23 13:35:39 +0000103 strerror(errno));
vapierd13d74b2006-02-11 07:24:00 +0000104 }
105
vapierd13d74b2006-02-11 07:24:00 +0000106 TEST_PAUSE;
Garrett Cooper2c282152010-12-16 00:55:50 -0800107}
vapierd13d74b2006-02-11 07:24:00 +0000108
Cyril Hrubis7224b782013-08-08 18:03:54 +0200109static void cleanup(void)
vapierd13d74b2006-02-11 07:24:00 +0000110{
Cyril Hrubisafe13b32014-08-14 10:26:45 +0200111 if (device)
112 tst_release_device(NULL, device);
113
114 tst_rmdir();
Markos Chandrasf4539c62012-01-03 09:41:10 +0000115}