Add missing checks to oxfstool
This commit is contained in:
parent
16e0fddaca
commit
a2cf756f4a
80
deps/ox/src/ox/fs/oxfstool.cpp
vendored
80
deps/ox/src/ox/fs/oxfstool.cpp
vendored
@ -248,23 +248,23 @@ int compact(int argc, char **args) {
|
|||||||
|
|
||||||
if (fs) {
|
if (fs) {
|
||||||
fs->resize();
|
fs->resize();
|
||||||
|
|
||||||
|
// write back to file
|
||||||
|
auto fsFile = fopen(fsPath, "wb");
|
||||||
|
if (fsFile) {
|
||||||
|
err = fwrite(fsBuff, fs->size(), 1, fsFile) != 1;
|
||||||
|
err |= fclose(fsFile);
|
||||||
|
if (err) {
|
||||||
|
fprintf(stderr, "Could not write to file system file.\n");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete fs;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Invalid file system.\n");
|
fprintf(stderr, "Invalid file system.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// write back to file
|
|
||||||
auto fsFile = fopen(fsPath, "wb");
|
|
||||||
if (fsFile) {
|
|
||||||
err = fwrite(fsBuff, fs->size(), 1, fsFile) != 1;
|
|
||||||
err |= fclose(fsFile);
|
|
||||||
if (err) {
|
|
||||||
fprintf(stderr, "Could not write to file system file.\n");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
err = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete fs;
|
|
||||||
delete []fsBuff;
|
delete []fsBuff;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Could not open file: %s\n", fsPath);
|
fprintf(stderr, "Could not open file: %s\n", fsPath);
|
||||||
@ -321,34 +321,36 @@ int remove(int argc, char **args) {
|
|||||||
int walk(int argc, char **args) {
|
int walk(int argc, char **args) {
|
||||||
int err = 0;
|
int err = 0;
|
||||||
size_t fsSize;
|
size_t fsSize;
|
||||||
auto fsPath = args[2];
|
if (argc >= 2) {
|
||||||
auto fsBuff = loadFileBuff(fsPath, &fsSize);
|
auto fsPath = args[2];
|
||||||
if (fsBuff) {
|
auto fsBuff = loadFileBuff(fsPath, &fsSize);
|
||||||
auto fs = createFileSystem(fsBuff, fsSize);
|
if (fsBuff) {
|
||||||
if (fs) {
|
auto fs = createFileSystem(fsBuff, fsSize);
|
||||||
cout << setw(9) << "Type |";
|
if (fs) {
|
||||||
cout << setw(10) << "Start |";
|
cout << setw(9) << "Type |";
|
||||||
cout << setw(10) << "End |";
|
cout << setw(10) << "Start |";
|
||||||
cout << setw(8) << "Size";
|
cout << setw(10) << "End |";
|
||||||
cout << endl;
|
cout << setw(8) << "Size";
|
||||||
cout << "-------------------------------------";
|
|
||||||
cout << endl;
|
|
||||||
fs->walk([](const char *type, uint64_t start, uint64_t end) {
|
|
||||||
cout << setw(7) << type << " |";
|
|
||||||
cout << setw(8) << start << " |";
|
|
||||||
cout << setw(8) << end << " |";
|
|
||||||
cout << setw(8) << (end - start);
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
return 0;
|
cout << "-------------------------------------";
|
||||||
});
|
cout << endl;
|
||||||
delete fs;
|
fs->walk([](const char *type, uint64_t start, uint64_t end) {
|
||||||
|
cout << setw(7) << type << " |";
|
||||||
|
cout << setw(8) << start << " |";
|
||||||
|
cout << setw(8) << end << " |";
|
||||||
|
cout << setw(8) << (end - start);
|
||||||
|
cout << endl;
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
delete fs;
|
||||||
|
} else {
|
||||||
|
cerr << "Invalid file system.\n";
|
||||||
|
err = 1;
|
||||||
|
}
|
||||||
|
delete []fsBuff;
|
||||||
} else {
|
} else {
|
||||||
cerr << "Invalid file system.\n";
|
err = 2;
|
||||||
err = 1;
|
|
||||||
}
|
}
|
||||||
delete []fsBuff;
|
|
||||||
} else {
|
|
||||||
err = 2;
|
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user