A dir stores a magic number
This commit is contained in:
parent
2d74935034
commit
9a97287a96
@ -5,6 +5,8 @@
|
||||
//TODO Remove and replace with exception hierarchy
|
||||
#include "fspp/fuse/FuseErrnoException.h"
|
||||
|
||||
#include "MagicNumbers.h"
|
||||
|
||||
using std::unique_ptr;
|
||||
using std::make_unique;
|
||||
using std::vector;
|
||||
@ -22,9 +24,22 @@ DirBlob::~DirBlob() {
|
||||
}
|
||||
|
||||
void DirBlob::InitializeEmptyDir() {
|
||||
*magicNumber() = MagicNumbers::DIR;
|
||||
*entryCounter() = 0;
|
||||
}
|
||||
|
||||
unsigned char *DirBlob::magicNumber() {
|
||||
return const_cast<unsigned char*>(magicNumber(const_cast<const Blob&>(*_blob)));
|
||||
}
|
||||
|
||||
const unsigned char *DirBlob::magicNumber(const blobstore::Blob &blob) {
|
||||
return (unsigned char*)blob.data();
|
||||
}
|
||||
|
||||
bool DirBlob::IsDir(const blobstore::Blob &blob) {
|
||||
return *magicNumber(blob) == MagicNumbers::DIR;
|
||||
}
|
||||
|
||||
unique_ptr<vector<string>> DirBlob::GetChildren() const {
|
||||
auto result = make_unique<vector<string>>();
|
||||
unsigned int entryCount = *entryCounter();
|
||||
@ -80,7 +95,7 @@ unsigned int *DirBlob::entryCounter() {
|
||||
}
|
||||
|
||||
const unsigned int *DirBlob::entryCounter() const {
|
||||
return (unsigned int*)(_blob->data());
|
||||
return (unsigned int*)((char*)_blob->data() + sizeof(unsigned char));
|
||||
}
|
||||
|
||||
char *DirBlob::entriesBegin() {
|
||||
@ -88,7 +103,7 @@ char *DirBlob::entriesBegin() {
|
||||
}
|
||||
|
||||
const char *DirBlob::entriesBegin() const {
|
||||
return (char *)(_blob->data())+sizeof(unsigned int);
|
||||
return (char *)(_blob->data())+sizeof(unsigned char) + sizeof(unsigned int);
|
||||
}
|
||||
|
||||
char *DirBlob::entriesEnd() {
|
||||
|
@ -20,7 +20,11 @@ public:
|
||||
void AddChild(const std::string &name, const std::string &blobKey);
|
||||
std::string GetBlobKeyForName(const std::string &name) const;
|
||||
|
||||
static bool IsDir(const blobstore::Blob &blob);
|
||||
|
||||
private:
|
||||
unsigned char *magicNumber();
|
||||
static const unsigned char *magicNumber(const blobstore::Blob &blob);
|
||||
unsigned int *entryCounter();
|
||||
const unsigned int *entryCounter() const;
|
||||
char *entriesBegin();
|
||||
|
16
src/cryfs_lib/impl/MagicNumbers.h
Normal file
16
src/cryfs_lib/impl/MagicNumbers.h
Normal file
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#ifndef CRYFS_LIB_IMPL_MAGICNUMBERS_H_
|
||||
#define CRYFS_LIB_IMPL_MAGICNUMBERS_H_
|
||||
|
||||
namespace cryfs {
|
||||
namespace MagicNumbers {
|
||||
|
||||
unsigned char DIR = 0x00;
|
||||
unsigned char FILE = 0x01;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user