From nobody Wed Jan 21 23:35:54 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4dxLDC0Pkmz6PtlC for ; Wed, 21 Jan 2026 23:35:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dxLDB6wHJz3mRW for ; Wed, 21 Jan 2026 23:35:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1769038555; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/xXdqrRuEJJqziANRt6kFqlCVP7tcMKzhJEwLimi0W8=; b=q9V0abrr+VlqHQ1d1+gQ917n2A10DM4PyPcuCbxMQpd8L1mDC2+RzLGH/qOsWVIoyDterk EZIiYYN3wK5WD+7g/OZqx+rpfT0D7IuIeDnJqPn/cOsjMY4b/fxuYa5B7kQ+T15rYB1Rzn F292+G5H2oCAO5tsf1xbmyOcOU0NqoQ7SaseesmuL1DuiXCSCvYmRNIhIfwSjOQCK7TO5R c561FElXpjf1nq1BZ/wOY5xVbHvUrHHs1LNenI/o0+9VwmTsdVJyzTjzhDEsFCzYsp2x5Y TPq/McMRlGOqlO4Y3hCYGlM9O53X9pa12WT5ECCGMQ37Vz8E2GcQVzoFYIU73w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1769038555; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/xXdqrRuEJJqziANRt6kFqlCVP7tcMKzhJEwLimi0W8=; b=wsrflafCFBp7yGBuoui3yXI5jdqEKzL1bRUGu9VwRM0RhvH81tWnCuW1TXup3zpMhLb8Ll fPLiSeI6qjftmeQ/1HuNkWFsGob5/izAZZS027WeNLXzSvVZSfwIDEuF6/b5+Ob2FuY3Z/ eG6WonKCTSCtC4watuMMXj7U+YkilFdskcoC7G9SsEHi6TckVKeJDJPnSew483rzrYpGfE T9pUpD99YJeyQQ3BVkuv8e89ZarrXFCjqyRNUwzO8ZQUOZszmZCDDfG5KEGVVLpBWpYwL2 Ej+/eRM4pt9nwp5Ok7FNE6DQqEJ9gbmTmSQKUGq8AkBD354OXwrPWPnPYdRiXw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1769038555; a=rsa-sha256; cv=none; b=dh6fv7+cEwjnN1bLehBpl2LQIh3xy9co6IsD1PR32VZ1GZL0kF2SFdz4wP0C/Ft5whb1Um 5Ud9oExBjzEIncE5yGs5qigVrgO5TqaAU93C1FIpKG+YSMbq3MaFwnut6rKT/swS4cd4n3 udnLtolDIQdFXy4Vri2VurWXgpGfybPgh+vylkhuwJUF4iyu40uZfXhVA6Qx3syyLln+40 WSI+uxBbOfbCraDR1OSarQYye+j+rB3hpCsKDNq+Qv9GYFUKFzyQhVbl+qKIrM6K0GA/g3 TQ3ORfiF0yibETmgsfot48pX6N5c55Ibot6b5am/rGqQAdkiL54VeX6Hdvqyng== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dxLDB6Fczz17Gr for ; Wed, 21 Jan 2026 23:35:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3a73d by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 21 Jan 2026 23:35:54 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: eacc501eff52 - main - truncate: fix a minor nit + add a hole-punching test List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: eacc501eff52db16b7b784c89a3a4a03c9a3ef34 Auto-Submitted: auto-generated Date: Wed, 21 Jan 2026 23:35:54 +0000 Message-Id: <697162da.3a73d.48c66da4@gitrepo.freebsd.org> The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=eacc501eff52db16b7b784c89a3a4a03c9a3ef34 commit eacc501eff52db16b7b784c89a3a4a03c9a3ef34 Author: Kyle Evans AuthorDate: 2026-01-21 23:34:27 +0000 Commit: Kyle Evans CommitDate: 2026-01-21 23:35:25 +0000 truncate: fix a minor nit + add a hole-punching test The struct spacectl_range we use is only really used in these three lines of code, so re-scope it down to just the dealloc branch. This is marginally easier to reason about what might be necessary to replace in porting our truncate(1) to other platforms. While we're here, add a test for the -d flag to be sure it really does punch a hole in the file. The test also tries to confirm that it does not disturb other segments of the file in the process, just to inspire some confidence that it's not corrupting the file somehow. Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D51207 --- usr.bin/truncate/tests/truncate_test.sh | 48 +++++++++++++++++++++++++++++++++ usr.bin/truncate/truncate.c | 3 ++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/usr.bin/truncate/tests/truncate_test.sh b/usr.bin/truncate/tests/truncate_test.sh index ec219059de42..845b3e1b4d84 100644 --- a/usr.bin/truncate/tests/truncate_test.sh +++ b/usr.bin/truncate/tests/truncate_test.sh @@ -438,6 +438,53 @@ rounddown_zero_body() [ ${st_size} -eq 0 ] || atf_fail "new file should now be 0 bytes" } +atf_test_case deallocate +deallocate_head() +{ + atf_set "descr" "Verifies that -d punches a hole in the file" + atf_set "require.user" "root" +} +deallocate_body() +{ + blocksz=$(stat -h . | cut -f1 -d' ') + atf_check test -n "$blocksz" + + # We use /dev/random here to defeat ZFS compression, which would + # collapse ranges of zeroes into holes without us deallocating it. This + # isn't a concern below because those are specificially for creating our + # reference files -- we expect the deallocate operation to result in + # ranges of zeroes, whether they end up creating a hole or not. + filesz=$((blocksz * 3)) + atf_check -e not-empty dd if=/dev/random of=sparse \ + bs=${filesz} count=1 conv=notrunc + + atf_check cp sparse sparse.orig + atf_check cp sparse sparse.orig.orig + + # Punch a hole in the middle, ensure that bit is zeroed out. + atf_check -e not-empty dd if=/dev/zero of=sparse.orig \ + bs=${blocksz} oseek=1 count=1 conv=notrunc + atf_check truncate -d -o ${blocksz} -l ${blocksz} sparse + atf_check cmp -s sparse sparse.orig + + # Clobber the end part of the original file and punch a hole in + # the same spot on the new file, ensure that it has zeroed out that + # portion. + atf_check -e not-empty dd if=/dev/zero of=sparse.orig \ + bs=${blocksz} oseek=2 count=1 conv=notrunc + atf_check truncate -d -o $((blocksz * 2)) -l ${blocksz} sparse + atf_check cmp -s sparse sparse.orig + + # Now bring the original file back and make sure that punching a hole + # in data at the beginning doesn't disturb the data at the end. + atf_check cp sparse.orig.orig sparse.orig + atf_check cp sparse.orig.orig sparse + atf_check -e not-empty dd if=/dev/zero of=sparse.orig \ + bs=${blocksz} oseek=0 count=1 conv=notrunc + atf_check truncate -d -l ${blocksz} sparse + atf_check cmp -s sparse sparse.orig +} + atf_init_test_cases() { atf_add_test_case illegal_option @@ -459,4 +506,5 @@ atf_init_test_cases() atf_add_test_case roundup atf_add_test_case rounddown atf_add_test_case rounddown_zero + atf_add_test_case deallocate } diff --git a/usr.bin/truncate/truncate.c b/usr.bin/truncate/truncate.c index d8484257294a..15be339df0e3 100644 --- a/usr.bin/truncate/truncate.c +++ b/usr.bin/truncate/truncate.c @@ -62,7 +62,6 @@ main(int argc, char **argv) int do_refer; int got_size; char *fname, *rname; - struct spacectl_range sr; fd = -1; rsize = tsize = sz = off = 0; @@ -198,6 +197,8 @@ main(int argc, char **argv) tsize = 0; if (do_dealloc == 1) { + struct spacectl_range sr; + sr.r_offset = off; sr.r_len = len; r = fspacectl(fd, SPACECTL_DEALLOC, &sr, 0, &sr);