14 #define _XOPEN_SOURCE 700
22 #include <sys/types.h>
30 #include "sion_error_handler.h"
42 #define DFUNCTION "_sion_keyval_check_env"
43 int _sion_keyval_check_env(
_sion_filedesc *sion_filedesc, sion_int64 file_mode_flags) {
46 sion_int32 keyvalmode_env;
47 sion_int32 keyvalmode_parm;
66 if(file_mode_flags&_SION_FMODE_KEYVAL_META) keyvalmode_parm=
SION_KEYVAL_META;
67 if(file_mode_flags&_SION_FMODE_KEYVAL_HASH) keyvalmode_parm=
SION_KEYVAL_HASH;
68 if(file_mode_flags&_SION_FMODE_KEYVAL_NONE) keyvalmode_parm=
SION_KEYVAL_NONE;
70 DPRINTFP((2, DFUNCTION, -1,
"keyval mode from parameter is=%s\n",
sion_keyval_type_to_str((
int) keyvalmode_parm)));
72 if(file_mode_flags&_SION_FMODE_READ) {
73 DPRINTFP((2, DFUNCTION, -1,
"file is opened for reading\n"));
79 DPRINTFP((2, DFUNCTION, -1,
"file read: parameter is 'unknown' keyvalmode will taken from file ...\n"));
84 DPRINTFP((2, DFUNCTION, -1,
"file read: keyvalmode of file is different to requested keyvalmode from parameter, aborting ...\n"));
85 return(_sion_errorprint(0,_SION_ERROR_RETURN,
"file read: keyvalmode of file is different to requested keyvalmode from parameter, aborting ...\n"));
88 DPRINTFP((2, DFUNCTION, -1,
"file read: keyvalmode of file is different to requested keyvalmode from environment, aborting ...\n"));
89 return(_sion_errorprint(0,_SION_ERROR_RETURN,
"file read: keyvalmode of file is different to requested keyvalmode from env-var, aborting ...\n"));
95 DPRINTFP((2, DFUNCTION, -1,
"file is opened for writing\n"));
109 #define DFUNCTION "_sion_keyval_dup_dataptr"
112 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
115 rc=_sion_keyval_dup_dataptr_inline(sion_filedesc,new_filedesc);
117 return(_sion_errorprint(0,_SION_ERROR_RETURN,
"trying to call sion_keyval_dup_dataptr in inknown keyval mode , aborting ...\n"));
120 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
127 #define DFUNCTION "sion_fwrite_key"
143 size_t sion_fwrite_key(
const void *data, uint64_t key,
size_t size,
size_t nitems,
int sid) {
148 DPRINTFTS(-1,
"enter sion_fwrite_key");
149 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
153 return(_sion_errorprint(0,_SION_ERROR_RETURN,
"invalid sion_filedesc, aborting %d ...\n", sid));
155 if(sion_filedesc->
rank<0) {
156 return(SION_NOT_SUCCESS);
158 DPRINTFP((2, DFUNCTION, -1,
"fwrite_key: key=%d size=%d, nitems=%d\n",(
int) key,(
int) size, (
int) nitems));
163 frc=_sion_store_and_write_key_and_len(sion_filedesc,key,len);
164 if(frc != SION_SUCCESS) {
165 return(_sion_errorprint_on_rank(-1,_SION_ERROR_RETURN,sion_filedesc->
rank,
166 "could not write meta data to file (frc=%d sid=%d) ...", (
int) frc, sid));
170 frc=_sion_write_value(sion_filedesc,data,key,len);
172 return(_sion_errorprint_on_rank(-1,_SION_ERROR_RETURN,sion_filedesc->
rank,
173 "could not write data (%d bytes) to file (frc=%d sid=%d) ...", (
int) len, (
int) frc, sid));
176 rc=(size_t) len / size;
178 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
179 DPRINTFTS(-1,
"leave sion_fwrite_key");
186 #define DFUNCTION "sion_fread_key"
202 size_t sion_fread_key(
void *data, uint64_t key,
size_t size,
size_t nitems,
int sid) {
204 size_t len, datalen=0;
207 DPRINTFTS(-1,
"enter sion_fread_key");
208 DPRINTFP((8, DFUNCTION, -1,
"enter\n"));
212 return(_sion_errorprint(0,_SION_ERROR_RETURN,
"invalid sion_filedesc, aborting %d ...\n", sid));
214 if(sion_filedesc->
rank<0) {
215 return(SION_NOT_SUCCESS);
217 DPRINTFP((32, DFUNCTION, -1,
"fread_key: sid=%d key=%ld size=%d, nitems=%d\n",(
int) sid, (
long) key,(
int) size, (
int) nitems));
222 if (_sion_find_and_read_key_and_len(sion_filedesc,key,len,&datalen) !=
224 DPRINTFP((8, DFUNCTION, -1,
"_sion_find_and_read_key_and_len return NOT SUCCESS\n"));
225 return(SION_NOT_SUCCESS);
229 len = ( (int) datalen/size ) * size;
232 frc=_sion_read_value(sion_filedesc,data,key,len);
234 return(SION_NOT_SUCCESS);
237 rc=(size_t) len / size;
239 DPRINTFP((8, DFUNCTION, -1,
"leave rc=%d\n",(
int) rc));
240 DPRINTFTS(-1,
"leave sion_fread_key");
245 #define DFUNCTION "sion_key_full_scan"
255 size_t rc=SION_NOT_SUCCESS;
258 DPRINTFTS(-1,
"enter sion_key_full_scan");
259 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
263 return(_sion_errorprint(0,_SION_ERROR_RETURN,
"invalid sion_filedesc, aborting %d ...\n", sid));
265 if(sion_filedesc->
rank<0) {
266 return(SION_NOT_SUCCESS);
269 rc=_sion_key_full_scan_inline(sion_filedesc);
271 return(_sion_errorprint(0,_SION_ERROR_RETURN,
"trying to perform full scan of file which is not opened in that mode, aborting ...\n"));
274 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
275 DPRINTFTS(-1,
"leave sion_key_full_scan");
281 #define DFUNCTION "sion_fread_key_iterator_reset"
291 size_t rc=SION_NOT_SUCCESS;
294 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
298 return(_sion_errorprint(0,_SION_ERROR_RETURN,
"invalid sion_filedesc, aborting %d ...\n", sid));
300 if(sion_filedesc->
rank<0) {
301 return(SION_NOT_SUCCESS);
305 rc=_sion_iterator_reset_inline(sion_filedesc);
307 return(_sion_errorprint(0,_SION_ERROR_RETURN,
"trying to reset iterator in keyval mode from file which is not opened in that mode, aborting ...\n"));
310 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
315 #define DFUNCTION "sion_fread_key_iterator_next"
327 size_t rc=SION_NOT_SUCCESS;
330 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
334 return(_sion_errorprint(0,_SION_ERROR_RETURN,
"invalid sion_filedesc, aborting %d ...\n", sid));
336 if(sion_filedesc->
rank<0) {
337 return(SION_NOT_SUCCESS);
340 rc=_sion_iterator_next_inline(sion_filedesc, keyptr, sizeptr);
341 DPRINTFP((2, DFUNCTION, -1,
"sion_fread_key_iterator_next: key=%d size=%d\n",(
int) *keyptr,(
int) *sizeptr));
343 return(_sion_errorprint(0,_SION_ERROR_RETURN,
"trying to forward iterator in keyval mode from file which is not opened in that mode, aborting ...\n"));
346 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
352 #define DFUNCTION "sion_seek_key"
365 int sion_seek_key(
int sid, uint64_t key,
int entrynum, sion_int64 posinentry) {
366 size_t rc=SION_NOT_SUCCESS;
369 DPRINTFTS(-1,
"enter sion_seek_key");
370 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
374 return(_sion_errorprint(0,_SION_ERROR_RETURN,
"invalid sion_filedesc, aborting %d ...\n", sid));
376 if(sion_filedesc->
rank<0) {
377 return(SION_NOT_SUCCESS);
381 return(_sion_errorprint(0,_SION_ERROR_RETURN,
"Error: SION_CURRENT_POS set in sion_search_key, but blovk is not SION_CURRENT_BLOCK, aborting ...\n"));
385 DPRINTFP((2, DFUNCTION, -1,
"sion_seek_key: key=%d entrynum=%d posinentry=%d\n",(
int) key,(
int) entrynum, (
int) posinentry));
386 rc=_sion_seek_key_inline(sion_filedesc, key, entrynum, posinentry);
388 return(_sion_errorprint(0,_SION_ERROR_RETURN,
"trying to search within key in keyval mode from file which is not opened in that mode, aborting ...\n"));
391 DPRINTFP((2, DFUNCTION, -1,
"leave rc=%d\n",rc));
392 DPRINTFTS(-1,
"leave sion_seek_key");
397 #define DFUNCTION "sion_get_keyval_mode"
411 DPRINTFTS(-1,
"enter sion_get_keyval_mode");
412 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
416 return(_sion_errorprint(
SION_KEYVAL_UNKNOWN,_SION_ERROR_RETURN,
"invalid sion_filedesc, aborting %d ...\n", sid));
421 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
422 DPRINTFTS(-1,
"leave sion_get_keyval_mode");
428 #define DFUNCTION "sion_keyval_type_to_str"
429 #define STR_PRT(X) case X: return # X
452 #define DFUNCTION "sion_key_list_iterator_reset"
462 size_t rc=SION_NOT_SUCCESS;
465 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
469 return(_sion_errorprint(0,_SION_ERROR_RETURN,
"invalid sion_filedesc, aborting %d ...\n", sid));
471 if(sion_filedesc->
rank<0) {
472 return(SION_NOT_SUCCESS);
476 rc=_sion_key_list_iterator_reset_inline(sion_filedesc);
478 return(_sion_errorprint(0,_SION_ERROR_RETURN,
"trying to reset iterator in keyval mode from file which is not opened in that mode, aborting ...\n"));
481 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
486 #define DFUNCTION "sion_key_list_iterator_next"
497 size_t rc=SION_NOT_SUCCESS;
500 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
504 return(_sion_errorprint(0,_SION_ERROR_RETURN,
"invalid sion_filedesc, aborting %d ...\n", sid));
506 if(sion_filedesc->
rank<0) {
507 return(SION_NOT_SUCCESS);
510 rc=_sion_key_list_iterator_next_inline(sion_filedesc, keyptr);
511 DPRINTFP((2, DFUNCTION, -1,
"sion_fread_key_iterator_next: key=%d\n",(
int) *keyptr));
513 return(_sion_errorprint(0,_SION_ERROR_RETURN,
"trying to forward iterator in keyval mode from file which is not opened in that mode, aborting ...\n"));
516 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
521 #define DFUNCTION "sion_key_get_stat"
533 size_t rc=SION_NOT_SUCCESS;
536 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
540 return(_sion_errorprint(0,_SION_ERROR_RETURN,
"invalid sion_filedesc, aborting %d ...\n", sid));
542 if(sion_filedesc->
rank<0) {
543 return(SION_NOT_SUCCESS);
546 rc=_sion_key_get_stat_inline(sion_filedesc, key, keystatptr);
547 DPRINTFP((2, DFUNCTION, -1,
"_sion_key_get_stat_inline: key=%d rc=%d\n",(
int) key, rc));
549 return(_sion_errorprint(0,_SION_ERROR_RETURN,
"trying to get stat of key from file which is not opened in that mode, aborting ...\n"));
552 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
561 #define DFUNCTION "_sion_store_and_write_key_and_len"
562 int _sion_store_and_write_key_and_len(
_sion_filedesc *sion_filedesc, uint64_t key,
size_t len) {
564 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
567 rc=_sion_store_and_write_key_and_len_inline(sion_filedesc,key,len);
569 return(_sion_errorprint(0,_SION_ERROR_RETURN,
"trying to write in keyval mode from file which is not opened in that mode, aborting ...\n"));
572 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
577 #define DFUNCTION "_sion_write_value"
578 int _sion_write_value(
_sion_filedesc *sion_filedesc,
const void *data, uint64_t key,
size_t len) {
580 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
583 rc=_sion_write_value_inline(sion_filedesc,data,key,len);
585 return(_sion_errorprint(0,_SION_ERROR_RETURN,
"trying to read in keyval mode from file which is not opened in that mode, aborting ...\n"));
588 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
593 #define DFUNCTION "_sion_find_and_read_key_and_len"
594 int _sion_find_and_read_key_and_len(
_sion_filedesc *sion_filedesc, uint64_t key,
size_t len,
size_t *datalen) {
595 int rc = SION_NOT_SUCCESS;
596 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
599 rc=_sion_find_and_read_key_and_len_inline(sion_filedesc, key, len, datalen);
601 return(_sion_errorprint(0,_SION_ERROR_RETURN,
"trying to read in keyval mode from file which is not opened in that mode, aborting ...\n"));
604 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
609 #define DFUNCTION "_sion_read_value"
610 int _sion_read_value(
_sion_filedesc *sion_filedesc,
void *data, uint64_t key,
size_t len) {
612 DPRINTFP((2, DFUNCTION, -1,
"enter\n"));
615 rc=_sion_read_value_inline(sion_filedesc,data,key,len);
617 return(_sion_errorprint(0,_SION_ERROR_RETURN,
"trying to read in keyval mode from file which is not opened in that mode, aborting ...\n"));
620 DPRINTFP((2, DFUNCTION, -1,
"leave\n"));
char * sion_keyval_type_to_str(int type)
Returns key value mode as string.
size_t sion_fwrite_key(const void *data, uint64_t key, size_t size, size_t nitems, int sid)
Writes data for key.
int sion_seek_key(int sid, uint64_t key, int entrynum, sion_int64 posinentry)
Seek to position in key.
int sion_get_keyval_mode(int sid)
Return selected mode for key value.
int sion_key_list_iterator_reset(int sid)
Resets key iterator.
int sion_key_full_scan(int sid)
Performs a full scan of all meta data in current file.
size_t sion_fread_key(void *data, uint64_t key, size_t size, size_t nitems, int sid)
Read data for key.
int sion_fread_key_iterator_reset(int sid)
Resets key iterator.
int sion_key_list_iterator_next(int sid, uint64_t *keyptr)
Forward to next key.
int sion_key_get_stat(int sid, uint64_t key, sion_key_stat_t *keystatptr)
get statistics about key
int sion_fread_key_iterator_next(int sid, uint64_t *keyptr, size_t *sizeptr)
Forward to next key.
#define SION_KEYVAL_INLINE
#define SION_KEYVAL_UNKNOWN
#define SION_KEYVAL_NOTSET
#define SION_CURRENT_BLOCK
void * _sion_vcdtovcon(int sid)
int _sion_vcdtype(int sid)
#define SION_FILEDESCRIPTOR
char * _sion_getenv(const char *name)
Sion File Descriptor Structure.