From 20185bb9c399a31ba2b509807c41d77ff62a52aa Mon Sep 17 00:00:00 2001 From: hyche Date: Tue, 29 Aug 2017 02:10:11 +0700 Subject: [PATCH] BTRFS: Implement RemoveEntries() for BTree that will remove consecutive items and its data. Signed-off-by: Augustin Cavalier --- src/add-ons/kernel/file_systems/btrfs/BTree.cpp | 37 +++++++++++++++++++++++++ src/add-ons/kernel/file_systems/btrfs/BTree.h | 3 ++ 2 files changed, 40 insertions(+) diff --git a/src/add-ons/kernel/file_systems/btrfs/BTree.cpp b/src/add-ons/kernel/file_systems/btrfs/BTree.cpp index 46325a6858..e5f3797323 100644 --- a/src/add-ons/kernel/file_systems/btrfs/BTree.cpp +++ b/src/add-ons/kernel/file_systems/btrfs/BTree.cpp @@ -780,6 +780,43 @@ BTree::InsertEntries(Transaction& transaction, Path* path, } +/* Like MakeEntries, but here we remove entries instead. + * Removed data stored in _data + * May merge those functions into one. + */ +status_t +BTree::RemoveEntries(Transaction& transaction, Path* path, + const btrfs_key& startKey, void** _data, int num) +{ + TRACE("BTree::RemoveEntries() num %i key (% " B_PRIu64 " %" B_PRIu8 " %" + B_PRIu64 ")\n", num, startKey.ObjectID(), startKey.Type(), + startKey.Offset()); + + status_t status = Traverse(BTREE_EXACT, path, startKey); + if (status < B_OK) + return status; + + int slot = status; + int length = -sizeof(btrfs_entry) * num; + for (int i = 0; i < num; i++) { + uint32 itemSize; + path->GetEntry(slot + i, NULL, &_data[i], &itemSize); + length -= itemSize; + } + + status = path->InternalCopy(transaction, 1); + if (status != B_OK) + return status; + + status = path->CopyOnWrite(transaction, 0, slot, num, length); + if (status == B_DIRECTORY_NOT_EMPTY) { + // TODO: merge node or push data + } + + return status; +} + + status_t BTree::PreviousLeaf(Path* path) const { diff --git a/src/add-ons/kernel/file_systems/btrfs/BTree.h b/src/add-ons/kernel/file_systems/btrfs/BTree.h index 839681da4a..1da3561417 100644 --- a/src/add-ons/kernel/file_systems/btrfs/BTree.h +++ b/src/add-ons/kernel/file_systems/btrfs/BTree.h @@ -78,6 +78,9 @@ public: status_t InsertEntries(Transaction& transaction, Path* path, btrfs_entry* entries, void** data, int num); + status_t RemoveEntries(Transaction& transaction, + Path* path, const btrfs_key& startKey, + void** _data, int num); Volume* SystemVolume() const { return fVolume; } status_t SetRoot(off_t logical, fsblock_t* block); -- 2.11.4.GIT