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