bfs: disable some block sizes when the partition size is too small

these would otherwise trigger an assert when initializing.
fixes #6781

Change-Id: I4fa34455e7734f6a4039705527bf5ab09b46998d
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5659
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
Jérôme Duval
2022-09-13 18:48:25 +00:00
committed by waddlesplash
parent eac10866e2
commit 750afaef94
3 changed files with 39 additions and 10 deletions
+14 -2
View File
@@ -103,8 +103,7 @@ BFSAddOn::CreatePartitionHandle(BMutablePartition* partition,
bool bool
BFSAddOn::CanInitialize(const BMutablePartition* partition) BFSAddOn::CanInitialize(const BMutablePartition* partition)
{ {
// TODO: Check partition size. return partition->Size() >= 1L * 1024 * 1024;
return true;
} }
@@ -130,6 +129,19 @@ BFSAddOn::ValidateInitialize(const BMutablePartition* partition, BString* name,
if (error != B_OK) if (error != B_OK)
return error; return error;
off_t size = partition->Size();
uint32 blockSize = parameters.blockSize;
if (size < 2 * 1024 * 1024) {
if (blockSize != 1024)
return B_BAD_VALUE;
} else if (size < 4 * 1024 * 1024) {
if (blockSize >= 4 * 1024)
return B_BAD_VALUE;
} else if (size < 8 * 1024 * 1024) {
if (blockSize >= 8 * 1024)
return B_BAD_VALUE;
}
return B_OK; return B_OK;
} }
@@ -59,6 +59,16 @@ InitializeBFSEditor::SetTo(BPartition* partition)
name = partition->ContentName(); name = partition->ContentName();
if (!name.IsEmpty()) if (!name.IsEmpty())
fNameControl->SetText(name.String()); fNameControl->SetText(name.String());
off_t size = partition->Size();
if (size < 2 * 1024 * 1024) {
f1KBlockMenuItem->SetMarked(true);
f2KBlockMenuItem->SetEnabled(false);
} else {
f2KBlockMenuItem->SetEnabled(true);
f2KBlockMenuItem->SetMarked(true);
}
f4KBlockMenuItem->SetEnabled(size >= 4 * 1024 * 1024);
f8KBlockMenuItem->SetEnabled(size >= 8 * 1024 * 1024);
} }
@@ -117,24 +127,26 @@ InitializeBFSEditor::_CreateViewControls()
BPopUpMenu* blocksizeMenu = new BPopUpMenu("blocksize"); BPopUpMenu* blocksizeMenu = new BPopUpMenu("blocksize");
BMessage* message = new BMessage(MSG_BLOCK_SIZE); BMessage* message = new BMessage(MSG_BLOCK_SIZE);
message->AddString("size", "1024"); message->AddString("size", "1024");
blocksizeMenu->AddItem(new BMenuItem( f1KBlockMenuItem = new BMenuItem(B_TRANSLATE("1024 (Mostly small files)"), message);
B_TRANSLATE("1024 (Mostly small files)"), message)); blocksizeMenu->AddItem(f1KBlockMenuItem);
message = new BMessage(MSG_BLOCK_SIZE); message = new BMessage(MSG_BLOCK_SIZE);
message->AddString("size", "2048"); message->AddString("size", "2048");
BMenuItem* defaultItem = new BMenuItem(B_TRANSLATE("2048 (Recommended)"), f2KBlockMenuItem = new BMenuItem(B_TRANSLATE("2048 (Recommended)"),
message); message);
blocksizeMenu->AddItem(defaultItem); blocksizeMenu->AddItem(f2KBlockMenuItem);
message = new BMessage(MSG_BLOCK_SIZE); message = new BMessage(MSG_BLOCK_SIZE);
message->AddString("size", "4096"); message->AddString("size", "4096");
blocksizeMenu->AddItem(new BMenuItem("4096", message)); f4KBlockMenuItem = new BMenuItem("4096", message);
blocksizeMenu->AddItem(f4KBlockMenuItem);
message = new BMessage(MSG_BLOCK_SIZE); message = new BMessage(MSG_BLOCK_SIZE);
message->AddString("size", "8192"); message->AddString("size", "8192");
blocksizeMenu->AddItem(new BMenuItem( f8KBlockMenuItem = new BMenuItem(
B_TRANSLATE("8192 (Mostly large files)"), message)); B_TRANSLATE("8192 (Mostly large files)"), message);
blocksizeMenu->AddItem(f8KBlockMenuItem);
fBlockSizeMenuField = new BMenuField(B_TRANSLATE("Blocksize:"), fBlockSizeMenuField = new BMenuField(B_TRANSLATE("Blocksize:"),
blocksizeMenu); blocksizeMenu);
defaultItem->SetMarked(true);
fUseIndicesCheckBox = new BCheckBox(B_TRANSLATE("Enable query support"), fUseIndicesCheckBox = new BCheckBox(B_TRANSLATE("Enable query support"),
NULL); NULL);
@@ -14,6 +14,7 @@
class BCheckBox; class BCheckBox;
class BMenuField; class BMenuField;
class BMenuItem;
class BTextControl; class BTextControl;
class BView; class BView;
@@ -41,6 +42,10 @@ private:
BTextControl* fNameControl; BTextControl* fNameControl;
BMenuField* fBlockSizeMenuField; BMenuField* fBlockSizeMenuField;
BCheckBox* fUseIndicesCheckBox; BCheckBox* fUseIndicesCheckBox;
BMenuItem* f1KBlockMenuItem;
BMenuItem* f2KBlockMenuItem;
BMenuItem* f4KBlockMenuItem;
BMenuItem* f8KBlockMenuItem;
}; };