From c407a13fc1f5842881c967d0132035c7db442d4a Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 1 Sep 2025 14:10:17 +0200 Subject: [PATCH] fallocate: update FALLOC_FL_WRITE_ZEROES Update to Zhang Yi's latest version of the patch. Unfortunately, I missed that he was still working on it (it was sent to the kernel mailing lists rather than the util-linux mailing list). Signed-off-by: Karel Zak --- sys-utils/fallocate.1.adoc | 6 +++--- sys-utils/fallocate.c | 13 +++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/sys-utils/fallocate.1.adoc b/sys-utils/fallocate.1.adoc index 0ec9ff9a9..69602f01c 100644 --- a/sys-utils/fallocate.1.adoc +++ b/sys-utils/fallocate.1.adoc @@ -77,11 +77,11 @@ Option *--keep-size* can be specified to prevent file length modification. Available since Linux 3.14 for ext4 (only for extent-based files) and XFS. *-w*, *--write-zeroes*:: -Zeroes space in the byte range starting at _offset_ and continuing for _length_ bytes. Within the specified range, blocks are preallocated for the regions that span the holes in the file. After a successful call, subsequent reads from this range will return zeroes, subsequent writes to that range do not require further changes to the file mapping metadata. +Zeroes space in the byte range starting at _offset_ and continuing for _length_ bytes. Within the specified range, written blocks are preallocated for the regions that span the holes in the file. After a successful call, subsequent reads from this range will return zeroes and subsequent writes to that range do not require further changes to the file mapping metadata. + -Zeroing is done within the filesystem by preferably submitting write zeores commands, the alternative way is submitting actual zeroed data, the specified range will be converted into written extents. The write zeroes command is typically faster than write actual data if the device supports unmap write zeroes, the specified range will not be physically zeroed out on the device. +Zeroing is done within the filesystem. The filesystem may use a hardware-accelerated zeroing command or may submit regular writes. The behavior depends on the filesystem design and the available hardware. + -Options *--keep-size* can not be specified for the write-zeroes operation. +Options *--keep-size* cannot be specified for the write-zeroes operation because allocating written blocks beyond the inode size is not permitted. include::man-common/help-version.adoc[] diff --git a/sys-utils/fallocate.c b/sys-utils/fallocate.c index 8d37fdad7..30c391406 100644 --- a/sys-utils/fallocate.c +++ b/sys-utils/fallocate.c @@ -17,8 +17,9 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include #include @@ -395,16 +396,16 @@ int main(int argc, char **argv) if (length == -2LL) length = 0; if (length < 0) - errx(EXIT_FAILURE, _("invalid length")); + errx(EXIT_FAILURE, _("invalid length value specified")); } else { /* it's safer to require the range specification (--length --offset) */ if (length == -2LL) errx(EXIT_FAILURE, _("no length argument specified")); if (length <= 0) - errx(EXIT_FAILURE, _("invalid length")); + errx(EXIT_FAILURE, _("invalid length value specified")); } if (offset < 0) - errx(EXIT_FAILURE, _("invalid offset")); + errx(EXIT_FAILURE, _("invalid offset value specified")); /* O_CREAT makes sense only for the default fallocate(2) behavior * when mode is no specified and new space is allocated */ @@ -439,7 +440,7 @@ int main(int argc, char **argv) fprintf(stdout, _("%s: %s (%ju bytes) zeroed.\n"), filename, str, length); else if (mode & FALLOC_FL_WRITE_ZEROES) - fprintf(stdout, _("%s: %s (%ju bytes) write zeroed.\n"), + fprintf(stdout, _("%s: %s (%ju bytes) written as zeroes.\n"), filename, str, length); else fprintf(stdout, _("%s: %s (%ju bytes) allocated.\n"), -- 2.47.3