Skip to content

Commit

Permalink
Fixed whitespace errors, formatting, some other small details.
Browse files Browse the repository at this point in the history
  • Loading branch information
sgan81 committed Mar 28, 2018
1 parent b69c458 commit 575dc11
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 172 deletions.
2 changes: 1 addition & 1 deletion ApfsLib/ApfsContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ bool ApfsContainer::Init()

ApfsVolume *ApfsContainer::GetVolume(int index)
{
return GetVolume(index, std::string());
return GetVolume(index, std::string());
}

ApfsVolume *ApfsContainer::GetVolume(int index, const std::string &passphrase)
Expand Down
2 changes: 1 addition & 1 deletion ApfsLib/ApfsContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ApfsContainer
bool Init();

ApfsVolume *GetVolume(int index, const std::string &passphrase);
ApfsVolume *GetVolume(int index);
ApfsVolume *GetVolume(int index);
int GetVolumeCnt() const;

bool ReadBlocks(byte_t *data, uint64_t blkid, uint64_t blkcnt = 1) const;
Expand Down
32 changes: 16 additions & 16 deletions ApfsLib/ApfsDir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,12 @@ bool ApfsDir::ListDirectory(std::vector<Name> &dir, uint64_t inode)
if (!rc)
break;


kdata = reinterpret_cast<const uint8_t *>(res.key);

