SRI-NOSC/ken/sys3.c

Compare this file to the similar file:
Show the results in this format:

#
#include "param.h"
#include "systm.h"
#include "filsys.h"
#include "reg.h"
#include "buf.h"
#include "user.h"
#include "inode.h"
#include "file.h"
#include "conf.h"

/*
 * the fstat system call.
 */
fstat()
{
	register *fp;

	fp = getf(u.u_ar0[R0]);
	/* if getf couldn't find it */
	if(fp == NULL)
		return;
#ifdef	NETSYS
	/* if this is a net file hop over to the good guys */
	if( fp->f_flag&FNET )
		netstat( fp,u.u_arg[0] );
	else
#endif	NETSYS
		stat1(fp->f_inode, u.u_arg[0]);
}

/*
 * the stat system call.
 */
stat()
{
	register ip;
	extern uchar;

	ip = namei(&uchar, 0);
#ifndef	NETSYS
	if(ip == NULL)
#endif	not NETSYS
#ifdef	NETSYS
	/* if inode has 0177776 for number then is in use as net node */
	if( ip == NULL || ip->i_number == 0177776 )
#endif	NETSYS
		return;
	stat1(ip, u.u_arg[1]);
	iput(ip);
}

/*
 * The basic routine for fstat and stat:
 * get the inode and pass appropriate parts back.
 */
stat1(ip, ub)
int *ip;
{
#ifndef UCBUFMOD
	register i, *bp, *cp;

	iupdat(ip, time);
	bp = bread(ip->i_dev, ldiv(ip->i_number+31, 16));
	cp = bp->b_addr + 32*lrem(ip->i_number+31, 16) + 24;
	ip = &(ip->i_dev);
	for(i=0; i<14; i++) {
		suword(ub, *ip++);
		ub =+ 2;
	}
	for(i=0; i<4; i++) {
		suword(ub, *cp++);
		ub =+ 2;
	}
#endif not UCBUFMOD
#ifdef UCBUFMOD
	register i, *bp, *p;

	iupdat(ip, time);
	bp = bread(ip->i_dev, ldiv(ip->i_number+31, 16));
	p = &(ip->i_dev);
	for(i=0; i<14; i++) {
		suword(ub, *p++);
		ub =+ 2;
	}
	btu(bp->b_paddr, 32*lrem(ip->i_number+31, 16) + 24, ub, 4);
#endif UCBUFMOD
	brelse(bp);
}

/*
 * the dup system call.
 */
dup()
{
	register i, *fp;

	fp = getf(u.u_ar0[R0]);
	if(fp == NULL)
		return;
	if ((i = ufalloc()) < 0)
		return;
	u.u_ofile[i] = fp;
	fp->f_count++;
}

/*
 * the mount system call.
 */
smount()
{
	int d;
	register *ip;
	register struct mount *mp, *smp;
	extern uchar;

	d = getmdev();
	if(u.u_error)
		return;
	u.u_dirp = u.u_arg[1];
	ip = namei(&uchar, 0);
	if(ip == NULL)
		return;
	if(ip->i_count!=1 || (ip->i_mode&(IFBLK&IFCHR))!=0)
		goto out;
	smp = NULL;
	for(mp = &mount[0]; mp < &mount[NMOUNT]; mp++) {
		if(mp->m_bufp != NULL) {
			if(d == mp->m_dev)
				goto out;
		} else
		if(smp == NULL)
			smp = mp;
	}
	if(smp == NULL)
		goto out;
	(*bdevsw[d.d_major].d_open)(d, !u.u_arg[2]);
	if(u.u_error)
		goto out;
	mp = bread(d, 1);
	if(u.u_error) {
		brelse(mp);
		goto out1;
	}
	smp->m_inodp = ip;
	smp->m_dev = d;
	smp->m_bufp = getblk(NODEV);
#ifndef UCBUFMOD
	bcopy(mp->b_addr, smp = smp->m_bufp->b_addr, 256);
	smp->s_ilock = 0;
	smp->s_flock = 0;
	smp->s_ronly = u.u_arg[2] & 1;
#endif not UCBUFMOD
#ifdef UCBUFMOD
	btk(mp->b_paddr, &0->s_isize, &smp->m_isize, 3);
		/* fetches isize, fsize, and nfree */
	smp->m_ninode = fbword(mp->b_paddr, &0->s_ninode);
	f1_copy(mp, smp->m_bufp, smp);	/* copy free lists */
	smp->m_ilock = 0;
	smp->m_flock = 0;
	smp->m_ronly = u.u_arg[2] & 1;
	smp->m_fmod = 0;
#endif UCBUFMOD
	brelse(mp);
	ip->i_flag =| IMOUNT;
	prele(ip);
	return;

out:
	u.u_error = EBUSY;
out1:
	iput(ip);
}

/*
 * the umount system call.
 */
sumount()
{
	int d;
	register struct inode *ip;
	register struct mount *mp;

	update();
	d = getmdev();
	if(u.u_error)
		return;
	for(mp = &mount[0]; mp < &mount[NMOUNT]; mp++)
		if(mp->m_bufp!=NULL && d==mp->m_dev)
			goto found;
	u.u_error = EINVAL;
	return;

found:
	for(ip = &inode[0]; ip < &inode[NINODE]; ip++)
		if(ip->i_number!=0 && d==ip->i_dev) {
			u.u_error = EBUSY;
			return;
		}
	(*bdevsw[d.d_major].d_close)(d, 0);
	ip = mp->m_inodp;
	ip->i_flag =& ~IMOUNT;
	iput(ip);
	ip = mp->m_bufp;
	mp->m_bufp = NULL;
	brelse(ip);
}

/*
 * Common code for mount and umount.
 * Check that the user's argument is a reasonable
 * thing on which to mount, and return the device number if so.
 */
getmdev()
{
	register d, *ip;
	extern uchar;

	ip = namei(&uchar, 0);
	if(ip == NULL)
		return;
	if((ip->i_mode&IFMT) != IFBLK)
		u.u_error = ENOTBLK;
	d = ip->i_addr[0];
	if(ip->i_addr[0].d_major >= nblkdev)
		u.u_error = ENXIO;
	iput(ip);
	return(d);
}