Cleanup, Add error handling for reading non-existent file

This commit is contained in:
2016-07-03 16:50:36 -05:00
parent 19c2b9580a
commit 2b01136bb4
3 changed files with 24 additions and 17 deletions
+3 -3
View File
@@ -15,13 +15,13 @@ FileSystem *createFileSystem(void *buff) {
FileSystem *fs = nullptr;
switch (type) {
case ox::fs::OxFS16:
case ox::fs::OxFS_16:
fs = new FileSystem16(buff);
break;
case ox::fs::OxFS32:
case ox::fs::OxFS_32:
fs = new FileSystem32(buff);
break;
case ox::fs::OxFS64:
case ox::fs::OxFS_64:
fs = new FileSystem64(buff);
break;
}
+3 -3
View File
@@ -16,9 +16,9 @@ namespace fs {
using namespace std;
enum FsType {
OxFS16 = 1,
OxFS32 = 2,
OxFS64 = 3
OxFS_16 = 1,
OxFS_32 = 2,
OxFS_64 = 3
};
struct FileStat {
+18 -11
View File
@@ -50,13 +50,13 @@ int format(int argc, char **args) {
// format
switch (type) {
case 16:
FileStore16::format(buff, size, ox::fs::OxFS16);
FileStore16::format(buff, size, ox::fs::OxFS_16);
break;
case 32:
FileStore32::format(buff, size, ox::fs::OxFS32);
FileStore32::format(buff, size, ox::fs::OxFS_32);
break;
case 64:
FileStore64::format(buff, size, ox::fs::OxFS64);
FileStore64::format(buff, size, ox::fs::OxFS_64);
break;
}
createFileSystem(buff);
@@ -88,16 +88,23 @@ int read(int argc, char **args) {
::size_t fsSize;
ox::std::uint64_t fileSize;
auto fs = createFileSystem(loadFileBuff(fsPath, &fsSize));
auto fsBuff = loadFileBuff(fsPath, &fsSize);
if (fsBuff) {
auto fs = createFileSystem(fsBuff);
auto output = fs->read(inode, &fileSize);
auto output = fs->read(inode, &fileSize);
if (output) {
fwrite(output, fileSize, 1, stdout);
err = 0;
if (output) {
fwrite(output, fileSize, 1, stdout);
err = 0;
}
delete fs;
delete fsBuff;
} else {
fprintf(stderr, "Could not open file: %s\n", fsPath);
}
delete fs;
}
return err;
}
@@ -110,7 +117,7 @@ int write(int argc, char **args) {
auto srcPath = args[4];
::size_t srcSize;
auto fsFile = fopen(fsPath, "rwb");
auto fsFile = fopen(fsPath, "rb");
if (fsFile) {
fseek(fsFile, 0, SEEK_END);