⛏️ index : haiku.git

author Andreas Henriksson <sausageboy@gmail.com> 2012-06-08 13:18:42.0 +02:00:00
committer Adrien Destugues <pulkomandy@pulkomandy.tk> 2025-12-13 13:59:12.0 +00:00:00
commit
3329194a328f24962d19c76358398f8ecd677338 [patch]
tree
2203ab5a43b98a04c21e8a45306d66be4b42905d
parent
2ae816f515916344b7e6a0838dba3143b892c121
download
3329194a328f24962d19c76358398f8ecd677338.tar.gz

bfs: support functions for moving an inode

Change-Id: I94bebc87b4b6ce467867f5672ffff6c7633f74d6
Reviewed-on: https://review.haiku-os.org/c/haiku/+/924
Reviewed-by: Axel Dörfler <axeld@pinc-software.de>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>

Diff

 src/add-ons/kernel/file_systems/bfs/Index.cpp | 21 +++++++++++++++++++++
 src/add-ons/kernel/file_systems/bfs/Index.h   |  5 ++++-
 src/add-ons/kernel/file_systems/bfs/Inode.cpp | 27 +++++++++++++++++++++++++++
 src/add-ons/kernel/file_systems/bfs/Inode.h   | 11 +++++++----
 4 files changed, 56 insertions(+), 8 deletions(-)

diff --git a/src/add-ons/kernel/file_systems/bfs/Index.cpp b/src/add-ons/kernel/file_systems/bfs/Index.cpp
index d25cf3e..3fa4328 100644
--- a/src/add-ons/kernel/file_systems/bfs/Index.cpp
+++ b/src/add-ons/kernel/file_systems/bfs/Index.cpp
@@ -1,5 +1,5 @@
/*
 * Copyright 2001-2017, Axel Dörfler, axeld@pinc-software.de.
 * Copyright 2001-2025, Axel Dörfler, axeld@pinc-software.de.
 * This file may be used under the terms of the MIT License.
 */

@@ -396,5 +396,24 @@
		inode->UpdateOldLastModified();

	return status;
}


status_t
Index::UpdateNodeID(Transaction& transaction, const uint8* key, uint16 length,
	off_t oldInodeID, off_t newInodeID)
{
	// Remove node and insert it with the new id (we can't use BPlusTree::Replace(), as it
	// doesn't handle trees where duplicates are allowed)
	BPlusTree* tree = Node()->Tree();

	status_t status = tree->Remove(transaction, key, length, oldInodeID);
	if (status == B_ENTRY_NOT_FOUND)
		return B_OK;

	if (status != B_OK)
		return status;

	return tree->Insert(transaction, key, length, newInodeID);
}

diff --git a/src/add-ons/kernel/file_systems/bfs/Index.h b/src/add-ons/kernel/file_systems/bfs/Index.h
index 5e675f7..437c084 100644
--- a/src/add-ons/kernel/file_systems/bfs/Index.h
+++ b/src/add-ons/kernel/file_systems/bfs/Index.h
@@ -1,5 +1,5 @@
/*
 * Copyright 2001-2012, Axel Dörfler, axeld@pinc-software.de.
 * Copyright 2001-2025, Axel Dörfler, axeld@pinc-software.de.
 * This file may be used under the terms of the MIT License.
 */
#ifndef INDEX_H
@@ -53,6 +53,9 @@
								Inode* inode);
			status_t		UpdateLastModified(Transaction& transaction,
								Inode* inode, bigtime_t modified = -1);

			status_t		UpdateNodeID(Transaction& transaction, const uint8* key, uint16 length,
								off_t oldInodeID, off_t newInodeID);

private:
							Index(const Index& other);
diff --git a/src/add-ons/kernel/file_systems/bfs/Inode.cpp b/src/add-ons/kernel/file_systems/bfs/Inode.cpp
index 49833bb..45e426f 100644
--- a/src/add-ons/kernel/file_systems/bfs/Inode.cpp
+++ b/src/add-ons/kernel/file_systems/bfs/Inode.cpp
@@ -1,5 +1,5 @@
/*
 * Copyright 2001-2020, Axel Dörfler, axeld@pinc-software.de.
 * Copyright 2001-2025, Axel Dörfler, axeld@pinc-software.de.
 * This file may be used under the terms of the MIT License.
 */

@@ -2833,6 +2833,31 @@
	// if either _id or _inode is passed, we will keep the inode locked
	if (_id == NULL && _inode == NULL)
		put_vnode(volume->FSVolume(), inode->ID());

	return B_OK;
}


status_t
Inode::CopyBlockTo(Transaction& transaction, off_t targetBlock)
{
	CachedBlock target(fVolume);
	status_t status = target.SetToWritable(transaction, targetBlock, true);
	if (status != B_OK)
		RETURN_ERROR(status);

	CachedBlock source(fVolume);
	status = source.SetTo(fID);
	if (status != B_OK)
		return status;

	uint8* targetData = (uint8*)target.WritableBlock();
	const uint8* sourceData = source.Block();
	memcpy(targetData, sourceData, fVolume->BlockSize());

	// update inode ID in target block
	bfs_inode* targetNode = (bfs_inode*)target.Block();
	targetNode->inode_num = fVolume->ToBlockRun(targetBlock);

	return B_OK;
}
diff --git a/src/add-ons/kernel/file_systems/bfs/Inode.h b/src/add-ons/kernel/file_systems/bfs/Inode.h
index 077ced4..51e7f21 100644
--- a/src/add-ons/kernel/file_systems/bfs/Inode.h
+++ b/src/add-ons/kernel/file_systems/bfs/Inode.h
@@ -1,5 +1,5 @@
/*
 * Copyright 2001-2020, Axel Dörfler, axeld@pinc-software.de.
 * Copyright 2001-2025, Axel Dörfler, axeld@pinc-software.de.
 * This file may be used under the terms of the MIT License.
 */
#ifndef INODE_H
@@ -192,6 +192,9 @@
			void*				Map() const { return fMap; }
			void				SetMap(void* map) { fMap = map; }

			// resize support
			status_t			CopyBlockTo(Transaction& transaction, off_t targetBlock);

#if _KERNEL_MODE && KDEBUG

			void				AssertReadLocked()
									{ ASSERT_READ_LOCKED_RW_LOCK(&fLock); }
@@ -354,13 +357,11 @@
		return CachedBlock::SetTo(fVolume->VnodeToBlock(inode->ID()));
	}

	status_t SetToWritable(Transaction& transaction, const Inode* inode,
		bool empty = false)
	status_t SetToWritable(Transaction& transaction, const Inode* inode, bool empty = false)
	{
		Unset();
		fVolume = inode->GetVolume();
		return CachedBlock::SetToWritable(transaction,
			fVolume->VnodeToBlock(inode->ID()), empty);
		return CachedBlock::SetToWritable(transaction, fVolume->VnodeToBlock(inode->ID()), empty);
	}

	const bfs_inode* Node() const { return (const bfs_inode*)Block(); }