24 Commits

Author SHA1 Message Date
gary e976fd3fe6 Upgrade FileStore format verion due to addition of packed attribute 2017-04-18 17:24:41 -05:00
gary 9308b5e59c Merge branch 'release-0.1' 2017-04-18 17:22:04 -05:00
gary df1605d189 Merge branch 'master' of github.com:wombatant/ox 2017-04-18 17:20:36 -05:00
gary e3ff37c6c9 Make FileSystem constructor explicit 2017-04-18 17:20:13 -05:00
gary 6e690ee98d Add support for reading from FileStore by type 2017-04-18 17:18:08 -05:00
gary 9b7c68efc9 Merge branch 'master' of github.com:wombatant/ox into release-0.1 2017-04-18 05:05:28 -05:00
gary 58400b950b Add install directory GBA build setup 2017-04-18 05:00:43 -05:00
gary aa1b3d0a74 Add alignment attributes to FS structs 2017-04-18 00:52:31 -05:00
gary b7775d3d82 Fix override warning and fix buffer overflow check 2017-04-14 01:50:57 -05:00
gary bf110e5341 Add a bounded read option for the file system 2017-04-13 20:16:42 -05:00
gary 9183815634 Fix GBA build not to build libraries that use stdlib 2017-04-13 04:31:30 -05:00
gary c6e33e5285 Fix error handling for opening an invalid file system 2017-04-13 04:07:24 -05:00
gary 709cfbf750 Remove inode parameter from space needed 2017-04-13 03:49:54 -05:00
gary 5c02645036 Fix issues with clarg parsing bools 2017-04-13 03:39:40 -05:00
gary 75e4aaa3b4 Make clargs use std::string 2017-04-13 03:19:53 -05:00
gary f2384e93c7 Merge branch 'release-0.0' 2017-04-13 02:22:17 -05:00
gary 7fdf5751b1 Add expandCopy and expandCopyCleanup 2017-04-13 02:12:26 -05:00
gary 0402fac389 Add string and in options to ClArgs 2017-04-12 23:52:21 -05:00
gary 17f09ab84a Merge branch 'release-0.0' 2017-04-12 22:14:00 -05:00
gary 9328113fcd Fix library paths in OxConfig.cmake 2017-04-12 22:03:56 -05:00
gary 4fde40ece9 Remove ox::std namespace 2017-04-12 21:28:59 -05:00
gary 5e80cc80b8 Add size check to createFileSystem 2017-04-12 21:26:23 -05:00
gary 9f3b338fed Add ClArgs library 2017-04-12 00:20:17 -05:00
gary 0052cccc14 Fix OxConfig.cmake to work with GBA builds again 2017-04-11 22:41:23 -05:00
12 changed files with 321 additions and 66 deletions
+3 -1
View File
@@ -7,9 +7,11 @@ include(address_sanitizer)
set(OX_BUILD_EXEC "ON" CACHE STRING "Build executables (ON/OFF)") set(OX_BUILD_EXEC "ON" CACHE STRING "Build executables (ON/OFF)")
set(OX_RUN_TESTS "ON" CACHE STRING "Run tests (ON/OFF)") set(OX_RUN_TESTS "ON" CACHE STRING "Run tests (ON/OFF)")
set(OX_USE_STDLIB "ON" CACHE STRING "Build libraries that need the std lib (ON/OFF)")
# can't run tests without building them # can't run tests without building them
if(OX_BUILD_EXEC STREQUAL "OFF") if(OX_BUILD_EXEC STREQUAL "OFF" OR OX_USE_STDLIB STREQUAL "OFF")
set(OX_BUILD_EXEC "OFF")
set(OX_RUN_TESTS "OFF") set(OX_RUN_TESTS "OFF")
endif() endif()
+9 -7
View File
@@ -1,9 +1,11 @@
if(${CMAKE_FIND_ROOT_PATH}) if("${CMAKE_FIND_ROOT_PATH}" STREQUAL "")
set(Ox_INCLUDE_DIRS ${CMAKE_FIND_ROOT_PATH}/include/)
set(OxStd_LIBRARY ${CMAKE_FIND_ROOT_PATH}/lib/ox/libOxStd.a)
set(OxFs_LIBRARY ${CMAKE_FIND_ROOT_PATH}/lib/ox/libOxFs.a)
else(${CMAKE_FIND_ROOT_PATH})
set(Ox_INCLUDE_DIRS /usr/local/include/) set(Ox_INCLUDE_DIRS /usr/local/include/)
set(OxStd_LIBRARY /usr/local/lib/ox/libOxStd.a) set(OxStd_LIBRARY /usr/local/lib/ox/libOxStd.a)
set(OxFs_LIBRARY /usr/local/lib/ox/libOxFs.a) set(OxFS_LIBRARY /usr/local/lib/ox/libOxFS.a)
endif(${CMAKE_FIND_ROOT_PATH}) set(OxClArgs_LIBRARY /usr/local/lib/ox/libOxClArgs.a)
else("${CMAKE_FIND_ROOT_PATH}" STREQUAL "")
set(Ox_INCLUDE_DIRS ${CMAKE_FIND_ROOT_PATH}/include/)
set(OxStd_LIBRARY ${CMAKE_FIND_ROOT_PATH}/lib/ox/libOxStd.a)
set(OxFS_LIBRARY ${CMAKE_FIND_ROOT_PATH}/lib/ox/libOxFS.a)
set(OxClArgs_LIBRARY ${CMAKE_FIND_ROOT_PATH}/lib/ox/libOxClArgs.a)
endif("${CMAKE_FIND_ROOT_PATH}" STREQUAL "")
+1 -1
View File
@@ -10,7 +10,7 @@ BUILD_TYPE=$2
if [[ $TARGET == windows ]]; then if [[ $TARGET == windows ]]; then
toolchain="-DCMAKE_TOOLCHAIN_FILE=cmake/Modules/Mingw.cmake" toolchain="-DCMAKE_TOOLCHAIN_FILE=cmake/Modules/Mingw.cmake"
elif [[ $TARGET == gba ]]; then elif [[ $TARGET == gba ]]; then
toolchain="-DCMAKE_TOOLCHAIN_FILE=cmake/Modules/GBA.cmake -DOX_BUILD_EXEC=OFF" toolchain="-DCMAKE_TOOLCHAIN_FILE=cmake/Modules/GBA.cmake -DOX_USE_STDLIB=OFF -DCMAKE_INSTALL_PREFIX=$DEVKITARM"
fi fi
if [[ $BUILD_TYPE == debug ]]; then if [[ $BUILD_TYPE == debug ]]; then
+3
View File
@@ -1,4 +1,7 @@
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
if(OX_USE_STDLIB STREQUAL "ON")
add_subdirectory(clargs)
endif(OX_USE_STDLIB STREQUAL "ON")
add_subdirectory(fs) add_subdirectory(fs)
add_subdirectory(std) add_subdirectory(std)
+20
View File
@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 2.8)
add_library(
OxClArgs
clargs.cpp
)
install(
FILES
clargs.hpp
DESTINATION
include/ox/clargs
)
install(
TARGETS
OxClArgs
LIBRARY DESTINATION lib/ox
ARCHIVE DESTINATION lib/ox
)
+55
View File
@@ -0,0 +1,55 @@
/*
* Copyright 2015 - 2017 gtalent2@gmail.com
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <ox/std/strops.hpp>
#include "clargs.hpp"
namespace ox {
namespace clargs {
using namespace ::std;
ClArgs::ClArgs(int argc, const char **args) {
for (int i = 0; i < argc; i++) {
string arg = args[i];
if (arg[0] == '-') {
while (arg[0] == '-' && arg.size()) {
arg = arg.substr(1);
}
m_bools[arg] = true;
// parse additional arguments
if (i < argc && args[i + 1]) {
string val = args[i + 1];
if (val.size() && val[i] != '-') {
if (val == "false") {
m_bools[arg] = false;
}
m_strings[arg] = val;
m_ints[arg] = ox_atoi(val.c_str());
i++;
}
}
}
}
}
bool ClArgs::getBool(const char *arg) {
return m_bools[arg];
}
string ClArgs::getString(const char *arg) {
return m_strings[arg];
}
int ClArgs::getInt(const char *arg) {
return m_ints[arg];
}
}
}
+34
View File
@@ -0,0 +1,34 @@
/*
* Copyright 2015 - 2017 gtalent2@gmail.com
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <map>
#include <string>
namespace ox {
namespace clargs {
class ClArgs {
private:
::std::map<::std::string, bool> m_bools;
::std::map<::std::string, ::std::string> m_strings;
::std::map<::std::string, int> m_ints;
public:
ClArgs(int argc, const char **args);
bool getBool(const char *arg);
::std::string getString(const char *arg);
int getInt(const char *arg);
};
}
}
+92 -19
View File
@@ -13,11 +13,11 @@ namespace ox {
namespace fs { namespace fs {
template<typename FsT, typename InodeId> template<typename FsT, typename InodeId>
struct FileStoreHeader { struct __attribute__((packed)) FileStoreHeader {
public: public:
typedef InodeId InodeId_t; typedef InodeId InodeId_t;
typedef FsT FsSize_t; typedef FsT FsSize_t;
const static auto VERSION = 4; const static auto VERSION = 5;
private: private:
uint16_t m_version; uint16_t m_version;
@@ -103,20 +103,22 @@ class FileStore {
struct StatInfo { struct StatInfo {
InodeId_t inodeId; InodeId_t inodeId;
typename Header::FsSize_t size; typename Header::FsSize_t size;
uint8_t fileType; uint8_t fileType;
}; };
private: private:
struct Inode { struct __attribute__((packed)) Inode {
private: private:
// the next Inode in memory // the next Inode in memory
typename Header::FsSize_t m_prev, m_next; typename Header::FsSize_t m_prev;
typename Header::FsSize_t m_next;
typename Header::FsSize_t m_dataLen; typename Header::FsSize_t m_dataLen;
InodeId_t m_id; InodeId_t m_id;
uint8_t m_fileType; uint8_t m_fileType;
typename Header::FsSize_t m_left, m_right; typename Header::FsSize_t m_left;
typename Header::FsSize_t m_right;
public: public:
typename Header::FsSize_t size(); typename Header::FsSize_t size();
@@ -143,7 +145,7 @@ class FileStore {
typename Header::FsSize_t getRight(); typename Header::FsSize_t getRight();
void setData(void *data, typename Header::FsSize_t size); void setData(void *data, typename Header::FsSize_t size);
void *getData(); uint8_t *getData();
}; };
Header m_header; Header m_header;
@@ -186,6 +188,35 @@ class FileStore {
*/ */
int read(InodeId_t id, void *data, typename Header::FsSize_t *size); int read(InodeId_t id, void *data, typename Header::FsSize_t *size);
/**
* Reads the "file" at the given id. You are responsible for freeing
* the data when done with it.
* @param id id of the "file"
* @param readStart where in the data to start reading
* @param readSize how much data to read
* @param data pointer to the pointer where the data is stored
* @param size pointer to a value that will be assigned the size of data
* @return 0 if read is a success
*/
int read(InodeId_t id, typename Header::FsSize_t readStart,
typename Header::FsSize_t readSize, void *data,
typename Header::FsSize_t *size);
/**
* Reads the "file" at the given id. You are responsible for freeing
* the data when done with it.
* @param id id of the "file"
* @param readStart where in the data to start reading
* @param readSize how much data to read
* @param data pointer to the pointer where the data is stored
* @param size pointer to a value that will be assigned the size of data
* @return 0 if read is a success
*/
template<typename T>
int read(InodeId_t id, typename Header::FsSize_t readStart,
typename Header::FsSize_t readSize, T *data,
typename Header::FsSize_t *size);
/** /**
* Reads the stat information of the inode of the given inode id. * 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. * If the returned inode id is 0, then the requested inode was not found.
@@ -200,7 +231,7 @@ class FileStore {
* @param size the size of the data to insert * @param size the size of the data to insert
* @return the space currently available in this file store. * @return the space currently available in this file store.
*/ */
typename Header::FsSize_t spaceNeeded(InodeId_t id, typename Header::FsSize_t size); typename Header::FsSize_t spaceNeeded(typename Header::FsSize_t size);
/** /**
* Returns the size of the file store. * Returns the size of the file store.
@@ -240,6 +271,21 @@ class FileStore {
*/ */
Inode *getInodeParent(Inode *root, InodeId_t id, typename Header::FsSize_t targetAddr); Inode *getInodeParent(Inode *root, InodeId_t id, typename Header::FsSize_t targetAddr);
/**
* Reads the "file" at the given id. You are responsible for freeing
* the data when done with it.
* @param inode inode of the "file"
* @param readStart where in the data to start reading
* @param readSize how much data to read
* @param data pointer to the pointer where the data is stored
* @param size pointer to a value that will be assigned the size of data
* @return 0 if read is a success
*/
template<typename T>
int read(Inode *inode, typename Header::FsSize_t readStart,
typename Header::FsSize_t readSize, T *data,
typename Header::FsSize_t *size);
/** /**
* Removes the inode of the given ID. * Removes the inode of the given ID.
* @param id the id of the file * @param id the id of the file
@@ -391,8 +437,8 @@ void FileStore<Header>::Inode::setData(void *data, typename Header::FsSize_t siz
template<typename Header> template<typename Header>
void *FileStore<Header>::Inode::getData() { uint8_t *FileStore<Header>::Inode::getData() {
return this + 1; return (uint8_t*) (this + 1);
} }
@@ -538,15 +584,42 @@ void FileStore<Header>::updateInodeAddress(InodeId_t id, typename Header::FsSize
template<typename Header> template<typename Header>
int FileStore<Header>::read(InodeId_t id, void *data, typename Header::FsSize_t *size) { int FileStore<Header>::read(InodeId_t id, void *data, typename Header::FsSize_t *size) {
auto inode = getInode(ptr<Inode*>(m_header.getRootInode()), id); auto inode = getInode(ptr<Inode*>(m_header.getRootInode()), id);
int retval = 1; return inode ? read(inode, 0, inode->getDataLen(), (uint8_t*) data, size) : 1;
if (inode) { }
if (size) {
*size = inode->getDataLen(); template<typename Header>
} int FileStore<Header>::read(InodeId_t id, typename Header::FsSize_t readStart,
ox_memcpy(data, inode->getData(), inode->getDataLen()); typename Header::FsSize_t readSize, void *data, typename Header::FsSize_t *size) {
retval = 0; auto inode = getInode(ptr<Inode*>(m_header.getRootInode()), id);
return inode ? read<uint8_t>(inode, readStart, readSize, (uint8_t*) data, size) : 1;
}
template<typename Header>
template<typename T>
int FileStore<Header>::read(InodeId_t id, typename Header::FsSize_t readStart,
typename Header::FsSize_t readSize, T *data, typename Header::FsSize_t *size) {
auto inode = getInode(ptr<Inode*>(m_header.getRootInode()), id);
return inode ? read(inode, readStart, readSize, data, size) : 1;
}
template<typename Header>
template<typename T>
int FileStore<Header>::read(Inode *inode, typename Header::FsSize_t readStart,
typename Header::FsSize_t readSize, T *data, typename Header::FsSize_t *size) {
// be sure read size is not greater than what is available to read
if (inode->getDataLen() - readStart < readSize) {
readSize = inode->getDataLen() - readStart;
} }
return retval; if (size) {
*size = readSize;
}
readSize /= sizeof(T);
T *it = (T*) &(inode->getData()[readStart]);
for (typename Header::FsSize_t i = 0; i < readSize; i++) {
*(data++) = *(it++);
}
return 0;
} }
template<typename Header> template<typename Header>
@@ -564,7 +637,7 @@ typename FileStore<Header>::StatInfo FileStore<Header>::stat(InodeId_t id) {
} }
template<typename Header> template<typename Header>
typename Header::FsSize_t FileStore<Header>::spaceNeeded(InodeId_t id, typename Header::FsSize_t size) { typename Header::FsSize_t FileStore<Header>::spaceNeeded(typename Header::FsSize_t size) {
return sizeof(Inode) + size; return sizeof(Inode) + size;
} }
+35 -1
View File
@@ -10,7 +10,7 @@
namespace ox { namespace ox {
namespace fs { namespace fs {
FileSystem *createFileSystem(void *buff) { FileSystem *createFileSystem(void *buff, size_t buffSize) {
auto version = ((FileStore16*) buff)->version(); auto version = ((FileStore16*) buff)->version();
auto type = ((FileStore16*) buff)->fsType(); auto type = ((FileStore16*) buff)->fsType();
FileSystem *fs = nullptr; FileSystem *fs = nullptr;
@@ -33,8 +33,42 @@ FileSystem *createFileSystem(void *buff) {
break; break;
} }
if (fs && fs->size() > buffSize) {
delete fs;
fs = nullptr;
}
return fs; return fs;
} }
FileSystem *expandCopy(FileSystem *fs, size_t size) {
auto fsBuff = fs->buff();
FileSystem *retval = nullptr;
if (fs->size() <= size) {
auto cloneBuff = new uint8_t[size];
ox_memcpy(cloneBuff, fsBuff, fs->size());
fsBuff = cloneBuff;
retval = createFileSystem(fsBuff, size);
retval->resize(size);
}
return retval;
}
FileSystem *expandCopyCleanup(FileSystem *fs, size_t size) {
auto out = expandCopy(fs, size);
if (out) {
delete[] fs->buff();
delete fs;
} else {
out = fs;
}
return out;
}
} }
} }
+55 -14
View File
@@ -36,6 +36,8 @@ class FileSystem {
virtual int read(uint64_t inode, void *buffer, size_t size) = 0; virtual int read(uint64_t inode, void *buffer, size_t size) = 0;
virtual int read(uint64_t inode, size_t readStart, size_t readSize, void *buffer, size_t *size) = 0;
virtual uint8_t *read(uint64_t inode, size_t *size) = 0; virtual uint8_t *read(uint64_t inode, size_t *size) = 0;
virtual int remove(uint64_t inode) = 0; virtual int remove(uint64_t inode) = 0;
@@ -46,14 +48,27 @@ 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 spaceNeeded(uint64_t size) = 0;
virtual uint64_t available() = 0; virtual uint64_t available() = 0;
virtual uint64_t size() = 0; virtual uint64_t size() = 0;
virtual uint8_t *buff() = 0;
}; };
FileSystem *createFileSystem(void *buff); FileSystem *createFileSystem(void *buff, size_t buffSize);
/**
* Creates a larger version of the given FileSystem.
*/
FileSystem *expandCopy(FileSystem *src);
/**
* Calls expandCopy and deletes the original FileSystem and buff a resize was
* performed.
*/
FileSystem *expandCopyCleanup(FileSystem *fs, size_t size);
template<typename FileStore, FsType FS_TYPE> template<typename FileStore, FsType FS_TYPE>
class FileSystemTemplate: public FileSystem { class FileSystemTemplate: public FileSystem {
@@ -91,15 +106,17 @@ class FileSystemTemplate: public FileSystem {
FileStore *store = nullptr; FileStore *store = nullptr;
public: public:
FileSystemTemplate(void *buff); explicit FileSystemTemplate(void *buff);
int mkdir(const char *path); int mkdir(const char *path);
int read(const char *path, void *buffer); int read(const char *path, void *buffer);
uint8_t *read(uint64_t inode, size_t *size) override; int read(uint64_t inode, void *buffer, size_t buffSize) override;
int read(uint64_t inode, void *buffer, size_t size) override; int read(uint64_t inode, size_t readStart, size_t readSize, void *buffer, size_t *size) override;
uint8_t *read(uint64_t inode, size_t *size) override;
void resize(uint64_t size = 0) override; void resize(uint64_t size = 0) override;
@@ -111,12 +128,14 @@ 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 spaceNeeded(uint64_t size) override;
uint64_t available() override; uint64_t available() override;
uint64_t size() override; uint64_t size() override;
uint8_t *buff() override;
static uint8_t *format(void *buffer, typename FileStore::FsSize_t size, bool useDirectories); static uint8_t *format(void *buffer, typename FileStore::FsSize_t size, bool useDirectories);
}; };
@@ -159,18 +178,35 @@ FileStat FileSystemTemplate<FileStore, FS_TYPE>::stat(uint64_t inode) {
#pragma warning(disable:4244) #pragma warning(disable:4244)
#endif #endif
template<typename FileStore, FsType FS_TYPE> template<typename FileStore, FsType FS_TYPE>
int FileSystemTemplate<FileStore, FS_TYPE>::read(uint64_t inode, void *buffer, size_t size) { int FileSystemTemplate<FileStore, FS_TYPE>::read(uint64_t inode, void *buffer, size_t buffSize) {
auto err = 1; auto stat = store->stat(inode);
auto s = store->stat(inode); if (stat.size <= buffSize) {
if (size == s.size) { return store->read(inode, buffer, nullptr);
err = store->read(inode, buffer, nullptr);
} }
return err; return 0;
;
} }
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(default:4244) #pragma warning(default:4244)
#endif #endif
#ifdef _MSC_VER
#pragma warning(disable:4244)
#endif
template<typename FileStore, FsType FS_TYPE>
int FileSystemTemplate<FileStore, FS_TYPE>::read(uint64_t inode, size_t readStart,
size_t readSize, void *buffer,
size_t *size) {
if (size) {
auto stat = store->stat(inode);
*size = stat.size;
}
return store->read(inode, readStart, readSize, buffer, nullptr);
}
#ifdef _MSC_VER
#pragma warning(disable:4244)
#endif
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(disable:4244) #pragma warning(disable:4244)
#endif #endif
@@ -219,8 +255,8 @@ void FileSystemTemplate<FileStore, FS_TYPE>::resize(uint64_t size) {
} }
template<typename FileStore, FsType FS_TYPE> template<typename FileStore, FsType FS_TYPE>
uint64_t FileSystemTemplate<FileStore, FS_TYPE>::spaceNeeded(uint64_t id, uint64_t size) { uint64_t FileSystemTemplate<FileStore, FS_TYPE>::spaceNeeded(uint64_t size) {
return store->spaceNeeded(id, size); return store->spaceNeeded(size);
} }
template<typename FileStore, FsType FS_TYPE> template<typename FileStore, FsType FS_TYPE>
@@ -233,6 +269,11 @@ uint64_t FileSystemTemplate<FileStore, FS_TYPE>::size() {
return store->size(); return store->size();
} }
template<typename FileStore, FsType FS_TYPE>
uint8_t *FileSystemTemplate<FileStore, FS_TYPE>::buff() {
return (uint8_t*) store;
}
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(disable:4244) #pragma warning(disable:4244)
#endif #endif
+14 -21
View File
@@ -35,7 +35,7 @@ char *loadFileBuff(FILE *file, ::size_t *sizeOut = nullptr) {
fseek(file, 0, SEEK_END); fseek(file, 0, SEEK_END);
const auto size = ftell(file); const auto size = ftell(file);
rewind(file); rewind(file);
auto buff = (char*) malloc(size); auto buff = new char[size];
auto itemsRead = fread(buff, size, 1, file); auto itemsRead = fread(buff, size, 1, file);
fclose(file); fclose(file);
if (sizeOut) { if (sizeOut) {
@@ -87,7 +87,7 @@ int format(int argc, char **args) {
auto type = ox_atoi(args[2]); auto type = ox_atoi(args[2]);
auto size = bytes(args[3]); auto size = bytes(args[3]);
auto path = args[4]; auto path = args[4];
auto buff = (uint8_t*) malloc(size); auto buff = new uint8_t[size];
if (size < sizeof(FileStore64)) { if (size < sizeof(FileStore64)) {
@@ -125,7 +125,7 @@ int format(int argc, char **args) {
} }
} }
free(buff); delete []buff;
if (err == 0) { if (err == 0) {
fprintf(stderr, "Created file system %s\n", path); fprintf(stderr, "Created file system %s\n", path);
@@ -148,7 +148,7 @@ int read(int argc, char **args) {
auto fsBuff = loadFileBuff(fsPath, &fsSize); auto fsBuff = loadFileBuff(fsPath, &fsSize);
if (fsBuff) { if (fsBuff) {
auto fs = createFileSystem(fsBuff); auto fs = createFileSystem(fsBuff, fsSize);
if (fs) { if (fs) {
auto output = fs->read(inode, &fileSize); auto output = fs->read(inode, &fileSize);
@@ -160,7 +160,7 @@ int read(int argc, char **args) {
} }
delete fs; delete fs;
free(fsBuff); delete []fsBuff;
} else { } else {
fprintf(stderr, "Invalid file system type: %d.\n", *(uint32_t*) fsBuff); fprintf(stderr, "Invalid file system type: %d.\n", *(uint32_t*) fsBuff);
} }
@@ -195,20 +195,13 @@ int write(int argc, char **args, bool expand) {
auto srcBuff = loadFileBuff(srcPath, &srcSize); auto srcBuff = loadFileBuff(srcPath, &srcSize);
if (srcBuff) { if (srcBuff) {
auto expanded = false; auto expanded = false;
auto fs = createFileSystem(fsBuff); auto fs = createFileSystem(fsBuff, fsSize);
if (fs) { if (fs) {
if (expand && fs->available() <= srcSize) { if (expand && fs->available() <= srcSize) {
auto needed = fs->size() + fs->spaceNeeded(inode, srcSize); auto needed = fs->size() + fs->spaceNeeded(srcSize);
auto cloneBuff = new uint8_t[needed];
ox_memcpy(cloneBuff, fsBuff, fsSize);
delete fs;
delete []fsBuff;
fsBuff = cloneBuff;
fs = createFileSystem(fsBuff);
fsSize = needed; fsSize = needed;
fs->resize(fsSize); fs = expandCopyCleanup(fs, needed);
fsBuff = fs->buff();
} }
err |= fs->write(inode, srcBuff, srcSize); err |= fs->write(inode, srcBuff, srcSize);
@@ -239,7 +232,7 @@ int write(int argc, char **args, bool expand) {
err = 1; err = 1;
} }
} }
free(srcBuff); delete []srcBuff;
} else { } else {
err = 1; err = 1;
fprintf(stderr, "Could not load source file: %s.\n", srcPath); fprintf(stderr, "Could not load source file: %s.\n", srcPath);
@@ -264,7 +257,7 @@ int compact(int argc, char **args) {
auto fsBuff = loadFileBuff(fsPath, &fsSize); auto fsBuff = loadFileBuff(fsPath, &fsSize);
if (fsBuff) { if (fsBuff) {
auto fs = createFileSystem(fsBuff); auto fs = createFileSystem(fsBuff, fsSize);
if (fs) { if (fs) {
fs->resize(); fs->resize();
@@ -285,7 +278,7 @@ int compact(int argc, char **args) {
} }
delete fs; delete fs;
free(fsBuff); delete []fsBuff;
} else { } else {
fprintf(stderr, "Could not open file: %s\n", fsPath); fprintf(stderr, "Could not open file: %s\n", fsPath);
} }
@@ -304,7 +297,7 @@ int remove(int argc, char **args) {
auto fsBuff = loadFileBuff(fsPath, &fsSize); auto fsBuff = loadFileBuff(fsPath, &fsSize);
if (fsBuff) { if (fsBuff) {
auto fs = createFileSystem(fsBuff); auto fs = createFileSystem(fsBuff, fsSize);
if (fs) { if (fs) {
err = fs->remove(inode); err = fs->remove(inode);
@@ -328,7 +321,7 @@ int remove(int argc, char **args) {
} }
delete fs; delete fs;
free(fsBuff); delete []fsBuff;
} else { } else {
fprintf(stderr, "Could not open file: %s\n", fsPath); fprintf(stderr, "Could not open file: %s\n", fsPath);
} }
-2
View File
@@ -23,11 +23,9 @@ typedef unsigned long uint64_t;
#endif #endif
namespace ox { namespace ox {
namespace std {
typedef uint32_t Error; typedef uint32_t Error;
}
} }
#if defined(_LP64) || defined(__ppc64__) || defined(__aarch64__) #if defined(_LP64) || defined(__ppc64__) || defined(__aarch64__)