2 * Copyright (C) 2001 Ximian Inc.
4 * Authors: Michael Zucchi <notzed@ximian.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU Lesser General Public
8 * License as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 #ifndef _CAMEL_BLOCK_FILE_H
22 #define _CAMEL_BLOCK_FILE_H
24 #include <camel/camel-object.h>
26 #include <libedataserver/e-msgport.h>
31 typedef guint32 camel_block_t; /* block offset, absolute, bottom BLOCK_SIZE_BITS always 0 */
32 typedef guint32 camel_key_t; /* this is a bitfield of (block offset:BLOCK_SIZE_BITS) */
34 typedef struct _CamelBlockRoot CamelBlockRoot;
35 typedef struct _CamelBlock CamelBlock;
36 typedef struct _CamelBlockFile CamelBlockFile;
37 typedef struct _CamelBlockFileClass CamelBlockFileClass;
39 #define CAMEL_BLOCK_FILE_SYNC (1<<0)
41 #define CAMEL_BLOCK_SIZE (1024)
42 #define CAMEL_BLOCK_SIZE_BITS (10) /* # bits to contain block_size bytes */
44 #define CAMEL_BLOCK_DIRTY (1<<0)
45 #define CAMEL_BLOCK_DETACHED (1<<1)
47 struct _CamelBlockRoot {
48 char version[8]; /* version number */
50 guint32 flags; /* flags for file */
51 guint32 block_size; /* block size of this file */
52 camel_block_t free; /* free block list */
53 camel_block_t last; /* pointer to end of blocks */
55 /* subclasses tack on, but no more than CAMEL_BLOCK_SIZE! */
58 /* LRU cache of blocks */
60 struct _CamelBlock *next;
61 struct _CamelBlock *prev;
68 unsigned char data[CAMEL_BLOCK_SIZE];
71 struct _CamelBlockFile {
74 struct _CamelBlockFilePrivate *priv;
84 CamelBlock *root_block;
87 int block_cache_limit;
88 int block_cache_count;
93 struct _CamelBlockFileClass {
94 CamelObjectClass parent;
96 int (*validate_root)(CamelBlockFile *);
97 int (*init_root)(CamelBlockFile *);
100 CamelType camel_block_file_get_type(void);
102 CamelBlockFile *camel_block_file_new(const char *path, int flags, const char version[8], size_t block_size);
103 int camel_block_file_rename(CamelBlockFile *bs, const char *path);
104 int camel_block_file_delete(CamelBlockFile *kf);
106 CamelBlock *camel_block_file_new_block(CamelBlockFile *bs);
107 int camel_block_file_free_block(CamelBlockFile *bs, camel_block_t id);
108 CamelBlock *camel_block_file_get_block(CamelBlockFile *bs, camel_block_t id);
109 void camel_block_file_detach_block(CamelBlockFile *bs, CamelBlock *bl);
110 void camel_block_file_attach_block(CamelBlockFile *bs, CamelBlock *bl);
111 void camel_block_file_touch_block(CamelBlockFile *bs, CamelBlock *bl);
112 void camel_block_file_unref_block(CamelBlockFile *bs, CamelBlock *bl);
113 int camel_block_file_sync_block(CamelBlockFile *bs, CamelBlock *bl);
114 int camel_block_file_sync(CamelBlockFile *bs);
116 /* ********************************************************************** */
118 typedef struct _CamelKeyFile CamelKeyFile;
119 typedef struct _CamelKeyFileClass CamelKeyFileClass;
121 struct _CamelKeyFile {
124 struct _CamelKeyFilePrivate *priv;
132 struct _CamelKeyFileClass {
133 CamelObjectClass parent;
136 CamelType camel_key_file_get_type(void);
138 CamelKeyFile * camel_key_file_new(const char *path, int flags, const char version[8]);
139 int camel_key_file_rename(CamelKeyFile *kf, const char *path);
140 int camel_key_file_delete(CamelKeyFile *kf);
142 int camel_key_file_write(CamelKeyFile *kf, camel_block_t *parent, size_t len, camel_key_t *records);
143 int camel_key_file_read(CamelKeyFile *kf, camel_block_t *start, size_t *len, camel_key_t **records);
147 #endif /* ! _CAMEL_BLOCK_FILE_H */