aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2022-09-18 13:27:28 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2022-09-24 16:42:05 +0000
commit8bdb2695d69710b7f2e7cc20820aab8b3f4668a6 (patch)
tree56071b3233438bf9759b80266bb4affff5da0cc1
parenta9c439ba104d83a2666d114dae9f26b2efb22d17 (diff)
downloadsrc-8bdb2695d69710b7f2e7cc20820aab8b3f4668a6.tar.gz
src-8bdb2695d69710b7f2e7cc20820aab8b3f4668a6.zip
tmpfs: truncate write if it would exceed the fs max file size or RLIMIT_FSIZE
PR: 164793 Reviewed by: asomers, jah, markj Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D36625
-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 079936946270..7a9ffed9696c 100644
--- a/sys/fs/tmpfs/tmpfs_vnops.c
+++ b/sys/fs/tmpfs/tmpfs_vnops.c
@@ -639,6 +639,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;
@@ -655,12 +656,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,
@@ -687,6 +688,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);
}