From nobody Tue Mar 19 06:53:09 2024 X-Original-To: dev-commits-src-branches@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 4TzMqn50pxz5Dh0F; Tue, 19 Mar 2024 06:53:09 +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 4TzMqn4VJDz4Bq0; Tue, 19 Mar 2024 06:53:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1710831189; 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=ivHNyxflLr+zUunaiJQ3XpPnXqrhhqEBpjXVMN4AHBc=; b=FRHrgAH0TEKW8DdnNyJzsI9cYmUvk4YMy6ZG2LCpazA+m77uwBKZ4+JmPAmJzZwzi+BTOM YXC+eUnnocUld5oeT7dFyxvuvGD++QwT9oxyufkFec3AHlmjIirMwtyo4IgKL6QRG/yNNB YjUVSqMyIIlB/uEDBOX0dPNtgwx8fwRRFPSKQ1WQu9ddAcekXeRluB5RnJouSqq5lipSUK 1CMJ7151hCHLZHND0d9BivAjg7eViwZeLnXAaA9Nz6hsVL5sSW+RR1w+3qp4hdpmL6ZFge 5U0ulnRZ5kmw3HywbpEeX6i5HFIeddog2h5R99SYPzXC9h4sxFn9W4eB5lDbFQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1710831189; a=rsa-sha256; cv=none; b=qhR8CUPeIqqUGsXTEyiivFGDYj+H8AsMwOm/H4SrXjA3NrNDszdLbYJcQ3PscmkSyvyI3E g51fLJ6nKRQkueQ+9Ay7zWkIucvPKUzIVehbV1NXBFn/HTMeaYOubEIIAGDksDFBZFSgd5 e4d3Ujxz2469MsJ9ZsR0+I34+3tSG+8msItwqrbzkFs2UVqfJvtABuA29Ho2Bss1aTfCTC QoogrEpEey0cDtnMgKcwLgtrn9+lklfrg3x4YD4m9Ev1IA6O6PEmlBcTWJqEFhLKWhNjcK Lst2ej1W2DY6OjjXhZDwBbTobHEy+O62jwzLIUfmQ0pecqEhRv8espS8pir1QQ== 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=1710831189; 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=ivHNyxflLr+zUunaiJQ3XpPnXqrhhqEBpjXVMN4AHBc=; b=g84858prt2eAA9rNS6dI/mH/T51L7W5XfUCQE25+vNn+oS1mtIcPfWdiBGP+HMMvDSyVhu E3QdVb/gzplhNics1ggqVv5NQ58X0WgiiX26Z+XSzUhS9p8oPE3kpDQrHm4QxwPmiSUai/ yI0nE5wqsVCaDMetiRBFYoo/3/qPYPFssIZiMFXmXtMHBuetVsdGo/UYshlJkaYMk7Pq01 vjkED8/aj6QOhrqt3OuvP0uV5+Gfh3f9xUuqKC8iTbIaRkde2Hu2cMX4fbW1GNiU/gdKTQ kdjmXnobdcjGaywXkTfYw1zB//GUwx6EEjwi2sHha55H4eFHwHl9JioNBlNc5A== 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 4TzMqn45s3zxf0; Tue, 19 Mar 2024 06:53:09 +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 42J6r9Ob023433; Tue, 19 Mar 2024 06:53:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42J6r9FR023430; Tue, 19 Mar 2024 06:53:09 GMT (envelope-from git) Date: Tue, 19 Mar 2024 06:53:09 GMT Message-Id: <202403190653.42J6r9FR023430@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Eugene Grosbein Subject: git: 229bdf30930b - stable/13 - mkimg(1): MFC: process non-seekable output gracefully List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 229bdf30930b543d31b593c22e0c3d2b061cc5e2 Auto-Submitted: auto-generated The branch stable/13 has been updated by eugen: URL: https://cgit.FreeBSD.org/src/commit/?id=229bdf30930b543d31b593c22e0c3d2b061cc5e2 commit 229bdf30930b543d31b593c22e0c3d2b061cc5e2 Author: Eugene Grosbein AuthorDate: 2024-03-12 15:55:42 +0000 Commit: Eugene Grosbein CommitDate: 2024-03-19 06:53:05 +0000 mkimg(1): MFC: 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. (cherry picked from commit 7f0dc6e2cdfa0317c9917dd46e9da9d3897a8fbb) --- 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 28ed0ca03ccf..333b8b8a5ecb 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 bcf500cd675f..f3bb9cb05708 100644 --- a/usr.bin/mkimg/mkimg.c +++ b/usr.bin/mkimg/mkimg.c @@ -556,6 +556,7 @@ mkimg(void) int main(int argc, char *argv[]) { + const char *format_name; int bcfd, outfd; int c, error; @@ -700,6 +701,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); @@ -710,10 +712,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");