2007-05-25 18:21:09 +00:00
|
|
|
#include <lladd/transactional.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2007-05-25 22:01:44 +00:00
|
|
|
int main (int argc, char ** argv) {
|
|
|
|
|
2007-05-25 18:21:09 +00:00
|
|
|
Tinit();
|
2007-05-25 22:01:44 +00:00
|
|
|
|
2007-05-25 18:21:09 +00:00
|
|
|
recordid rootEntry;
|
2007-05-25 22:01:44 +00:00
|
|
|
|
2007-05-25 18:21:09 +00:00
|
|
|
int xid = Tbegin();
|
2007-05-25 22:01:44 +00:00
|
|
|
|
2007-06-07 21:53:09 +00:00
|
|
|
if(TrecordType(xid, ROOT_RECORD) == INVALID_SLOT) {
|
2007-05-25 18:21:09 +00:00
|
|
|
|
|
|
|
// ThashAlloc() will work here as well.
|
2007-05-25 22:01:44 +00:00
|
|
|
rootEntry = Talloc(xid, sizeof(int));
|
|
|
|
|
2007-05-25 18:21:09 +00:00
|
|
|
assert(ROOT_RECORD.page == rootEntry.page);
|
|
|
|
assert(ROOT_RECORD.slot == rootEntry.slot);
|
2007-05-25 22:01:44 +00:00
|
|
|
// rootEntry.size will be sizeof(int) from above.
|
2007-05-25 18:21:09 +00:00
|
|
|
int zero = 0;
|
|
|
|
|
|
|
|
Tset(xid, rootEntry, &zero);
|
2007-05-25 22:01:44 +00:00
|
|
|
|
2007-05-25 18:21:09 +00:00
|
|
|
printf("New store; root = 0\n");
|
2007-05-25 22:01:44 +00:00
|
|
|
|
2007-05-25 18:21:09 +00:00
|
|
|
} else {
|
2007-05-25 22:01:44 +00:00
|
|
|
|
|
|
|
// The store already is initialized. If this were a real program,
|
|
|
|
// it would use some magic to make sure that it is compatible with
|
|
|
|
// the program that created the store...
|
|
|
|
|
2007-05-25 18:21:09 +00:00
|
|
|
rootEntry = ROOT_RECORD;
|
2007-05-25 22:01:44 +00:00
|
|
|
rootEntry.size = sizeof(int); // Same as sizeof(int) above.
|
|
|
|
|
2007-05-25 18:21:09 +00:00
|
|
|
int root;
|
|
|
|
|
2007-05-25 22:01:44 +00:00
|
|
|
Tread(xid, rootEntry, &root);
|
|
|
|
|
2007-05-25 18:21:09 +00:00
|
|
|
printf("Old store: %d -> ", root);
|
|
|
|
root++;
|
|
|
|
printf("%d\n", root);
|
2007-05-25 22:01:44 +00:00
|
|
|
|
|
|
|
Tset(xid, rootEntry, &root);
|
|
|
|
|
2007-05-25 18:21:09 +00:00
|
|
|
}
|
2007-05-25 22:01:44 +00:00
|
|
|
|
|
|
|
Tcommit(xid);
|
|
|
|
|
2007-05-25 18:21:09 +00:00
|
|
|
Tdeinit();
|
|
|
|
}
|