btrfs-progs: dump-tree: add helper to print timespec
authorDavid Sterba <dsterba@suse.com>
Mon, 31 Oct 2016 15:00:53 +0000 (16:00 +0100)
committerDavid Sterba <dsterba@suse.com>
Wed, 9 Nov 2016 12:47:29 +0000 (13:47 +0100)
Signed-off-by: David Sterba <dsterba@suse.com>
print-tree.c

index 136ce56..ff68b67 100644 (file)
@@ -908,6 +908,25 @@ static void inode_flags_to_str(u64 flags, char *ret)
                strcat(ret, "none");
 }
 
+static void print_timespec(struct extent_buffer *eb,
+               struct btrfs_timespec *timespec, const char *prefix,
+               const char *suffix)
+{
+       struct tm tm;
+       u64 tmp_u64;
+       u32 tmp_u32;
+       time_t tmp_time;
+       char timestamp[256];
+
+       tmp_u64 = btrfs_timespec_sec(eb, timespec);
+       tmp_u32 = btrfs_timespec_nsec(eb, timespec);
+       tmp_time = tmp_u64;
+       localtime_r(&tmp_time, &tm);
+       strftime(timestamp, sizeof(timestamp),
+                       "%Y-%m-%d %H:%M:%S", &tm);
+       printf("%s%llu.%u (%s)%s", prefix, (unsigned long long)tmp_u64, tmp_u32,
+                       timestamp, suffix);
+}
 static void print_inode_item(struct extent_buffer *eb, struct btrfs_item *item,
                                struct btrfs_inode_item *ii)
 {