X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/2530ab22f56855b2f137c65cf454311fc9824c77..069ee7886cc06b3db4a8d67f2a03a2f4e8d30fa6:/Cytore.hpp diff --git a/Cytore.hpp b/Cytore.hpp index cb6c4241..c0bad09b 100644 --- a/Cytore.hpp +++ b/Cytore.hpp @@ -50,7 +50,7 @@ struct Header { uint32_t version_; uint32_t size_; uint32_t reserved_; -}; +} _packed; template class Offset { @@ -80,11 +80,11 @@ class Offset { bool IsNull() const { return offset_ == 0; } -}; +} _packed; struct Block { Cytore::Offset reserved_; -}; +} _packed; template static _finline Type_ Round(Type_ value, Type_ size) { @@ -142,8 +142,11 @@ class File { bool Truncate_(size_t capacity) { capacity = Round(capacity, Block_); + int error(ftruncate(file_, capacity)); - _assert(error == 0); + if (error != 0) + return false; + Map_(capacity); return true; } @@ -175,7 +178,7 @@ class File { return blocks_.size() * Block_; } - void Open(const char *path) { + void Open(const char *path) { open: _assert(file_ == -1); file_ = open(path, O_RDWR | O_CREAT | O_EXLOCK, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); _assert(file_ != -1); @@ -187,11 +190,19 @@ class File { size_t size(stat.st_size); if (size == 0) { - _assert(Truncate_(core)); + if (!Truncate_(core)) { + unlink(path); + _assert(false); + } + Header_().magic_ = Magic; Size_() = core; + } else if (size < core) { + close(file_); + file_ = -1; + unlink(path); + goto open; } else { - _assert(size >= core); // XXX: this involves an unneccessary call to ftruncate() _assert(Truncate_(size)); _assert(Header_().magic_ == Magic);