]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
e2fsck: don't flush to device opened in read-only mode
authorKonstantin Chistyakov <Konstantin.Chistyakov@paragon-software.com>
Mon, 29 May 2017 23:11:38 +0000 (19:11 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 29 May 2017 23:11:42 +0000 (19:11 -0400)
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 <tytso@mit.edu>
e2fsck/unix.c

index b6025535586abe213c51f9bcdffd4c42a645ee1b..ff961483b864c29dcf544639b58a81ea167ffeb4 100644 (file)
@@ -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);