BTRFS: Implement RemoveEntries() for BTree that will remove consecutive items and its data.

Signed-off-by: Augustin Cavalier <waddlesplash@gmail.com>
This commit is contained in:
hyche 2017-08-29 02:10:11 +07:00 committed by Augustin Cavalier
parent 84bc447cae
commit 20185bb9c3
2 changed files with 40 additions and 0 deletions

View File

@ -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
{

View File

@ -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);