Skip to content

Commit

Permalink
bfs tools: missing null check, 64bit support
Browse files Browse the repository at this point in the history
* Some NULL checks were missing, but on 32-bit machines recover will still fail on my big data partition as it goes out of memory.
* Pack structures that are mapped to on-disk data, so when using a 64-bit compiler, no padding is inserted. Hopefully with 8GB of RAM I have enough to recover my data.
  • Loading branch information
pulkomandy committed Jul 8, 2015
1 parent 3c35829 commit 2df2dca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
30 changes: 15 additions & 15 deletions src/bin/bfs_tools/lib/bfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#endif


struct block_run {
struct __attribute__((packed)) block_run {
int32 allocation_group;
uint16 start;
uint16 length;
Expand All @@ -37,24 +37,24 @@ typedef block_run inode_addr;

#define BFS_DISK_NAME_LENGTH 32

struct disk_super_block
struct __attribute__((packed)) disk_super_block
{
char name[BFS_DISK_NAME_LENGTH];
int32 magic1;
int32 fs_byte_order;
uint32 block_size;
uint32 block_shift;
off_t num_blocks;
off_t used_blocks;
int64 num_blocks;
int64 used_blocks;
int32 inode_size;
int32 magic2;
int32 blocks_per_ag;
int32 ag_shift;
int32 num_ags;
int32 flags;
block_run log_blocks;
off_t log_start;
off_t log_end;
int64 log_start;
int64 log_end;
int32 magic3;
inode_addr root_dir;
inode_addr indices;
Expand All @@ -74,22 +74,22 @@ struct disk_super_block

#define NUM_DIRECT_BLOCKS 12

struct data_stream
struct __attribute__((packed)) data_stream
{
block_run direct[NUM_DIRECT_BLOCKS];
off_t max_direct_range;
int64 max_direct_range;
block_run indirect;
off_t max_indirect_range;
int64 max_indirect_range;
block_run double_indirect;
off_t max_double_indirect_range;
off_t size;
int64 max_double_indirect_range;
int64 size;
};

//**************************************

struct bfs_inode;

struct small_data
struct __attribute__((packed)) small_data
{
uint32 type;
uint16 name_size;
Expand All @@ -111,16 +111,16 @@ struct small_data

#define SHORT_SYMLINK_NAME_LENGTH 144 // length incl. terminating '\0'

struct bfs_inode
struct __attribute__((packed)) bfs_inode
{
int32 magic1;
inode_addr inode_num;
int32 uid;
int32 gid;
int32 mode; // see sys/stat.h
int32 flags;
bigtime_t create_time;
bigtime_t last_modified_time;
int64 create_time;
int64 last_modified_time;
inode_addr parent;
inode_addr attributes;
uint32 type; // attribute type
Expand Down
7 changes: 5 additions & 2 deletions src/bin/bfs_tools/recover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ getNameIndex(Disk &disk)
InodeGetter getter(disk, *iterator);
Inode* node = getter.Node();

if (!node->IsIndex() || node->Name() == NULL)
if (!node || !node->IsIndex() || node->Name() == NULL)
continue;
if (!strcmp(node->Name(), "name") && node->Mode() & S_STR_INDEX)
return dynamic_cast<Directory *>(node);
Expand Down Expand Up @@ -435,6 +435,9 @@ checkStructure(Disk &disk)
if ((count % 50) == 0)
fprintf(stderr, "%" B_PRIdOFF " inodes processed...\33[1A\n", count);

if (node == NULL)
continue;

if (node->IsDirectory() && !node->IsIndex()) {
// check if all entries are in the hashtable
checkDirectoryContents(disk, (Directory*)node);
Expand Down Expand Up @@ -697,7 +700,7 @@ copyInodes(Disk& disk, const char* copyTo)
InodeGetter getter(disk, *iterator);
Inode* node = getter.Node();

if (!node->IsIndex() && !node->IsAttributeDirectory())
if (node && !node->IsIndex() && !node->IsAttributeDirectory())
node->CopyTo(copyTo, true, &source);

if ((++count % 500) == 0)
Expand Down

0 comments on commit 2df2dca

Please sign in to comment.