CamelKeyFile
3
CAMEL Library

# CamelKeyFile

## Synopsis

    typedef             camel_block_t;
    typedef             camel_key_t;
                        CamelBlockRoot;
                        CamelBlock;
                        CamelBlockFile;
    #define             CAMEL_BLOCK_FILE_SYNC
    #define             CAMEL_BLOCK_SIZE
    #define             CAMEL_BLOCK_SIZE_BITS
    #define             CAMEL_BLOCK_DIRTY
    #define             CAMEL_BLOCK_DETACHED
    CamelBlockFile*     camel_block_file_new                (const char *path,
                                                             int flags,
                                                             const char version[8],
                                                             size_t block_size);
    int                 camel_block_file_rename             (CamelBlockFile *bs,
                                                             const char *path);
    int                 camel_block_file_delete             (CamelBlockFile *kf);
    CamelBlock*         camel_block_file_new_block          (CamelBlockFile *bs);
    int                 camel_block_file_free_block         (CamelBlockFile *bs,
                                                             camel_block_t id);
    CamelBlock*         camel_block_file_get_block          (CamelBlockFile *bs,
                                                             camel_block_t id);
    void                camel_block_file_detach_block       (CamelBlockFile *bs,
                                                             CamelBlock *bl);
    void                camel_block_file_attach_block       (CamelBlockFile *bs,
                                                             CamelBlock *bl);
    void                camel_block_file_touch_block        (CamelBlockFile *bs,
                                                             CamelBlock *bl);
    void                camel_block_file_unref_block        (CamelBlockFile *bs,
                                                             CamelBlock *bl);
    int                 camel_block_file_sync_block         (CamelBlockFile *bs,
                                                             CamelBlock *bl);
    int                 camel_block_file_sync               (CamelBlockFile *bs);
                        CamelKeyFile;
    CamelKeyFile*       camel_key_file_new                  (const char *path,
                                                             int flags,
                                                             const char version[8]);
    int                 camel_key_file_rename               (CamelKeyFile *kf,
                                                             const char *path);
    int                 camel_key_file_delete               (CamelKeyFile *kf);
    int                 camel_key_file_write                (CamelKeyFile *kf,
                                                             camel_block_t *parent,
                                                             size_t len,
                                                             camel_key_t *records);
    int                 camel_key_file_read                 (CamelKeyFile *kf,
                                                             camel_block_t *start,
                                                             size_t *len,
                                                             camel_key_t **records);

## Description

## Details

### camel_block_t

    typedef guint32 camel_block_t;	/* block offset, absolute, bottom BLOCK_SIZE_BITS always 0 */

### camel_key_t

    typedef guint32 camel_key_t;	/* this is a bitfield of (block offset:BLOCK_SIZE_BITS) */

### CamelBlockRoot

    typedef struct {
    	char version[8];	/* version number */

    	guint32 flags;		/* flags for file */
    	guint32 block_size;	/* block size of this file */
    	camel_block_t free;	/* free block list */
    	camel_block_t last;	/* pointer to end of blocks */

    	/* subclasses tack on, but no more than CAMEL_BLOCK_SIZE! */
    } CamelBlockRoot;

### CamelBlock

    typedef struct {
    	struct _CamelBlock *next;
    	struct _CamelBlock *prev;

    	camel_block_t id;
    	guint32 flags;
    	guint32 refcount;
    	guint32 align00;

    	unsigned char data[CAMEL_BLOCK_SIZE];
    } CamelBlock;

### CamelBlockFile

    typedef struct {
    	CamelObject parent;

    	struct _CamelBlockFilePrivate *priv;

    	char version[8];
    	char *path;
    	int flags;

    	int fd;
    	size_t block_size;

    	CamelBlockRoot *root;
    	CamelBlock *root_block;

    	/* make private? */
    	int block_cache_limit;
    	int block_cache_count;
    	EDList block_cache;
    	GHashTable *blocks;
    } CamelBlockFile;

