Rev 3536 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 3536 | Rev 3597 | ||
|---|---|---|---|
| Line 42... | Line 42... | ||
| 42 | #include <futex.h> |
42 | #include <futex.h> |
| 43 | #include <rwlock.h> |
43 | #include <rwlock.h> |
| 44 | #include <libadt/hash_table.h> |
44 | #include <libadt/hash_table.h> |
| 45 | #include <libadt/list.h> |
45 | #include <libadt/list.h> |
| 46 | 46 | ||
| - | 47 | /* |
|
| - | 48 | * Flags that can be used with block_get(). |
|
| - | 49 | */ |
|
| - | 50 | ||
| - | 51 | /** |
|
| - | 52 | * This macro is a symbolic value for situations where no special flags are |
|
| - | 53 | * needed. |
|
| - | 54 | */ |
|
| - | 55 | #define BLOCK_FLAGS_NONE 0 |
|
| - | 56 | ||
| - | 57 | /** |
|
| - | 58 | * When the client of block_get() intends to overwrite the current contents of |
|
| - | 59 | * the block, this flag is used to avoid the unnecessary read. |
|
| - | 60 | */ |
|
| - | 61 | #define BLOCK_FLAGS_NOREAD 1 |
|
| - | 62 | ||
| - | 63 | typedef unsigned bn_t; /**< Block number type. */ |
|
| - | 64 | ||
| 47 | typedef struct block { |
65 | typedef struct block { |
| 48 | /** Futex protecting the reference count. */ |
66 | /** Futex protecting the reference count. */ |
| 49 | futex_t lock; |
67 | futex_t lock; |
| 50 | /** Number of references to the block_t structure. */ |
68 | /** Number of references to the block_t structure. */ |
| 51 | unsigned refcnt; |
69 | unsigned refcnt; |
| Line 54... | Line 72... | ||
| 54 | /** Readers / Writer lock protecting the contents of the block. */ |
72 | /** Readers / Writer lock protecting the contents of the block. */ |
| 55 | rwlock_t contents_lock; |
73 | rwlock_t contents_lock; |
| 56 | /** Handle of the device where the block resides. */ |
74 | /** Handle of the device where the block resides. */ |
| 57 | dev_handle_t dev_handle; |
75 | dev_handle_t dev_handle; |
| 58 | /** Block offset on the block device. Counted in 'size'-byte blocks. */ |
76 | /** Block offset on the block device. Counted in 'size'-byte blocks. */ |
| 59 | off_t boff; |
77 | bn_t boff; |
| 60 | /** Size of the block. */ |
78 | /** Size of the block. */ |
| 61 | size_t size; |
79 | size_t size; |
| 62 | /** Link for placing the block into the free block list. */ |
80 | /** Link for placing the block into the free block list. */ |
| 63 | link_t free_link; |
81 | link_t free_link; |
| 64 | /** Link for placing the block into the block hash table. */ |
82 | /** Link for placing the block into the block hash table. */ |
| 65 | link_t hash_link; |
83 | link_t hash_link; |
| 66 | /** Buffer with the block data. */ |
84 | /** Buffer with the block data. */ |
| 67 | void *data; |
85 | void *data; |
| 68 | } block_t; |
86 | } block_t; |
| 69 | 87 | ||
| 70 | extern int block_init(dev_handle_t, size_t, off_t, size_t); |
88 | extern int block_init(dev_handle_t, size_t); |
| 71 | extern void block_fini(dev_handle_t); |
89 | extern void block_fini(dev_handle_t); |
| - | 90 | ||
| - | 91 | extern int block_bb_read(dev_handle_t, off_t, size_t); |
|
| 72 | extern void *block_bb_get(dev_handle_t); |
92 | extern void *block_bb_get(dev_handle_t); |
| 73 | 93 | ||
| - | 94 | extern int block_cache_init(dev_handle_t, size_t, unsigned); |
|
| - | 95 | ||
| 74 | extern block_t *block_get(dev_handle_t, off_t, size_t); |
96 | extern block_t *block_get(dev_handle_t, bn_t, int flags); |
| 75 | extern void block_put(block_t *); |
97 | extern void block_put(block_t *); |
| 76 | 98 | ||
| 77 | extern bool block_read(int, off_t *, size_t *, off_t *, void *, size_t, size_t); |
99 | extern int block_read(int, off_t *, size_t *, off_t *, void *, size_t, size_t); |
| 78 | 100 | ||
| 79 | #endif |
101 | #endif |
| 80 | 102 | ||
| 81 | /** @} |
103 | /** @} |
| 82 | */ |
104 | */ |