From nobody Tue Mar 12 16:58:32 2024 X-Original-To: dev-commits-src-main@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 4TvKbY0fJNz5F8Pt; Tue, 12 Mar 2024 16:58:33 +0000 (UTC) (envelope-from brooks@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (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 "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TvKbY05j9z4541; Tue, 12 Mar 2024 16:58:33 +0000 (UTC) (envelope-from brooks@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1710262713; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=rhNa/1esXg6BmG4m1qM+ogec0RKGTkD00hzXJNwbyAc=; b=pjq+bUCB7GMhddsnpDMq2tZh/5M2lDXlYytQriH3+upHMtnll9qMV2ETyxpjt4Tsg+EPha DfCKW7c3sa3TNGmzZK4YBEA0Sj080m76DGQR5Jo09ql/1n/ePGGZGC8a3KTCMvL7pSV+9Z XpI1DRrGOahHilZ9IvQDLQ30Wr4DlQ08WaGSMVgyAadBMg/2099yCNtX35dtAW10Mx6ZlC gDlnyGdg1Qc+QeG1mKxCS5TI4QtPAdtdacBGeYIc0ZAN4peZMqCcea2CmnGiRluS+bimOM qlkZm9VMPYnZvZ0Iz8fkb5Tp9vQZPYcQ7oS/EvmBvEyLXG7RARZ1MhrdFskuiw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1710262713; a=rsa-sha256; cv=none; b=k/NYbzpDlLg+ZFyfi07YXtnjqkBwDFkgftEaFnvU24UxcQDjnBpn9rY4RmAtcUZXoAQme1 tw/0I/gw29rrU5u+xA/p8U1rg6++/KUzBhqjAmbxuA20ugyNESDVyRL4qGGVraBLk9Jb/N ZHvfmbzI1R9GzGoXD2ZSJ92Mx8R3FrPRCTohWtljqhMhEfveS5ZR3Gt8nxnYJao8v3ARx4 PLCIm4xsjGrEQaKkasRULelXFD4eJXTl1866rWYtzeDRV2JgeQgbDmkdsv7h1r5AtuF0aM oBEeLSBxvQ308kPdOMiDTmreGGjYU9+rKxIZ4hY1BRVAl4RXTFeF3cKYJaYD2A== 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=1710262713; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=rhNa/1esXg6BmG4m1qM+ogec0RKGTkD00hzXJNwbyAc=; b=p0d8ieQxPcC71iYl1qSVmPGR6j5jL0/vhMQudJfXV/Et9kG4rCb1mR5DSU5Nf7ugFBC/4U z15qZ/FdCumDAvLnwaxvNAzMFA4n6OtizvQe3jEE/ko/U5XVk8YDZQ5XIdUF0YEbFh9nX7 JkM0RWgVF5eeboORIGKNnBdyOfzvosbLcH2BHno86UI1TJE4GsHhuCW5o897fcwlYICrnA l8qJ5l7YEIfG8KoAc2EnHBDzNwBRcd4zq9IA36uhTSD32xwpcBVmxQ22BDpUS0JjZctVi6 wLBcBYuRUjwTu76CM9ZiorHOeAdsdgMHinVbAA5gTs9/QVN67r2tCDiRnO4jlg== Received: from spindle.one-eyed-alien.net (spindle.one-eyed-alien.net [199.48.129.229]) (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) (Authenticated sender: brooks/mail) by smtp.freebsd.org (Postfix) with ESMTPSA id 4TvKbX6ggPzPFQ; Tue, 12 Mar 2024 16:58:32 +0000 (UTC) (envelope-from brooks@freebsd.org) Received: by spindle.one-eyed-alien.net (Postfix, from userid 3001) id 5ECA43C019B; Tue, 12 Mar 2024 16:58:32 +0000 (UTC) Date: Tue, 12 Mar 2024 16:58:32 +0000 From: Brooks Davis To: Eugene Grosbein Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: 7f0dc6e2cdfa - main - mkimg(1): process non-seekable output gracefully Message-ID: References: <202403121600.42CG0OKT011953@gitrepo.freebsd.org> List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202403121600.42CG0OKT011953@gitrepo.freebsd.org> On Tue, Mar 12, 2024 at 04:00:24PM +0000, Eugene Grosbein wrote: > 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; const struct mkimg_format* format; It seems weird to cache a single member. For that matter, caching anyting seems like overkill given than format_selected() just returns a global variable's value. > 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 Maybe add a flag for non-seeking formats rather than hardcoding a strcmp? -- Brooks