Index: lib/libc/sys/fspacectl.2 =================================================================== --- lib/libc/sys/fspacectl.2 +++ lib/libc/sys/fspacectl.2 @@ -27,7 +27,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd August 4, 2021 +.Dd August 18, 2021 .Dt FSPACECTL 2 .Os .Sh NAME @@ -67,6 +67,7 @@ .Fa spacectl_range structure it points to is updated to contain the unprocessed operation range after the system call returns. +The file descriptor's file offset is not used or modified by the system call. Both .Fa rqsr and @@ -92,9 +93,9 @@ .Fa rqsr argument. The -.Va "rqsr->r_offset" +.Fa "rqsr->r_offset" has to be a value greater than or equal to 0, and the -.Va "rqsr->r_len" +.Fa "rqsr->r_len" has to be a value greater than 0. .Pp If the file system supports hole-punching, @@ -137,6 +138,12 @@ .Fa "range->r_len" argument was less than or equal to zero. .It Bq Er EINVAL +The value of +.Fa "range->r_offset" + +.Fa "range->r_len" +is greater than +.Dv OFF_MAX . +.It Bq Er EINVAL An invalid or unsupported flag is included in .Fa flags . .It Bq Er EINVAL Index: sys/kern/vfs_default.c =================================================================== --- sys/kern/vfs_default.c +++ sys/kern/vfs_default.c @@ -1138,15 +1138,17 @@ vp = ap->a_vp; offset = *ap->a_offset; - len = *ap->a_len; cred = ap->a_cred; error = VOP_GETATTR(vp, &va, cred); if (error) return (error); - len = omin(OFF_MAX - offset, *ap->a_len); - while (len > 0) { + /* Handle the case when offset is beyond EOF */ + len = omin(va.va_size - offset, *ap->a_len); + if (len < 0) + len = 0; + while (len != 0) { noff = offset; error = vn_bmap_seekhole_locked(vp, FIOSEEKDATA, &noff, cred); if (error) { @@ -1184,7 +1186,7 @@ len -= xfersize; if (should_yield()) break; - } + } while (len > 0); out: *ap->a_offset = offset; *ap->a_len = len;