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 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 General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #ifndef _CAMEL_BLOCK_FILE_H
22 #define _CAMEL_BLOCK_FILE_H
24 #include <camel/camel-object.h>
26 #include <e-util/e-msgport.h>
29 typedef guint32 camel_block_t; /* block offset, absolute, bottom BLOCK_SIZE_BITS always 0 */
30 typedef guint32 camel_key_t; /* this is a bitfield of (block offset:BLOCK_SIZE_BITS) */
32 typedef struct _CamelBlockRoot CamelBlockRoot;
33 typedef struct _CamelBlock CamelBlock;
34 typedef struct _CamelBlockFile CamelBlockFile;
35 typedef struct _CamelBlockFileClass CamelBlockFileClass;
37 #define CAMEL_BLOCK_FILE_SYNC (1<<0)
39 #define CAMEL_BLOCK_SIZE (1024)
40 #define CAMEL_BLOCK_SIZE_BITS (10) /* # bits to contain block_size bytes */
42 #define CAMEL_BLOCK_DIRTY (1<<0)
43 #define CAMEL_BLOCK_DETACHED (1<<1)
45 struct _CamelBlockRoot {
46 char version[8]; /* version number */
48 guint32 flags; /* flags for file */
49 guint32 block_size; /* block size of this file */
50 camel_block_t free; /* free block list */
51 camel_block_t last; /* pointer to end of blocks */
53 /* subclasses tack on, but no more than CAMEL_BLOCK_SIZE! */
56 /* LRU cache of blocks */
58 struct _CamelBlock *next;
59 struct _CamelBlock *prev;
66 unsigned char data[CAMEL_BLOCK_SIZE];
69 struct _CamelBlockFile {
72 struct _CamelBlockFilePrivate *priv;
82 CamelBlock *root_block;
85 int block_cache_limit;
86 int block_cache_count;
91 struct _CamelBlockFileClass {
92 CamelObjectClass parent;
94 int (*validate_root)(CamelBlockFile *);
95 int (*init_root)(CamelBlockFile *);
98 CamelType camel_block_file_get_type(void);
100 CamelBlockFile *camel_block_file_new(const char *path, int flags, const char version[8], size_t block_size);
101 int camel_block_file_rename(CamelBlockFile *bs, const char *path);
102 int camel_block_file_delete(CamelBlockFile *kf);
104 CamelBlock *camel_block_file_new_block(CamelBlockFile *bs);
105 int camel_block_file_free_block(CamelBlockFile *bs, camel_block_t id);
106 CamelBlock *camel_block_file_get_block(CamelBlockFile *bs, camel_block_t id);
107 void camel_block_file_detach_block(CamelBlockFile *bs, CamelBlock *bl);
108 void camel_block_file_attach_block(CamelBlockFile *bs, CamelBlock *bl);
109 void camel_block_file_touch_block(CamelBlockFile *bs, CamelBlock *bl);
110 void camel_block_file_unref_block(CamelBlockFile *bs, CamelBlock *bl);
111 int camel_block_file_sync_block(CamelBlockFile *bs, CamelBlock *bl);
112 int camel_block_file_sync(CamelBlockFile *bs);
114 /* ********************************************************************** */
116 typedef struct _CamelKeyFile CamelKeyFile;
117 typedef struct _CamelKeyFileClass CamelKeyFileClass;
119 struct _CamelKeyFile {
122 struct _CamelKeyFilePrivate *priv;
130 struct _CamelKeyFileClass {
131 CamelObjectClass parent;
134 CamelType camel_key_file_get_type(void);
136 CamelKeyFile * camel_key_file_new(const char *path, int flags, const char version[8]);
137 int camel_key_file_rename(CamelKeyFile *kf, const char *path);
138 int camel_key_file_delete(CamelKeyFile *kf);
140 int camel_key_file_write(CamelKeyFile *kf, camel_block_t *parent, size_t len, camel_key_t *records);
141 int camel_key_file_read(CamelKeyFile *kf, camel_block_t *start, size_t *len, camel_key_t **records);
144 #endif /* ! _CAMEL_BLOCK_FILE_H */