aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2022-09-18 13:27:28 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2022-10-08 00:29:36 +0000
commit2bd3dbe3dd60aeb84ebc52f23f0f4205d3eb082d (patch)
tree58577449a977257fd770c7f16b7ee02374f4f684
parent337b0852e942205246f16c30a923900edbb16a8c (diff)
downloadsrc-2bd3dbe3dd60aeb84ebc52f23f0f4205d3eb082d.tar.gz
src-2bd3dbe3dd60aeb84ebc52f23f0f4205d3eb082d.zip
tmpfs: truncate write if it would exceed the fs max file size or RLIMIT_FSIZE
PR: 164793 (cherry picked from commit 8bdb2695d69710b7f2e7cc20820aab8b3f4668a6)
-rw-r--r--sys/fs/tmpfs/tmpfs_vnops.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/sys/fs/tmpfs/tmpfs_vnops.c b/sys/fs/tmpfs/tmpfs_vnops.c
index c1133cdaa1db..ab5a99b1be66 100644
--- a/sys/fs/tmpfs/tmpfs_vnops.c
+++ b/sys/fs/tmpfs/tmpfs_vnops.c
@@ -646,6 +646,7 @@ tmpfs_write(struct vop_write_args *v)
struct uio *uio;
struct tmpfs_node *node;
off_t oldsize;
+ ssize_t r;
int error, ioflag;
mode_t newmode;
@@ -662,12 +663,12 @@ tmpfs_write(struct vop_write_args *v)
return (0);
if (ioflag & IO_APPEND)
uio->uio_offset = node->tn_size;
- if (uio->uio_offset + uio->uio_resid >
- VFS_TO_TMPFS(vp->v_mount)->tm_maxfilesize)
- return (EFBIG);
- error = vn_rlimit_fsize(vp, uio, uio->uio_td);
- if (error != 0)
+ error = vn_rlimit_fsizex(vp, uio, VFS_TO_TMPFS(vp->v_mount)->
+ tm_maxfilesize, &r, uio->uio_td);
+ if (error != 0) {
+ vn_rlimit_fsizex_res(uio, r);
return (error);
+ }
if (uio->uio_offset + uio->uio_resid > node->tn_size) {
error = tmpfs_reg_resize(vp, uio->uio_offset + uio->uio_resid,
@@ -694,6 +695,7 @@ out:
MPASS(IMPLIES(error == 0, uio->uio_resid == 0));
MPASS(IMPLIES(error != 0, oldsize == node->tn_size));
+ vn_rlimit_fsizex_res(uio, r);
return (error);
}