2 * UCW Library -- Configuration files: journaling
4 * (c) 2001--2006 Robert Spalek <robert@ucw.cz>
5 * (c) 2003--2012 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>
20 struct old_pools *prev;
22 }; // link-list of older cf_pool's
24 struct cf_journal_item {
25 struct cf_journal_item *prev;
32 cf_set_journalling(int enable)
34 struct cf_context *cc = cf_get_context();
36 cc->enable_journal = enable;
40 cf_journal_block(void *ptr, uint len)
42 struct cf_context *cc = cf_get_context();
43 if (!cc->enable_journal)
45 struct cf_journal_item *ji = cf_malloc(sizeof(struct cf_journal_item) + len);
46 ji->prev = cc->journal;
49 memcpy(ji->copy, ptr, len);
55 // swaps the contents of the memory and the journal, and reverses the list
57 struct cf_context *cc = cf_get_context();
58 struct cf_journal_item *curr, *prev, *next;
59 for (next=NULL, curr=cc->journal; curr; next=curr, curr=prev)
63 for (uint i=0; i<curr->len; i++)
65 byte x = curr->copy[i];
66 curr->copy[i] = curr->ptr[i];
73 struct cf_journal_item *
74 cf_journal_new_transaction(uint new_pool)
76 struct cf_context *cc = cf_get_context();
78 cc->pool = mp_new(1<<10);
79 struct cf_journal_item *oldj = cc->journal;
85 cf_journal_commit_transaction(uint new_pool, struct cf_journal_item *oldj)
87 struct cf_context *cc = cf_get_context();
90 struct old_pools *p = cf_malloc(sizeof(struct old_pools));
97 struct cf_journal_item **j = &cc->journal;
105 cf_journal_rollback_transaction(uint new_pool, struct cf_journal_item *oldj)
107 struct cf_context *cc = cf_get_context();
108 if (!cc->enable_journal)
115 cc->pool = cc->pools ? cc->pools->pool : NULL;
120 cf_journal_delete(void)
122 struct cf_context *cc = cf_get_context();
123 for (struct old_pools *p=cc->pools; p; p=cc->pools)