• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 mount(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 #include "safe_macros.h"
29 
30 static void setup(void);
31 static void cleanup(void);
32 
33 char *TCID = "mount01";
34 int TST_TOTAL = 1;
35 
36 #define DIR_MODE (S_IRWXU | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP)
37 #define MNTPOINT "mntpoint"
38 
39 static const char *device;
40 static const char *fs_type;
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 
52 		tst_count = 0;
53 
54 		TEST(mount(device, MNTPOINT, fs_type, 0, NULL));
55 
56 		if (TEST_RETURN != 0) {
57 			tst_resm(TFAIL | TTERRNO, "mount(2) failed");
58 		} else {
59 			tst_resm(TPASS, "mount(2) passed ");
60 			TEST(tst_umount(MNTPOINT));
61 			if (TEST_RETURN != 0) {
62 				tst_brkm(TBROK | TTERRNO, cleanup,
63 					 "umount(2) failed");
64 			}
65 		}
66 	}
67 
68 	cleanup();
69 	tst_exit();
70 }
71 
setup(void)72 static void setup(void)
73 {
74 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
75 
76 	tst_require_root();
77 
78 	tst_tmpdir();
79 
80 	fs_type = tst_dev_fs_type();
81 	device = tst_acquire_device(cleanup);
82 
83 	if (!device)
84 		tst_brkm(TCONF, cleanup, "Failed to obtain block device");
85 
86 	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
87 
88 	SAFE_MKDIR(cleanup, MNTPOINT, DIR_MODE);
89 
90 	TEST_PAUSE;
91 }
92 
cleanup(void)93 static void cleanup(void)
94 {
95 	if (device)
96 		tst_release_device(device);
97 
98 	tst_rmdir();
99 }
100