From nobody Tue Mar 12 16:00:24 2024 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 4TvJJT1XM3z5F4KF; Tue, 12 Mar 2024 16:00:25 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TvJJT10g0z3y1L; Tue, 12 Mar 2024 16:00:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1710259225; 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=W0STMcKL0kTYg0DGuLJtJc8sD70W1esoi9YQppaqW+M=; b=XnQBALtGTEw8P7yzXqNkIISda0DwMQ30Wub9BMtx71o9q/Y8KQZEHb+bUAySOjvGGD7jwL 4+GfBAR4O/X5/FYlc36ECYY5o6Dbb5FOA15iM9Lxj4OzSlNoQIn4NmBwagfu5tllHDNQaX XLI0+yVUYVAye+Bf0YTMFzZbCrdlMNnbGDVvFz4s1YI2siHmba/iFoFYnopTP9FKqWjbxi 9H/WOgcZd6HMif+J0Fqs2Uk+ruZD5CphgNZsnKs2dG+kMGd7G1YU+zPLofgqLVdNNnPbYr RHuXKaecPCmqYzDuk6WDwKUSCFddbI7rePKyX0JwJWQmdOSXKpw/y+9FExGIxg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1710259225; a=rsa-sha256; cv=none; b=XMqL6JItFB1u/MID4yuBnC/KPrDL/JQYn7aK/LhmlMhGQ/hDi1xuN9frGaVDr6MgkWC2Gr DEpDleC2x9LejD/qEMOizuC7KjE4WL6MTQ6Vh6IHxhp3h4rRgO5gDg1LZgRXhBQpY8waVK v0+x4DaEq3npIn0vRZV/ir/YIdR9yEP20PPgO0M3VL+JfAn0Hus7q2vMlZf9u8/kelkBOg 5CGXXsJcWEz4cs0d9CJZKKeFTqaF6qdGK6+Emm16wPkoN5oYvi4shbTw2TVUCxOAbuPw0V D+K8HgcQk+h5kfWEuVHPg3TCwXiwmTjYmoDNrhsfL4nlEfEEtexqVjHFNT+X6g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1710259225; 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=W0STMcKL0kTYg0DGuLJtJc8sD70W1esoi9YQppaqW+M=; b=b74k44I38gAbmxo5sttD4NDSEYRAN+WbB4MyCf/9BksBmej+shlrKSwIRex+TYlqu6XEIs yn/oVE1kmDgEDIeRPOqtBR2nj6zx4mo2lMew6mAYtk/yFZhqoa1Ucf5R16c57asw0oGVRu GueE0ujDMLPEgWDKierdMcEWMyRF0AT9rBpeUf/qdJ/Vl1YAjx+CHP6APcI6tcs0PZK+ku ezZh+ZhD9G5H5Kic90EJ2NgXTJ5Z5Ta/hBPekqElI5cTLUnv6swmrzMZ4KBkdxPGOyWFm5 fQCIIHP0WFfB5HLstQjvLMn2v7BoKPmSjLKatcyUvDc/Un1dq1/W7B4NqjPPXw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TvJJT0by5z1K78; Tue, 12 Mar 2024 16:00:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 42CG0OZX011956; Tue, 12 Mar 2024 16:00:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42CG0OKT011953; Tue, 12 Mar 2024 16:00:24 GMT (envelope-from git) Date: Tue, 12 Mar 2024 16:00:24 GMT Message-Id: <202403121600.42CG0OKT011953@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Eugene Grosbein Subject: git: 7f0dc6e2cdfa - main - mkimg(1): process non-seekable output gracefully 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: eugen X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7f0dc6e2cdfa0317c9917dd46e9da9d3897a8fbb Auto-Submitted: auto-generated The branch main has been updated by eugen: URL: https://cgit.FreeBSD.org/src/commit/?id=7f0dc6e2cdfa0317c9917dd46e9da9d3897a8fbb commit 7f0dc6e2cdfa0317c9917dd46e9da9d3897a8fbb Author: Eugene Grosbein AuthorDate: 2024-03-12 15:55:42 +0000 Commit: Eugene Grosbein CommitDate: 2024-03-12 16:00:21 +0000 mkimg(1): process non-seekable output gracefully mkimg may make severe load only to fail in the end if output is non-seekable pipe, socket or FIFO unless output format is raw disk image. Check it out and fail early. Make it clear in the manual. MFC after: 1 week --- usr.bin/mkimg/mkimg.1 | 3 ++- usr.bin/mkimg/mkimg.c | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/usr.bin/mkimg/mkimg.1 b/usr.bin/mkimg/mkimg.1 index 820fb9ad1d5a..82bbee53a267 100644 --- a/usr.bin/mkimg/mkimg.1 +++ b/usr.bin/mkimg/mkimg.1 @@ -22,7 +22,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd February 28, 2024 +.Dd March 12, 2024 .Dt MKIMG 1 .Os .Sh NAME @@ -64,6 +64,7 @@ The image file is a raw disk image by default, but the format of the image file can be specified with the .Ar format argument. +Most formats require seekable output, except of raw disk image. .Pp The disk image can be made bootable by specifying the scheme-specific boot block contents with the diff --git a/usr.bin/mkimg/mkimg.c b/usr.bin/mkimg/mkimg.c index 541d534f967f..3cd9b03c06e9 100644 --- a/usr.bin/mkimg/mkimg.c +++ b/usr.bin/mkimg/mkimg.c @@ -555,6 +555,7 @@ mkimg(void) int main(int argc, char *argv[]) { + const char *format_name; int bcfd, outfd; int c, error; @@ -699,6 +700,7 @@ main(int argc, char *argv[]) errc(EX_DATAERR, error, "boot code"); } + format_name = format_selected()->name; if (verbose) { fprintf(stderr, "Logical sector size: %u\n", secsz); fprintf(stderr, "Physical block size: %u\n", blksz); @@ -709,10 +711,20 @@ main(int argc, char *argv[]) fprintf(stderr, "Partitioning scheme: %s\n", scheme_selected()->name); fprintf(stderr, "Output file format: %s\n", - format_selected()->name); + format_name); fputc('\n', stderr); } +#if defined(SPARSE_WRITE) + /* + * sparse_write() fails if output is not seekable so fail early + * not wasting some load unless output format is raw + */ + if (strcmp("raw", format_name) && + lseek(outfd, (off_t)0, SEEK_CUR) == -1 && errno == ESPIPE) + errx(EX_USAGE, "%s: output must be seekable", format_name); +#endif + error = image_init(); if (error) errc(EX_OSERR, error, "cannot initialize");