mmapstorage: improve set operation
@@ -195,7 +195,6 @@ static void elektraMmapstorageWriteKeySet (char * mappedRegion, KeySet * keySet)
// move KeySet itself to the mapped region
keySet->flags |= KS_FLAG_MMAP;
memcpy (ksRegion, keySet, SIZEOF_KEYSET);
- //fwrite (keySet, SIZEOF_KEYSET, 1, fp);
return;
}
@@ -229,7 +228,7 @@ static void elektraMmapstorageWriteKeySet (char * mappedRegion, KeySet * keySet)
dataNextFreeBlock += keyValueSize;
// move Key itself
- Key * mmapKey = (Key *) ksRegion + SIZEOF_KEYSET + (keyIndex * SIZEOF_KEY);
+ void * mmapKey = ksRegion + SIZEOF_KEYSET + (keyIndex * SIZEOF_KEY);
cur->flags |= KEY_FLAG_MMAP;
memcpy (mmapKey, cur, SIZEOF_KEY);
//fwrite (cur, keyValueSize, 1, fp);
@@ -250,6 +249,15 @@ static void elektraMmapstorageWriteKeySet (char * mappedRegion, KeySet * keySet)
memcpy (ksRegion, keySet, SIZEOF_KEYSET);
}
+static void mmapToKeySet (char * mappedRegion, KeySet * returned)
+{
+ KeySet * keySet = (KeySet *) (mappedRegion + SIZEOF_MMAPINFO);
+ returned->array = keySet->array;
+ returned->size = keySet->size;
+ ksRewind(returned);
+ returned->flags = keySet->flags;
+}
+
int elektraMmapstorageOpen (Plugin * handle ELEKTRA_UNUSED, Key * errorKey ELEKTRA_UNUSED)
{
// plugin initialization logic
@@ -313,7 +321,7 @@ int elektraMmapstorageGet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Ke
ELEKTRA_LOG ("mappedRegion == MAP_FAILED");
return -1;
}
- ELEKTRA_LOG ("mappedRegion size: %lld", sbuf.st_size);
+ ELEKTRA_LOG_WARNING ("mappedRegion size: %l", sbuf.st_size);
char * ksRegion = mappedRegion + SIZEOF_MMAPINFO;
ksCopy (returned, (KeySet *) ksRegion);
@@ -359,8 +367,8 @@ int elektraMmapstorageSet (Plugin * handle ELEKTRA_UNUSED, KeySet * returned, Ke
elektraMmapstorageWriteKeySet (mappedRegion, returned);
- ksCopy(returned, (KeySet *) mappedRegion);
- returned->flags |= KS_FLAG_MMAP;
+ //ksCopy(returned, (KeySet *) mappedRegion);
+ mmapToKeySet(mappedRegion, returned);
// TODO FIXME: don't use ksCopy but replace all fields inside the KeySet.
// just replace the pointers to Key ** array and so on
