]> wimlib.net Git - wimlib/blobdiff - src/dentry.c
Various fixes
[wimlib] / src / dentry.c
index 2f0cabd3d577f4eef9581c15fb58e370337e2cb0..f5a3fe1476cabf07bae615680b07b2f22b001061 100644 (file)
  * 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
@@ -78,13 +80,17 @@ void stbuf_to_dentry(const struct stat *stbuf, struct dentry *dentry)
        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;
@@ -413,6 +419,7 @@ struct file_attr_flag file_attr_flags[] = {
 int print_dentry(struct dentry *dentry, void *lookup_table)
 {
        const u8 *hash;
+       struct lookup_table_entry *lte;
 
        printf("[DENTRY]\n");
        printf("Length            = %"PRIu64"\n", dentry->length);
@@ -423,17 +430,23 @@ int print_dentry(struct dentry *dentry, void *lookup_table)
                                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);
-       hash = dentry_stream_hash(dentry, 0);
-       if (hash) {
-               printf("Hash              = 0x"); 
-               print_hash(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);
@@ -448,7 +461,17 @@ int print_dentry(struct dentry *dentry, void *lookup_table)
        puts("\"");
        printf("Short Name Length = %hu\n", dentry->short_name_len);
        printf("Full Path (UTF-8) = \"%s\"\n", dentry->full_path_utf8);
-       print_lookup_table_entry(dentry_stream_lte(dentry, 0, lookup_table));
+       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');
+               }
+       }
        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);