Renamed RecordId to InodeId.
This commit is contained in:
+31
-11
@@ -21,9 +21,10 @@ class FileStore {
|
|||||||
struct FsHeader {
|
struct FsHeader {
|
||||||
uint32_t version;
|
uint32_t version;
|
||||||
FsSize_t rootDir = -1;
|
FsSize_t rootDir = -1;
|
||||||
|
bool insertLeft = false; // crude tree balancing mechanism
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef FsSize_t RecordId;
|
typedef uint16_t InodeId_t;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Inode {
|
struct Inode {
|
||||||
@@ -36,7 +37,7 @@ class FileStore {
|
|||||||
FsSize_t m_data;
|
FsSize_t m_data;
|
||||||
|
|
||||||
FsSize_t size();
|
FsSize_t size();
|
||||||
void setId(RecordId);
|
void setId(InodeId_t);
|
||||||
void setData(uint8_t *data, int size);
|
void setData(uint8_t *data, int size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -70,7 +71,15 @@ class FileStore {
|
|||||||
* @param data the contents of the file
|
* @param data the contents of the file
|
||||||
* @param dataLen the number of bytes data points to
|
* @param dataLen the number of bytes data points to
|
||||||
*/
|
*/
|
||||||
void write(RecordId id, void *data, FsSize_t dataLen);
|
void write(void *data, FsSize_t dataLen);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes the given data to a "file" with the given id.
|
||||||
|
* @param id the id of the file
|
||||||
|
* @param data the contents of the file
|
||||||
|
* @param dataLen the number of bytes data points to
|
||||||
|
*/
|
||||||
|
void write(InodeId_t id, void *data, FsSize_t dataLen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the "file" at the given id. You are responsible for freeing
|
* Reads the "file" at the given id. You are responsible for freeing
|
||||||
@@ -80,13 +89,19 @@ class FileStore {
|
|||||||
* @param size pointer to a value that will be assigned the size of data
|
* @param size pointer to a value that will be assigned the size of data
|
||||||
* @return 0 if read is a success
|
* @return 0 if read is a success
|
||||||
*/
|
*/
|
||||||
int read(RecordId id, void *data, FsSize_t *size);
|
int read(InodeId_t id, void *data, FsSize_t *size);
|
||||||
|
|
||||||
static uint8_t version();
|
static uint8_t version();
|
||||||
|
|
||||||
static uint8_t *format(uint8_t *buffer, size_t size, bool hasDirectories);
|
static uint8_t *format(uint8_t *buffer, size_t size, bool hasDirectories);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/**
|
||||||
|
* Gets the header section of the file system.
|
||||||
|
* @return the header section of the file system.
|
||||||
|
*/
|
||||||
|
FsHeader *getHeader();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the record at the given id.
|
* Gets the record at the given id.
|
||||||
* @param root the root node to start comparing on
|
* @param root the root node to start comparing on
|
||||||
@@ -94,7 +109,7 @@ class FileStore {
|
|||||||
* @param pathLen number of characters in pathLen
|
* @param pathLen number of characters in pathLen
|
||||||
* @return the requested Inode, if available
|
* @return the requested Inode, if available
|
||||||
*/
|
*/
|
||||||
Inode *getRecord(FileStore::Inode *root, RecordId id);
|
Inode *getRecord(FileStore::Inode *root, InodeId_t id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an address for a new Inode.
|
* Gets an address for a new Inode.
|
||||||
@@ -140,7 +155,7 @@ FsSize_t FileStore<FsSize_t>::Inode::size() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename FsSize_t>
|
template<typename FsSize_t>
|
||||||
void FileStore<FsSize_t>::Inode::setId(RecordId id) {
|
void FileStore<FsSize_t>::Inode::setId(InodeId_t id) {
|
||||||
this->m_id = id;
|
this->m_id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,19 +189,19 @@ FileStore<FsSize_t>::FileStore(uint8_t *begin, uint8_t *end, Error *error): m_ve
|
|||||||
template<typename FsSize_t>
|
template<typename FsSize_t>
|
||||||
void FileStore<FsSize_t>::init() {
|
void FileStore<FsSize_t>::init() {
|
||||||
memset(m_begin, 0, m_end - m_begin);
|
memset(m_begin, 0, m_end - m_begin);
|
||||||
m_version = version;
|
m_version = version();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename FsSize_t>
|
template<typename FsSize_t>
|
||||||
void FileStore<FsSize_t>::write(RecordId id, void *data, FsSize_t dataLen) {
|
void FileStore<FsSize_t>::write(InodeId_t id, void *data, FsSize_t dataLen) {
|
||||||
const FsSize_t size = offsetof(FileStore::Inode, m_id) + dataLen;
|
const FsSize_t size = offsetof(Inode, m_id) + dataLen;
|
||||||
auto rec = (Inode*) alloc(size);
|
auto rec = (Inode*) alloc(size);
|
||||||
rec->dataLen = dataLen;
|
rec->dataLen = dataLen;
|
||||||
insert(m_root, rec);
|
insert(m_root, rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename FsSize_t>
|
template<typename FsSize_t>
|
||||||
int FileStore<FsSize_t>::read(RecordId id, void *data, FsSize_t *size) {
|
int FileStore<FsSize_t>::read(InodeId_t id, void *data, FsSize_t *size) {
|
||||||
auto rec = getRecord(m_root, id);
|
auto rec = getRecord(m_root, id);
|
||||||
int retval = 1;
|
int retval = 1;
|
||||||
if (rec) {
|
if (rec) {
|
||||||
@@ -200,7 +215,12 @@ int FileStore<FsSize_t>::read(RecordId id, void *data, FsSize_t *size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename FsSize_t>
|
template<typename FsSize_t>
|
||||||
typename FileStore<FsSize_t>::Inode *FileStore<FsSize_t>::getRecord(FileStore::Inode *root, RecordId id) {
|
typename FileStore<FsSize_t>::FsHeader *FileStore<FsSize_t>::getHeader() {
|
||||||
|
return (FsHeader*) m_begin;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename FsSize_t>
|
||||||
|
typename FileStore<FsSize_t>::Inode *FileStore<FsSize_t>::getRecord(FileStore::Inode *root, InodeId_t id) {
|
||||||
auto cmp = root->m_id > id;
|
auto cmp = root->m_id > id;
|
||||||
FsSize_t recPt;
|
FsSize_t recPt;
|
||||||
if (cmp) {
|
if (cmp) {
|
||||||
|
|||||||
Reference in New Issue
Block a user