Add some error handling to oxfstool format and fix a couple of memory leaks

This commit is contained in:
2016-07-09 11:33:47 -05:00
parent 1bca0c46a7
commit 10290faf49
+31 -20
View File
@@ -79,31 +79,42 @@ int format(int argc, char **args) {
printf("Size: %llu bytes\n", size); printf("Size: %llu bytes\n", size);
printf("Type: %d\n", type); printf("Type: %d\n", type);
// format if (size < sizeof(FileStore64)) {
switch (type) { err = 1;
case 16:
FileStore16::format(buff, size, ox::fs::OxFS_16);
break;
case 32:
FileStore32::format(buff, size, ox::fs::OxFS_32);
break;
case 64:
FileStore64::format(buff, size, ox::fs::OxFS_64);
break;
} }
createFileSystem(buff);
auto file = fopen(path, "wb"); if (err) {
if (file) { // format
fwrite(buff, size, 1, file); switch (type) {
err = fclose(file); case 16:
if (err) { FileStore16::format(buff, size, ox::fs::OxFS_16);
printf("Could not write to file: %s.\n", path); break;
case 32:
FileStore32::format(buff, size, ox::fs::OxFS_32);
break;
case 64:
FileStore64::format(buff, size, ox::fs::OxFS_64);
break;
default:
err = 1;
}
if (err) {
auto file = fopen(path, "wb");
if (file) {
err = fwrite(buff, size, 1, file);
err |= fclose(file);
if (err) {
printf("Could not write to file: %s.\n", path);
}
} else {
printf("Could not open file: %s.\n", path);
}
} }
} else {
printf("Could not open file: %s.\n", path);
} }
free(buff);
if (err == 0) { if (err == 0) {
printf("Created file system %s\n", path); printf("Created file system %s\n", path);
} }