From b67bf3b085c38e30c35bded55004d6dadefb7dd4 Mon Sep 17 00:00:00 2001 From: Konstantin Chistyakov Date: Mon, 29 May 2017 19:11:38 -0400 Subject: [PATCH] e2fsck: don't flush to device opened in read-only mode If the e2fsck is called with both the -f and -n options, it will complete with an exit status of 8 due to an error when trying to flush the io_channel (which was opened read-only) when built on on Cygwin on Windows 8.1 and Windows 10. Apparently Cygwin is unhappy when fsync is called on a file descriptor opened read-only. Signed-off-by: Theodore Ts'o --- e2fsck/unix.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/e2fsck/unix.c b/e2fsck/unix.c index b602553..ff96148 100644 --- a/e2fsck/unix.c +++ b/e2fsck/unix.c @@ -1898,15 +1898,17 @@ no_journal: ext2fs_mark_super_dirty(fs); } - e2fsck_write_bitmaps(ctx); - if (fs->flags & EXT2_FLAG_DIRTY) { - pctx.errcode = ext2fs_flush(ctx->fs); + if (!(ctx->options & E2F_OPT_READONLY)) { + e2fsck_write_bitmaps(ctx); + if (fs->flags & EXT2_FLAG_DIRTY) { + pctx.errcode = ext2fs_flush(ctx->fs); + if (pctx.errcode) + fix_problem(ctx, PR_6_FLUSH_FILESYSTEM, &pctx); + } + pctx.errcode = io_channel_flush(ctx->fs->io); if (pctx.errcode) - fix_problem(ctx, PR_6_FLUSH_FILESYSTEM, &pctx); + fix_problem(ctx, PR_6_IO_FLUSH, &pctx); } - pctx.errcode = io_channel_flush(ctx->fs->io); - if (pctx.errcode) - fix_problem(ctx, PR_6_IO_FLUSH, &pctx); if (was_changed) { int fs_fixed = (ctx->flags & E2F_FLAG_PROBLEMS_FIXED); -- 1.8.3.1