Add file type field to inodes

This commit is contained in:
2016-07-06 00:50:22 -05:00
parent e5e85a147c
commit 7c900eda10
2 changed files with 16 additions and 10 deletions
+7 -6
View File
@@ -22,17 +22,17 @@ class FileStore {
struct StatInfo { struct StatInfo {
InodeId_t inodeId; InodeId_t inodeId;
FsSize_t size; FsSize_t size;
ox::std::uint8_t fileType;
}; };
private: private:
struct Inode { struct Inode {
// the next Inode in memory // the next Inode in memory
FsSize_t prev, next; FsSize_t prev, next;
// The following variables should not be assumed to exist
FsSize_t dataLen; FsSize_t dataLen;
InodeId_t m_id; InodeId_t m_id;
ox::std::uint8_t refs; ox::std::uint8_t refs;
ox::std::uint8_t fileType;
FsSize_t left, right; FsSize_t left, right;
FsSize_t size(); FsSize_t size();
@@ -55,7 +55,7 @@ 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
*/ */
int write(void *data, FsSize_t dataLen); int write(void *data, FsSize_t dataLen, ox::std::uint8_t fileType = 0);
/** /**
* Writes the given data to a "file" with the given id. * Writes the given data to a "file" with the given id.
@@ -63,7 +63,7 @@ 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
*/ */
int write(InodeId_t id, void *data, FsSize_t dataLen); int write(InodeId_t id, void *data, FsSize_t dataLen, ox::std::uint8_t fileType = 0);
/** /**
* Removes the inode of the given ID. * Removes the inode of the given ID.
@@ -212,18 +212,19 @@ void *FileStore<FsSize_t>::Inode::data() {
// FileStore // FileStore
template<typename FsSize_t> template<typename FsSize_t>
int FileStore<FsSize_t>::write(void *data, FsSize_t dataLen) { int FileStore<FsSize_t>::write(void *data, FsSize_t dataLen, ox::std::uint8_t fileType) {
return 1; return 1;
} }
template<typename FsSize_t> template<typename FsSize_t>
int FileStore<FsSize_t>::write(InodeId_t id, void *data, FsSize_t dataLen) { int FileStore<FsSize_t>::write(InodeId_t id, void *data, FsSize_t dataLen, ox::std::uint8_t fileType) {
auto retval = 1; auto retval = 1;
const FsSize_t size = sizeof(Inode) + dataLen; const FsSize_t size = sizeof(Inode) + dataLen;
auto inode = (Inode*) alloc(size); auto inode = (Inode*) alloc(size);
if (inode) { if (inode) {
remove(id); remove(id);
inode->m_id = id; inode->m_id = id;
inode->fileType = fileType;
inode->setData(data, dataLen); inode->setData(data, dataLen);
auto root = ptr<Inode*>(m_rootInode); auto root = ptr<Inode*>(m_rootInode);
if (insert(root, inode) || root == inode) { if (insert(root, inode) || root == inode) {
+9 -4
View File
@@ -21,6 +21,11 @@ enum FsType {
OxFS_64 = 3 OxFS_64 = 3
}; };
enum FileType {
NormalFile = 1,
Directory = 2
};
struct FileStat { struct FileStat {
uint64_t inode; uint64_t inode;
uint64_t size; uint64_t size;
@@ -36,7 +41,7 @@ class FileSystem {
virtual int remove(ox::std::uint64_t inode) = 0; virtual int remove(ox::std::uint64_t inode) = 0;
virtual int write(ox::std::uint64_t inode, void *buffer, ox::std::uint64_t size) = 0; virtual int write(ox::std::uint64_t inode, void *buffer, ox::std::uint64_t size, ox::std::uint8_t fileType = NormalFile) = 0;
virtual FileStat stat(ox::std::uint64_t inode) = 0; virtual FileStat stat(ox::std::uint64_t inode) = 0;
}; };
@@ -89,7 +94,7 @@ class FileSystemTemplate: public FileSystem {
int remove(ox::std::uint64_t inode); int remove(ox::std::uint64_t inode);
int write(ox::std::uint64_t inode, void *buffer, ox::std::uint64_t size) override; int write(ox::std::uint64_t inode, void *buffer, ox::std::uint64_t size, ox::std::uint8_t fileType) override;
FileStat stat(const char *path); FileStat stat(const char *path);
@@ -156,8 +161,8 @@ int FileSystemTemplate<FileStore>::remove(ox::std::uint64_t inode) {
} }
template<typename FileStore> template<typename FileStore>
int FileSystemTemplate<FileStore>::write(ox::std::uint64_t inode, void *buffer, ox::std::uint64_t size) { int FileSystemTemplate<FileStore>::write(ox::std::uint64_t inode, void *buffer, ox::std::uint64_t size, ox::std::uint8_t fileType) {
return store->write(inode, buffer, size); return store->write(inode, buffer, size, fileType);
} }
template<typename FileStore> template<typename FileStore>