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(-)
@@ -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)
{
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);
}
@@ -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);
@@ -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 (_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());
bfs_inode* targetNode = (bfs_inode*)target.Block();
targetNode->inode_num = fVolume->ToBlockRun(targetBlock);
return B_OK;
}
@@ -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; }
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(); }