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 <pulkomandy@pulkomandy.tk>
This commit is contained in:
Jérôme Duval 2022-09-11 23:29:19 +02:00 committed by waddlesplash
parent eac10866e2
commit 750afaef94
3 changed files with 39 additions and 10 deletions

View File

@ -103,8 +103,7 @@ BFSAddOn::CreatePartitionHandle(BMutablePartition* partition,
bool
BFSAddOn::CanInitialize(const BMutablePartition* partition)
{
// TODO: Check partition size.
return true;
return partition->Size() >= 1L * 1024 * 1024;
}
@ -130,6 +129,19 @@ BFSAddOn::ValidateInitialize(const BMutablePartition* partition, BString* name,
if (error != B_OK)
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;
}

View File

@ -59,6 +59,16 @@ InitializeBFSEditor::SetTo(BPartition* partition)
name = partition->ContentName();
if (!name.IsEmpty())
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");
BMessage* message = new BMessage(MSG_BLOCK_SIZE);
message->AddString("size", "1024");
blocksizeMenu->AddItem(new BMenuItem(
B_TRANSLATE("1024 (Mostly small files)"), message));
f1KBlockMenuItem = new BMenuItem(B_TRANSLATE("1024 (Mostly small files)"), message);
blocksizeMenu->AddItem(f1KBlockMenuItem);
message = new BMessage(MSG_BLOCK_SIZE);
message->AddString("size", "2048");
BMenuItem* defaultItem = new BMenuItem(B_TRANSLATE("2048 (Recommended)"),
f2KBlockMenuItem = new BMenuItem(B_TRANSLATE("2048 (Recommended)"),
message);
blocksizeMenu->AddItem(defaultItem);
blocksizeMenu->AddItem(f2KBlockMenuItem);
message = new BMessage(MSG_BLOCK_SIZE);
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->AddString("size", "8192");
blocksizeMenu->AddItem(new BMenuItem(
B_TRANSLATE("8192 (Mostly large files)"), message));
f8KBlockMenuItem = new BMenuItem(
B_TRANSLATE("8192 (Mostly large files)"), message);
blocksizeMenu->AddItem(f8KBlockMenuItem);
fBlockSizeMenuField = new BMenuField(B_TRANSLATE("Blocksize:"),
blocksizeMenu);
defaultItem->SetMarked(true);
fUseIndicesCheckBox = new BCheckBox(B_TRANSLATE("Enable query support"),
NULL);

View File

@ -14,6 +14,7 @@
class BCheckBox;
class BMenuField;
class BMenuItem;
class BTextControl;
class BView;
@ -41,6 +42,10 @@ private:
BTextControl* fNameControl;
BMenuField* fBlockSizeMenuField;
BCheckBox* fUseIndicesCheckBox;
BMenuItem* f1KBlockMenuItem;
BMenuItem* f2KBlockMenuItem;
BMenuItem* f4KBlockMenuItem;
BMenuItem* f8KBlockMenuItem;
};