* along with wimlib; if not, see http://www.gnu.org/licenses/.
*/
+#include <errno.h>
+#include <sys/stat.h>
+#include <time.h>
+#include <unistd.h>
+
#include "wimlib_internal.h"
#include "dentry.h"
#include "io.h"
#include "timestamp.h"
#include "lookup_table.h"
#include "sha1.h"
-#include <errno.h>
-#include <unistd.h>
-#include <sys/stat.h>
/*
* Returns true if @dentry has the UTF-8 file name @name that has length
u64 dentry_total_length(const struct dentry *dentry)
{
u64 length = (dentry->length + 7) & ~7;
- for (u16 i = 0 ; i < dentry->num_ads; i++)
+ for (u16 i = 0; i < dentry->num_ads; i++)
length += ads_entry_length(&dentry->ads_entries[i]);
return length;
}
else
dentry->hard_link = (u64)stbuf->st_ino |
((u64)stbuf->st_dev << (sizeof(ino_t) * 8));
+ /* Set timestamps */
+ dentry->creation_time = timespec_to_wim_timestamp(&stbuf->st_mtim);
+ dentry->last_write_time = timespec_to_wim_timestamp(&stbuf->st_mtim);
+ dentry->last_access_time = timespec_to_wim_timestamp(&stbuf->st_atim);
}
/* Makes all timestamp fields for the dentry be the current time. */
void dentry_update_all_timestamps(struct dentry *dentry)
{
- u64 now = get_timestamp();
+ u64 now = get_wim_timestamp();
dentry->creation_time = now;
dentry->last_access_time = now;
dentry->last_write_time = now;
struct ads_entry *dentry_get_ads_entry(struct dentry *dentry,
const char *stream_name)
{
- size_t stream_name_len = strlen(stream_name);
+ size_t stream_name_len;
if (!stream_name)
return NULL;
- for (u16 i = 0; i < dentry->num_ads; i++)
- if (ads_entry_has_name(&dentry->ads_entries[i],
- stream_name, stream_name_len))
- return &dentry->ads_entries[i];
+ if (dentry->num_ads) {
+ u16 i = 0;
+ stream_name_len = strlen(stream_name);
+ do {
+ if (ads_entry_has_name(&dentry->ads_entries[i],
+ stream_name, stream_name_len))
+ return &dentry->ads_entries[i];
+ } while (++i != dentry->num_ads);
+ }
return NULL;
}
struct ads_entry *ads_entries;
struct ads_entry *new_entry;
+ DEBUG("Add alternate data stream %s:%s",
+ dentry->file_name_utf8, stream_name);
+
if (dentry->num_ads == 0xffff)
return NULL;
num_ads = dentry->num_ads + 1;
cur->next->prev = cur;
}
}
- dentry->ads_entries = ads_entries;
new_entry = &ads_entries[num_ads - 1];
+ ads_entry_init(new_entry);
if (change_ads_name(new_entry, stream_name) != 0)
return NULL;
+ dentry->ads_entries = ads_entries;
dentry->num_ads = num_ads;
- ads_entry_init(new_entry);
return new_entry;
}
* NULL if the resource entry for the dentry is not to be printed. */
int print_dentry(struct dentry *dentry, void *lookup_table)
{
+ const u8 *hash;
struct lookup_table_entry *lte;
- unsigned i;
printf("[DENTRY]\n");
printf("Length = %"PRIu64"\n", dentry->length);
printf("Attributes = 0x%x\n", dentry->attributes);
- for (i = 0; i < ARRAY_LEN(file_attr_flags); i++)
+ for (unsigned i = 0; i < ARRAY_LEN(file_attr_flags); i++)
if (file_attr_flags[i].flag & dentry->attributes)
printf(" FILE_ATTRIBUTE_%s is set\n",
file_attr_flags[i].name);
printf("Security ID = %d\n", dentry->security_id);
printf("Subdir offset = %"PRIu64"\n", dentry->subdir_offset);
- /*printf("Unused1 = 0x%"PRIu64"\n", dentry->unused1);*/
- /*printf("Unused2 = %"PRIu64"\n", dentry->unused2);*/
- printf("Creation Time = 0x%"PRIx64"\n", dentry->creation_time);
- printf("Last Access Time = 0x%"PRIx64"\n", dentry->last_access_time);
- printf("Last Write Time = 0x%"PRIx64"\n", dentry->last_write_time);
- printf("Hash = 0x");
- print_hash(dentry->hash);
- putchar('\n');
+#if 0
+ printf("Unused1 = 0x%"PRIu64"\n", dentry->unused1);
+ printf("Unused2 = %"PRIu64"\n", dentry->unused2);
+#endif
+#if 0
+ printf("Creation Time = 0x%"PRIx64"\n");
+ printf("Last Access Time = 0x%"PRIx64"\n");
+ printf("Last Write Time = 0x%"PRIx64"\n");
+#endif
+
+ time_t creat_time = wim_timestamp_to_unix(dentry->creation_time);
+ time_t access_time = wim_timestamp_to_unix(dentry->last_access_time);
+ time_t mod_time = wim_timestamp_to_unix(dentry->last_write_time);
+ printf("Creation Time = %s", asctime(localtime(&creat_time)));
+ printf("Last Access Time = %s", asctime(localtime(&access_time)));
+ printf("Last Write Time = %s", asctime(localtime(&mod_time)));
+
printf("Reparse Tag = 0x%"PRIx32"\n", dentry->reparse_tag);
printf("Hard Link Group = 0x%"PRIx64"\n", dentry->hard_link);
printf("Number of Alternate Data Streams = %hu\n", dentry->num_ads);
puts("\"");
printf("Short Name Length = %hu\n", dentry->short_name_len);
printf("Full Path (UTF-8) = \"%s\"\n", dentry->full_path_utf8);
- if (lookup_table && (lte = __lookup_resource(lookup_table, dentry->hash)))
- print_lookup_table_entry(lte, NULL);
- else
- putchar('\n');
+ lte = dentry_stream_lte(dentry, 0, lookup_table);
+ if (lte) {
+ print_lookup_table_entry(lte);
+ } else {
+ hash = dentry_stream_hash(dentry, 0);
+ if (hash) {
+ printf("Hash = 0x");
+ print_hash(hash);
+ putchar('\n');
+ putchar('\n');
+ }
+ }
for (u16 i = 0; i < dentry->num_ads; i++) {
printf("[Alternate Stream Entry %u]\n", i);
printf("Name = \"%s\"\n", dentry->ads_entries[i].stream_name_utf8);
printf("Name Length (UTF-16) = %u\n",
dentry->ads_entries[i].stream_name_len);
- printf("Hash = 0x");
- print_hash(dentry->ads_entries[i].hash);
- if (lookup_table &&
- (lte = __lookup_resource(lookup_table,
- dentry->ads_entries[i].hash)))
- {
- print_lookup_table_entry(lte, NULL);
- } else {
+ hash = dentry_stream_hash(dentry, i + 1);
+ if (hash) {
+ printf("Hash = 0x");
+ print_hash(hash);
putchar('\n');
}
+ print_lookup_table_entry(dentry_stream_lte(dentry, i + 1,
+ lookup_table));
}
return 0;
}
return get_names(&entry->stream_name, &entry->stream_name_utf8,
&entry->stream_name_len,
&entry->stream_name_utf8_len,
- new_name);
+ new_name);
}
/* Parameters for calculate_dentry_statistics(). */
DEBUG2("ADS length = %"PRIu64, length);
p += 8; /* Unused */
- p = get_bytes(p, WIM_HASH_SIZE, (u8*)cur_entry->hash);
+ p = get_bytes(p, SHA1_HASH_SIZE, (u8*)cur_entry->hash);
p = get_u16(p, &cur_entry->stream_name_len);
DEBUG2("Stream name length = %u", cur_entry->stream_name_len);
p = get_u64(p, &dentry->last_access_time);
p = get_u64(p, &dentry->last_write_time);
- p = get_bytes(p, WIM_HASH_SIZE, dentry->hash);
+ p = get_bytes(p, SHA1_HASH_SIZE, dentry->hash);
/*
* I don't know what's going on here. It seems like M$ screwed up the
* aligned on the next 8-byte boundary. Here's an example of the
* aligned data:
*
- * 01000000400000006c786bbac58ede11b0bb00261870892ab6adb76fe63a3
- * e468fca86530d2effa16c786bbac58ede11b0bb00261870892a0000000000
- * 0000000000000000000000
+ * 01000000 40000000 6c786bba c58ede11 b0bb0026 1870892a b6adb76f
+ * e63a3e46 8fca8653 0d2effa1 6c786bba c58ede11 b0bb0026 1870892a
+ * 00000000 00000000 00000000 00000000
*
* Here's one interpretation of how the data is laid out.
*
* struct unknown {
* u32 field1; (always 0x00000001)
* u32 field2; (always 0x40000000)
- * u16 field3;
- * u32 field4;
- * u32 field5;
- * u32 field6;
* u8 data[48]; (???)
* u64 reserved1; (always 0)
* u64 reserved2; (always 0)
hash = dentry->lte->hash;
else
hash = dentry->hash;
- p = put_bytes(p, WIM_HASH_SIZE, hash);
+ p = put_bytes(p, SHA1_HASH_SIZE, hash);
if (dentry->attributes & FILE_ATTRIBUTE_REPARSE_POINT) {
p = put_zeroes(p, 4);
p = put_u32(p, dentry->reparse_tag);
if (p - orig_p < dentry->length)
p = put_zeroes(p, dentry->length - (p - orig_p));
- p = put_zeroes(p, (8 - (p - orig_p) % 8) % 8);
+ p = put_zeroes(p, (8 - dentry->length % 8) % 8);
for (u16 i = 0; i < dentry->num_ads; i++) {
p = put_u64(p, ads_entry_length(&dentry->ads_entries[i]));
p = put_u64(p, 0); /* Unused */
- p = put_bytes(p, WIM_HASH_SIZE, dentry->ads_entries[i].hash);
+ if (dentry->resolved && dentry->ads_entries[i].lte)
+ hash = dentry->ads_entries[i].lte->hash;
+ else
+ hash = dentry->ads_entries[i].hash;
+ p = put_bytes(p, SHA1_HASH_SIZE, hash);
p = put_u16(p, dentry->ads_entries[i].stream_name_len);
p = put_bytes(p, dentry->ads_entries[i].stream_name_len,
(u8*)dentry->ads_entries[i].stream_name);
+ p = put_u16(p, 0);
p = put_zeroes(p, (8 - (p - orig_p) % 8) % 8);
}
return p;