libext2fs: don't mark the superblock as dirty if the fs was opened r/o

If the file system is read/only opened with a backup superblock, and
the file system has uninit_bg enabled, the super block must not be
marked as dirty; otherwise, ext2fs_close() will call ext2fs_flush(),
which will fail, since the file descriptor for the block device was
opened read/only, and then the file descriptor won't actually be
closed.

This is normally not a problem since most of the time the program will
exit shortly after calling ext2fs_close(), and many programs don't
bother checking the error return from ext2fs_close(), especially if
the file system was opened read/only.

A big exception to this is e2fsck, since it opens and close the file
systems during its startup, and to make matters worse, registers an
error handler which will noisly complain about the failed writes
caused by ext2fs_flush().

Fix this by not marking the superblock as dirty if the file system was
opened read/only.  The changes to the block group descriptors to clear
the uninit bits will still happen, so that e2fsck -n will properly
scan the whole file system.  However, those changes will get dropped
when the file system handle is closed.

Addresses-SourceForge-Bug: #3444351

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
bitmap-optimize
Theodore Ts'o 2012-02-20 20:27:58 -05:00
parent bbdb7a5f28
commit 48b8910820
1 changed files with 2 additions and 1 deletions

View File

@ -382,7 +382,8 @@ errcode_t ext2fs_open2(const char *name, const char *io_options,
* anyway to avoid printing a lot of spurious errors. */
ext2fs_group_desc_csum_set(fs, group);
}
ext2fs_mark_super_dirty(fs);
if (fs->flags & EXT2_FLAG_RW)
ext2fs_mark_super_dirty(fs);
}
fs->flags &= ~EXT2_FLAG_NOFREE_ON_ERROR;