/* * pocli_pmemobj_do_tx_alloc -- pmemobj_tx_zalloc() and pmemobj_tx_zalloc() * commands common part */ static enum pocli_ret pocli_pmemobj_do_tx_alloc(struct pocli_ctx *ctx, struct pocli_args *args, PMEMoid (*fn_alloc)(size_t size, uint64_t type_num)) { if (args->argc != 4) return POCLI_ERR_ARGS; if (pmemobj_tx_stage() != TX_STAGE_WORK) return pocli_err(ctx, POCLI_ERR_ARGS, "cannot use in stage different than TX_STAGE_WORK\n"); PMEMoid *oidp = NULL; uint64_t type_num = 0; size_t size = 0; enum pocli_ret ret; ret = pocli_args_obj(ctx, args, 1, &oidp); if (ret) return ret; if (oidp == &ctx->root) return pocli_err(ctx, POCLI_ERR_ARGS, "cannot allocate to root object\n"); ret = pocli_args_size(args, 2, &size); if (ret) return ret; ret = pocli_args_number(args, 3, &type_num); if (ret) return ret; *oidp = fn_alloc(size, type_num); pocli_printf(ctx, "%s(%zu, %llu): off = 0x%llx uuid = 0x%llx\n", args->argv[0], size, type_num, oidp->off, oidp->pool_uuid_lo); return ret; }
/* * pocli_pmemobj_do_alloc -- pmemobj_alloc and pmemobj_zalloc() common part */ static enum pocli_ret pocli_pmemobj_do_alloc(struct pocli_ctx *ctx, struct pocli_args *args, int (fn_alloc)(PMEMobjpool *pop, PMEMoid *oid, size_t size, uint64_t type_num)) { if (args->argc != 4) return POCLI_ERR_ARGS; PMEMoid *oidp = NULL; uint64_t type_num = 0; size_t size = 0; enum pocli_ret ret; ret = pocli_args_obj(ctx, args, 1, &oidp); if (ret) return ret; if (oidp == &ctx->root) return pocli_err(ctx, POCLI_ERR_ARGS, "cannot allocate to root object\n"); ret = pocli_args_number(args, 2, &type_num); if (ret) return ret; ret = pocli_args_size(args, 3, &size); if (ret) return ret; int r = fn_alloc(ctx->pop, oidp, size, type_num); pocli_printf(ctx, "%s(%s, %zu, %llu): %d\n", args->argv[0], args->argv[1], size, type_num, r); return ret; }
vi_rc ReadDataFile( char *file, char **buffer, bool (*fn_alloc)( int ), bool (*fn_save)( int, char* ), bool bounddata ) #endif { GENERIC_FILE gf; int i, dcnt, len, size; char token[MAX_STR], buff[MAX_STR]; char *buffdata; bool hasvals; /* * get file and buffer */ #ifdef VICOMP if( !SpecialOpen( file, &gf ) ) { #else if( !SpecialOpen( file, &gf, bounddata ) ) { #endif return( ERR_FILE_NOT_FOUND ); } /* * get counts */ if( SpecialFgets( buff, MAX_STR - 1, &gf ) < 0 ) { SpecialFclose( &gf ); return( ERR_INVALID_DATA_FILE ); } dcnt = atoi( buff ); hasvals = fn_alloc( dcnt ); buffdata = NULL; size = 0; /* * read all tokens */ for( i = 0; i < dcnt; i++ ) { len = SpecialFgets( buff, sizeof( buff ) - 1, &gf ); if( len < 0 ) { SpecialFclose( &gf ); return( ERR_INVALID_DATA_FILE ); } if( hasvals ) { len = NextWord1( buff, token ); if( len <= 0 ) { SpecialFclose( &gf ); return( ERR_INVALID_DATA_FILE ); } } else { memcpy( token, buff, len + 1 ); } len++; buffdata = MemReAlloc( buffdata, size + len + 1 ); memcpy( &buffdata[size], token, len ); size += len; buffdata[size] = 0; if( hasvals ) { if( NextWord1( buff, token ) <= 0 ) { SpecialFclose( &gf ); return( ERR_INVALID_DATA_FILE ); } fn_save( i, token ); } } SpecialFclose( &gf ); *buffer = buffdata; return( ERR_NO_ERR ); } /* ReadDataFile */