Added file stat.
This commit is contained in:
@@ -27,6 +27,11 @@ class FileStore {
|
||||
|
||||
typedef uint16_t InodeId_t;
|
||||
|
||||
struct StatInfo {
|
||||
InodeId_t inodeId;
|
||||
FsSize_t size;
|
||||
};
|
||||
|
||||
private:
|
||||
struct Inode {
|
||||
// the next Inode in memory
|
||||
@@ -92,6 +97,14 @@ class FileStore {
|
||||
*/
|
||||
int read(InodeId_t id, void *data, FsSize_t *size);
|
||||
|
||||
/**
|
||||
* Reads the stat information of the inode of the given inode id.
|
||||
* If the returned inode id is 0, then the requested inode was not found.
|
||||
* @param id id of the inode to stat
|
||||
* @return the stat information of the inode of the given inode id
|
||||
*/
|
||||
StatInfo stat(InodeId_t id);
|
||||
|
||||
static uint8_t version();
|
||||
|
||||
static uint8_t *format(uint8_t *buffer, FsSize_t size);
|
||||
@@ -232,6 +245,19 @@ int FileStore<FsSize_t>::read(InodeId_t id, void *data, FsSize_t *size) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
template<typename FsSize_t>
|
||||
typename FileStore<FsSize_t>::StatInfo FileStore<FsSize_t>::stat(InodeId_t id) {
|
||||
auto inode = getRecord(m_root, id);
|
||||
StatInfo stat;
|
||||
if (inode) {
|
||||
stat.size = inode->dataLen;
|
||||
stat.inodeId = id;
|
||||
} else {
|
||||
stat.inodeId = 0;
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
template<typename FsSize_t>
|
||||
typename FileStore<FsSize_t>::FsHeader *FileStore<FsSize_t>::getHeader() {
|
||||
return (FsHeader*) m_begin;
|
||||
|
||||
@@ -16,13 +16,32 @@
|
||||
namespace wombat {
|
||||
namespace fs {
|
||||
|
||||
struct FileStat {
|
||||
uint64_t inode;
|
||||
uint64_t size;
|
||||
};
|
||||
|
||||
template<typename FileStore>
|
||||
class FileSystem {
|
||||
|
||||
private:
|
||||
FileStore *store = nullptr;
|
||||
|
||||
public:
|
||||
int read(const char *path, void *buffer);
|
||||
|
||||
FileStat stat(const char *path);
|
||||
};
|
||||
|
||||
template<typename FileStore>
|
||||
FileStat FileSystem<FileStore>::stat(const char *path) {
|
||||
FileStat stat;
|
||||
auto s = store->stat(path);
|
||||
stat.size = s.size;
|
||||
stat.inode = s.inodeId;
|
||||
return stat;
|
||||
}
|
||||
|
||||
typedef FileSystem<FileStore16> FileSystem16;
|
||||
typedef FileSystem<FileStore32> FileSystem32;
|
||||
typedef FileSystem<FileStore64> FileSystem64;
|
||||
|
||||
Reference in New Issue
Block a user