Beispiel #1
0
static void make_meta(lua_State* L)
{
    static const luaL_Reg conn_methods[] =
    {
        { "__gc", conn_gc },
        { "__tostring", conn_tostring },
        { "setCharset", conn_set_charset },
        { "setReconnect", conn_set_reconnect },
        { "setConnectTimeout", conn_set_connect_timeout },
        { "setWriteTimeout", conn_set_write_timeout },
        { "setReadTimeout", conn_set_read_timeout },
        { "setProtocol", conn_set_protocol },
        { "setCompress", conn_set_compress },
        { "escape", conn_escape_string },
        { "connect", conn_connect },
        { "ping", conn_ping },
        { "close", conn_close },
        { "execute", conn_execute },
        { "commit", conn_commit },
        { "rollback", conn_rollback },
        { NULL, NULL },
    };

    static const luaL_Reg cursor_methods[] =
    {
        { "__gc", cursor_gc },
        { "fetch", cursor_fetch },
        { "fetchAll", cursor_fetch_all },
        { "numrows", cursor_numrows },
        { NULL, NULL },
    };

    create_meta(L, LUAMYSQL_CONN, conn_methods);
    create_meta(L, LUAMYSQL_CURSOR, cursor_methods);
}
Beispiel #2
0
/*
 * Open an output GIF file.
 */
    int
GIFmoOpen(WS_STATE_PTR ws)
{
  /* Output file not opened or written to until flushed */

    Gint status = 1;
    initLogFlag();
    assert(ws != NULL);
    assert(ws->wscolour <= gdMaxColors);
    if ((ws->mf.cgmo = (mf_cgmo*)umalloc(sizeof(mf_cgmo))) != NULL) {
	mf_cgmo	*cgmo	= ws->mf.cgmo;
	cgmo->ws = ws;

	if (find_meta(cgmo) != 0){
	  msgWarn("GIFmoOpen:metafile already open\n");
	} else {
	  create_meta(cgmo, DefaultSize, DefaultSize);
	  
	  cgmo->ws = ws;
	  cgmo->type = MF_GIF;
	  unlink(ws->conn);
	  status = OK;
	}
    }
    return status;
}
Beispiel #3
0
//Add a <key,value> pair to the cache
//If key already exists, overwrite the old value
//If maxmem capacity is exceeded, values will be removed
void cache_set(cache_t cache, _key_t key, val_t val, uint32_t val_size)
{
  cache_real_obj *c = cache->cache;

  //Delete the value if it's already in the cache.
  meta_t old = get_key_loc(cache,key);
  if (old != NULL) cache_delete(cache, key);

  uint64_t available_memory = cache->cache->size - cache_space_used(cache);
  printf("Trying to add a value of size %"PRIu32", with available memory %"PRIu64"\n",val_size,available_memory);
  if (available_memory < val_size)
    {
      printf("   Increasing size.\n");
      defrag(cache, 1); //This doubles the cache size (defragmenting at the same time).
    }
  bucket_timer_up(cache);
  //Create a new meta object and pair it to a slab address, and copy the value over
  meta_t next_meta = create_meta(cache,key,val_size);
  next_meta->address = get_address(c->slab_manager,val_size);
  //enact eviction policy if we need space
  if (next_meta->address == NULL){
    uint32_t val_slab_class = get_slab_class(c->slab_manager, val_size);
    cache_evict(cache, val_slab_class);
    next_meta->address = get_address(c->slab_manager,val_size);
    if (next_meta->address == NULL){
      uint32_t slab_class = get_slab_class(c->slab_manager, val_size);
      printf("Couldn't add a %u-%u byte value because there are no slabs of that range, and no free slabs to be allocated\n",slab_class>>1, slab_class);
      free(next_meta);
      return;
    }
Beispiel #4
0
/*
 * Read metadata block from disk, possibly create it if it does not exist and
 * and open flags allow
 */
static int read_meta(TEE_Result *errno, struct sql_fs_fd *fdp)
{
	size_t msize = meta_size();
	size_t out_size = sizeof(fdp->meta);
	uint8_t *meta = NULL;
	int rc = -1;

	*errno = TEE_ERROR_GENERIC;

	meta = malloc(msize);
	if (!meta) {
		*errno = TEE_ERROR_OUT_OF_MEMORY;
		goto exit;
	}

	rc = tee_fs_rpc_lseek(OPTEE_MSG_RPC_CMD_SQL_FS, fdp->fd, 0,
			      TEE_FS_SEEK_SET);
	if (rc < 0)
		goto exit;

	rc = sql_fs_read_rpc(fdp->fd, meta, msize);
	if (rc < 0) {
		/* Read error */
		goto exit;
	} else if (rc == 0) {
		/* No meta data on disk yet */
		if (!(fdp->flags & TEE_FS_O_CREATE))
			goto exit;
		rc = create_meta(errno, fdp);
	} else if (rc == (int)msize) {
#ifdef CFG_ENC_FS
		TEE_Result res;

		res = tee_fs_decrypt_file(META_FILE, meta, msize,
					  (uint8_t *)&fdp->meta, &out_size,
					  fdp->encrypted_fek);
		if (res != TEE_SUCCESS) {
			*errno = res;
			rc = -1;
			goto exit;
		}
#else
		memcpy((uint8_t *)&fdp->meta,
		       meta + tee_fs_get_header_size(META_FILE),
		       out_size);
#endif
		rc = 0;
	} else {
		/* Unexpected data length */
		rc = -1;
	}
exit:
	free(meta);
	return rc;
}