1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 #ifndef BLOCK_BACKEND_H
4 #define BLOCK_BACKEND_H
5 
6 #include "block.h"
7 
8 typedef struct BlockBackend BlockBackend;
9 
10 struct BlockBackend {
11 
12     BHandle* (*open_block) (BlockBackend *bend,
13                             const char *store_id, int version,
14                             const char *block_id, int rw_type);
15 
16     int      (*read_block) (BlockBackend *bend, BHandle *handle, void *buf, int len);
17 
18     int      (*write_block) (BlockBackend *bend, BHandle *handle, const void *buf, int len);
19 
20     int      (*commit_block) (BlockBackend *bend, BHandle *handle);
21 
22     int      (*close_block) (BlockBackend *bend, BHandle *handle);
23 
24     int      (*exists) (BlockBackend *bend,
25                         const char *store_id, int version,
26                         const char *block_id);
27 
28     int      (*remove_block) (BlockBackend *bend,
29                               const char *store_id, int version,
30                               const char *block_id);
31 
32     BMetadata* (*stat_block) (BlockBackend *bend,
33                               const char *store_id, int version,
34                               const char *block_id);
35 
36     BMetadata* (*stat_block_by_handle) (BlockBackend *bend, BHandle *handle);
37 
38     void     (*block_handle_free) (BlockBackend *bend, BHandle *handle);
39 
40     int      (*foreach_block) (BlockBackend *bend,
41                                const char *store_id,
42                                int version,
43                                SeafBlockFunc process,
44                                void *user_data);
45 
46     int         (*copy) (BlockBackend *bend,
47                          const char *src_store_id,
48                          int src_version,
49                          const char *dst_store_id,
50                          int dst_version,
51                          const char *block_id);
52 
53     /* Only valid for version 1 repo. Remove all blocks for the repo. */
54     int      (*remove_store) (BlockBackend *bend,
55                               const char *store_id);
56 
57     void*    be_priv;           /* backend private field */
58 
59 };
60 
61 
62 BlockBackend* load_block_backend (GKeyFile *config);
63 
64 #endif
65