/*
 * $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 *
 */

/*	Copyright (c) 1984 AT&T	*/
/*	  All Rights Reserved  	*/

/*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
/*	The copyright notice above does not evidence any   	*/
/*	actual or intended publication of such source code.	*/

#ident	"$Header: setmnt.c 1.5 89/10/10 $@(#)setmnt:setmnt.c	4.6"
#include <sys/param.h>
#include <signal.h>

#ifndef RT
#include <sys/types.h>
#include <sys/sysmacros.h>
#endif

#ifdef _SEQUENT_

#include <stdio.h>
#include <mntent.h>

struct	 mntent newmnt;
FILE	*mnttab;
#define MNTTAB		MNTTABNAME

#else	/* !seqeunt */

#include <mnttab.h>

struct mnttab mtab[NMOUNT], *mp;
#define MNTTAB		"/etc/mnttab"

#endif	/* !_SEQUENT_ */

extern time_t time();

main()
{

	int	rec, i, setcount;
	char	*cp,inbuf[80];
	time_t	date;

	setcount = 0;
	if ((rec = creat(MNTTAB, 0644)) < 0) {
		(void) write(2,"creat error\n",12);
		exit(1);
	}
#ifdef _SEQUENT_
	(void) close(rec);
	if ((mnttab = setmntent(MNTTAB, "a")) == NULL) {
		fprintf(stderr, "setmnt: warning: cannot create ");
		perror(MNTTAB);
		exit(1);
	}
#endif
	(void) time(&date);
	while(1) {
		for(cp = inbuf;;cp++) {
			if (read(0,cp,1) != 1) {
#ifdef _SEQUENT_
				endmntent(mnttab);
#else	/* !_SEQUENT_ */
				write(rec,mtab, sizeof mtab[0] * setcount);
#endif	/* !_SEQUENT_ */
				exit(1);
			}
			if (*cp == '\n') {
				*cp = '\0';
				break;
			}
		}
		for(cp = inbuf; *cp && *cp != ' '; cp++);
		*cp++ = '\0';

#ifdef _SEQUENT_
		/*
		 *	Put the entry into the mount table.
		 */

		newmnt.mnt_fsname = inbuf;
		newmnt.mnt_dir    = cp;
		newmnt.mnt_type   = MNTTYPE_UFS;
		newmnt.mnt_opts   = "rw";
		newmnt.mnt_time	  = date;

		if (addmntent(mnttab, &newmnt)) {
			fprintf(stderr, "setmnt: warning: cannot write ");
			perror(MNTTAB);
			exit(1);
		}
#else	/* !_SEQUENT_ */
		setcount++;
		for(mp = mtab; mp <&mtab[NMOUNT]; mp++)  {
			if(mp->mt_dev[0] == 0) {
				strncpy(mp->mt_dev, inbuf, sizeof mp->mt_dev);
				strncpy(mp->mt_filsys, cp, sizeof mp->mt_filsys);
				mp->mt_time = date;
				mp->mt_ro_flg = 0;
				break;
			}
		}
#endif	/* !_SEQUENT_ */
		for (i = 0; i < 72; i++) {
			inbuf[i] = '\0';
		}
	}
}
