haiku/headers/private/fs_shell/fssh_fs_cache.h
Axel Dörfler 5d0afa4e4e * cache_detach_sub_transaction() didn't really work: it did not put all needed
blocks into the new transaction, but it would set that transaction on all
  blocks of the old transaction, too. Also, it did not correctly update the
  num_blocks/sub_num_blocks fields of the old transaction. Even worse, it did
  return B_OK instead of the ID of the new transaction...
* get_writable_cached_block() did not correctly maintain the number of blocks
  in the sub transaction.
* write_cached_block() did not free the original_data of a block when it wrote
  it back as part of a previous transaction.
* Changed "cookie" for cache_next_block_in_transaction() to "long", so it will
  be 64 bits when needed.
* Improved the API for detaching sub transactions: you can now get the blocks
  of only the main (parent) transaction as well, added new
  cache_block_in_main_transaction() function.
* BFS now flushes the log when there is no space left for the current
  transaction.
* _WriteTransactionToLog() allocated a "vecs" array, but never freed it.
* _WriteTransactionToLog() now also supports detaching the current sub
  transaction if the whole thing is getting too large (it will now also panic
  if that doesn't work out).
* Removed a useless optimization: making the blocks available in the cache
  isn't really needed, as all blocks in a transaction are locked into the
  cache, anyway.
* Implemented Transaction::WriteBlocks().
* Minor cleanup, removed some dead code, fixed warnings in the fs_shell's
  block_cache when compiled with debug output on.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23610 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-01-18 17:07:18 +00:00

116 lines
4.3 KiB
C

/*
* Copyright 2004-2008, Haiku Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _FSSH_FS_CACHE_H
#define _FSSH_FS_CACHE_H
//! File System File and Block Caches
#include "fssh_fs_interface.h"
enum {
FSSH_TRANSACTION_WRITTEN,
FSSH_TRANSACTION_ABORTED,
FSSH_TRANSACTION_ENDED
};
typedef void (*fssh_transaction_notification_hook)(int32_t id, int32_t event,
void *data);
#ifdef __cplusplus
extern "C" {
#endif
/* transactions */
extern int32_t fssh_cache_start_transaction(void *_cache);
extern fssh_status_t fssh_cache_sync_transaction(void *_cache, int32_t id);
extern fssh_status_t fssh_cache_end_transaction(void *_cache, int32_t id,
fssh_transaction_notification_hook hook,
void *data);
extern fssh_status_t fssh_cache_abort_transaction(void *_cache, int32_t id);
extern int32_t fssh_cache_detach_sub_transaction(void *_cache,
int32_t id, fssh_transaction_notification_hook hook,
void *data);
extern fssh_status_t fssh_cache_abort_sub_transaction(void *_cache,
int32_t id);
extern fssh_status_t fssh_cache_start_sub_transaction(void *_cache,
int32_t id);
extern fssh_status_t fssh_cache_add_transaction_listener(void *_cache,
int32_t id, fssh_transaction_notification_hook hook,
void *data);
extern fssh_status_t fssh_cache_remove_transaction_listener(void *_cache,
int32_t id, fssh_transaction_notification_hook hook,
void *data);
extern fssh_status_t fssh_cache_next_block_in_transaction(void *_cache,
int32_t id, bool mainOnly, long *_cookie,
fssh_off_t *_blockNumber, void **_data,
void **_unchangedData);
extern int32_t fssh_cache_blocks_in_transaction(void *_cache,
int32_t id);
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);
/* block cache */
extern void fssh_block_cache_delete(void *_cache, bool allowWrites);
extern void * fssh_block_cache_create(int fd, fssh_off_t numBlocks,
fssh_size_t blockSize, bool readOnly);
extern fssh_status_t fssh_block_cache_sync(void *_cache);
extern fssh_status_t fssh_block_cache_sync_etc(void *_cache,
fssh_off_t blockNumber, fssh_size_t numBlocks);
extern fssh_status_t fssh_block_cache_make_writable(void *_cache,
fssh_off_t blockNumber, int32_t transaction);
extern void * fssh_block_cache_get_writable_etc(void *_cache,
fssh_off_t blockNumber, fssh_off_t base,
fssh_off_t length, int32_t transaction);
extern void * fssh_block_cache_get_writable(void *_cache,
fssh_off_t blockNumber, int32_t transaction);
extern void * fssh_block_cache_get_empty(void *_cache,
fssh_off_t blockNumber, int32_t transaction);
extern const void * fssh_block_cache_get_etc(void *_cache,
fssh_off_t blockNumber, fssh_off_t base,
fssh_off_t length);
extern const void * fssh_block_cache_get(void *_cache,
fssh_off_t blockNumber);
extern fssh_status_t fssh_block_cache_set_dirty(void *_cache,
fssh_off_t blockNumber, bool isDirty,
int32_t transaction);
extern void fssh_block_cache_put(void *_cache,
fssh_off_t blockNumber);
/* file cache */
extern void * fssh_file_cache_create(fssh_mount_id mountID,
fssh_vnode_id vnodeID, fssh_off_t size);
extern void fssh_file_cache_delete(void *_cacheRef);
extern fssh_status_t fssh_file_cache_set_size(void *_cacheRef,
fssh_off_t size);
extern fssh_status_t fssh_file_cache_sync(void *_cache);
extern fssh_status_t fssh_file_cache_read(void *_cacheRef, void *cookie,
fssh_off_t offset, void *bufferBase,
fssh_size_t *_size);
extern fssh_status_t fssh_file_cache_write(void *_cacheRef, void *cookie,
fssh_off_t offset, const void *buffer,
fssh_size_t *_size);
/* file map */
extern void * fssh_file_map_create(fssh_mount_id mountID,
fssh_vnode_id vnodeID, fssh_off_t size);
extern void fssh_file_map_delete(void *_map);
extern void fssh_file_map_set_size(void *_map, fssh_off_t size);
extern void fssh_file_map_invalidate(void *_map, fssh_off_t offset,
fssh_off_t size);
extern fssh_status_t fssh_file_map_translate(void *_map, fssh_off_t offset,
fssh_size_t size, struct fssh_file_io_vec *vecs,
fssh_size_t *_count);
#ifdef __cplusplus
}
#endif
#endif /* _FSSH_FS_CACHE_H */