From ee8cf35f07e207a2c17ba3c7d350a252c33e9497 Mon Sep 17 00:00:00 2001 From: Kyle Ambroff-Kao Date: Mon, 6 Apr 2020 18:54:11 -0700 Subject: [PATCH] bfs: Return B_NAME_TOO_LONG from BPlusTree::Find This patch makes "UnitTester BNode" pass. Several tests which attempt to create or access a directory entry that exceeds the maximum length assume that B_NAME_TOO_LONG status will be returned, since that is what BeOS does. When constructing a BNode with a path like "/tmp/some really long filename larger than 256 characters...", the vfs eventually calls bfs_lookup() which calls BPlusTree::Find(). In the case of a really long entry, Find() returns B_BAD_VALUE. This patch just changes BPlusTree::Find to return the more specific error that matches BeOS. Additionally this patch fixes some assertions in NodeTest. BeOS seems to have been missing some error checking code in the initialization of BNode, specifically with BNode(Directory*, const char*) and the equivalent SetTo method. If you provide an empty string for the child entry name to either of those, B_OK will be returned. But either way you initialize the object, when you try to use it, like with BNode::GetAttrInfo(), you'll get B_BAD_VALUE. This just changes any assertions for this situation to expect B_ENTRY_NOT_FOUND, which is the actual initialization error Haiku sets. This and the change to bfs resolves many assertions the following storage tests: * TestCaller BFile::Init Test 1 * TestCaller BFile::Init Test 2 * TestCaller BNode::Init Test1 * TestCaller BNode::Init Test2 * TestCaller BSymLink::Init Test 1 * TestCaller BSymLink::Init Test 2 Change-Id: I8598352aa341ffcab9f7bc3e6740ae1cb3dbab8c Reviewed-on: https://review.haiku-os.org/c/haiku/+/2490 Reviewed-by: waddlesplash --- src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp | 7 ++++--- src/tests/kits/storage/NodeTest.cpp | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp b/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp index 47125d67e5..c64c07c3c4 100644 --- a/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp +++ b/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp @@ -2276,11 +2276,12 @@ BPlusTree::Replace(Transaction& transaction, const uint8* key, uint16 keyLength, status_t BPlusTree::Find(const uint8* key, uint16 keyLength, off_t* _value) { - if (keyLength < BPLUSTREE_MIN_KEY_LENGTH - || keyLength > BPLUSTREE_MAX_KEY_LENGTH - || key == NULL) + if (key == NULL || keyLength < BPLUSTREE_MIN_KEY_LENGTH) RETURN_ERROR(B_BAD_VALUE); + if (keyLength > BPLUSTREE_MAX_KEY_LENGTH) + RETURN_ERROR(B_NAME_TOO_LONG); + if (fAllowDuplicates) RETURN_ERROR(B_BAD_TYPE); diff --git a/src/tests/kits/storage/NodeTest.cpp b/src/tests/kits/storage/NodeTest.cpp index 193a128a2d..5dc8e22fef 100644 --- a/src/tests/kits/storage/NodeTest.cpp +++ b/src/tests/kits/storage/NodeTest.cpp @@ -383,7 +383,7 @@ NodeTest::InitTest1() BDirectory pathDir(dirSuperLink); CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK ); BNode node(&pathDir, ""); - CPPUNIT_ASSERT( node.InitCheck() == B_OK ); + CPPUNIT_ASSERT(node.InitCheck() == B_ENTRY_NOT_FOUND); } NextSubTest(); { @@ -564,8 +564,8 @@ NodeTest::InitTest2() // NextSubTest(); CPPUNIT_ASSERT( pathDir.SetTo(dirSuperLink) == B_OK ); - CPPUNIT_ASSERT( node.SetTo(&pathDir, "") == B_OK ); - CPPUNIT_ASSERT( node.InitCheck() == B_OK ); + CPPUNIT_ASSERT(node.SetTo(&pathDir, "") == B_ENTRY_NOT_FOUND); + CPPUNIT_ASSERT(node.InitCheck() == B_ENTRY_NOT_FOUND); // NextSubTest(); CPPUNIT_ASSERT( pathDir.SetTo(existingSuperFile) == B_OK );