From aac0f095b5ed1273f91d87009f3b551eedcee085 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sun, 31 May 2015 00:30:23 -0500 Subject: [PATCH] Use macros to iterate through extraction aliases --- include/wimlib/apply.h | 4 ++++ src/extract.c | 5 +---- src/ntfs-3g_apply.c | 20 +++++--------------- src/unix_apply.c | 4 +--- src/win32_apply.c | 43 +++++++++++------------------------------- 5 files changed, 22 insertions(+), 54 deletions(-) diff --git a/include/wimlib/apply.h b/include/wimlib/apply.h index 2d706b4e..f9a4a2f1 100644 --- a/include/wimlib/apply.h +++ b/include/wimlib/apply.h @@ -139,6 +139,10 @@ report_apply_error(struct apply_ctx *ctx, int error_code, const tchar *path) list_first_entry(&(inode)->i_extraction_aliases, \ struct wim_dentry, d_extraction_alias_node) +#define inode_for_each_extraction_alias(dentry, inode) \ + list_for_each_entry(dentry, &(inode)->i_extraction_aliases, \ + d_extraction_alias_node) + extern int extract_blob_list(struct apply_ctx *ctx, const struct read_blob_callbacks *cbs); diff --git a/src/extract.c b/src/extract.c index 04d0b797..c794620d 100644 --- a/src/extract.c +++ b/src/extract.c @@ -328,10 +328,7 @@ extract_chunk_wrapper(const void *chunk, size_t size, void *_ctx) const struct wim_inode *inode = targets[i].inode; const struct wim_dentry *dentry; - list_for_each_entry(dentry, - &inode->i_extraction_aliases, - d_extraction_alias_node) - { + inode_for_each_extraction_alias(dentry, inode) { progress->extract.completed_bytes += size; if (ctx->cur_blob_offset == ctx->cur_blob->size) progress->extract.completed_streams++; diff --git a/src/ntfs-3g_apply.c b/src/ntfs-3g_apply.c index 10f514cd..9de5774b 100644 --- a/src/ntfs-3g_apply.c +++ b/src/ntfs-3g_apply.c @@ -518,17 +518,12 @@ ntfs_3g_create_directories(struct wim_dentry *root, static struct wim_dentry * ntfs_3g_first_extraction_alias(struct wim_inode *inode) { - struct list_head *next = inode->i_extraction_aliases.next; struct wim_dentry *dentry; - do { - dentry = list_entry(next, struct wim_dentry, - d_extraction_alias_node); + inode_for_each_extraction_alias(dentry, inode) if (dentry_has_short_name(dentry)) - break; - next = next->next; - } while (next != &inode->i_extraction_aliases); - return dentry; + return dentry; + return inode_first_extraction_dentry(inode); } /* @@ -573,7 +568,6 @@ ntfs_3g_create_nondirectory(struct wim_inode *inode, struct wim_dentry *first_dentry; ntfs_inode *dir_ni; ntfs_inode *ni; - struct list_head *next; struct wim_dentry *dentry; int ret; @@ -629,17 +623,13 @@ ntfs_3g_create_nondirectory(struct wim_inode *inode, } /* Create additional links if present. */ - next = inode->i_extraction_aliases.next; - do { - dentry = list_entry(next, struct wim_dentry, - d_extraction_alias_node); + inode_for_each_extraction_alias(dentry, inode) { if (dentry != first_dentry) { ret = ntfs_3g_add_link(ni, dentry); if (ret) goto out_close_ni; } - next = next->next; - } while (next != &inode->i_extraction_aliases); + } /* Set metadata. */ ret = ntfs_3g_set_metadata(ni, inode, ctx); diff --git a/src/unix_apply.c b/src/unix_apply.c index dc614913..5dcb3864 100644 --- a/src/unix_apply.c +++ b/src/unix_apply.c @@ -330,9 +330,7 @@ unix_create_hardlinks(const struct wim_inode *inode, const struct wim_dentry *dentry; const char *newpath; - list_for_each_entry(dentry, &inode->i_extraction_aliases, - d_extraction_alias_node) - { + inode_for_each_extraction_alias(dentry, inode) { if (dentry == first_dentry) continue; diff --git a/src/win32_apply.c b/src/win32_apply.c index f4a2d753..7593f20e 100644 --- a/src/win32_apply.c +++ b/src/win32_apply.c @@ -458,7 +458,6 @@ static int will_externally_back_inode(struct wim_inode *inode, struct win32_apply_ctx *ctx, const struct wim_dentry **excluded_dentry_ret) { - struct list_head *next; struct wim_dentry *dentry; struct blob_descriptor *blob; int ret; @@ -486,10 +485,8 @@ will_externally_back_inode(struct wim_inode *inode, struct win32_apply_ctx *ctx, * We need to check the patterns in [PrepopulateList] against every name * of the inode, in case any of them match. */ - next = inode->i_extraction_aliases.next; - do { - dentry = list_entry(next, struct wim_dentry, - d_extraction_alias_node); + + inode_for_each_extraction_alias(dentry, inode) { ret = calculate_dentry_full_path(dentry); if (ret) @@ -502,8 +499,7 @@ will_externally_back_inode(struct wim_inode *inode, struct win32_apply_ctx *ctx, *excluded_dentry_ret = dentry; return WIM_BACKING_EXCLUDED; } - next = next->next; - } while (next != &inode->i_extraction_aliases); + } inode->i_can_externally_back = 1; return 0; @@ -1028,17 +1024,12 @@ prepare_target(struct list_head *dentry_list, struct win32_apply_ctx *ctx) static struct wim_dentry * first_extraction_alias(const struct wim_inode *inode) { - struct list_head *next = inode->i_extraction_aliases.next; struct wim_dentry *dentry; - do { - dentry = list_entry(next, struct wim_dentry, - d_extraction_alias_node); + inode_for_each_extraction_alias(dentry, inode) if (dentry_has_short_name(dentry)) - break; - next = next->next; - } while (next != &inode->i_extraction_aliases); - return dentry; + return dentry; + return inode_first_extraction_dentry(inode); } /* @@ -1706,23 +1697,17 @@ static int create_links(HANDLE h, const struct wim_dentry *first_dentry, struct win32_apply_ctx *ctx) { - const struct wim_inode *inode; - const struct list_head *next; + const struct wim_inode *inode = first_dentry->d_inode; const struct wim_dentry *dentry; int ret; - inode = first_dentry->d_inode; - next = inode->i_extraction_aliases.next; - do { - dentry = list_entry(next, struct wim_dentry, - d_extraction_alias_node); + inode_for_each_extraction_alias(dentry, inode) { if (dentry != first_dentry) { ret = create_link(h, dentry, ctx); if (ret) return ret; } - next = next->next; - } while (next != &inode->i_extraction_aliases); + } return 0; } @@ -2178,18 +2163,12 @@ begin_extract_blob(struct blob_descriptor *blob, void *_ctx) } else { /* Hard links not supported. Extract the blob * separately to each alias of the inode. */ - struct list_head *next; - - next = inode->i_extraction_aliases.next; - do { - dentry = list_entry(next, struct wim_dentry, - d_extraction_alias_node); + inode_for_each_extraction_alias(dentry, inode) { ret = begin_extract_blob_instance(blob, dentry, strm, ctx); ret = check_apply_error(dentry, ctx, ret); if (ret) goto fail; - next = next->next; - } while (next != &inode->i_extraction_aliases); + } } } -- 2.43.0