2 // lf_hfs_generic_buf.h
5 // Created by Yakov Ben Zaken on 22/03/2018.
8 #ifndef lf_hfs_generic_buf_h
9 #define lf_hfs_generic_buf_h
13 #define BUF_SKIP_NONLOCKED 0x01
14 #define BUF_SKIP_LOCKED 0x02
15 #define BUF_SCAN_CLEAN 0x04 /* scan the clean buffers */
16 #define BUF_SCAN_DIRTY 0x08 /* scan the dirty buffers */
17 #define BUF_NOTIFY_BUSY 0x10 /* notify the caller about the busy pages during the scan */
20 #define GEN_BUF_WRITE_LOCK 0x00001000 // When set, the buffer does not get written to media. It will be written as part of a journal transaction.
21 #define GEN_BUF_NON_CACHED 0x00002000 // If set, the buffer is not cached.
22 #define GEN_BUF_IS_UPTODATE 0x00004000 // Set if memory content is equal or newer than media content
23 #define GEN_BUF_PHY_BLOCK 0x00008000 // Indicates that the uBlockN field contains a physical block number
24 #define GEN_BUF_LITTLE_ENDIAN 0x00010000 // When set, the data in the buffer contains small-endian data and should not be written to media
26 typedef struct GenericBuffer
{
29 pthread_mutex_t sLock
; // Sync access to buffer arguments + data
30 pthread_t pLockingThread
; // Allows recursive lock by the same thread
31 uint32_t uLockCnt
; // Allows recursive lock by the same thread
32 pthread_t sOwnerThread
; // Current owner of buffer.
33 pthread_cond_t sOwnerCond
; // Clicked everytime a buffer owner is released.
34 uint32_t uUseCnt
; // Counts the number of buffer allocations
42 void (*pfFunc
)(struct GenericBuffer
*psBuf
, void *pvArg
); // A function to be called at the last minute before disk-write
43 void *pvCallbackArgs
; // pfFunc args
44 } GenericLFBuf
, *GenericLFBufPtr
;
47 uint32_t buf_cache_size
;
48 uint32_t max_buf_cache_size
;
49 uint32_t max_gen_buf_uncached
;
50 uint32_t gen_buf_uncached
;
51 uint32_t buf_cache_remove
;
52 uint32_t buf_cache_cleanup
;
54 uint64_t buf_total_allocated_size
;
57 extern CacheStats_S gCacheStat
;
60 GenericLFBufPtr
lf_hfs_generic_buf_allocate( vnode_t psVnode
, daddr64_t uBlockN
, uint32_t uBlockSize
, uint64_t uFlags
);
61 int lf_hfs_generic_buf_take_ownership(GenericLFBuf
*psBuf
, pthread_mutex_t
*pSem
);
62 int lf_hfs_generic_buf_take_ownership_retry(GenericLFBuf
*psBuf
);
63 int lf_hfs_generic_buf_validate_owner(GenericLFBuf
*psBuf
);
64 GenericLFBufPtr
lf_hfs_generic_buf_duplicate(GenericLFBufPtr pBuff
, uint32_t uExtraCacheFlags
);
65 errno_t
lf_hfs_generic_buf_read( GenericLFBufPtr psBuf
);
66 errno_t
lf_hfs_generic_buf_write( GenericLFBufPtr psBuf
);
67 void lf_hfs_generic_buf_invalidate( GenericLFBufPtr psBuf
);
68 void lf_hfs_generic_buf_release( GenericLFBufPtr psBuf
);
69 void lf_hfs_generic_buf_clear( GenericLFBufPtr psBuf
);
70 void lf_hfs_generic_buf_set_cache_flag(GenericLFBufPtr psBuf
, uint64_t uCacheFlags
);
71 void lf_hfs_generic_buf_clear_cache_flag(GenericLFBufPtr psBuf
, uint64_t uCacheFlags
);
72 void lf_hfs_generic_buf_override_owner(GenericLFBufPtr psBuf
);
73 void lf_hfs_generic_buf_lock(GenericLFBufPtr psBuf
);
74 void lf_hfs_generic_buf_unlock(GenericLFBufPtr psBuf
);
75 void lf_hfs_generic_buf_cache_init( void );
76 void lf_hfs_generic_buf_cache_deinit( void );
77 void lf_hfs_generic_buf_cache_clear_by_iFD( int iFD
);
78 void lf_hfs_generic_buf_cache_update( GenericLFBufPtr psBuf
);
79 void lf_hfs_generic_buf_cache_remove_vnode(vnode_t vp
);
80 void lf_hfs_generic_buf_cache_UnLockBufCache(void);
81 void lf_hfs_generic_buf_cache_LockBufCache(void);
83 typedef int (*IterateCallback
)(GenericLFBuf
*psBuff
, void *pvArgs
);
84 int lf_hfs_generic_buf_write_iterate(vnode_t psVnode
, IterateCallback pfCallback
, uint32_t uFlags
, void *pvArgs
);
87 #endif /* lf_hfs_generic_buf_h */