From 4368661f03c331391322659823f38d92ece893e7 Mon Sep 17 00:00:00 2001 From: hyche Date: Thu, 24 Aug 2017 02:02:17 +0700 Subject: [PATCH] BTRFS: Implement GetNewBlock() function that will find the logical address for allocating and convert it to physical block. Signed-off-by: Augustin Cavalier --- src/add-ons/kernel/file_systems/btrfs/Volume.cpp | 14 ++++++++++++++ src/add-ons/kernel/file_systems/btrfs/Volume.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/src/add-ons/kernel/file_systems/btrfs/Volume.cpp b/src/add-ons/kernel/file_systems/btrfs/Volume.cpp index ee2cf118cb..5a86ca2e22 100644 --- a/src/add-ons/kernel/file_systems/btrfs/Volume.cpp +++ b/src/add-ons/kernel/file_systems/btrfs/Volume.cpp @@ -534,6 +534,20 @@ Volume::FindBlock(off_t logical, off_t& physical) } +/* Wrapper function for allocating new block + */ +status_t +Volume::GetNewBlock(uint64& logical, fsblock_t& physical, uint64 start, + uint64 flags) +{ + status_t status = fExtentAllocator->AllocateTreeBlock(logical, start, flags); + if (status != B_OK) + return status; + + return FindBlock(logical, physical); +} + + // #pragma mark - Disk scanning and initialization diff --git a/src/add-ons/kernel/file_systems/btrfs/Volume.h b/src/add-ons/kernel/file_systems/btrfs/Volume.h index 4f9acf52cc..11b4debc3a 100644 --- a/src/add-ons/kernel/file_systems/btrfs/Volume.h +++ b/src/add-ons/kernel/file_systems/btrfs/Volume.h @@ -62,6 +62,9 @@ public: status_t FindBlock(off_t logical, fsblock_t& physical); status_t FindBlock(off_t logical, off_t& physical); + status_t GetNewBlock(uint64& logical, fsblock_t& physical, + uint64 start = (uint64)-1, + uint64 flags = BTRFS_BLOCKGROUP_FLAG_METADATA); private: mutex fLock;