Cleanup, Add error handling for reading non-existent file
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
@@ -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);
|
||||||
|
|
||||||
auto output = fs->read(inode, &fileSize);
|
if (fsBuff) {
|
||||||
|
auto fs = createFileSystem(fsBuff);
|
||||||
|
|
||||||
if (output) {
|
auto output = fs->read(inode, &fileSize);
|
||||||
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;
|
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);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user