if (g_debug > 8) {
if (g_debug > 8)
{
DumpBuffer(kdata, res.key_len, "entry key");
DumpBuffer(reinterpret_cast<const uint8_t*>(res.val), res.val_len,
"entry val");
DumpBuffer(reinterpret_cast<const uint8_t*>(res.val), res.val_len, "entry val");
}

e.parent_id = *reinterpret_cast<const uint64_t *>(kdata);
Expand Down Expand Up @@ -292,10 +291,11 @@ bool ApfsDir::ReadFile(void* data, uint64_t inode, uint64_t offs, size_t size)
key.inode = inode | KeyType_Extent;
key.offset = offs;

if (g_debug > 8) {
if (g_debug > 8)
{
std::cout << "ReadFile for inode " << inode
<< ", offset=" << offs
<< "\n";
<< std::endl;
}

rc = m_bt.Lookup(e, &key, sizeof(key), CompareStdDirKey, this, false);
Expand All @@ -309,11 +309,11 @@ bool ApfsDir::ReadFile(void* data, uint64_t inode, uint64_t offs, size_t size)
if (g_debug > 8) {
std::cout << " key->inode=" << ext_key->inode
<< "; key->offset=" << ext_key->offset
<< "\n"
<< std::endl
<< " val->size=" << ext_val->size
<< "; val->block=" << ext_val->block
<< "; val->crypto_id=" << ext_val->crypto_id
<< "\n";
<< std::endl;
}

if (ext_key->inode != key.inode)
Expand All @@ -325,9 +325,9 @@ bool ApfsDir::ReadFile(void* data, uint64_t inode, uint64_t offs, size_t size)
uint64_t extent_size = ext_val->size & 0x00FFFFFFFFFFFFFFULL;

if (g_debug > 8) {
std::cout << " key has offset " << ext_key->offset << "\n"
std::cout << " key has offset " << ext_key->offset << std::endl
<< " val has block=" << ext_val->block
<< ", size=" << extent_size << "\n";
<< ", size=" << extent_size << std::endl;
}

cur_size = size;
Expand All @@ -341,10 +341,10 @@ bool ApfsDir::ReadFile(void* data, uint64_t inode, uint64_t offs, size_t size)
ext_val->crypto_id + idx);
if (g_debug > 8) {
std::cout << "reading at offset " << offs
<< " length " << cur_size
<< " length " << cur_size
<< " starting from block " << block_id + idx
<< " (extent starts at block " << block_id
<< ")\n";
<< ")" << std::endl;
}
}
else {
Expand Down Expand Up @@ -416,7 +416,7 @@ bool ApfsDir::GetAttribute(std::vector<uint8_t>& data, uint64_t inode, const cha
adata = reinterpret_cast<const uint8_t *>(res.val) + sizeof(APFS_Attribute);

if (g_debug > 8) {
std::cout << "GetAttribute: type=" << attr->type << "\n";
std::cout << "GetAttribute: type=" << attr->type << std::endl;
}

// Original has attr->type == 1, but apparently this could work for
Expand All @@ -426,15 +426,15 @@ bool ApfsDir::GetAttribute(std::vector<uint8_t>& data, uint64_t inode, const cha
assert(attr->size == 0x30);
alnk = reinterpret_cast<const APFS_AttributeLink *>(adata);
if (g_debug > 8) {
std::cout << "parsing as a link\n"
std::cout << "parsing as a link" << std::endl
<< " size=" << alnk->size
<< " size_on_disk=" << alnk->size_on_disk
<< "\n";
<< std::endl;
Inode inode_info;
GetInode(inode_info, alnk->object_id);
std::cout << " inode says size=" << inode_info.sizes.size
<< " size_on_disk=" << inode_info.sizes.size_on_disk
<< "\n";
<< std::endl;
}

if (g_debug > 8)
Expand Down
4 changes: 2 additions & 2 deletions ApfsLib/ApfsNodeMapperBTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ bool ApfsNodeMapperBTree::Init(uint64_t hdr_block_id, uint64_t version)
blk.resize(m_container.GetBlocksize());

if (!m_container.ReadAndVerifyHeaderBlock(blk.data(), hdr_block_id)) {
std::cerr << "ERROR: header block NOT verified\n";
std::cerr << "ERROR: header block NOT verified" << std::endl;
return false;
}

memcpy(&m_root_ptr, blk.data(), sizeof(APFS_Block_4_B_BTreeRootPtr));

if (m_root_ptr.hdr.type != 0x4000000B) {
std::cerr << "ERROR: wrong header type 0x" << std::hex
<< m_root_ptr.hdr.type << "\n";
<< m_root_ptr.hdr.type << std::endl;
return false;
}

Expand Down
30 changes: 14 additions & 16 deletions ApfsLib/ApfsVolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ bool ApfsVolume::Init(uint64_t blkid_volhdr)
if (m_sb.signature != 0x42535041)
return false;

if (!m_nodemap_dir.Init(m_sb.blockid_nodemap, m_sb.hdr.version)) {
std::cerr << "WARNING: m_nodemap_dir init failed\n";
}
if (!m_nodemap_dir.Init(m_sb.blockid_nodemap, m_sb.hdr.version))
std::cerr << "WARNING: m_nodemap_dir init failed" << std::endl;

if ((m_sb.flags_108 & 3) != 1)
{
Expand All @@ -75,7 +74,8 @@ bool ApfsVolume::Init(uint64_t blkid_volhdr)
std::cout << "Volume " << m_sb.vol_name << " is encrypted." << std::endl;

// Try self-service first
if (!m_container.GetVolumeKey(vek, m_sb.guid)) {
if (!m_container.GetVolumeKey(vek, m_sb.guid))
{
if (m_container.GetPasswordHint(str, m_sb.guid))
std::cout << "Hint: " << str << std::endl;

Expand All @@ -88,22 +88,20 @@ bool ApfsVolume::Init(uint64_t blkid_volhdr)
return false;
}
}
if (g_debug > 0) {
std::cerr << "Setting the VEK and m_is_encrypted\n";
}
if (g_debug > 0)
std::cerr << "Setting the VEK and m_is_encrypted" << std::endl;
m_aes.SetKey(vek, vek + 0x10);
m_is_encrypted = true;
}

if(!m_bt_directory.Init(m_sb.nodeid_rootdir, m_sb.hdr.version, &m_nodemap_dir)) {
std::cerr << "WARNING: m_bt_directory init failed\n";
}
if (!m_bt_blockmap.Init(m_sb.blockid_blockmap, m_sb.hdr.version)) {
std::cerr << "WARNING: m_bt_blockmap init failed\n";
}
if (!m_bt_snapshots.Init(m_sb.blockid_4xBx10_map, m_sb.hdr.version)) {
std::cerr << "WARNING: m_bt_snapshots init failed\n";
}
if (!m_bt_directory.Init(m_sb.nodeid_rootdir, m_sb.hdr.version, &m_nodemap_dir))
std::cerr << "WARNING: m_bt_directory init failed" << std::endl;

if (!m_bt_blockmap.Init(m_sb.blockid_blockmap, m_sb.hdr.version))
std::cerr << "WARNING: m_bt_blockmap init failed" << std::endl;

if (!m_bt_snapshots.Init(m_sb.blockid_4xBx10_map, m_sb.hdr.version))
std::cerr << "WARNING: m_bt_snapshots init failed" << std::endl;

return true;
}
Expand Down
26 changes: 14 additions & 12 deletions ApfsLib/BTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ bool BTree::Init(uint64_t root_node_id, uint64_t version, ApfsNodeMapper *node_m
memcpy(&m_treeinfo, m_root_node->block().data() + m_root_node->block().size() - sizeof(APFS_BTFooter), sizeof(APFS_BTFooter));
return true;
}
else {
std::cerr << "ERROR: could not find root_node_id " << root_node_id << "\n";
else
{
std::cerr << "ERROR: could not find root_node_id " << root_node_id << std::endl;
return false;
}
}
Expand Down Expand Up @@ -229,7 +230,7 @@ bool BTree::Lookup(BTreeEntry &result, const void *key, size_t key_size, BTCompa

if (!node)
{
std::cerr << "BTree::Lookup: Node " << nodeid << " with parent " << parentid << " not found.";
std::cerr << "BTree::Lookup: Node " << nodeid << " with parent " << parentid << " not found." << std::endl;
return false;
}
}
Expand Down Expand Up @@ -380,8 +381,9 @@ std::shared_ptr<BTreeNode> BTree::GetNode(uint64_t nodeid, uint64_t parentid)

if (m_nodeid_map)
{
if (!m_nodeid_map->GetBlockID(ni, nodeid, m_version)) {
std::cerr << "ERROR: m_nodeid_map available, but no such nodeid\n";
if (!m_nodeid_map->GetBlockID(ni, nodeid, m_version))
{
std::cerr << "ERROR: m_nodeid_map available, but no nodeid " << std::hex << nodeid << " with version " << m_version << std::endl;
return node;
}
}
Expand All @@ -391,22 +393,22 @@ std::shared_ptr<BTreeNode> BTree::GetNode(uint64_t nodeid, uint64_t parentid)
if (m_volume)
{
// TODO: is the crypto_id always equal to the block ID here?
if (!m_volume->ReadBlocks(blk.data(), ni.block_no, 1, (ni.flags & 4) != 0,
ni.block_no)) {
std::cerr << "ERROR: volume ReadBlocks failed\n";
if (!m_volume->ReadBlocks(blk.data(), ni.block_no, 1, (ni.flags & 4) != 0, ni.block_no))
{
std::cerr << "ERROR: volume ReadBlocks failed!" << std::endl;
return node;
}


if (!VerifyBlock(blk.data(), blk.size())) {
std::cerr << "ERROR: (volume) VerifyBlock failed\n";
if (!VerifyBlock(blk.data(), blk.size()))
{
std::cerr << "ERROR: (volume) VerifyBlock failed!" << std::endl;
return node;
}
}
else
{
if (!m_container.ReadAndVerifyHeaderBlock(blk.data(), ni.block_no)) {
std::cerr << "ERROR: ReadAndVerifyHeaderBlock failed\n";
std::cerr << "ERROR: ReadAndVerifyHeaderBlock failed!" << std::endl;
return node;
}
}
Expand Down
Loading

0 comments on commit 575dc11

Please sign in to comment.