diff --git a/usr.bin/mkimg/mkimg.1 b/usr.bin/mkimg/mkimg.1 index 820fb9ad1d5..82bbee53a26 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 541d534f967..3cd9b03c06e 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");