Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CacheZone object are now shared_ptr. #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/CachedReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

//#define NO_CACHE

CachedReader::CachedReader(std::shared_ptr<Reader> reader, CacheZone* zone, const std::string& tag)
CachedReader::CachedReader(std::shared_ptr<Reader> reader, std::shared_ptr<CacheZone> zone, const std::string& tag)
: m_reader(reader), m_zone(zone), m_tag(tag)
{
}
Expand Down
4 changes: 2 additions & 2 deletions src/CachedReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
class CachedReader : public Reader
{
public:
CachedReader(std::shared_ptr<Reader> reader, CacheZone* zone, const std::string& tag);
CachedReader(std::shared_ptr<Reader> reader, std::shared_ptr<CacheZone> zone, const std::string& tag);

virtual int32_t read(void* buf, int32_t count, uint64_t offset) override;
virtual uint64_t length() override;
private:
void nonCachedRead(void* buf, int32_t count, uint64_t offset);
private:
std::shared_ptr<Reader> m_reader;
CacheZone* m_zone;
std::shared_ptr<CacheZone> m_zone;
const std::string m_tag;
};

Expand Down
6 changes: 3 additions & 3 deletions src/DMGDisk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "exceptions.h"

DMGDisk::DMGDisk(std::shared_ptr<Reader> reader)
: m_reader(reader), m_zone(40000)
: m_reader(reader), m_zone(std::make_shared<CacheZone>(40000))
{
uint64_t offset = m_reader->length();

Expand Down Expand Up @@ -244,11 +244,11 @@ std::shared_ptr<Reader> DMGDisk::readerForPartition(int index)
m_reader->length() - data_offset));

