diff --git a/headers/os/drivers/fs_cache.h b/headers/os/drivers/fs_cache.h index 9a71a5b5e1..8c8193c35d 100644 --- a/headers/os/drivers/fs_cache.h +++ b/headers/os/drivers/fs_cache.h @@ -53,6 +53,7 @@ extern status_t cache_next_block_in_transaction(void *cache, int32 id, extern int32 cache_blocks_in_transaction(void *cache, int32 id); extern int32 cache_blocks_in_main_transaction(void *cache, int32 id); extern int32 cache_blocks_in_sub_transaction(void *cache, int32 id); +extern bool cache_has_block_in_transaction(void* cache, int32 id, off_t blockNumber); /* block cache */ extern void block_cache_delete(void *cache, bool allowWrites); diff --git a/headers/private/fs_shell/fssh_api_wrapper.h b/headers/private/fs_shell/fssh_api_wrapper.h index 233f8b49f7..7c1e0b35a5 100644 --- a/headers/private/fs_shell/fssh_api_wrapper.h +++ b/headers/private/fs_shell/fssh_api_wrapper.h @@ -835,6 +835,7 @@ #define cache_blocks_in_transaction fssh_cache_blocks_in_transaction #define cache_blocks_in_main_transaction fssh_cache_blocks_in_main_transaction #define cache_blocks_in_sub_transaction fssh_cache_blocks_in_sub_transaction +#define cache_has_block_in_transaction fssh_cache_has_block_in_transaction /* block cache */ #define block_cache_delete fssh_block_cache_delete diff --git a/headers/private/fs_shell/fssh_fs_cache.h b/headers/private/fs_shell/fssh_fs_cache.h index 88cc9a392e..c27052c484 100644 --- a/headers/private/fs_shell/fssh_fs_cache.h +++ b/headers/private/fs_shell/fssh_fs_cache.h @@ -62,6 +62,8 @@ extern int32_t fssh_cache_blocks_in_main_transaction(void *_cache, int32_t id); extern int32_t fssh_cache_blocks_in_sub_transaction(void *_cache, int32_t id); +extern bool fssh_cache_has_block_in_transaction(void *_cache, + int32_t id, fssh_off_t blockNumber); /* block cache */ extern void fssh_block_cache_delete(void *_cache, bool allowWrites); diff --git a/src/system/kernel/cache/block_cache.cpp b/src/system/kernel/cache/block_cache.cpp index 9482bec2de..5d76a79d10 100644 --- a/src/system/kernel/cache/block_cache.cpp +++ b/src/system/kernel/cache/block_cache.cpp @@ -3301,6 +3301,21 @@ cache_blocks_in_sub_transaction(void* _cache, int32 id) } +/*! Check if block is in transaction +*/ +bool +cache_has_block_in_transaction(void* _cache, int32 id, off_t blockNumber) +{ + block_cache* cache = (block_cache*)_cache; + TransactionLocker locker(cache); + + cached_block* block = cache->hash->Lookup(blockNumber); + + return (block != NULL && block->transaction != NULL + && block->transaction->id == id); +} + + // #pragma mark - public block cache API diff --git a/src/tools/fs_shell/block_cache.cpp b/src/tools/fs_shell/block_cache.cpp index 461e0bc308..26132ec664 100644 --- a/src/tools/fs_shell/block_cache.cpp +++ b/src/tools/fs_shell/block_cache.cpp @@ -1462,6 +1462,20 @@ fssh_cache_blocks_in_sub_transaction(void* _cache, int32_t id) } +bool +fssh_cache_has_block_in_transaction(void* _cache, int32_t id, + fssh_off_t blockNumber) +{ + block_cache* cache = (block_cache*)_cache; + MutexLocker locker(&cache->lock); + + cached_block* block = (cached_block*)hash_lookup(cache->hash, &blockNumber); + + return (block != NULL && block->transaction != NULL + && block->transaction->id == id); +} + + // #pragma mark - public block cache API