### CAMEL_BLOCK_FILE_SYNC

    #define CAMEL_BLOCK_FILE_SYNC (1<<0)

### CAMEL_BLOCK_SIZE

    #define CAMEL_BLOCK_SIZE (1024)

### CAMEL_BLOCK_SIZE_BITS

    #define CAMEL_BLOCK_SIZE_BITS (10) /* # bits to contain block_size bytes */

### CAMEL_BLOCK_DIRTY

    #define CAMEL_BLOCK_DIRTY (1<<0)

### CAMEL_BLOCK_DETACHED

    #define CAMEL_BLOCK_DETACHED (1<<1)

### camel_block_file_new ()

    CamelBlockFile*     camel_block_file_new                (const char *path,
                                                             int flags,
                                                             const char version[8],
                                                             size_t block_size);

`path` :

`flags` :

`version` :

`block_size` :

Returns :

### camel_block_file_rename ()

    int                 camel_block_file_rename             (CamelBlockFile *bs,
                                                             const char *path);

`bs` :

`path` :

Returns :

### camel_block_file_delete ()

    int                 camel_block_file_delete             (CamelBlockFile *kf);

`kf` :

Returns :

### camel_block_file_new_block ()

    CamelBlock*         camel_block_file_new_block          (CamelBlockFile *bs);

`bs` :

Returns :

### camel_block_file_free_block ()

    int                 camel_block_file_free_block         (CamelBlockFile *bs,
                                                             camel_block_t id);

`bs` :

`id` :

Returns :

### camel_block_file_get_block ()

    CamelBlock*         camel_block_file_get_block          (CamelBlockFile *bs,
                                                             camel_block_t id);

`bs` :

`id` :

Returns :

### camel_block_file_detach_block ()

    void                camel_block_file_detach_block       (CamelBlockFile *bs,
                                                             CamelBlock *bl);

`bs` :

`bl` :

### camel_block_file_attach_block ()

    void                camel_block_file_attach_block       (CamelBlockFile *bs,
                                                             CamelBlock *bl);

`bs` :

`bl` :

### camel_block_file_touch_block ()

    void                camel_block_file_touch_block        (CamelBlockFile *bs,
                                                             CamelBlock *bl);

`bs` :

`bl` :

### camel_block_file_unref_block ()

    void                camel_block_file_unref_block        (CamelBlockFile *bs,
                                                             CamelBlock *bl);

`bs` :

`bl` :

### camel_block_file_sync_block ()

    int                 camel_block_file_sync_block         (CamelBlockFile *bs,
                                                             CamelBlock *bl);

`bs` :

`bl` :

Returns :

### camel_block_file_sync ()

    int                 camel_block_file_sync               (CamelBlockFile *bs);

`bs` :

Returns :

### CamelKeyFile

    typedef struct {
    	CamelObject parent;

    	struct _CamelKeyFilePrivate *priv;

    	FILE *fp;
    	char *path;
    	int flags;
    	off_t last;
    } CamelKeyFile;

### camel_key_file_new ()

    CamelKeyFile*       camel_key_file_new                  (const char *path,
                                                             int flags,
                                                             const char version[8]);

`path` :

`flags` :

`version` :

Returns :

### camel_key_file_rename ()

    int                 camel_key_file_rename               (CamelKeyFile *kf,
                                                             const char *path);

`kf` :

`path` :

Returns :

### camel_key_file_delete ()

    int                 camel_key_file_delete               (CamelKeyFile *kf);

`kf` :

Returns :

### camel_key_file_write ()

    int                 camel_key_file_write                (CamelKeyFile *kf,
                                                             camel_block_t *parent,
                                                             size_t len,
                                                             camel_key_t *records);

`kf` :

`parent` :

`len` :

`records` :

Returns :

### camel_key_file_read ()

    int                 camel_key_file_read                 (CamelKeyFile *kf,
                                                             camel_block_t *start,
                                                             size_t *len,
                                                             camel_key_t **records);

`kf` :

`start` :

`len` :

`records` :

Returns :