-/* vfs_syscalls.c 4.5 %G% */
+/* vfs_syscalls.c 4.17 82/01/19 */
#include "../h/param.h"
#include "../h/systm.h"
#include "../h/conf.h"
#include "../h/stat.h"
#include "../h/inline.h"
+#include "../h/socket.h"
+#include "../h/socketvar.h"
/*
* the fstat system call.
uap = (struct a *)u.u_ap;
fp = getf(uap->fdes);
- if(fp == NULL)
+ if (fp == NULL)
return;
- stat1(fp->f_inode, uap->sb, fp->f_flag&FPIPE? fp->f_un.f_offset: 0);
+ if (fp->f_flag & FSOCKET)
+ u.u_error = sostat(fp->f_socket, uap->sb);
+ else
+ stat1(fp->f_inode, uap->sb);
}
/*
- * the stat system call.
+ * Stat system call.
*/
stat()
{
uap = (struct a *)u.u_ap;
ip = namei(uchar, 0);
- if(ip == NULL)
+ if (ip == NULL)
return;
- stat1(ip, uap->sb, (off_t)0);
+ stat1(ip, uap->sb);
iput(ip);
}
* The basic routine for fstat and stat:
* get the inode and pass appropriate parts back.
*/
-stat1(ip, ub, pipeadj)
-register struct inode *ip;
-struct stat *ub;
-off_t pipeadj;
+stat1(ip, ub)
+ register struct inode *ip;
+ struct stat *ub;
{
register struct dinode *dp;
register struct buf *bp;
IUPDAT(ip, &time, &time, 0);
/*
- * first copy from inode table
+ * First copy from inode table
*/
ds.st_dev = ip->i_dev;
ds.st_ino = ip->i_number;
ds.st_uid = ip->i_uid;
ds.st_gid = ip->i_gid;
ds.st_rdev = (dev_t)ip->i_un.i_rdev;
- ds.st_size = ip->i_size - pipeadj;
+ ds.st_size = ip->i_size;
/*
- * next the dates in the disk
+ * Next the dates in the disk
*/
bp = bread(ip->i_dev, itod(ip->i_number));
dp = bp->b_un.b_dino;
}
/*
- * the dup system call.
+ * Dup system call.
*/
dup()
{
m = uap->fdes & ~077;
uap->fdes &= 077;
fp = getf(uap->fdes);
- if(fp == NULL)
+ if (fp == NULL)
return;
if ((m&0100) == 0) {
if ((i = ufalloc()) < 0)
u.u_error = EBADF;
return;
}
- if (u.u_vrpages[i]) {
- u.u_error = ETXTBSY;
- return;
- }
u.u_r.r_val1 = i;
}
- if (i!=uap->fdes) {
+ if (i != uap->fdes) {
if (u.u_ofile[i]!=NULL)
- closef(u.u_ofile[i]);
+ closef(u.u_ofile[i], 0);
+ if (u.u_error)
+ return;
u.u_ofile[i] = fp;
fp->f_count++;
}
}
/*
- * the mount system call.
+ * Mount system call.
*/
smount()
{
char *freg;
int ronly;
} *uap;
+ register char *cp;
uap = (struct a *)u.u_ap;
dev = getmdev();
- if(u.u_error)
+ if (u.u_error)
return;
u.u_dirp = (caddr_t)uap->freg;
ip = namei(uchar, 0);
- if(ip == NULL)
+ if (ip == NULL)
return;
- if(ip->i_count!=1 || (ip->i_mode&(IFBLK&IFCHR))!=0)
+ if (ip->i_count!=1 || (ip->i_mode&IFMT) != IFDIR)
goto out;
smp = NULL;
- for(mp = &mount[0]; mp < &mount[NMOUNT]; mp++) {
- if(mp->m_bufp != NULL) {
- if(dev == mp->m_dev)
+ for (mp = &mount[0]; mp < &mount[NMOUNT]; mp++) {
+ if (mp->m_bufp != NULL) {
+ if (dev == mp->m_dev)
goto out;
} else
- if(smp == NULL)
+ if (smp == NULL)
smp = mp;
}
mp = smp;
- if(mp == NULL)
+ if (mp == NULL)
goto out;
(*bdevsw[major(dev)].d_open)(dev, !uap->ronly);
- if(u.u_error)
+ if (u.u_error)
goto out;
bp = bread(dev, SUPERB);
- if(u.u_error) {
+ if (u.u_error) {
brelse(bp);
goto out1;
}
fp->s_ronly = uap->ronly & 1;
fp->s_nbehind = 0;
fp->s_lasti = 1;
+ u.u_dirp = uap->freg;
+ for (cp = fp->s_fsmnt; cp < &fp->s_fsmnt[sizeof (fp->s_fsmnt) - 1]; )
+ if ((*cp++ = uchar()) == 0)
+ u.u_dirp--; /* get 0 again */
+ *cp = 0;
brelse(bp);
ip->i_flag |= IMOUNT;
- prele(ip);
+ irele(ip);
return;
out:
};
dev = getmdev();
- if(u.u_error)
+ if (u.u_error)
return;
xumount(dev); /* remove unused sticky files from text table */
- update();
- for(mp = &mount[0]; mp < &mount[NMOUNT]; mp++)
- if(mp->m_bufp != NULL && dev == mp->m_dev)
+ update(0);
+ for (mp = &mount[0]; mp < &mount[NMOUNT]; mp++)
+ if (mp->m_bufp != NULL && dev == mp->m_dev)
goto found;
u.u_error = EINVAL;
return;
found:
stillopen = 0;
- for(ip = &inode[0]; ip < &inode[NINODE]; ip++)
+ for (ip = inode; ip < inodeNINODE; ip++)
if (ip->i_number != 0 && dev == ip->i_dev) {
u.u_error = EBUSY;
return;
stillopen++;
ip = mp->m_inodp;
ip->i_flag &= ~IMOUNT;
- plock(ip);
+ ilock(ip);
iput(ip);
if ((bp = getblk(dev, SUPERB)) != mp->m_bufp)
panic("umount");
flag = !bp->b_un.b_filsys->s_ronly;
mp->m_bufp = NULL;
brelse(bp);
+ mpurge(mp - &mount[0]);
if (!stillopen) {
- mpurge(mp - &mount[0]);
(*bdevsw[major(dev)].d_close)(dev, flag);
binval(dev);
}
if (!suser())
return(NODEV);
ip = namei(uchar, 0);
- if(ip == NULL)
+ if (ip == NULL)
return(NODEV);
- if((ip->i_mode&IFMT) != IFBLK)
+ if ((ip->i_mode&IFMT) != IFBLK)
u.u_error = ENOTBLK;
dev = (dev_t)ip->i_un.i_rdev;
- if(major(dev) >= nblkdev)
+ if (major(dev) >= nblkdev)
u.u_error = ENXIO;
iput(ip);
return(dev);