2014-12-07 10:42:16 +01:00
|
|
|
#pragma once
|
2014-12-09 17:19:59 +01:00
|
|
|
#ifndef CRYFS_LIB_IMPL_DIRBLOCK_H_
|
|
|
|
#define CRYFS_LIB_IMPL_DIRBLOCK_H_
|
2014-12-07 10:42:16 +01:00
|
|
|
|
2014-12-09 17:19:59 +01:00
|
|
|
#include <blockstore/interface/Block.h>
|
2014-12-07 10:42:16 +01:00
|
|
|
#include "fspp/utils/macros.h"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace cryfs{
|
|
|
|
|
2014-12-09 17:19:59 +01:00
|
|
|
class DirBlock {
|
2014-12-07 10:42:16 +01:00
|
|
|
public:
|
2014-12-09 17:19:59 +01:00
|
|
|
DirBlock(std::unique_ptr<blockstore::Block> block);
|
|
|
|
virtual ~DirBlock();
|
2014-12-07 10:42:16 +01:00
|
|
|
|
|
|
|
void InitializeEmptyDir();
|
|
|
|
std::unique_ptr<std::vector<std::string>> GetChildren() const;
|
2014-12-09 17:19:59 +01:00
|
|
|
void AddChild(const std::string &name, const std::string &blockKey);
|
|
|
|
std::string GetBlockKeyForName(const std::string &name) const;
|
2014-12-07 10:42:16 +01:00
|
|
|
|
2014-12-09 17:19:59 +01:00
|
|
|
static bool IsDir(const blockstore::Block &block);
|
2014-12-09 11:13:50 +01:00
|
|
|
|
2014-12-07 10:42:16 +01:00
|
|
|
private:
|
2014-12-09 11:13:50 +01:00
|
|
|
unsigned char *magicNumber();
|
2014-12-09 17:19:59 +01:00
|
|
|
static const unsigned char *magicNumber(const blockstore::Block &block);
|
2014-12-07 10:42:16 +01:00
|
|
|
unsigned int *entryCounter();
|
|
|
|
const unsigned int *entryCounter() const;
|
|
|
|
char *entriesBegin();
|
|
|
|
const char *entriesBegin() const;
|
|
|
|
char *entriesEnd();
|
|
|
|
|
|
|
|
const char *readAndAddNextChild(const char *pos, std::vector<std::string> *result) const;
|
|
|
|
void assertEnoughSpaceLeft(char *insertPos, size_t insertSize) const;
|
|
|
|
|
2014-12-09 17:19:59 +01:00
|
|
|
std::unique_ptr<blockstore::Block> _block;
|
2014-12-07 10:42:16 +01:00
|
|
|
|
2014-12-09 17:19:59 +01:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(DirBlock);
|
2014-12-07 10:42:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|