Skip to content

Commit

Permalink
bfs_tools: add some extra checks to avoid crashes.
Browse files Browse the repository at this point in the history
I'm not sure I'm fixing the root cause of problems here, but this avoids
some crashes and I could recover my files this way.
  • Loading branch information
pulkomandy committed Jul 13, 2015
1 parent 10e6523 commit 76e7f56
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
14 changes: 9 additions & 5 deletions src/bin/bfs_tools/lib/Inode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Inode::SetTo(bfs_inode *inode)


status_t
Inode::InitCheck()
Inode::InitCheck() const
{
if (!fInode)
return B_ERROR;
Expand Down Expand Up @@ -304,6 +304,10 @@ Inode::SetName(const char *name)
const char *
Inode::Name() const
{
if (InitCheck() != B_OK) {
puts("Not getting name because node is invalid");
return NULL;
}
small_data *data = fInode->small_data_start;
while (!data->IsLast(fInode)) {
if (data->type == FILE_NAME_TYPE
Expand Down Expand Up @@ -929,7 +933,7 @@ File::~File()


status_t
File::InitCheck()
File::InitCheck() const
{
status_t status = DataStream::InitCheck();
if (status == B_OK)
Expand Down Expand Up @@ -1006,7 +1010,7 @@ Attribute::~Attribute()


status_t
Attribute::InitCheck()
Attribute::InitCheck() const
{
status_t status = DataStream::InitCheck();
if (status == B_OK)
Expand Down Expand Up @@ -1053,7 +1057,7 @@ Directory::~Directory()


status_t
Directory::InitCheck()
Directory::InitCheck() const
{
status_t status = DataStream::InitCheck();
if (status == B_OK)
Expand Down Expand Up @@ -1322,7 +1326,7 @@ Symlink::~Symlink()


status_t
Symlink::InitCheck()
Symlink::InitCheck() const
{
status_t status = Inode::InitCheck();
if (status == B_OK)
Expand Down
10 changes: 5 additions & 5 deletions src/bin/bfs_tools/lib/Inode.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Inode {
virtual ~Inode();

status_t SetTo(bfs_inode *inode);
virtual status_t InitCheck();
virtual status_t InitCheck() const;

bool IsFile() const { return S_ISREG(fInode->mode); }
bool IsDirectory() const { return S_ISDIR(fInode->mode); }
Expand Down Expand Up @@ -131,7 +131,7 @@ class File : public DataStream {
File(const Inode &inode);
~File();

virtual status_t InitCheck();
virtual status_t InitCheck() const;
virtual status_t CopyTo(const char *path, bool fullPath = true,
Inode::Source *source = NULL);
};
Expand All @@ -143,7 +143,7 @@ class Attribute : public File {
Attribute(const Inode &inode);
~Attribute();

virtual status_t InitCheck();
virtual status_t InitCheck() const;
virtual status_t CopyTo(const char *path, bool fullPath = true,
Inode::Source *source = NULL);

Expand All @@ -157,7 +157,7 @@ class Directory : public DataStream {
Directory(const Inode &inode);
~Directory();

virtual status_t InitCheck();
virtual status_t InitCheck() const;
virtual status_t CopyTo(const char *path, bool fullPath = true,
Inode::Source *source = NULL);

Expand Down Expand Up @@ -186,7 +186,7 @@ class Symlink : public Inode {
Symlink(const Inode &inode);
~Symlink();

virtual status_t InitCheck();
virtual status_t InitCheck() const;
virtual status_t CopyTo(const char *path, bool fullPath = true,
Inode::Source *source = NULL);

Expand Down
10 changes: 9 additions & 1 deletion src/bin/bfs_tools/recover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,15 @@ checkStructure(Disk &disk)

if (node->IsDirectory() && !node->IsIndex()) {
// check if all entries are in the hashtable
checkDirectoryContents(disk, (Directory*)node);
Directory* directory = dynamic_cast<Directory*>(node);
if (directory != NULL)
checkDirectoryContents(disk, directory);
else {
printf("Node \"%s\" at %" B_PRId32
",%d looks like a directory, but isn't.\n",
node->Name(), node->BlockRun().allocation_group,
node->BlockRun().start);
}
}

// check for the parent directory
Expand Down

0 comments on commit 76e7f56

Please sign in to comment.