Skip to content

Commit

Permalink
msdosfs: truncate write if it would exceed the fs max file size or RL…
Browse files Browse the repository at this point in the history
…IMIT_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
  • Loading branch information
kostikbel committed Sep 24, 2022
1 parent 87525ef commit a9c439b
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions sys/fs/msdosfs/msdosfs_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ msdosfs_write(struct vop_write_args *ap)
{
int n;
int croffset;
ssize_t resid;
ssize_t resid, r;
u_long osize;
int error = 0;
u_long count;
Expand Down Expand Up @@ -659,16 +659,15 @@ msdosfs_write(struct vop_write_args *ap)
/*
* The caller is supposed to ensure that
* uio->uio_offset >= 0 and uio->uio_resid >= 0.
*/
if ((uoff_t)uio->uio_offset + uio->uio_resid > MSDOSFS_FILESIZE_MAX)
return (EFBIG);

/*
*
* If they've exceeded their filesize limit, tell them about it.
*/
error = vn_rlimit_fsize(vp, uio, uio->uio_td);
if (error != 0)
error = vn_rlimit_fsizex(vp, uio, MSDOSFS_FILESIZE_MAX, &r,
uio->uio_td);
if (error != 0) {
vn_rlimit_fsizex_res(uio, r);
return (error);
}

/*
* If the offset we are starting the write at is beyond the end of
Expand All @@ -678,8 +677,10 @@ msdosfs_write(struct vop_write_args *ap)
*/
if (uio->uio_offset > dep->de_FileSize) {
error = deextend(dep, uio->uio_offset, cred);
if (error)
if (error != 0) {
vn_rlimit_fsizex_res(uio, r);
return (error);
}
}

/*
Expand Down Expand Up @@ -822,6 +823,7 @@ msdosfs_write(struct vop_write_args *ap)
}
} else if (ioflag & IO_SYNC)
error = deupdat(dep, 1);
vn_rlimit_fsizex_res(uio, r);
return (error);
}

Expand Down

0 comments on commit a9c439b

Please sign in to comment.