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 ox {
|
||||||
namespace fs {
|
namespace fs {
|
||||||
|
|
||||||
template<typename FsT>
|
template<typename FsT, typename InodeId>
|
||||||
struct FileStoreHeader {
|
struct FileStoreHeader {
|
||||||
|
typedef InodeId InodeId_t;
|
||||||
typedef FsT FsSize_t;
|
typedef FsT FsSize_t;
|
||||||
const static auto VERSION = 2;
|
const static auto VERSION = 4;
|
||||||
|
|
||||||
uint16_t version;
|
uint16_t version;
|
||||||
uint16_t fsType;
|
uint16_t fsType;
|
||||||
@@ -28,7 +29,7 @@ template<typename Header>
|
|||||||
class FileStore {
|
class FileStore {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef uint16_t InodeId_t;
|
typedef typename Header::InodeId_t InodeId_t;
|
||||||
typedef typename Header::FsSize_t FsSize_t;
|
typedef typename Header::FsSize_t FsSize_t;
|
||||||
const static auto VERSION = Header::VERSION;
|
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;
|
return (uint8_t*) buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef FileStore<FileStoreHeader<uint16_t>> FileStore16;
|
typedef FileStore<FileStoreHeader<uint16_t, uint16_t>> FileStore16;
|
||||||
typedef FileStore<FileStoreHeader<uint32_t>> FileStore32;
|
typedef FileStore<FileStoreHeader<uint32_t, uint16_t>> FileStore32;
|
||||||
typedef FileStore<FileStoreHeader<uint64_t>> FileStore64;
|
typedef FileStore<FileStoreHeader<uint64_t, uint16_t>> FileStore64;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,19 +11,26 @@ namespace ox {
|
|||||||
namespace fs {
|
namespace fs {
|
||||||
|
|
||||||
FileSystem *createFileSystem(void *buff) {
|
FileSystem *createFileSystem(void *buff) {
|
||||||
|
auto version = ((FileStore16*) buff)->version();
|
||||||
auto type = ((FileStore16*) buff)->fsType();
|
auto type = ((FileStore16*) buff)->fsType();
|
||||||
FileSystem *fs = nullptr;
|
FileSystem *fs = nullptr;
|
||||||
|
|
||||||
switch (type) {
|
switch (version) {
|
||||||
case ox::fs::OxFS_16:
|
case 4:
|
||||||
fs = new FileSystem16(buff);
|
switch (type) {
|
||||||
break;
|
case ox::fs::OxFS_16:
|
||||||
case ox::fs::OxFS_32:
|
fs = new FileSystem16(buff);
|
||||||
fs = new FileSystem32(buff);
|
break;
|
||||||
break;
|
case ox::fs::OxFS_32:
|
||||||
case ox::fs::OxFS_64:
|
fs = new FileSystem32(buff);
|
||||||
fs = new FileSystem64(buff);
|
break;
|
||||||
|
case ox::fs::OxFS_64:
|
||||||
|
fs = new FileSystem64(buff);
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fs;
|
return fs;
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ int write(int argc, char **args, bool expand) {
|
|||||||
free(srcBuff);
|
free(srcBuff);
|
||||||
} else {
|
} else {
|
||||||
err = 1;
|
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