2 * UCW Library -- Configuration files: journaling
4 * (c) 2001--2006 Robert Spalek <robert@ucw.cz>
5 * (c) 2003--2006 Martin Mares <mj@ucw.cz>
7 * This software may be freely distributed and used according to the terms
8 * of the GNU Lesser General Public License.
13 #include "lib/conf-internal.h"
14 #include "lib/mempool.h"
18 static struct old_pools {
19 struct old_pools *prev;
21 } *pools; // link-list of older cf_pool's
23 uns cf_need_journal = 1; // some programs do not need journal
24 static struct cf_journal_item {
25 struct cf_journal_item *prev;
32 cf_journal_block(void *ptr, uns len)
36 struct cf_journal_item *ji = cf_malloc(sizeof(struct cf_journal_item) + len);
40 memcpy(ji->copy, ptr, len);
46 // swaps the contents of the memory and the journal, and reverses the list
48 struct cf_journal_item *curr, *prev, *next;
49 for (next=NULL, curr=journal; curr; next=curr, curr=prev)
53 for (uns i=0; i<curr->len; i++)
55 byte x = curr->copy[i];
56 curr->copy[i] = curr->ptr[i];
63 struct cf_journal_item *
64 cf_journal_new_transaction(uns new_pool)
67 cf_pool = mp_new(1<<10);
68 struct cf_journal_item *oldj = journal;
74 cf_journal_commit_transaction(uns new_pool, struct cf_journal_item *oldj)
78 struct old_pools *p = cf_malloc(sizeof(struct old_pools));
85 struct cf_journal_item **j = &journal;
93 cf_journal_rollback_transaction(uns new_pool, struct cf_journal_item *oldj)
96 die("Cannot rollback the configuration, because the journal is disabled.");
102 cf_pool = pools ? pools->pool : NULL;
107 cf_journal_delete(void)
109 for (struct old_pools *p=pools; p; p=pools)
116 /* TODO: more space efficient journal */