2 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
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 #if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
22 #error "Only <camel/camel.h> can be included directly."
25 #ifndef CAMEL_BLOCK_FILE_H
26 #define CAMEL_BLOCK_FILE_H
28 #include <camel/camel-object.h>
30 #include <sys/types.h>
32 /* Standard GObject macros */
33 #define CAMEL_TYPE_BLOCK_FILE \
34 (camel_block_file_get_type ())
35 #define CAMEL_BLOCK_FILE(obj) \
36 (G_TYPE_CHECK_INSTANCE_CAST \
37 ((obj), CAMEL_TYPE_BLOCK_FILE, CamelBlockFile))
38 #define CAMEL_BLOCK_FILE_CLASS(cls) \
39 (G_TYPE_CHECK_CLASS_CAST \
40 ((cls), CAMEL_TYPE_BLOCK_FILE, CamelBlockFileClass))
41 #define CAMEL_IS_BLOCK_FILE(obj) \
42 (G_TYPE_CHECK_INSTANCE_TYPE \
43 ((obj), CAMEL_TYPE_BLOCK_FILE))
44 #define CAMEL_IS_BLOCK_FILE_CLASS(cls) \
45 (G_TYPE_CHECK_CLASS_TYPE \
46 ((cls), CAMEL_TYPE_BLOCK_FILE))
47 #define CAMEL_BLOCK_FILE_GET_CLASS(obj) \
48 (G_TYPE_INSTANCE_GET_CLASS \
49 ((obj), CAMEL_TYPE_BLOCK_FILE, CamelBlockFileClass))
51 #define CAMEL_TYPE_KEY_FILE \
52 (camel_key_file_get_type ())
53 #define CAMEL_KEY_FILE(obj) \
54 (G_TYPE_CHECK_INSTANCE_CAST \
55 ((obj), CAMEL_TYPE_KEY_FILE, CamelKeyFile))
56 #define CAMEL_KEY_FILE_CLASS(cls) \
57 (G_TYPE_CHECK_CLASS_CAST \
58 ((cls), CAMEL_TYPE_KEY_FILE, CamelKeyFileClass))
59 #define CAMEL_IS_KEY_FILE(obj) \
60 (G_TYPE_CHECK_INSTANCE_TYPE \
61 ((obj), CAMEL_TYPE_KEY_FILE))
62 #define CAMEL_IS_KEY_FILE_CLASS(cls) \
63 (G_TYPE_CHECK_CLASS_TYPE \
64 ((cls), CAMEL_TYPE_KEY_FILE))
65 #define CAMEL_KEY_FILE_GET_CLASS(obj) \
66 (G_TYPE_INSTANCE_GET_CLASS \
67 ((obj), CAMEL_TYPE_KEY_FILE, CamelKeyFileClass))
71 typedef guint32 camel_block_t; /* block offset, absolute, bottom BLOCK_SIZE_BITS always 0 */
72 typedef guint32 camel_key_t; /* this is a bitfield of (block offset:BLOCK_SIZE_BITS) */
74 typedef struct _CamelBlockRoot CamelBlockRoot;
75 typedef struct _CamelBlock CamelBlock;
76 typedef struct _CamelBlockFile CamelBlockFile;
77 typedef struct _CamelBlockFileClass CamelBlockFileClass;
78 typedef struct _CamelBlockFilePrivate CamelBlockFilePrivate;
81 CAMEL_BLOCK_FILE_SYNC = 1 << 0
82 } CamelBlockFileFlags;
84 #define CAMEL_BLOCK_SIZE (1024)
85 #define CAMEL_BLOCK_SIZE_BITS (10) /* # bits to contain block_size bytes */
88 CAMEL_BLOCK_DIRTY = 1 << 0,
89 CAMEL_BLOCK_DETACHED = 1 << 1
92 struct _CamelBlockRoot {
93 gchar version[8]; /* version number */
95 guint32 flags; /* flags for file */
96 guint32 block_size; /* block size of this file */
97 camel_block_t free; /* free block list */
98 camel_block_t last; /* pointer to end of blocks */
100 /* subclasses tack on, but no more than CAMEL_BLOCK_SIZE! */
103 /* LRU cache of blocks */
106 CamelBlockFlags flags;
110 guchar data[CAMEL_BLOCK_SIZE];
113 struct _CamelBlockFile {
115 CamelBlockFilePrivate *priv;
119 CamelBlockFileFlags flags;
124 CamelBlockRoot *root;
125 CamelBlock *root_block;
128 gint block_cache_limit;
129 gint block_cache_count;
134 struct _CamelBlockFileClass {
135 CamelObjectClass parent;
137 gint (*validate_root)(CamelBlockFile *);
138 gint (*init_root)(CamelBlockFile *);
141 GType camel_block_file_get_type (void);
142 CamelBlockFile *camel_block_file_new (const gchar *path,
144 const gchar version[8],
146 gint camel_block_file_rename (CamelBlockFile *bs,
148 gint camel_block_file_delete (CamelBlockFile *kf);
149 CamelBlock * camel_block_file_new_block (CamelBlockFile *bs);
150 gint camel_block_file_free_block (CamelBlockFile *bs,
152 CamelBlock * camel_block_file_get_block (CamelBlockFile *bs,
154 void camel_block_file_detach_block (CamelBlockFile *bs,
156 void camel_block_file_attach_block (CamelBlockFile *bs,
158 void camel_block_file_touch_block (CamelBlockFile *bs,
160 void camel_block_file_unref_block (CamelBlockFile *bs,
162 gint camel_block_file_sync_block (CamelBlockFile *bs,
164 gint camel_block_file_sync (CamelBlockFile *bs);
166 /* ********************************************************************** */
168 typedef struct _CamelKeyFile CamelKeyFile;
169 typedef struct _CamelKeyFileClass CamelKeyFileClass;
170 typedef struct _CamelKeyFilePrivate CamelKeyFilePrivate;
172 struct _CamelKeyFile {
174 CamelKeyFilePrivate *priv;
182 struct _CamelKeyFileClass {
183 CamelObjectClass parent;
186 GType camel_key_file_get_type (void);
188 CamelKeyFile * camel_key_file_new (const gchar *path, gint flags, const gchar version[8]);
189 gint camel_key_file_rename (CamelKeyFile *kf, const gchar *path);
190 gint camel_key_file_delete (CamelKeyFile *kf);
192 gint camel_key_file_write (CamelKeyFile *kf, camel_block_t *parent, gsize len, camel_key_t *records);
193 gint camel_key_file_read (CamelKeyFile *kf, camel_block_t *start, gsize *len, camel_key_t **records);
197 #endif /* CAMEL_BLOCK_FILE_H */