From: Theodore Ts'o Date: Wed, 4 Jul 2018 04:18:30 +0000 (-0400) Subject: e2fsck: fix kernel compat functions to use kernel error return conventions X-Git-Tag: v1.44.3-rc2~7 X-Git-Url: https://git.whamcloud.com/tools/e2fsprogs.git/?a=commitdiff_plain;h=d8cbb80348aac26c007f6d13eb879e080c9b01f4;p=tools%2Fe2fsprogs.git e2fsck: fix kernel compat functions to use kernel error return conventions Fix journal_bmap() and sync_blockdev() to use the kernel error convetions (e.g., -EIO instead of EIO) since they are called by reovery.c, which is shared userspace / kernel code. Without this, e2fsck might print an error message like this: /sbin/e2fsck: Unknown code ____ 251 while recovering journal of /dev/mapper/thin-vol instead of what it should have printed which was this: /sbin/e2fsck: Input/output error while recovering journal of /dev/mapper/thin-vol Signed-off-by: Theodore Ts'o --- diff --git a/e2fsck/journal.c b/e2fsck/journal.c index c4f58f1..e83f3a9 100644 --- a/e2fsck/journal.c +++ b/e2fsck/journal.c @@ -112,7 +112,7 @@ int journal_bmap(journal_t *journal, blk64_t block, unsigned long long *phys) retval= ext2fs_bmap2(inode->i_ctx->fs, inode->i_ino, &inode->i_ext2, NULL, 0, block, 0, &pblk); *phys = pblk; - return (int) retval; + return -1 * ((int) retval); #endif } @@ -153,7 +153,7 @@ int sync_blockdev(kdev_t kdev) else io = kdev->k_ctx->journal_io; - return io_channel_flush(io) ? EIO : 0; + return io_channel_flush(io) ? -EIO : 0; } void ll_rw_block(int rw, int nr, struct buffer_head *bhp[]) @@ -289,6 +289,7 @@ static errcode_t e2fsck_get_journal(e2fsck_t ctx, journal_t **ret_journal) errcode_t retval = 0; io_manager io_ptr = 0; unsigned long long start = 0; + int ret; int ext_journal = 0; int tried_backup_jnl = 0; @@ -389,8 +390,10 @@ static errcode_t e2fsck_get_journal(e2fsck_t ctx, journal_t **ret_journal) #else journal->j_inode = j_inode; ctx->journal_io = ctx->fs->io; - if ((retval = (errcode_t) journal_bmap(journal, 0, &start)) != 0) + if ((ret = journal_bmap(journal, 0, &start)) != 0) { + retval = (errcode_t) (-1 * ret); goto errout; + } #endif } else { ext_journal = 1;