diff options
author | Li Xi <lixi@ddn.com> | 2019-09-05 16:30:40 +0800 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2021-01-25 15:17:27 -0500 |
commit | f3c2256490297201c63139ba0fea5c6b09bca3cf (patch) | |
tree | 6e279d11ef66e1663ed5fc0dabac55631158ca49 | |
parent | bb78742b5e2e95c3e7e9a76755144fdf8ec12285 (diff) | |
download | e2fsprogs-f3c2256490297201c63139ba0fea5c6b09bca3cf.tar.gz |
e2fsck: merge dblist after thread finishes
Merge dblist properly.
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r-- | e2fsck/pass1.c | 19 | ||||
-rw-r--r-- | lib/ext2fs/dblist.c | 36 | ||||
-rw-r--r-- | lib/ext2fs/ext2fs.h | 1 |
3 files changed, 56 insertions, 0 deletions
diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index 17dfe0842..b01b415a6 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -2244,12 +2244,14 @@ static int e2fsck_pass1_merge_fs(ext2_filsys dest, ext2_filsys src) ext2fs_inode_bitmap inode_map; ext2fs_block_bitmap block_map; ext2_badblocks_list badblocks; + ext2_dblist dblist; dest_io = dest->io; dest_image_io = dest->image_io; inode_map = dest->inode_map; block_map = dest->block_map; badblocks = dest->badblocks; + dblist = dest->dblist; memcpy(dest, src, sizeof(struct struct_ext2_filsys)); dest->io = dest_io; @@ -2258,6 +2260,7 @@ static int e2fsck_pass1_merge_fs(ext2_filsys dest, ext2_filsys src) dest->inode_map = inode_map; dest->block_map = block_map; dest->badblocks = badblocks; + dest->dblist = dblist; if (dest->dblist) dest->dblist->fs = dest; @@ -2276,6 +2279,19 @@ static int e2fsck_pass1_merge_fs(ext2_filsys dest, ext2_filsys src) if (retval) goto out; + if (src->dblist) { + if (dest->dblist) { + retval = ext2fs_merge_dblist(src->dblist, + dest->dblist); + if (retval) + goto out; + } else { + dest->dblist = src->dblist; + dest->dblist->fs = dest; + src->dblist = NULL; + } + } + if (src->badblocks) { if (dest->badblocks == NULL) retval = ext2fs_badblocks_copy(src->badblocks, @@ -2292,6 +2308,9 @@ out: ext2fs_free_generic_bmap(src->block_map); if (src->badblocks) ext2fs_badblocks_list_free(src->badblocks); + if (src->dblist) + ext2fs_free_dblist(src->dblist); + return retval; } diff --git a/lib/ext2fs/dblist.c b/lib/ext2fs/dblist.c index bbdb221d6..1fdd8f432 100644 --- a/lib/ext2fs/dblist.c +++ b/lib/ext2fs/dblist.c @@ -120,6 +120,42 @@ errcode_t ext2fs_copy_dblist(ext2_dblist src, ext2_dblist *dest) } /* + * Merge a directory block list @src to @dest + */ +errcode_t ext2fs_merge_dblist(ext2_dblist src, ext2_dblist dest) +{ + unsigned long long src_count = src->count; + unsigned long long dest_count = dest->count; + unsigned long long size = src_count + dest_count; + size_t size_entry = sizeof(struct ext2_db_entry2); + struct ext2_db_entry2 *array, *array2; + errcode_t retval; + + if (src_count == 0) + return 0; + + if (src->sorted || (dest->sorted && dest_count != 0)) + return EINVAL; + + retval = ext2fs_get_array(size, size_entry, &array); + if (retval) + return retval; + + array2 = array; + memcpy(array, src->list, src_count * size_entry); + array += src_count; + memcpy(array, dest->list, dest_count * size_entry); + ext2fs_free_mem(&dest->list); + + dest->list = array2; + dest->count = src_count + dest_count; + dest->size = size; + dest->sorted = 0; + + return 0; +} + +/* * Close a directory block list * * (moved to closefs.c) diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index 000eb0460..ec8cf1270 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -1137,6 +1137,7 @@ extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino, blk_t blk, int blockcnt); extern errcode_t ext2fs_add_dir_block2(ext2_dblist dblist, ext2_ino_t ino, blk64_t blk, e2_blkcnt_t blockcnt); +extern errcode_t ext2fs_merge_dblist(ext2_dblist src, ext2_dblist dest); extern void ext2fs_dblist_sort(ext2_dblist dblist, EXT2_QSORT_TYPE (*sortfunc)(const void *, const void *)); |