Add checks to ensure the file store is a supported version and move the
the InodeId_t type into Header's type parameter
This commit is contained in:
@@ -12,10 +12,11 @@
|
||||
namespace ox {
|
||||
namespace fs {
|
||||
|
||||
template<typename FsT>
|
||||
template<typename FsT, typename InodeId>
|
||||
struct FileStoreHeader {
|
||||
typedef InodeId InodeId_t;
|
||||
typedef FsT FsSize_t;
|
||||
const static auto VERSION = 2;
|
||||
const static auto VERSION = 4;
|
||||
|
||||
uint16_t version;
|
||||
uint16_t fsType;
|
||||
@@ -28,7 +29,7 @@ template<typename Header>
|
||||
class FileStore {
|
||||
|
||||
public:
|
||||
typedef uint16_t InodeId_t;
|
||||
typedef typename Header::InodeId_t InodeId_t;
|
||||
typedef typename Header::FsSize_t FsSize_t;
|
||||
const static auto VERSION = Header::VERSION;
|
||||
|
||||
@@ -597,9 +598,9 @@ uint8_t *FileStore<Header>::format(uint8_t *buffer, typename Header::FsSize_t si
|
||||
return (uint8_t*) buffer;
|
||||
}
|
||||
|
||||
typedef FileStore<FileStoreHeader<uint16_t>> FileStore16;
|
||||
typedef FileStore<FileStoreHeader<uint32_t>> FileStore32;
|
||||
typedef FileStore<FileStoreHeader<uint64_t>> FileStore64;
|
||||
typedef FileStore<FileStoreHeader<uint16_t, uint16_t>> FileStore16;
|
||||
typedef FileStore<FileStoreHeader<uint32_t, uint16_t>> FileStore32;
|
||||
typedef FileStore<FileStoreHeader<uint64_t, uint16_t>> FileStore64;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,19 +11,26 @@ namespace ox {
|
||||
namespace fs {
|
||||
|
||||
FileSystem *createFileSystem(void *buff) {
|
||||
auto version = ((FileStore16*) buff)->version();
|
||||
auto type = ((FileStore16*) buff)->fsType();
|
||||
FileSystem *fs = nullptr;
|
||||
|
||||
switch (type) {
|
||||
case ox::fs::OxFS_16:
|
||||
fs = new FileSystem16(buff);
|
||||
break;
|
||||
case ox::fs::OxFS_32:
|
||||
fs = new FileSystem32(buff);
|
||||
break;
|
||||
case ox::fs::OxFS_64:
|
||||
fs = new FileSystem64(buff);
|
||||
switch (version) {
|
||||
case 4:
|
||||
switch (type) {
|
||||
case ox::fs::OxFS_16:
|
||||
fs = new FileSystem16(buff);
|
||||
break;
|
||||
case ox::fs::OxFS_32:
|
||||
fs = new FileSystem32(buff);
|
||||
break;
|
||||
case ox::fs::OxFS_64:
|
||||
fs = new FileSystem64(buff);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return fs;
|
||||
|
||||
@@ -236,7 +236,7 @@ int write(int argc, char **args, bool expand) {
|
||||
free(srcBuff);
|
||||
} else {
|
||||
err = 1;
|
||||
fprintf(stderr, "Could not load source file.\n");
|
||||
fprintf(stderr, "Could not load source file: %s.\n", srcPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user