Re: [PATCH RFC] gen_init_cpio: Do fsync() only on regular files
From: Dmitry Safonov
Date: Mon Oct 06 2025 - 23:09:20 EST
On Tue, Oct 7, 2025 at 2:17 AM David Disseldorp <ddiss@xxxxxxx> wrote:
[..]
> The code change looks fine, but the commit message is a bit verbose IMO.
> Please drop the first and last paragraphs. The reproducer could also be
> simplified to e.g.
> echo | usr/gen_init_cpio /dev/stdin > /dev/null
hehe, OK, let me simplify that in v2.
>
> With that:
> Reviewed-by: David Disseldorp <ddiss@xxxxxxx>
>
> > Fixes: ae18b94099b0 ("gen_init_cpio: support -o <output_file> parameter")
> > Cc: David Disseldorp <ddiss@xxxxxxx>
> > Cc: Nicolas Schier <nsc@xxxxxxxxxx>
> > Signed-off-by: Dmitry Safonov <dima@xxxxxxxxxx>
> > ---
[..]
>
> Another option would be to catch the EINVAL error, e.g.
>
> --- a/usr/gen_init_cpio.c
> +++ b/usr/gen_init_cpio.c
> @@ -112,7 +112,10 @@ static int cpio_trailer(void)
> push_pad(padlen(offset, 512)) < 0)
> return -1;
>
> - return fsync(outfd);
> + if (fsync(outfd) < 0 && errno != EINVAL)
> + return -1;
> +
> + return 0;
> }
>
> It may be a little portable than isfdtype(), but I don't feel strongly
> either way.
Yeah, maybe worth avoiding breking compilation on some weird set ups,
going to use your version for v2.
Thanks,
Dmitry