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 "ucw/getopt.h"
14 #include "ucw/conf-internal.h"
15 #include "ucw/mempool.h"
19 static struct old_pools {
20 struct old_pools *prev;
22 } *pools; // link-list of older cf_pool's
24 uns cf_need_journal = 1; // some programs do not need journal
25 static struct cf_journal_item {
26 struct cf_journal_item *prev;
33 cf_journal_block(void *ptr, uns len)
37 struct cf_journal_item *ji = cf_malloc(sizeof(struct cf_journal_item) + len);
41 memcpy(ji->copy, ptr, len);
47 // swaps the contents of the memory and the journal, and reverses the list
49 struct cf_journal_item *curr, *prev, *next;
50 for (next=NULL, curr=journal; curr; next=curr, curr=prev)
54 for (uns i=0; i<curr->len; i++)
56 byte x = curr->copy[i];
57 curr->copy[i] = curr->ptr[i];
64 struct cf_journal_item *
65 cf_journal_new_transaction(uns new_pool)
68 cf_pool = mp_new(1<<10);
69 struct cf_journal_item *oldj = journal;
75 cf_journal_commit_transaction(uns new_pool, struct cf_journal_item *oldj)
79 struct old_pools *p = cf_malloc(sizeof(struct old_pools));
86 struct cf_journal_item **j = &journal;
94 cf_journal_rollback_transaction(uns new_pool, struct cf_journal_item *oldj)
97 die("Cannot rollback the configuration, because the journal is disabled.");
103 cf_pool = pools ? pools->pool : NULL;
108 cf_journal_delete(void)
110 for (struct old_pools *p=pools; p; p=pools)
117 /* TODO: more space efficient journal */