summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2017-01-09 10:21:46 +0000
committerkib <kib@FreeBSD.org>2017-01-09 10:21:46 +0000
commit33f24c480d74bcbd8d40ff6da0611ea130dfd7dd (patch)
tree00c1e2274548d3afa02d14a953115637dc5bb159
parentcc89476efad66e1b62efa4c62f6694e6017c88c6 (diff)
downloadFreeBSD-src-33f24c480d74bcbd8d40ff6da0611ea130dfd7dd.zip
FreeBSD-src-33f24c480d74bcbd8d40ff6da0611ea130dfd7dd.tar.gz
MFC r311108:
Move common code from kern_statfs() and kern_fstatfs() into a new helper.
-rw-r--r--sys/kern/vfs_syscalls.c106
1 files changed, 41 insertions, 65 deletions
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 80b93a1..a338c0f 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -244,6 +244,45 @@ statfs_scale_blocks(struct statfs *sf, long max_size)
sf->f_bavail >>= shift;
}
+static int
+kern_do_statfs(struct thread *td, struct mount *mp, struct statfs *buf)
+{
+ struct statfs *sp, sb;
+ int error;
+
+ if (mp == NULL)
+ return (EBADF);
+ error = vfs_busy(mp, 0);
+ vfs_rel(mp);
+ if (error != 0)
+ return (error);
+#ifdef MAC
+ error = mac_mount_check_stat(td->td_ucred, mp);
+ if (error != 0)
+ goto out;
+#endif
+ /*
+ * Set these in case the underlying filesystem fails to do so.
+ */
+ sp = &mp->mnt_stat;
+ sp->f_version = STATFS_VERSION;
+ sp->f_namemax = NAME_MAX;
+ sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
+ error = VFS_STATFS(mp, sp);
+ if (error != 0)
+ goto out;
+ if (priv_check(td, PRIV_VFS_GENERATION)) {
+ bcopy(sp, &sb, sizeof(sb));
+ sb.f_fsid.val[0] = sb.f_fsid.val[1] = 0;
+ prison_enforce_statfs(td->td_ucred, mp, &sb);
+ sp = &sb;
+ }
+ *buf = *sp;
+out:
+ vfs_unbusy(mp);
+ return (error);
+}
+
/*
* Get filesystem statistics.
*/
@@ -275,7 +314,6 @@ kern_statfs(struct thread *td, char *path, enum uio_seg pathseg,
struct statfs *buf)
{
struct mount *mp;
- struct statfs *sp, sb;
struct nameidata nd;
int error;
@@ -288,35 +326,7 @@ kern_statfs(struct thread *td, char *path, enum uio_seg pathseg,
vfs_ref(mp);
NDFREE(&nd, NDF_ONLY_PNBUF);
vput(nd.ni_vp);
- error = vfs_busy(mp, 0);
- vfs_rel(mp);
- if (error != 0)
- return (error);
-#ifdef MAC
- error = mac_mount_check_stat(td->td_ucred, mp);
- if (error != 0)
- goto out;
-#endif
- /*
- * Set these in case the underlying filesystem fails to do so.
- */
- sp = &mp->mnt_stat;
- sp->f_version = STATFS_VERSION;
- sp->f_namemax = NAME_MAX;
- sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
- error = VFS_STATFS(mp, sp);
- if (error != 0)
- goto out;
- if (priv_check(td, PRIV_VFS_GENERATION)) {
- bcopy(sp, &sb, sizeof(sb));
- sb.f_fsid.val[0] = sb.f_fsid.val[1] = 0;
- prison_enforce_statfs(td->td_ucred, mp, &sb);
- sp = &sb;
- }
- *buf = *sp;
-out:
- vfs_unbusy(mp);
- return (error);
+ return (kern_do_statfs(td, mp, buf));
}
/*
@@ -350,7 +360,6 @@ kern_fstatfs(struct thread *td, int fd, struct statfs *buf)
{
struct file *fp;
struct mount *mp;
- struct statfs *sp, sb;
struct vnode *vp;
cap_rights_t rights;
int error;
@@ -369,40 +378,7 @@ kern_fstatfs(struct thread *td, int fd, struct statfs *buf)
vfs_ref(mp);
VOP_UNLOCK(vp, 0);
fdrop(fp, td);
- if (mp == NULL) {
- error = EBADF;
- goto out;
- }
- error = vfs_busy(mp, 0);
- vfs_rel(mp);
- if (error != 0)
- return (error);
-#ifdef MAC
- error = mac_mount_check_stat(td->td_ucred, mp);
- if (error != 0)
- goto out;
-#endif
- /*
- * Set these in case the underlying filesystem fails to do so.
- */
- sp = &mp->mnt_stat;
- sp->f_version = STATFS_VERSION;
- sp->f_namemax = NAME_MAX;
- sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
- error = VFS_STATFS(mp, sp);
- if (error != 0)
- goto out;
- if (priv_check(td, PRIV_VFS_GENERATION)) {
- bcopy(sp, &sb, sizeof(sb));
- sb.f_fsid.val[0] = sb.f_fsid.val[1] = 0;
- prison_enforce_statfs(td->td_ucred, mp, &sb);
- sp = &sb;
- }
- *buf = *sp;
-out:
- if (mp)
- vfs_unbusy(mp);
- return (error);
+ return (kern_do_statfs(td, mp, buf));
}
/*
OpenPOWER on IntegriCloud