# HG changeset patch # Parent 842332badf18a799f544dcc155f077ead4bc9cd3 Add VOP_FALLOCATE and VOP_FDISCARD. diff -r 842332badf18 share/man/man9/vnodeops.9 --- a/share/man/man9/vnodeops.9 Sun Mar 23 02:30:23 2014 -0400 +++ b/share/man/man9/vnodeops.9 Sun Mar 23 02:53:37 2014 -0400 @@ -42,6 +42,8 @@ .Nm VOP_SETATTR , .Nm VOP_READ , .Nm VOP_WRITE , +.Nm VOP_FALLOCATE, +.Nm VOP_FDISCARD, .Nm VOP_IOCTL , .Nm VOP_FCNTL , .Nm VOP_POLL , @@ -115,6 +117,10 @@ .Fn VOP_WRITE "struct vnode *vp" "struct uio *uio" "int ioflag" \ "kauth_cred_t cred" .Ft int +.Fn VOP_FALLOCATE "struct vnode *vp" "off_t pos" "off_t len" +.Ft int +.Fn VOP_FDISCARD "struct vnode *vp" "off_t pos" "off_t len" +.Ft int .Fn VOP_IOCTL "struct vnode *vp" "u_long command" "void *data" \ "int fflag" "kauth_cred_t cred" .Ft int @@ -235,6 +241,8 @@ .It VOP_SETATTR Set file attributes .It VOP_READ Read from a file .It VOP_WRITE Write to a file +.It VOP_FALLOCATE Allocate backing for a file +.It VOP_FDISCARD Discard backing for a file .It VOP_IOCTL Perform device-specific I/O .It VOP_FCNTL Perform file control .It VOP_POLL Test if poll event has occurred @@ -649,6 +657,50 @@ .Pp Zero is returned on success, otherwise an error is returned. The vnode should be locked on entry and remains locked on exit. +.It Fn VOP_FALLOCATE "vp" "pos" "len" +Allocate backing store. +The argument +.Fa vp +is the vnode for the file. +The +.Fa pos +and +.Fa len +arguments (specified in bytes) name an extent within the file. +The blocks underlying this range, rounding up at the top and down at +the bottom if needed, are checked; if no physical storage is +allocated, a physical block is allocated and zeroed. +This operation removes +.Dq holes +from files. +.It Fn VOP_FDISCARD "vp" "pos" "len" +Discard backing store. +The argument +.Fa vp +is the vnode for the file. +The +.Fa pos +and +.Fa len +arguments (specified in bytes) name an extent within the file. +The blocks underlying this range, rounding down at the top and up at +the bottom if needed, are checked. If any physical storage is used, +it is deallocated. +This operation creates +.Dq holes +in files. +Discarded blocks of regular files read back afterwards as zeroes. +On devices, the underlying discard-block operation if any (e.g. ATA +TRIM) is issued. +The device handles this as it sees fit. +In particular it is +.Em not +guaranteed that discarded blocks on devices will be zeroed; reading a +discarded block might produce zeros, or ones, or the previously +existing data, or some other data, or trash. +.\" XXX: if you discard part of a block in a regular file, should that +.\" part be explicitly zeroed? Also, how do you find the underlying +.\" block size? .It Fn VOP_IOCTL "vp" "command" "data" "fflag" "cred" Perform device-specific I/O. The argument diff -r 842332badf18 sys/kern/vnode_if.src --- a/sys/kern/vnode_if.src Sun Mar 23 02:30:23 2014 -0400 +++ b/sys/kern/vnode_if.src Sun Mar 23 02:53:37 2014 -0400 @@ -171,6 +171,24 @@ }; # +#% fallocate vp L L L +# +vop_fallocate { + IN LOCKED=YES struct vnode *vp; + IN off_t pos; + IN off_t len; +}; + +# +#% fallocate vp L L L +# +vop_fdiscard { + IN LOCKED=YES struct vnode *vp; + IN off_t pos; + IN off_t len; +}; + +# #% ioctl vp U U U # vop_ioctl {