return std::shared_ptr<Reader>(
new CachedReader(std::shared_ptr<Reader>(new DMGPartition(r, table)), &m_zone, partName.str())
new CachedReader(std::shared_ptr<Reader>(new DMGPartition(r, table)), m_zone, partName.str())
);
} else {
return std::shared_ptr<Reader>(
new CachedReader(std::shared_ptr<Reader>(new DMGPartition(m_reader, table)), &m_zone, partName.str())
new CachedReader(std::shared_ptr<Reader>(new DMGPartition(m_reader, table)), m_zone, partName.str())
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/DMGDisk.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DMGDisk : public PartitionedDisk
std::vector<Partition> m_partitions;
UDIFResourceFile m_udif;
xmlDocPtr m_kolyXML;
CacheZone m_zone;
std::shared_ptr<CacheZone> m_zone;
};

#endif
Expand Down
2 changes: 1 addition & 1 deletion src/HFSAttributeBTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <unicode/unistr.h>
#include "unichar.h"
using icu::UnicodeString;
HFSAttributeBTree::HFSAttributeBTree(std::shared_ptr<HFSFork> fork, CacheZone* zone)
HFSAttributeBTree::HFSAttributeBTree(std::shared_ptr<HFSFork> fork, std::shared_ptr<CacheZone> zone)
: HFSBTree(fork, zone, "Attribute")
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/HFSAttributeBTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class HFSAttributeBTree : protected HFSBTree
{
public:
HFSAttributeBTree(std::shared_ptr<HFSFork> fork, CacheZone* zone);
HFSAttributeBTree(std::shared_ptr<HFSFork> fork, std::shared_ptr<CacheZone> zone);

typedef std::map<std::string, std::vector<uint8_t>> AttributeMap;

Expand Down
2 changes: 1 addition & 1 deletion src/HFSBTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "CacheZone.h"
#include "exceptions.h"

HFSBTree::HFSBTree(std::shared_ptr<HFSFork> fork, CacheZone* zone, const char* cacheTag)
HFSBTree::HFSBTree(std::shared_ptr<HFSFork> fork, std::shared_ptr<CacheZone> zone, const char* cacheTag)
: m_fork(fork)
{
BTNodeDescriptor desc0;
Expand Down
2 changes: 1 addition & 1 deletion src/HFSBTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class HFSBTree
{
public:
HFSBTree(std::shared_ptr<HFSFork> fork, CacheZone* zone, const char* cacheTag);
HFSBTree(std::shared_ptr<HFSFork> fork, std::shared_ptr<CacheZone> zone, const char* cacheTag);

struct Key
{
Expand Down
3 changes: 1 addition & 2 deletions src/HFSCatalogBTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static const int MAX_SYMLINKS = 50;

extern UConverter *g_utf16be;

HFSCatalogBTree::HFSCatalogBTree(std::shared_ptr<HFSFork> fork, HFSVolume* volume, CacheZone* zone)
HFSCatalogBTree::HFSCatalogBTree(std::shared_ptr<HFSFork> fork, HFSVolume* volume, std::shared_ptr<CacheZone> zone)
: HFSBTree(fork, zone, "Catalog"), m_volume(volume), m_hardLinkDirID(0)
{
HFSPlusCatalogFileOrFolder ff;
Expand Down Expand Up @@ -265,7 +265,6 @@ int HFSCatalogBTree::stat(std::string path, HFSPlusCatalogFileOrFolder* s)

return 0;
}
extern int mustbreak;

void HFSCatalogBTree::appendNameAndHFSPlusCatalogFileOrFolderFromLeafForParentId(std::shared_ptr<HFSBTreeNode> leafNodePtr, HFSCatalogNodeID cnid, std::map<std::string, std::shared_ptr<HFSPlusCatalogFileOrFolder>>& map)
{
Expand Down
2 changes: 1 addition & 1 deletion src/HFSCatalogBTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class HFSCatalogBTree : protected HFSBTree
{
public:
// using HFSBTree::HFSBTree;
HFSCatalogBTree(std::shared_ptr<HFSFork> fork, HFSVolume* volume, CacheZone* zone);
HFSCatalogBTree(std::shared_ptr<HFSFork> fork, HFSVolume* volume, std::shared_ptr<CacheZone> zone);

int listDirectory(const std::string& path, std::map<std::string, std::shared_ptr<HFSPlusCatalogFileOrFolder>>& contents);

Expand Down
2 changes: 1 addition & 1 deletion src/HFSExtentsOverflowBTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "exceptions.h"
#include <stdexcept>

HFSExtentsOverflowBTree::HFSExtentsOverflowBTree(std::shared_ptr<HFSFork> fork, CacheZone* zone)
HFSExtentsOverflowBTree::HFSExtentsOverflowBTree(std::shared_ptr<HFSFork> fork, std::shared_ptr<CacheZone> zone)
: HFSBTree(fork, zone, "ExtentsOverflow")
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/HFSExtentsOverflowBTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class HFSExtentsOverflowBTree : protected HFSBTree
{
public:
HFSExtentsOverflowBTree(std::shared_ptr<HFSFork> fork, CacheZone* zone);
HFSExtentsOverflowBTree(std::shared_ptr<HFSFork> fork, std::shared_ptr<CacheZone> zone);
void findExtentsForFile(HFSCatalogNodeID cnid, bool resourceFork, uint32_t startBlock, std::vector<HFSPlusExtentDescriptor>& extraExtents);
private:
static int cnidComparator(const Key* indexKey, const Key* desiredKey);
Expand Down
8 changes: 4 additions & 4 deletions src/HFSVolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

HFSVolume::HFSVolume(std::shared_ptr<Reader> reader)
: m_reader(reader), m_embeddedReader(nullptr), m_overflowExtents(nullptr), m_attributes(nullptr),
m_fileZone(6400), m_btreeZone(6400)
m_fileZone(std::make_shared<CacheZone>(6400)), m_btreeZone(std::make_shared<CacheZone>(6400))
{
static_assert(sizeof(HFSPlusVolumeHeader) >= sizeof(HFSMasterDirectoryBlock), "Bad read is about to happen");

Expand All @@ -27,12 +27,12 @@ HFSVolume::HFSVolume(std::shared_ptr<Reader> reader)
throw io_error("Invalid HFS+/HFSX signature");

std::shared_ptr<HFSFork> fork (new HFSFork(this, m_header.extentsFile));
m_overflowExtents = new HFSExtentsOverflowBTree(fork, &m_btreeZone);
m_overflowExtents = new HFSExtentsOverflowBTree(fork, m_btreeZone);

if (m_header.attributesFile.logicalSize != 0)
{
fork.reset(new HFSFork(this, m_header.attributesFile, kHFSAttributesFileID));
m_attributes = new HFSAttributeBTree(fork, &m_btreeZone);
m_attributes = new HFSAttributeBTree(fork, m_btreeZone);
}
}

Expand Down Expand Up @@ -93,7 +93,7 @@ void HFSVolume::usage(uint64_t& totalBytes, uint64_t& freeBytes) const
HFSCatalogBTree* HFSVolume::rootCatalogTree()
{
std::shared_ptr<HFSFork> fork (new HFSFork(this, m_header.catalogFile, kHFSCatalogFileID));
HFSCatalogBTree* btree = new HFSCatalogBTree(fork, this, &m_btreeZone);
HFSCatalogBTree* btree = new HFSCatalogBTree(fork, this, m_btreeZone);

return btree;
}
Expand Down
6 changes: 3 additions & 3 deletions src/HFSVolume.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class HFSVolume

static bool isHFSPlus(std::shared_ptr<Reader> reader);

inline CacheZone* getFileZone() { return &m_fileZone; }
inline CacheZone* getBtreeZone() { return &m_btreeZone; }
inline std::shared_ptr<CacheZone> getFileZone() { return m_fileZone; }
inline std::shared_ptr<CacheZone> getBtreeZone() { return m_btreeZone; }
private:
void processEmbeddedHFSPlus(HFSMasterDirectoryBlock* block);
private:
Expand All @@ -37,7 +37,7 @@ class HFSVolume
HFSExtentsOverflowBTree* m_overflowExtents;
HFSAttributeBTree* m_attributes;
HFSPlusVolumeHeader m_header;
CacheZone m_fileZone, m_btreeZone;
std::shared_ptr<CacheZone> m_fileZone, m_btreeZone;

friend class HFSBTree;
friend class HFSFork;
Expand Down