#include <stdint.h>
#include <string.h>
+#include <stdlib.h>
#include "coquet.h"
#include "util.h"
#include "sha2.h"
* | global_iv | 16 32
* | sb_hash | 48 32
* | sb_serial | 80 8
+ * | description | 88 128
* +-------------------+
- * | unused | 88 936
+ * | unused | 216 808
* +-------------------+
* | current | 1024 512
* +-------------------+
* +-------------------+
* | block_size | 0 1
* | nursery_size | 1 1
- * | unused | 2 126
* +-------------------+
- * | description | 128 128
- * +-------------------+
- * | unused | 256 256
+ * | unused | 2 510
* +-------------------+
*/
.sb_serial = 0,
.sb_hash = {0,},
.version = COQUET_VERSION,
- .from_b = 1
+ .from_b = 1,
+ .desc = {0,},
};
/* Blindly do a extraction. Note that we may not have any verification
return 0;
}
super->version = be_decode(data+8,8);
- /* (all versions are fine for now). */
+ /* (all versions are fine for now). TODO */
memcpy(super->global_iv,data+16,GLOBAL_IV_LEN);
memset(super->sb_hash,0,HASH_LEN);
+ memcpy(super->desc,data+88,DESC_LEN);
super->sb_serial = be_decode(data+80,8);
extract_config(data+1024,&(super->current));
r = (cq->vfs_funcs.random)(cq->vfs_data,
super->global_iv, GLOBAL_IV_LEN);
+ memset(super->desc,0,DESC_LEN);
if(r != COQUET_RET_OK) {
return r;
}
be_encode(data+8,COQUET_VERSION,8);
memcpy(data+16,super->global_iv,GLOBAL_IV_LEN);
be_encode(data+80,serial,8);
+ memcpy(data+88,super->desc,DESC_LEN);
intract_config(data+1024,&(super->current));
intract_config(data+1536,&(super->desired));
return ret;
}
+void cq_super_set_desc(struct cq_super *super, char *desc) {
+ memset(super->desc,0,DESC_LEN);
+ strncpy_ok(super->desc,desc,DESC_LEN);
+}
+
+char * cq_super_get_desc(struct cq_super *super) {
+ char *out;
+
+ out = malloc(DESC_LEN+1);
+ memcpy(out,super->desc,DESC_LEN);
+ out[DESC_LEN] = '\0';
+ return out;
+}
+
#ifdef COQUET_TEST
#include <stdio.h>
coquet_t cq;
int i,r;
struct cq_super super;
+ char *desc;
printf("testing superblock\n");
test_bail(&cq,r);
super.desired.nursery_size = 11; /* change something for B */
+ cq_super_set_desc(&super,"test file");
cq_super_save(&cq,&super,1);
test_bail(&cq,r);
test_assert(super.desired.block_size == 12,"dbsize");
test_assert(super.current.nursery_size == 10,"cnurs");
test_assert(super.desired.nursery_size == 11,"dnurs");
+
+ desc = cq_super_get_desc(&super);
+ test_assert(!strcmp(desc,"test file"),"desc");
+ free(desc);
+
for(i=0;i<GLOBAL_IV_LEN;i++)
test_assert(super.global_iv[i] == 0xA5,"iv");
corruption
a/b choice
magic
+desc truncation
*/
#define HALF_BYTES 2048
#define SUPER_BYTES (HALF_BYTES*2)
#define GLOBAL_IV_LEN 32
+#define DESC_LEN 128
#define NUM_LOCKS 32
struct cq_super_config {
};
struct cq_super {
+ /* Access these directly */
struct cq_super_config current, desired;
uint64_t version;
- uint64_t sb_serial;
uint8_t global_iv[GLOBAL_IV_LEN];
+
+ /* DANGER! Don't access directly, use cq_super_*_desc */
+ char desc[DESC_LEN];
+
+ /* superblock internal stuff, you probably don't need, and certainly
+ * shouldn't alter.
+ */
+ uint64_t sb_serial;
uint8_t sb_hash[32]; /* HMAC SHA512-256 using global_iv */
int from_b; /* true if loaded from b, false if from a */
};
int cq_super_save(coquet_t *cq, struct cq_super *super, bool_t wait);
int cq_super_load(coquet_t *cq, struct cq_super *super, bool_t create);
+void cq_super_set_desc(struct cq_super *super, char *desc);
+char * cq_super_get_desc(struct cq_super *super);
#ifdef COQUET_TEST
void test_superblock();