/*
*      SCCS:   @(#)install/userintf/gen_mnt	1.1 (01/21/97)  VSXgen release 1.4
*
*	UniSoft Ltd., London, England
*/
/***********************************************************************

NAME:		gen_mnt - user-modifiable mount/unmount routines
PROJECT:	VSX (X/OPEN Validation Suite)
AUTHOR:		Geoff Clare, UniSoft Ltd.
DATE CREATED:	December 1996
MODIFICATIONS:
	Andrew Dingwall, UniSoft Ltd., December 2000
	This version for ext2 file systems on Linux

************************************************************************/

#include <sys/mount.h>

static char fstype[] = "ext2";

/*
 *	Mnt_rw() mounts the file system specified by "spec" onto the
 *	directory "dir" for reading and writing.
 *	It returns 0 for success, -1 for failure.
 */

public int
mnt_rw(spec, dir)
char *spec;
char *dir;
{
	int ret;

	ret = mount(spec, dir, fstype, 0, (void *) 0);
	if (ret == -1 && errno == EBUSY)
	{
		(void) unmnt(spec, dir);
		errno = 0;
		ret = mount(spec, dir, fstype, 0, (void *) 0);
	}

	return ret;
}

/*
 *	Mnt_ro() mounts the file system specified by "spec" onto the
 *	directory "dir" for reading only.
 *	It returns 0 for success, -1 for failure.
 */

public int
mnt_ro(spec, dir)
char *spec;
char *dir;
{
	int ret;

	ret = mount(spec, dir, fstype, MS_RDONLY, (void *) 0);
	if (ret == -1 && errno == EBUSY)
	{
		(void) unmnt(spec, dir);
		errno = 0;
		ret = mount(spec, dir, fstype, MS_RDONLY, (void *) 0);
	}

	return ret;
}

/*
 *	Unmnt() unmounts the file system specified by "spec" from the
 *	directory "dir" where it has previously been mounted.
 *	It returns 0 for success, -1 for failure.
 */

/* ARGSUSED */
public int
unmnt(spec, dir)
char *spec;
char *dir;
{
	return umount(spec);
}

