NetBSD Problem Report #60532
From ivan@siamics.net Mon Aug 3 08:32:37 2026
Return-Path: <ivan@siamics.net>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
client-signature RSA-PSS (2048 bits) client-digest SHA256)
(Client CN "mail.netbsd.org", Issuer "YR2" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 8EDB91A923B
for <gnats-bugs@gnats.NetBSD.org>; Mon, 3 Aug 2026 08:32:37 +0000 (UTC)
Message-Id: <XtYk2pwRVTdldNiDWz5Bnj_4Ub2rZD_P@niodd.siamics.net>
Date: Sun, 2 Aug 2026 13:57:37 +0000
From: Ivan Shmakov <ivan@siamics.net>
To: gnats-bugs@netbsd.org
Subject: port truncate(1) from FreeBSD
X-From4GNATS: "Ivan Shmakov via gnats" <gnats-admin@NetBSD.org>
>Number: 60532
>Category: bin
>Synopsis: port truncate(1) from FreeBSD
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Mon Aug 03 08:35:00 +0000 2026
>Last-Modified: Mon Aug 03 16:55:01 +0000 2026
>Originator: Ivan Shmakov
>Release: NetBSD 10.1
>Organization:
Dbus-free station.
>Environment:
Architecture: x86_64
Machine: amd64
>Description:
Please port truncate(1) [1] from FreeBSD:
> NAME
> truncate - resize files or manage file space
> SYNOPSIS
> truncate [-c] -s [+|-|%|/]size[SUFFIX] file ...
> truncate [-c] -r rfile file ...
> truncate [-c] -d [-o offset[SUFFIX]] -l length[SUFFIX] file ...
> DESCRIPTION
> The truncate utility adjusts the length of each regular file
> given on the command-line, or performs space management with
> the given offset and the length over a regular file given on
> the command-line.
[1] http://man.freebsd.org/cgi/man.cgi?query=truncate&sektion=1
truncate(1) allows for directly changing the size of a file,
including creating a sparse file. In place of the old trick of
using dd(1) to write a block at an offset of size minus one:
$ dd if=/dev/zero of=bigdisk.2048.udf seek=9999999 count=1
(From newfs_udf(8).) It becomes possible to create a sparse
file like:
$ truncate -s5000000K -- bigdisk.2048.udf
Also, I find it occasionally convenient when recovering after
adding arbitrary data to a file by accident; like, say:
$ date >> foo
$ truncate -s-29 -- foo
>How-To-Repeat:
>Fix:
>Audit-Trail:
From: Valery Ushakov <uwe@stderr.spb.ru>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: bin/60532: port truncate(1) from FreeBSD
Date: Mon, 3 Aug 2026 19:50:51 +0300
Do we want FreeBSD version or Linux version?
FreeBSD has `-d` (for which we lack the necessary kernel support) and
it's `-o` means something different (it's a companion for `-d`,
instead of Linux `--io-blocks`).
-uwe
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.