1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 3 #ifndef SEAF_BLOCK_MGR_H 4 #define SEAF_BLOCK_MGR_H 5 6 #include <glib.h> 7 #include <glib-object.h> 8 #include <stdint.h> 9 10 #include "block.h" 11 12 struct _SeafileSession; 13 14 typedef struct _SeafBlockManager SeafBlockManager; 15 16 struct _SeafBlockManager { 17 struct _SeafileSession *seaf; 18 19 struct BlockBackend *backend; 20 }; 21 22 23 SeafBlockManager * 24 seaf_block_manager_new (struct _SeafileSession *seaf, 25 const char *seaf_dir); 26 27 /* 28 * Open a block for read or write. 29 * 30 * @store_id: id for the block store 31 * @version: data format version for the repo 32 * @block_id: ID of block. 33 * @rw_type: BLOCK_READ or BLOCK_WRITE. 34 * Returns: A handle for the block. 35 */ 36 BlockHandle * 37 seaf_block_manager_open_block (SeafBlockManager *mgr, 38 const char *store_id, 39 int version, 40 const char *block_id, 41 int rw_type); 42 43 /* 44 * Read data from a block. 45 * The semantics is similar to readn. 46 * 47 * @handle: Hanlde returned by seaf_block_manager_open_block(). 48 * @buf: Data wuold be copied into this buf. 49 * @len: At most @len bytes would be read. 50 * 51 * Returns: the bytes read. 52 */ 53 int 54 seaf_block_manager_read_block (SeafBlockManager *mgr, 55 BlockHandle *handle, 56 void *buf, int len); 57 58 /* 59 * Write data to a block. 60 * The semantics is similar to writen. 61 * 62 * @handle: Hanlde returned by seaf_block_manager_open_block(). 63 * @buf: Data to be written to the block. 64 * @len: At most @len bytes would be written. 65 * 66 * Returns: the bytes written. 67 */ 68 int 69 seaf_block_manager_write_block (SeafBlockManager *mgr, 70 BlockHandle *handle, 71 const void *buf, int len); 72 73 /* 74 * Commit a block to storage. 75 * The block must be opened for write. 76 * 77 * @handle: Hanlde returned by seaf_block_manager_open_block(). 78 * 79 * Returns: 0 on success, -1 on error. 80 */ 81 int 82 seaf_block_manager_commit_block (SeafBlockManager *mgr, 83 BlockHandle *handle); 84 85 /* 86 * Close an open block. 87 * 88 * @handle: Hanlde returned by seaf_block_manager_open_block(). 89 * 90 * Returns: 0 on success, -1 on error. 91 */ 92 int 93 seaf_block_manager_close_block (SeafBlockManager *mgr, 94 BlockHandle *handle); 95 96 void 97 seaf_block_manager_block_handle_free (SeafBlockManager *mgr, 98 BlockHandle *handle); 99 100 gboolean 101 seaf_block_manager_block_exists (SeafBlockManager *mgr, 102 const char *store_id, 103 int version, 104 const char *block_id); 105 106 int 107 seaf_block_manager_remove_block (SeafBlockManager *mgr, 108 const char *store_id, 109 int version, 110 const char *block_id); 111 112 BlockMetadata * 113 seaf_block_manager_stat_block (SeafBlockManager *mgr, 114 const char *store_id, 115 int version, 116 const char *block_id); 117 118 BlockMetadata * 119 seaf_block_manager_stat_block_by_handle (SeafBlockManager *mgr, 120 BlockHandle *handle); 121 122 int 123 seaf_block_manager_foreach_block (SeafBlockManager *mgr, 124 const char *store_id, 125 int version, 126 SeafBlockFunc process, 127 void *user_data); 128 129 int 130 seaf_block_manager_copy_block (SeafBlockManager *mgr, 131 const char *src_store_id, 132 int src_version, 133 const char *dst_store_id, 134 int dst_version, 135 const char *block_id); 136 137 /* Remove all blocks for a repo. Only valid for version 1 repo. */ 138 int 139 seaf_block_manager_remove_store (SeafBlockManager *mgr, 140 const char *store_id); 141 142 guint64 143 seaf_block_manager_get_block_number (SeafBlockManager *mgr, 144 const char *store_id, 145 int version); 146 147 gboolean 148 seaf_block_manager_verify_block (SeafBlockManager *mgr, 149 const char *store_id, 150 int version, 151 const char *block_id, 152 gboolean *io_error); 153 154 #endif 155