From 313c155f5e11169b9d2d7d10945fe47c41374cb7 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Tue, 28 Aug 2012 19:47:50 -0500 Subject: [PATCH] Cleanups and rename dentry->hard_link to dentry->link_group_id --- src/dentry.c | 16 ++++++++-------- src/dentry.h | 2 +- src/hardlink.c | 45 +++++++++++++++++++++++++++++++-------------- src/mount.c | 16 ++++++++-------- src/ntfs-capture.c | 2 +- 5 files changed, 49 insertions(+), 32 deletions(-) diff --git a/src/dentry.c b/src/dentry.c index 8a285e25..0515c27b 100644 --- a/src/dentry.c +++ b/src/dentry.c @@ -110,9 +110,9 @@ void stbuf_to_dentry(const struct stat *stbuf, struct dentry *dentry) dentry->attributes = FILE_ATTRIBUTE_NORMAL; } if (sizeof(ino_t) >= 8) - dentry->hard_link = (u64)stbuf->st_ino; + dentry->link_group_id = (u64)stbuf->st_ino; else - dentry->hard_link = (u64)stbuf->st_ino | + dentry->link_group_id = (u64)stbuf->st_ino | ((u64)stbuf->st_dev << (sizeof(ino_t) * 8)); /* Set timestamps */ dentry->creation_time = timespec_to_wim_timestamp(&stbuf->st_mtim); @@ -522,7 +522,7 @@ int print_dentry(struct dentry *dentry, void *lookup_table) printf("Last Write Time = %s UTC\n", p); printf("Reparse Tag = 0x%"PRIx32"\n", dentry->reparse_tag); - printf("Hard Link Group = 0x%"PRIx64"\n", dentry->hard_link); + printf("Hard Link Group = 0x%"PRIx64"\n", dentry->link_group_id); printf("Number of Alternate Data Streams = %hu\n", dentry->num_ads); printf("Filename = \""); print_string(dentry->file_name, dentry->file_name_len); @@ -1136,7 +1136,7 @@ int read_dentry(const u8 metadata_resource[], u64 metadata_resource_len, p += 4; } else { p = get_u32(p, &dentry->reparse_tag); - p = get_u64(p, &dentry->hard_link); + p = get_u64(p, &dentry->link_group_id); } /* By the way, the reparse_reserved field does not actually exist (at @@ -1392,13 +1392,13 @@ static u8 *write_dentry(const struct dentry *dentry, u8 *p) p = put_u32(p, dentry->reparse_tag); p = put_zeroes(p, 4); } else { - u64 hard_link; + u64 link_group_id; p = put_u32(p, 0); if (dentry->link_group_list.next == &dentry->link_group_list) - hard_link = 0; + link_group_id = 0; else - hard_link = dentry->hard_link; - p = put_u64(p, hard_link); + link_group_id = dentry->link_group_id; + p = put_u64(p, link_group_id); } p = put_u16(p, dentry->num_ads); p = put_u16(p, dentry->short_name_len); diff --git a/src/dentry.h b/src/dentry.h index 38ce12f2..8d57668a 100644 --- a/src/dentry.h +++ b/src/dentry.h @@ -231,7 +231,7 @@ struct dentry { * Unfortunately, in some WIMs it is NOT the case that all dentries that * share this field are actually in the same hard link set, although the * WIMs that wimlib writes maintain this restriction. */ - u64 hard_link; + u64 link_group_id; /* Number of alternate data streams associated with this file. */ u16 num_ads; diff --git a/src/hardlink.c b/src/hardlink.c index a94bb862..d28f69c4 100644 --- a/src/hardlink.c +++ b/src/hardlink.c @@ -134,7 +134,7 @@ int link_group_table_insert(struct dentry *dentry, void *__table) size_t pos; struct link_group *group; - if (dentry->hard_link == 0) { + if (dentry->link_group_id == 0) { /* Single group--- Add to the list of extra groups (we can't put * it in the table itself because all the singles have a link * group ID of 0) */ @@ -152,10 +152,10 @@ int link_group_table_insert(struct dentry *dentry, void *__table) * though) */ /* Try adding to existing hard link group */ - pos = dentry->hard_link % table->capacity; + pos = dentry->link_group_id % table->capacity; group = table->array[pos]; while (group) { - if (group->link_group_id == dentry->hard_link) { + if (group->link_group_id == dentry->link_group_id) { list_add(&dentry->link_group_list, group->dentry_list); return 0; @@ -168,7 +168,7 @@ int link_group_table_insert(struct dentry *dentry, void *__table) group = MALLOC(sizeof(struct link_group)); if (!group) return WIMLIB_ERR_NOMEM; - group->link_group_id = dentry->hard_link; + group->link_group_id = dentry->link_group_id; group->next = table->array[pos]; INIT_LIST_HEAD(&dentry->link_group_list); group->dentry_list = &dentry->link_group_list; @@ -218,7 +218,7 @@ u64 assign_link_group_ids_to_list(struct link_group *group, u64 id, dentry = container_of(cur_head, struct dentry, link_group_list); - dentry->hard_link = id; + dentry->link_group_id = id; cur_head = cur_head->next; } while (cur_head != cur_group->dentry_list); cur_group->link_group_id = id; @@ -336,6 +336,19 @@ static bool dentries_consistent(const struct dentry * restrict ref_dentry, return true; } +#ifdef ENABLE_DEBUG +static void +print_dentry_list(const struct dentry *first_dentry) +{ + const struct dentry *dentry; + do { + printf("`%s'\n", dentry->full_path_utf8); + } while ((dentry = container_of(dentry->link_group_list.next, + struct dentry, + link_group_list)) != first_dentry); +} +#endif + /* Fix up a "true" link group and check for inconsistencies */ static int fix_true_link_group(struct dentry *first_dentry) @@ -399,19 +412,19 @@ fix_true_link_group(struct dentry *first_dentry) * * - Assign all the dentries in the link group the most recent timestamp * among all the corresponding timestamps in the link group, for each of - * the three categories of time stamps + * the three categories of time stamps. * * - Make sure the dentry->hash field is valid in all the dentries, if * possible (this field may be all zeroes, and in the context of a hard - * link group must be interpreted as implicitly refering to the same stream - * as another dentry is the hard link group that does *not* have all zeroes - * for the stream hash). + * link group this must be interpreted as implicitly refering to the same + * stream as another dentry in the hard link group that does NOT have all + * zeroes for this field). * * - Make sure dentry->num_ads is the same in all the dentries in the link - * group. In some cases, it's possible for it to be set to 0 when it must - * be interpreted as being the same as the number of alternate data streams - * in another dentry in the hard link group that has a nonzero number of - * alternate data streams. + * group. In some cases, it's possible for it to be set to 0 when it + * actually must be interpreted as being the same as the number of + * alternate data streams in another dentry in the hard link group that has + * a nonzero number of alternate data streams. * * - Make sure only the dentry->ads_entries array is only allocated for one * dentry in the hard link group. This dentry will have @@ -457,10 +470,14 @@ fix_nominal_link_group(struct link_group *group, /* If there are no dentries with data streams, we require the nominal * link group to be a true link group */ - if (list_empty(&dentries_with_data_streams)) + if (list_empty(&dentries_with_data_streams)) { + #ifdef ENABLE_DEBUG + + #endif return fix_true_link_group(container_of(group->dentry_list, struct dentry, link_group_list)); + } /* One or more dentries had data streams specified. We check each of * these dentries for consistency with the others to form a set of true diff --git a/src/mount.c b/src/mount.c index 9385b529..8a9640c3 100644 --- a/src/mount.c +++ b/src/mount.c @@ -214,7 +214,7 @@ int dentry_to_stbuf(const struct dentry *dentry, struct stat *stbuf) else stbuf->st_mode = S_IFREG | 0644; - stbuf->st_ino = (ino_t)dentry->hard_link; + stbuf->st_ino = (ino_t)dentry->link_group_id; stbuf->st_nlink = dentry_link_group_size(dentry); stbuf->st_uid = getuid(); @@ -321,7 +321,7 @@ lte_extract_fds(struct lookup_table_entry *old_lte, u64 link_group) num_transferred_fds = 0; for (u16 i = 0; i < old_lte->num_allocated_fds; i++) if (old_lte->fds[i] && old_lte->fds[i]->dentry && - old_lte->fds[i]->dentry->hard_link == link_group) + old_lte->fds[i]->dentry->link_group_id == link_group) num_transferred_fds++; DEBUG("Transferring %u file descriptors", num_transferred_fds); @@ -332,7 +332,7 @@ lte_extract_fds(struct lookup_table_entry *old_lte, u64 link_group) } for (u16 i = 0, j = 0; ; i++) { if (old_lte->fds[i] && old_lte->fds[i]->dentry && - old_lte->fds[i]->dentry->hard_link == link_group) { + old_lte->fds[i]->dentry->link_group_id == link_group) { struct wimlib_fd *fd = old_lte->fds[i]; old_lte->fds[i] = NULL; fd->lte = new_lte; @@ -384,7 +384,7 @@ static void lte_transfer_stream_entries(struct lookup_table_entry *new_lte, do { struct dentry *d; d = container_of(pos, struct dentry, link_group_list); - wimlib_assert(d->hard_link == dentry->hard_link); + wimlib_assert(d->link_group_id == dentry->link_group_id); lte_transfer_dentry(new_lte, d); pos = pos->next; } while (pos != &dentry->link_group_list); @@ -483,7 +483,7 @@ static int extract_resource_to_staging_dir(struct dentry *dentry, * XXX*/ wimlib_assert(old_lte->refcnt > link_group_size); - new_lte = lte_extract_fds(old_lte, dentry->hard_link); + new_lte = lte_extract_fds(old_lte, dentry->link_group_id); if (!new_lte) { ret = -ENOMEM; goto out_delete_staging_file; @@ -1142,7 +1142,7 @@ static int wimfs_mkdir(const char *path, mode_t mode) newdir = new_dentry(basename); newdir->attributes |= FILE_ATTRIBUTE_DIRECTORY; newdir->resolved = true; - newdir->hard_link = next_link_group_id++; + newdir->link_group_id = next_link_group_id++; link_dentry(newdir, parent); return 0; } @@ -1193,7 +1193,7 @@ static int wimfs_mknod(const char *path, mode_t mode, dev_t rdev) if (!dentry) return -ENOMEM; dentry->resolved = true; - dentry->hard_link = next_link_group_id++; + dentry->link_group_id = next_link_group_id++; dentry->lte_group_list.type = STREAM_TYPE_NORMAL; INIT_LIST_HEAD(&dentry->lte_group_list.list); link_dentry(dentry, parent); @@ -1603,7 +1603,7 @@ static int wimfs_symlink(const char *to, const char *from) dentry->attributes = FILE_ATTRIBUTE_REPARSE_POINT; dentry->reparse_tag = WIM_IO_REPARSE_TAG_SYMLINK; - dentry->hard_link = next_link_group_id++; + dentry->link_group_id = next_link_group_id++; if (dentry_set_symlink(dentry, to, w->lookup_table, <e) != 0) goto out_free_dentry; diff --git a/src/ntfs-capture.c b/src/ntfs-capture.c index 1a2b4963..9dc0b9d4 100644 --- a/src/ntfs-capture.c +++ b/src/ntfs-capture.c @@ -466,7 +466,7 @@ static int build_dentry_tree_ntfs_recursive(struct dentry **root_p, root->last_access_time = le64_to_cpu(ni->last_access_time); root->security_id = le32_to_cpu(ni->security_id); root->attributes = le32_to_cpu(attributes); - root->hard_link = ni->mft_no; + root->link_group_id = ni->mft_no; root->resolved = true; if (attributes & FILE_ATTR_REPARSE_POINT) { -- 2.43.0