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; FileSystem *fs = nullptr;
switch (type) { switch (type) {
case ox::fs::OxFS16: case ox::fs::OxFS_16:
fs = new FileSystem16(buff); fs = new FileSystem16(buff);
break; break;
case ox::fs::OxFS32: case ox::fs::OxFS_32:
fs = new FileSystem32(buff); fs = new FileSystem32(buff);
break; break;
case ox::fs::OxFS64: case ox::fs::OxFS_64:
fs = new FileSystem64(buff); fs = new FileSystem64(buff);
break; break;
} }
+3 -3
View File
@@ -16,9 +16,9 @@ namespace fs {
using namespace std; using namespace std;
enum FsType { enum FsType {
OxFS16 = 1, OxFS_16 = 1,
OxFS32 = 2, OxFS_32 = 2,
OxFS64 = 3 OxFS_64 = 3
}; };
struct FileStat { struct FileStat {
+18 -11
View File
@@ -50,13 +50,13 @@ int format(int argc, char **args) {
// format // format
switch (type) { switch (type) {
case 16: case 16:
FileStore16::format(buff, size, ox::fs::OxFS16); FileStore16::format(buff, size, ox::fs::OxFS_16);
break; break;
case 32: case 32:
FileStore32::format(buff, size, ox::fs::OxFS32); FileStore32::format(buff, size, ox::fs::OxFS_32);
break; break;
case 64: case 64:
FileStore64::format(buff, size, ox::fs::OxFS64); FileStore64::format(buff, size, ox::fs::OxFS_64);
break; break;
} }
createFileSystem(buff); createFileSystem(buff);
@@ -88,16 +88,23 @@ int read(int argc, char **args) {
::size_t fsSize; ::size_t fsSize;
ox::std::uint64_t fileSize; 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) { if (output) {
fwrite(output, fileSize, 1, stdout); fwrite(output, fileSize, 1, stdout);
err = 0; err = 0;
}
delete fs;
delete fsBuff;
} else {
fprintf(stderr, "Could not open file: %s\n", fsPath);
} }
delete fs;
} }
return err; return err;
} }
@@ -110,7 +117,7 @@ int write(int argc, char **args) {
auto srcPath = args[4]; auto srcPath = args[4];
::size_t srcSize; ::size_t srcSize;
auto fsFile = fopen(fsPath, "rwb"); auto fsFile = fopen(fsPath, "rb");
if (fsFile) { if (fsFile) {
fseek(fsFile, 0, SEEK_END); fseek(fsFile, 0, SEEK_END);