Fix write-expand to factor in the space needed for the inode header
This commit is contained in:
+1
-1
@@ -15,7 +15,7 @@ endif()
|
|||||||
|
|
||||||
if(NOT MSVC)
|
if(NOT MSVC)
|
||||||
add_definitions(
|
add_definitions(
|
||||||
-std=c++11
|
-std=c++14
|
||||||
-Wall
|
-Wall
|
||||||
-nostdlib
|
-nostdlib
|
||||||
-fno-exceptions
|
-fno-exceptions
|
||||||
|
|||||||
@@ -94,6 +94,14 @@ class FileStore {
|
|||||||
*/
|
*/
|
||||||
StatInfo stat(InodeId_t id);
|
StatInfo stat(InodeId_t id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the space needed for this data at the given inode address.
|
||||||
|
* @param id the target inode id
|
||||||
|
* @param size the size of the data to insert
|
||||||
|
* @return the space currently available in this file store.
|
||||||
|
*/
|
||||||
|
FsSize_t spaceNeeded(InodeId_t id, FsSize_t size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the size of the file store.
|
* Returns the size of the file store.
|
||||||
* @return the size of the file store.
|
* @return the size of the file store.
|
||||||
@@ -396,6 +404,16 @@ typename FileStore<FsSize_t>::StatInfo FileStore<FsSize_t>::stat(InodeId_t id) {
|
|||||||
return stat;
|
return stat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename FsSize_t>
|
||||||
|
FsSize_t FileStore<FsSize_t>::spaceNeeded(InodeId_t id, FsSize_t size) {
|
||||||
|
FsSize_t needed = sizeof(Inode) + size;;
|
||||||
|
auto inode = getInode(ptr<Inode*>(m_rootInode), id);
|
||||||
|
if (inode) {
|
||||||
|
needed -= inode->size();
|
||||||
|
}
|
||||||
|
return needed;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename FsSize_t>
|
template<typename FsSize_t>
|
||||||
FsSize_t FileStore<FsSize_t>::size() {
|
FsSize_t FileStore<FsSize_t>::size() {
|
||||||
return m_size;
|
return m_size;
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ class FileSystem {
|
|||||||
|
|
||||||
virtual FileStat stat(uint64_t inode) = 0;
|
virtual FileStat stat(uint64_t inode) = 0;
|
||||||
|
|
||||||
|
virtual uint64_t spaceNeeded(uint64_t id, uint64_t size) = 0;
|
||||||
|
|
||||||
virtual uint64_t available() = 0;
|
virtual uint64_t available() = 0;
|
||||||
|
|
||||||
virtual uint64_t size() = 0;
|
virtual uint64_t size() = 0;
|
||||||
@@ -109,6 +111,8 @@ class FileSystemTemplate: public FileSystem {
|
|||||||
|
|
||||||
FileStat stat(uint64_t inode) override;
|
FileStat stat(uint64_t inode) override;
|
||||||
|
|
||||||
|
uint64_t spaceNeeded(uint64_t id, uint64_t size) override;
|
||||||
|
|
||||||
uint64_t available() override;
|
uint64_t available() override;
|
||||||
|
|
||||||
uint64_t size() override;
|
uint64_t size() override;
|
||||||
@@ -214,6 +218,11 @@ void FileSystemTemplate<FileStore, FS_TYPE>::resize(uint64_t size) {
|
|||||||
return store->resize(size);
|
return store->resize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename FileStore, FsType FS_TYPE>
|
||||||
|
uint64_t FileSystemTemplate<FileStore, FS_TYPE>::spaceNeeded(uint64_t id, uint64_t size) {
|
||||||
|
return store->spaceNeeded(id, size);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename FileStore, FsType FS_TYPE>
|
template<typename FileStore, FsType FS_TYPE>
|
||||||
uint64_t FileSystemTemplate<FileStore, FS_TYPE>::available() {
|
uint64_t FileSystemTemplate<FileStore, FS_TYPE>::available() {
|
||||||
return store->available();
|
return store->available();
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
using namespace ox::fs;
|
using namespace ox::fs;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
const static auto oxfstoolVersion = "1.1.0";
|
const static auto oxfstoolVersion = "1.1.1";
|
||||||
const static auto usage = "usage:\n"
|
const static auto usage = "usage:\n"
|
||||||
"\toxfs format [16,32,64] <size> <path>\n"
|
"\toxfs format [16,32,64] <size> <path>\n"
|
||||||
"\toxfs read <FS file> <inode>\n"
|
"\toxfs read <FS file> <inode>\n"
|
||||||
@@ -198,7 +198,7 @@ int write(int argc, char **args, bool expand) {
|
|||||||
auto fs = createFileSystem(fsBuff);
|
auto fs = createFileSystem(fsBuff);
|
||||||
if (fs) {
|
if (fs) {
|
||||||
if (expand && fs->available() <= srcSize) {
|
if (expand && fs->available() <= srcSize) {
|
||||||
auto needed = (fs->size() - fs->available()) + fsSize;
|
auto needed = fs->spaceNeeded(inode, srcSize);
|
||||||
auto cloneBuff = new uint8_t[needed];
|
auto cloneBuff = new uint8_t[needed];
|
||||||
ox_memcpy(cloneBuff, fsBuff, fsSize);
|
ox_memcpy(cloneBuff, fsBuff, fsSize);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user