summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>1999-05-31 17:34:39 +0000
committermillert <millert@openbsd.org>1999-05-31 17:34:39 +0000
commitef921adb8d7e32b181c8c0cee764ec21824f98e1 (patch)
tree92c8c81d878d3dd317c727134865748e6b031e98 /sys/kern
parentUse connection-oriented transport (ie: TCP) when possible. This makes (diff)
downloadwireguard-openbsd-ef921adb8d7e32b181c8c0cee764ec21824f98e1.tar.xz
wireguard-openbsd-ef921adb8d7e32b181c8c0cee764ec21824f98e1.zip
New struct statfs with mount options. NOTE: this replaces statfs(2),
fstatfs(2), and getfsstat(2) so you will need to build a new kernel before doing a "make build" or you will get "unimplemented syscall" errors. The new struct statfs has the following featuires: o Has a u_int32_t flags field--now softdep can have a real flag. o Uses u_int32_t instead of longs (nicer on the alpha). Note: the man page used to lie about setting invalid/unused fields to -1. SunOS does that but our code never has. o Gets rid of f_type completely. It hasn't been used since NetBSD 0.9 and having it there but always 0 is confusing. It is conceivable that this may cause some old code to not compile but that is better than silently breaking. o Adds a mount_info union that contains the FSTYPE_args struct. This means that "mount" can now tell you all the options a filesystem was mounted with. This is especially nice for NFS. Other changes: o The linux statfs emulation didn't convert between BSD fs names and linux f_type numbers. Now it does, since the BSD f_type number is useless to linux apps (and has been removed anyway) o FreeBSD's struct statfs is different from our (both old and new) and thus needs conversion. Previously, the OpenBSD syscalls were used without any real translation. o mount(8) will now show extra info when invoked with no arguments. However, to see *everything* you need to use the -v (verbose) flag.
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/init_sysent.c20
-rw-r--r--sys/kern/syscalls.c11
-rw-r--r--sys/kern/syscalls.master15
-rw-r--r--sys/kern/vfs_subr.c3
-rw-r--r--sys/kern/vfs_syscalls.c183
5 files changed, 208 insertions, 24 deletions
diff --git a/sys/kern/init_sysent.c b/sys/kern/init_sysent.c
index b8e88982db8..e3e3482e214 100644
--- a/sys/kern/init_sysent.c
+++ b/sys/kern/init_sysent.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: init_sysent.c,v 1.37 1999/05/22 21:25:51 weingart Exp $ */
+/* $OpenBSD: init_sysent.c,v 1.38 1999/05/31 17:34:47 millert Exp $ */
/*
* System call switch table.
@@ -77,8 +77,8 @@ struct sysent sysent[] = {
sys_chown }, /* 16 = chown */
{ 1, s(struct sys_obreak_args),
sys_obreak }, /* 17 = break */
- { 3, s(struct sys_getfsstat_args),
- sys_getfsstat }, /* 18 = getfsstat */
+ { 3, s(struct sys_ogetfsstat_args),
+ sys_ogetfsstat }, /* 18 = ogetfsstat */
{ 3, s(struct compat_43_sys_lseek_args),
compat_43(sys_lseek) }, /* 19 = compat_43 olseek */
{ 0, 0,
@@ -370,10 +370,10 @@ struct sysent sysent[] = {
#endif
{ 4, s(struct compat_43_sys_getdirentries_args),
compat_43(sys_getdirentries) }, /* 156 = compat_43 ogetdirentries */
- { 2, s(struct sys_statfs_args),
- sys_statfs }, /* 157 = statfs */
- { 2, s(struct sys_fstatfs_args),
- sys_fstatfs }, /* 158 = fstatfs */
+ { 2, s(struct sys_ostatfs_args),
+ sys_ostatfs }, /* 157 = ostatfs */
+ { 2, s(struct sys_ofstatfs_args),
+ sys_ofstatfs }, /* 158 = ofstatfs */
{ 0, 0,
sys_nosys }, /* 159 = unimplemented */
{ 0, 0,
@@ -685,5 +685,11 @@ struct sysent sysent[] = {
{ 0, 0,
sys_nosys }, /* 259 = unimplemented */
#endif
+ { 3, s(struct sys_getfsstat_args),
+ sys_getfsstat }, /* 260 = getfsstat */
+ { 2, s(struct sys_statfs_args),
+ sys_statfs }, /* 261 = statfs */
+ { 2, s(struct sys_fstatfs_args),
+ sys_fstatfs }, /* 262 = fstatfs */
};
diff --git a/sys/kern/syscalls.c b/sys/kern/syscalls.c
index b918a0d242a..60b518fe2fe 100644
--- a/sys/kern/syscalls.c
+++ b/sys/kern/syscalls.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: syscalls.c,v 1.37 1999/05/22 21:25:51 weingart Exp $ */
+/* $OpenBSD: syscalls.c,v 1.38 1999/05/31 17:34:47 millert Exp $ */
/*
* System call names.
@@ -26,7 +26,7 @@ char *syscallnames[] = {
"chmod", /* 15 = chmod */
"chown", /* 16 = chown */
"break", /* 17 = break */
- "getfsstat", /* 18 = getfsstat */
+ "ogetfsstat", /* 18 = ogetfsstat */
"compat_43_olseek", /* 19 = compat_43 olseek */
"getpid", /* 20 = getpid */
"mount", /* 21 = mount */
@@ -177,8 +177,8 @@ char *syscallnames[] = {
"#155 (unimplemented)", /* 155 = unimplemented */
#endif
"compat_43_ogetdirentries", /* 156 = compat_43 ogetdirentries */
- "statfs", /* 157 = statfs */
- "fstatfs", /* 158 = fstatfs */
+ "ostatfs", /* 157 = ostatfs */
+ "ofstatfs", /* 158 = ofstatfs */
"#159 (unimplemented)", /* 159 = unimplemented */
"#160 (unimplemented)", /* 160 = unimplemented */
#if defined(NFSCLIENT) || defined(NFSSERVER)
@@ -354,4 +354,7 @@ char *syscallnames[] = {
#else
"#259 (unimplemented)", /* 259 = unimplemented */
#endif
+ "getfsstat", /* 260 = getfsstat */
+ "statfs", /* 261 = statfs */
+ "fstatfs", /* 262 = fstatfs */
};
diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master
index 0eaf5345051..58e865bef0f 100644
--- a/sys/kern/syscalls.master
+++ b/sys/kern/syscalls.master
@@ -1,4 +1,4 @@
-; $OpenBSD: syscalls.master,v 1.35 1999/05/22 21:23:40 weingart Exp $
+; $OpenBSD: syscalls.master,v 1.36 1999/05/31 17:34:47 millert Exp $
; $NetBSD: syscalls.master,v 1.32 1996/04/23 10:24:21 mycroft Exp $
; @(#)syscalls.master 8.2 (Berkeley) 1/13/94
@@ -70,7 +70,7 @@
16 STD { int sys_chown(const char *path, uid_t uid, \
gid_t gid); }
17 STD { int sys_obreak(char *nsize); } break
-18 STD { int sys_getfsstat(struct statfs *buf, long bufsize, \
+18 STD { int sys_ogetfsstat(struct statfs *buf, long bufsize, \
int flags); }
19 COMPAT_43 { long sys_lseek(int fd, long offset, int whence); } \
olseek
@@ -290,9 +290,9 @@
#endif
156 COMPAT_43 { int sys_getdirentries(int fd, char *buf, \
int count, long *basep); } ogetdirentries
-157 STD { int sys_statfs(const char *path, \
- struct statfs *buf); }
-158 STD { int sys_fstatfs(int fd, struct statfs *buf); }
+157 STD { int sys_ostatfs(const char *path, \
+ struct ostatfs *buf); }
+158 STD { int sys_ofstatfs(int fd, struct ostatfs *buf); }
159 UNIMPL
160 UNIMPL
#if defined(NFSCLIENT) || defined(NFSSERVER)
@@ -514,3 +514,8 @@
#else
259 UNIMPL
#endif
+260 STD { int sys_getfsstat(struct statfs *buf, size_t bufsize, \
+ int flags); }
+261 STD { int sys_statfs(const char *path, \
+ struct statfs *buf); }
+262 STD { int sys_fstatfs(int fd, struct statfs *buf); }
diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index 4df9a385a12..a44fa140711 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_subr.c,v 1.38 1999/05/06 15:59:40 mickey Exp $ */
+/* $OpenBSD: vfs_subr.c,v 1.39 1999/05/31 17:34:48 millert Exp $ */
/* $NetBSD: vfs_subr.c,v 1.53 1996/04/22 01:39:13 christos Exp $ */
/*
@@ -222,7 +222,6 @@ vfs_rootmountalloc(fstypename, devname, mpp)
mp->mnt_flag = MNT_RDONLY;
mp->mnt_vnodecovered = NULLVP;
vfsp->vfc_refcount++;
- mp->mnt_stat.f_type = vfsp->vfc_typenum;
mp->mnt_flag |= vfsp->vfc_flags & MNT_VISFLAGMASK;
strncpy(mp->mnt_stat.f_fstypename, vfsp->vfc_name, MFSNAMELEN);
mp->mnt_stat.f_mntonname[0] = '/';
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 46eca31aab0..f2f2892bb74 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_syscalls.c,v 1.56 1999/02/26 04:51:17 art Exp $ */
+/* $OpenBSD: vfs_syscalls.c,v 1.57 1999/05/31 17:34:48 millert Exp $ */
/* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */
/*
@@ -70,6 +70,7 @@ int usermount = 0; /* sysctl: by default, users may not mount */
static int change_dir __P((struct nameidata *, struct proc *));
void checkdirs __P((struct vnode *));
+void statfs_to_ostatfs __P((struct proc *, struct mount *, struct statfs *, struct ostatfs *));
/*
* Redirection info so we don't have to include the union fs routines in
@@ -248,7 +249,6 @@ sys_mount(p, v, retval)
vfs_busy(mp, LK_NOWAIT, 0, p);
mp->mnt_op = vfsp->vfc_vfsops;
mp->mnt_vfc = vfsp;
- mp->mnt_stat.f_type = vfsp->vfc_typenum;
mp->mnt_flag |= (vfsp->vfc_flags & MNT_VISFLAGMASK);
strncpy(mp->mnt_stat.f_fstypename, vfsp->vfc_name, MFSNAMELEN);
mp->mnt_vnodecovered = vp;
@@ -643,15 +643,15 @@ sys_getfsstat(p, v, retval)
{
register struct sys_getfsstat_args /* {
syscallarg(struct statfs *) buf;
- syscallarg(long) bufsize;
+ syscallarg(size_t) bufsize;
syscallarg(int) flags;
} */ *uap = v;
register struct mount *mp, *nmp;
register struct statfs *sp;
- caddr_t sfsp;
- long count, maxcount, error;
struct statfs sb;
- int flags = SCARG(uap, flags);
+ caddr_t sfsp;
+ size_t count, maxcount;
+ int error, flags = SCARG(uap, flags);
maxcount = SCARG(uap, bufsize) / sizeof(struct statfs);
sfsp = (caddr_t)SCARG(uap, buf);
@@ -2360,3 +2360,174 @@ getvnode(fdp, fd, fpp)
*fpp = fp;
return (0);
}
+
+/*
+ * At some point (before 2.6 is released), these will move to
+ * sys/compat/vfs_syscalls_25.c
+ */
+
+/*
+ * Convert struct statfs -> struct ostatfs
+ */
+void
+statfs_to_ostatfs(p, mp, sp, osp)
+ struct proc *p;
+ struct mount *mp;
+ struct statfs *sp;
+ struct ostatfs *osp;
+{
+#if defined(COMPAT_09) || defined(COMPAT_43)
+ osp->f_type = mp->mnt_vfc->vfc_typenum;
+#else
+ osp->f_type = 0;
+#endif
+ osp->f_flags = mp->mnt_flag & 0xffff;
+ osp->f_bsize = sp->f_bsize;
+ osp->f_iosize = sp->f_iosize;
+ osp->f_blocks = sp->f_blocks;
+ osp->f_bfree = sp->f_bfree;
+ osp->f_bavail = sp->f_bavail;
+ osp->f_files = sp->f_files;
+ osp->f_ffree = sp->f_ffree;
+ /* Don't let non-root see filesystem id (for NFS security) */
+ if (suser(p->p_ucred, &p->p_acflag))
+ osp->f_fsid.val[0] = osp->f_fsid.val[1] = 0;
+ else
+ bcopy(&sp->f_fsid, &osp->f_fsid, sizeof(osp->f_fsid));
+ osp->f_owner = sp->f_owner;
+ osp->f_syncwrites = sp->f_syncwrites;
+ osp->f_asyncwrites = sp->f_asyncwrites;
+ bcopy(sp->f_fstypename, osp->f_fstypename, MFSNAMELEN);
+ bcopy(sp->f_mntonname, osp->f_mntonname, MNAMELEN);
+ bcopy(sp->f_mntfromname, osp->f_mntfromname, MNAMELEN);
+}
+
+/*
+ * Get filesystem statistics.
+ */
+/* ARGSUSED */
+int
+sys_ostatfs(p, v, retval)
+ struct proc *p;
+ void *v;
+ register_t *retval;
+{
+ register struct sys_ostatfs_args /* {
+ syscallarg(char *) path;
+ syscallarg(struct ostatfs *) buf;
+ } */ *uap = v;
+ register struct mount *mp;
+ register struct statfs *sp;
+ struct ostatfs osb;
+ int error;
+ struct nameidata nd;
+
+ NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
+ if ((error = namei(&nd)) != 0)
+ return (error);
+ mp = nd.ni_vp->v_mount;
+ sp = &mp->mnt_stat;
+ vrele(nd.ni_vp);
+ if ((error = VFS_STATFS(mp, sp, p)) != 0)
+ return (error);
+
+ statfs_to_ostatfs(p, mp, sp, &osb);
+ return (copyout((caddr_t)&osb, (caddr_t)SCARG(uap, buf), sizeof(osb)));
+}
+
+/*
+ * Get filesystem statistics.
+ */
+/* ARGSUSED */
+int
+sys_ofstatfs(p, v, retval)
+ struct proc *p;
+ void *v;
+ register_t *retval;
+{
+ register struct sys_ofstatfs_args /* {
+ syscallarg(int) fd;
+ syscallarg(struct ostatfs *) buf;
+ } */ *uap = v;
+ struct file *fp;
+ struct mount *mp;
+ register struct statfs *sp;
+ struct ostatfs osb;
+ int error;
+
+ if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
+ return (error);
+ mp = ((struct vnode *)fp->f_data)->v_mount;
+ sp = &mp->mnt_stat;
+ if ((error = VFS_STATFS(mp, sp, p)) != 0)
+ return (error);
+
+ statfs_to_ostatfs(p, mp, sp, &osb);
+ return (copyout((caddr_t)&osb, (caddr_t)SCARG(uap, buf), sizeof(osb)));
+}
+
+/*
+ * Get statistics on all filesystems.
+ */
+int
+sys_ogetfsstat(p, v, retval)
+ struct proc *p;
+ void *v;
+ register_t *retval;
+{
+ register struct sys_ogetfsstat_args /* {
+ syscallarg(struct ostatfs *) buf;
+ syscallarg(long) bufsize;
+ syscallarg(int) flags;
+ } */ *uap = v;
+ register struct mount *mp, *nmp;
+ register struct statfs *sp;
+ struct ostatfs osb;
+ caddr_t sfsp;
+ long count, maxcount;
+ int error, flags = SCARG(uap, flags);
+
+ maxcount = SCARG(uap, bufsize) / sizeof(struct ostatfs);
+ sfsp = (caddr_t)SCARG(uap, buf);
+ count = 0;
+ simple_lock(&mountlist_slock);
+ for (mp = mountlist.cqh_first; mp != (void *)&mountlist; mp = nmp) {
+ if (vfs_busy(mp, LK_NOWAIT, &mountlist_slock, p)) {
+ nmp = mp->mnt_list.cqe_next;
+ continue;
+ }
+ if (sfsp && count < maxcount) {
+ sp = &mp->mnt_stat;
+
+ /* Refresh stats unless MNT_NOWAIT is specified */
+ if (flags != MNT_NOWAIT &&
+ flags != MNT_LAZY &&
+ (flags == MNT_WAIT ||
+ flags == 0) &&
+ (error = VFS_STATFS(mp, sp, p))) {
+ simple_lock(&mountlist_slock);
+ nmp = mp->mnt_list.cqe_next;
+ vfs_unbusy(mp, p);
+ continue;
+ }
+
+ statfs_to_ostatfs(p, mp, sp, &osb);
+ error = copyout((caddr_t)&osb, sfsp, sizeof(osb));
+ if (error) {
+ vfs_unbusy(mp, p);
+ return (error);
+ }
+ sfsp += sizeof(osb);
+ }
+ count++;
+ simple_lock(&mountlist_slock);
+ nmp = mp->mnt_list.cqe_next;
+ vfs_unbusy(mp, p);
+ }
+ simple_unlock(&mountlist_slock);
+ if (sfsp && count > maxcount)
+ *retval = maxcount;
+ else
+ *retval = count;
+ return (0);
+}