Skip to content

Commit

Permalink
Fix Ubuntu compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jivanpal committed Aug 29, 2021
1 parent 746c90e commit b707cb9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 28 deletions.
1 change: 1 addition & 0 deletions include/drat/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define DRAT_IO_H

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <assert.h>
#include <sys/errno.h>
Expand Down
14 changes: 10 additions & 4 deletions include/drat/print-fs-records.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ void print_fs_records(j_rec_t** fs_records) {
fprintf(stderr, "- ");

switch ( (hdr->obj_id_and_type & OBJ_TYPE_MASK) >> OBJ_TYPE_SHIFT ) {
// NOTE: Need to enclose each case in a block `{}` since the
// names `key` and `val` are potentially declared multiple times
// in this switch-statement (though in practice it is not a
// concern since every `case` here ends in a `break`.)
/*
* NOTE: Need to enclose each case in a block `{}` since the
* names `key` and `val` are potentially declared multiple times
* in the same variable scope (though in practice it is not a
* concern since every `case` here ends in a `break`.)
*
* This practice also prevents the following error when compiling
* on Linux: "a label can only be part of a statement and a
* declaration is not a statement".
*/
case APFS_TYPE_SNAP_METADATA: {
j_snap_metadata_key_t* key = fs_rec->data;
j_snap_metadata_val_t* val = fs_rec->data + fs_rec->key_len;
Expand Down
54 changes: 30 additions & 24 deletions include/drat/string/xf.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,62 +98,68 @@ void print_xf_pair(xf_pair_t* xf_pair) {
/*
* xfield types whose values are of unknown data type (e.g. reserved types,
* Finder data, purgeable flags) appear together at the bottom of this list.
*
* NOTE: Need to enclose each case here in a block `{}` to prevent the
* following error when compiling on Linux: "a label can only be part of
* a statement and a declaration is not a statement". This practice also
* mitigates the possibility of names being declared multiple times in the
* same variable scope.
*/
switch(xf_pair->key.x_type) {
case INO_EXT_TYPE_SNAP_XID:
case INO_EXT_TYPE_SNAP_XID: {
xid_t* snap_xid = value;
printf("Snapshot XID: %#"PRIx64"\n", *snap_xid);
break;
case INO_EXT_TYPE_DELTA_TREE_OID:
} break;
case INO_EXT_TYPE_DELTA_TREE_OID: {
oid_t* delta_tree_oid = value;
printf("Delta tree Virtual OID: %#"PRIx64"\n", *delta_tree_oid);
break;
case INO_EXT_TYPE_DOCUMENT_ID:
} break;
case INO_EXT_TYPE_DOCUMENT_ID: {
uint32_t* document_id = value;
printf("Document ID: %#"PRIx32"\n", *document_id);
break;
case INO_EXT_TYPE_NAME:
} break;
case INO_EXT_TYPE_NAME: {
char* name = value;
printf("Item name: %s\n", name);
break;
case INO_EXT_TYPE_PREV_FSIZE:
} break;
case INO_EXT_TYPE_PREV_FSIZE: {
uint64_t* size = value;
printf("Previous file size: %"PRIu64" bytes\n", *size);
break;
case INO_EXT_TYPE_DSTREAM:
} break;
case INO_EXT_TYPE_DSTREAM: {
j_dstream_t* dstream = value;
print_j_dstream(dstream);
break;
case INO_EXT_TYPE_DIR_STATS_KEY:
} break;
case INO_EXT_TYPE_DIR_STATS_KEY: {
j_dir_stats_val_t* dir_stats = value;
print_j_dir_stats_val(dir_stats);
break;
case INO_EXT_TYPE_FS_UUID:
} break;
case INO_EXT_TYPE_FS_UUID: {
unsigned char* uuid = value;
printf("Filesystem UUID: ");
print_uuid(uuid);
printf("\n");
break;
case INO_EXT_TYPE_SPARSE_BYTES:
} break;
case INO_EXT_TYPE_SPARSE_BYTES: {
uint64_t* bytes = value;
printf("Number of sparse bytes: %"PRIu64" bytes\n", *bytes);
break;
case INO_EXT_TYPE_RDEV:
} break;
case INO_EXT_TYPE_RDEV: {
uint32_t* rdev = value;
printf("Device ID: %#"PRIx32"\n", *rdev);
break;
case INO_EXT_TYPE_ORIG_SYNC_ROOT_ID:
} break;
case INO_EXT_TYPE_ORIG_SYNC_ROOT_ID: {
uint64_t* inode_number = value;
printf("Inode number: %#"PRIx64"\n", *inode_number);
break;
} break;

// xfield types whose value is of unknown type
case INO_EXT_TYPE_RESERVED_6:
case INO_EXT_TYPE_RESERVED_9:
case INO_EXT_TYPE_RESERVED_12:
case INO_EXT_TYPE_FINDER_INFO:
case INO_EXT_TYPE_PURGEABLE_FLAGS:
default:
default: {
printf("Value has unknown type. Hexdump:\n");
// Print hexdump
for (uint16_t i = 0; i < xf_pair->key.x_size; i++) {
Expand All @@ -165,7 +171,7 @@ void print_xf_pair(xf_pair_t* xf_pair) {
printf("%02x", xf_pair->value[i]);
}
printf("\n");
break;
} break;
}
}

Expand Down

0 comments on commit b707cb9

Please sign in to comment.