X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=print-tree.c;h=45350fea0963148023ce493624bb8de147d90c13;hb=89f5a8f97ca8c53759a1dcd8117808db2086643f;hp=e53b9aac13a21964f0c536bd4770d0a6032759cc;hpb=5fbc00cc7342f46f607079ae920b338b6253250d;p=platform%2Fupstream%2Fbtrfs-progs.git diff --git a/print-tree.c b/print-tree.c index e53b9aa..45350fe 100644 --- a/print-tree.c +++ b/print-tree.c @@ -198,9 +198,17 @@ void print_chunk_item(struct extent_buffer *eb, struct btrfs_chunk *chunk) { u16 num_stripes = btrfs_chunk_num_stripes(eb, chunk); int i; - u32 chunk_item_size = btrfs_chunk_item_size(num_stripes); + u32 chunk_item_size; char chunk_flags_str[32] = {0}; + /* The chunk must contain at least one stripe */ + if (num_stripes < 1) { + printf("invalid num_stripes: %u\n", num_stripes); + return; + } + + chunk_item_size = btrfs_chunk_item_size(num_stripes); + if ((unsigned long)chunk + chunk_item_size > eb->len) { printf("\t\tchunk item invalid\n"); return; @@ -315,6 +323,9 @@ static void compress_type_to_str(u8 compress_type, char *ret) case BTRFS_COMPRESS_LZO: strcpy(ret, "lzo"); break; + case BTRFS_COMPRESS_ZSTD: + strcpy(ret, "zstd"); + break; default: sprintf(ret, "UNKNOWN.%d", compress_type); } @@ -540,6 +551,26 @@ static void root_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_root_item(struct extent_buffer *leaf, int slot) { struct btrfs_root_item *ri; @@ -587,6 +618,18 @@ static void print_root_item(struct extent_buffer *leaf, int slot) btrfs_root_stransid(&root_item), btrfs_root_rtransid(&root_item)); } + if (btrfs_timespec_sec(leaf, btrfs_root_ctime(ri))) + print_timespec(leaf, btrfs_root_ctime(ri), + "\t\tctime ", "\n"); + if (btrfs_timespec_sec(leaf, btrfs_root_otime(ri))) + print_timespec(leaf, btrfs_root_otime(ri), + "\t\totime ", "\n"); + if (btrfs_timespec_sec(leaf, btrfs_root_stime(ri))) + print_timespec(leaf, btrfs_root_stime(ri), + "\t\tstime ", "\n"); + if (btrfs_timespec_sec(leaf, btrfs_root_rtime(ri))) + print_timespec(leaf, btrfs_root_rtime(ri), + "\t\trtime ", "\n"); } btrfs_disk_key_to_cpu(&drop_key, &root_item.drop_progress); @@ -783,6 +826,17 @@ void btrfs_print_key(struct btrfs_disk_key *disk_key) case BTRFS_UUID_KEY_RECEIVED_SUBVOL: printf(" 0x%016llx)", (unsigned long long)offset); break; + + /* + * Key offsets of ROOT_ITEM point to tree root, print them in human + * readable format. Especially useful for trees like data/tree reloc + * tree, whose tree id can be negative. + */ + case BTRFS_ROOT_ITEM_KEY: + printf(" "); + print_objectid(stdout, offset, type); + printf(")"); + break; default: if (offset == (u64)-1) printf(" -1)"); @@ -845,26 +899,6 @@ 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_inode_item *ii) { @@ -885,8 +919,8 @@ static void print_inode_item(struct extent_buffer *eb, btrfs_inode_uid(eb, ii), btrfs_inode_gid(eb, ii), (unsigned long long)btrfs_inode_rdev(eb,ii), - (unsigned long long)btrfs_inode_flags(eb,ii), (unsigned long long)btrfs_inode_sequence(eb, ii), + (unsigned long long)btrfs_inode_flags(eb,ii), flags_str); print_timespec(eb, btrfs_inode_atime(ii), "\t\tatime ", "\n"); print_timespec(eb, btrfs_inode_ctime(ii), "\t\tctime ", "\n"); @@ -1102,6 +1136,18 @@ static void print_temporary_item(struct extent_buffer *eb, void *ptr, } } +static void print_extent_csum(struct extent_buffer *eb, + struct btrfs_fs_info *fs_info, u32 item_size, u64 start) +{ + u32 size; + + size = (item_size / btrfs_super_csum_size(fs_info->super_copy)) * + fs_info->sectorsize; + printf("\t\trange start %llu end %llu length %u\n", + (unsigned long long)start, + (unsigned long long)start + size, size); +} + /* Caller must ensure sizeof(*ret) >= 14 "WRITTEN|RELOC" */ static void header_flags_to_str(u64 flags, char *ret) { @@ -1233,16 +1279,10 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *eb) case BTRFS_CSUM_ITEM_KEY: printf("\t\tcsum item\n"); break; - case BTRFS_EXTENT_CSUM_KEY: { - u16 csum_size = - btrfs_super_csum_size(root->fs_info->super_copy); - u32 size = (item_size / csum_size) * - root->fs_info->sectorsize; - printf("\t\textent csum item range %llu-%llu\n", - (unsigned long long)disk_key.offset, - (unsigned long long)disk_key.offset + size); + case BTRFS_EXTENT_CSUM_KEY: + print_extent_csum(eb, root->fs_info, item_size, + offset); break; - } case BTRFS_EXTENT_DATA_KEY: print_file_extent_item(eb, item, i, ptr); break; @@ -1319,7 +1359,7 @@ void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb, int fol printf("node %llu level %d items %d free %u generation %llu owner %llu\n", (unsigned long long)eb->start, btrfs_header_level(eb), nr, - (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr, + (u32)BTRFS_NODEPTRS_PER_BLOCK(root->fs_info) - nr, (unsigned long long)btrfs_header_generation(eb), (unsigned long long)btrfs_header_owner(eb)); print_uuids(eb);