Beispiel #1
0
static int
xfs_fsal_inode2handle(int fd, ino_t ino, vfs_file_handle_t *fh)
{
	xfs_bstat_t bstat;
	struct xfs_filehandle hdl;
        void *data, *fhdata;
        size_t sz, fhsz;
        int rv;

        if(fh->handle_bytes < sizeof(hdl)) {
                errno = E2BIG;
                return -1;
        }
	if((xfs_fsal_bulkstat_inode(fd, ino, &bstat) < 0) ||
           (fd_to_handle(fd, &data, &sz) < 0))
		return -1;

        if ((rv = handle_to_fshandle(data, sz, &fhdata, &fhsz)) >= 0) {
                memset(&hdl, 0, sizeof(hdl));
                memcpy(&hdl.fh_fshdl, fhdata, fhsz);
                hdl.fh_sz_following = XFS_FILEHANDLE_SZ_FOLLOWING;
                hdl.fh_gen = bstat.bs_gen;
                hdl.fh_ino = bstat.bs_ino;

                memcpy(fh->handle, &hdl, sizeof(hdl));
                fh->handle_bytes = sizeof(hdl);
                free_handle(fhdata, fhsz);
        }

        free_handle(data, sz);
	return rv;
}
void oz_knl_handle_release_all (OZ_Thread *thread, OZ_Procmode procmode)

{
  Handleent *he;
  Long refc;
  OZ_Handle hi;
  OZ_Handletbl *handletbl;
  void *object;

  handletbl = OZ_SYS_PDATA_FROM_KNL (OZ_PROCMODE_KNL) -> handletbl;
  OZ_KNL_CHKOBJTYPE (handletbl, OZ_OBJTYPE_HANDLETBL);

  if (handletbl == NULL) return;					/* maybe this is the cleanupproc thread - there is no table */
  if (thread == NULL) thread = oz_knl_thread_getcur ();			/* default to current thread */

  LOCKTABLE_EX (handletbl);
  for (hi = 0; ++ hi <= handletbl -> curmask;) {
    he = handletbl -> ents + hi;					/* point to entry in question */
    if (he -> procmode < procmode) continue;				/* make sure processor mode allows access */
    if (he -> thread != thread) continue;				/* make sure it was assigned by given thread */
    refc = oz_hw_atomic_and_long (&(he -> refcount), -2);		/* release if not already */
    if (refc == 1) {
      object = free_handle (handletbl, hi);				/* wasn't already released, free entry */
      UNLOCKTABLE_EX (handletbl);
      OBJINCREFC (OZ_KNL_GETOBJTYPE (object), object, -1);
      LOCKTABLE_EX (handletbl);
    }
  }
  UNLOCKTABLE_EX (handletbl);
}
Beispiel #3
0
fsal_status_t fsal_internal_fd2handle(xfsfsal_op_context_t * p_context,
                                      int fd, xfsfsal_handle_t * phandle)
{
  int rc = 0;
  struct stat ino;

  char *handle_val;
  size_t handle_len;

  if(!phandle)
    ReturnCode(ERR_FSAL_FAULT, 0);

  memset(phandle, 0, sizeof(xfsfsal_handle_t));

  /* retrieve inode */
  rc = fstat(fd, &ino);
  if(rc)
    ReturnCode(posix2fsal_error(errno), errno);
  phandle->data.inode = ino.st_ino;
  phandle->data.type = DT_UNKNOWN;  /** Put here something smarter */

  if((rc = fd_to_handle(fd, (void **)(&handle_val), &handle_len)) < 0)
    ReturnCode(posix2fsal_error(errno), errno);

  memcpy(phandle->data.handle_val, handle_val, handle_len);
  phandle->data.handle_len = handle_len;

  free_handle(handle_val, handle_len);

  ReturnCode(ERR_FSAL_NO_ERROR, 0);
}                               /* fsal_internal_fd2handle */
void oz_knl_handle_putback (OZ_Handle handle)

{
  Handleent *he;
  Long refc;
  OZ_Handle hi;
  OZ_Handletbl *handletbl;
  void *object;

  handletbl = OZ_SYS_PDATA_FROM_KNL (OZ_PROCMODE_KNL) -> handletbl;
  OZ_KNL_CHKOBJTYPE (handletbl, OZ_OBJTYPE_HANDLETBL);

  LOCKTABLE_SH (handletbl);					/* lock the handle table */
  hi = handle & handletbl -> curmask;				/* get handle's index in table */
  he = handletbl -> ents + hi;					/* point to entry in question */
  refc = atomic_inc_long (&(he -> refcount), -2);		/* decrement ref count, leave bit <00> alone */
  UNLOCKTABLE_SH (handletbl);					/* unlock the handle table */
  if (refc <= 0) {						/* see if handle needs to be freed off */
    if (refc < 0) oz_crash ("oz_knl_handle_putback: he %p -> refcount %d", he, refc);
    LOCKTABLE_EX (handletbl);					/* if so, get exclusive access to table */
    hi = handle & handletbl -> curmask;				/* point to entry again (it may have moved) */
    he = handletbl -> ents + hi;
    object = free_handle (handletbl, hi);			/* release the entry */
    UNLOCKTABLE_EX (handletbl);
    OBJINCREFC (OZ_KNL_GETOBJTYPE (object), object, -1);	/* release object pointer */
  }
}
status_t GraphicBuffer::unflatten(
        void const*& buffer, size_t& size, int const*& fds, size_t& count) {
    if (size < 8*sizeof(int)) return NO_MEMORY;

    int const* buf = static_cast<int const*>(buffer);
    if (buf[0] != 'GBFR') return BAD_TYPE;

    const size_t numFds  = buf[6];
    const size_t numInts = buf[7];

    const size_t sizeNeeded = (8 + numInts) * sizeof(int);
    if (size < sizeNeeded) return NO_MEMORY;

    size_t fdCountNeeded = 0;
    if (count < fdCountNeeded) return NO_MEMORY;

    if (handle) {
        // free previous handle if any
        free_handle();
    }

    if (numFds || numInts) {
        width  = buf[1];
        height = buf[2];
        stride = buf[3];
        format = buf[4];
        usage  = buf[5];
        native_handle* h = native_handle_create(numFds, numInts);
        memcpy(h->data,          fds,     numFds*sizeof(int));
        memcpy(h->data + numFds, &buf[8], numInts*sizeof(int));
        handle = h;
#ifndef MTK_DEFAULT_AOSP
        ALOGD("create handle(%p) (w:%d, h:%d, f:%d)",
            handle, stride, height, format);
#endif
    } else {
        width = height = stride = format = usage = 0;
        handle = NULL;
    }

    mOwner = ownHandle;

    if (handle != 0) {
        status_t err = mBufferMapper.registerBuffer(handle);
        if (err != NO_ERROR) {
            width = height = stride = format = usage = 0;
            handle = NULL;
            ALOGE("unflatten: registerBuffer failed: %s (%d)",
                    strerror(-err), err);
            return err;
        }
    }

    buffer = reinterpret_cast<void const*>(static_cast<int const*>(buffer) + sizeNeeded);
    size -= sizeNeeded;
    fds += numFds;
    count -= numFds;

    return NO_ERROR;
}
uLong oz_knl_handle_release (OZ_Handle handle, OZ_Procmode procmode)

{
  Handleent *he;
  Long refc;
  OZ_Handletbl *handletbl;
  uLong sts;
  void *object;

  handletbl = OZ_SYS_PDATA_FROM_KNL (OZ_PROCMODE_KNL) -> handletbl;
  OZ_KNL_CHKOBJTYPE (handletbl, OZ_OBJTYPE_HANDLETBL);

  object = NULL;								// assume entry is in use by someone
  LOCKTABLE_EX (handletbl);							// get exclusive access to table so we can call free_handle
  sts = find_handle (handletbl, handle, procmode, &he);				// find entry to be released
  if (sts == OZ_SUCCESS) {
    refc = atomic_inc_long (&(he -> refcount), -1);				// if found, clear the assigned bit (refcount<00>)
    if (refc == 0) {								// check for all references gone
      object = free_handle (handletbl, handle & handletbl -> curmask);		// if so, free the entry off and get object pointer
    }
  }
  UNLOCKTABLE_EX (handletbl);							// unlock table
  if (object != NULL) {
    OBJINCREFC (OZ_KNL_GETOBJTYPE (object), object, -1);			// if we actually freed the entry, release object pointer
  }
  return (sts);
}
Beispiel #7
0
static void
on_handle_dealloc_close(uv_handle_t *handle)
{
    PyGILState_STATE gstate = PyGILState_Ensure();

    free_handle(handle);

    PyGILState_Release(gstate);
}
Beispiel #8
0
/* Decrements HANDLE's reference count.
   If the reference count drops to 0, HANDLE is destroyed. */
void
fh_unref (struct file_handle *handle)
{
  if (handle != NULL)
    {
      assert (handle->ref_cnt > 0);
      if (--handle->ref_cnt == 0)
        free_handle (handle);
    }
}
Beispiel #9
0
int sqlcli( int aArg1 )
{
    SQLRETURN    rc;


    SQLHENV  env;  // Environment Handle
    SQLHDBC  dbc;  // Connection Handle
    int      conn_flag;

    env = SQL_NULL_HENV;
    dbc = SQL_NULL_HDBC;
    conn_flag = 0;

    /* allocate handle */
    rc = alloc_handle(env, dbc);
    if ( rc != SQL_SUCCESS )
    {
        free_handle(env, dbc, conn_flag);
        exit(1);
    }

    /* Connect to Altibase Server */
    rc = db_connect(dbc, conn_flag);
    if ( rc != SQL_SUCCESS )
    {
        free_handle(env, dbc, conn_flag);
        exit(1);
    }

    /* select data */
    rc = execute_select(dbc);
    if ( rc != SQL_SUCCESS )
    {
        free_handle(env, dbc, conn_flag);
        exit(1);
    }

    /* disconnect, free handles */
    free_handle(env, dbc, conn_flag);
}
status_t GraphicBuffer::unflatten(void const* buffer, size_t size,
        int fds[], size_t count)
{
    if (size < 8*sizeof(int)) return NO_MEMORY;

    int const* buf = static_cast<int const*>(buffer);
    if (buf[0] != 'GBFR') return BAD_TYPE;

    const size_t numFds  = buf[6];
    const size_t numInts = buf[7];

    const size_t sizeNeeded = (8 + numInts) * sizeof(int);
    if (size < sizeNeeded) return NO_MEMORY;

    size_t fdCountNeeded = 0;
    if (count < fdCountNeeded) return NO_MEMORY;

    if (handle) {
        // free previous handle if any
        free_handle();
    }

    if (numFds || numInts) {
        width  = buf[1];
        height = buf[2];
        stride = buf[3];
        format = buf[4];
        usage  = buf[5];
        native_handle* h = native_handle_create(numFds, numInts);
        memcpy(h->data,          fds,     numFds*sizeof(int));
        memcpy(h->data + numFds, &buf[8], numInts*sizeof(int));
        handle = h;
    } else {
        width = height = stride = format = usage = 0;
        handle = NULL;
    }

    mOwner = ownHandle;

    if (handle != 0) {
        status_t err = mBufferMapper.registerBuffer(handle);
        if (err != NO_ERROR) {
            width = height = stride = format = usage = 0;
            handle = NULL;
            ALOGE("unflatten: registerBuffer failed: %s (%d)",
                    strerror(-err), err);
            return err;
        }
    }

    return NO_ERROR;
}
Beispiel #11
0
struct vfs_exp_handle_ops *
get_handle_ops(char *mntdir)
{
        void *data;
        size_t sz;

        /* This is a secret handshake which libhandle requires to
         * make sure open_by_handle will work */
        if(path_to_fshandle(mntdir, &data, &sz) < 0)
                return NULL;
        free_handle(data, sz);

        return &xfs_ops;
}
Beispiel #12
0
void destroy_handles(void){
	ul_db_handle_list_t * element, * del;
	int i;
	element = db_handles;
	while(element){
		for(i=0; i<DB_NUM; i++){
			if(element->handle->db[i].dbh){
				element->handle->db[i].dbf.close(element->handle->db[i].dbh);
				element->handle->db[i].dbh = NULL;
			}
		}
		del = element;
		element = element->next;
		free_handle(del);
	}
}
Beispiel #13
0
static int __ocmem_free(int id, struct ocmem_buf *buf)
{
	int ret = 0;
	struct ocmem_handle *handle = buffer_to_handle(buf);

	if (!handle)
		return -EINVAL;

	mutex_lock(&handle->handle_mutex);
	ret = process_free(id, handle);
	mutex_unlock(&handle->handle_mutex);

	if (ret)
		return -EINVAL;

	free_handle(handle);
	return 0;
}
Beispiel #14
0
static void
Handle_tp_dealloc(Handle *self)
{
    ASSERT(self->uv_handle);
    self->uv_handle->data = NULL;
    if (self->initialized && !uv_is_closing(self->uv_handle)) {
        uv_close(self->uv_handle, on_handle_dealloc_close);
    } else {
        /* Refcount is increased in close(), so it's guaranteed that if we arrived here and the user had called close(),
         * the callback was already executed and it's safe to free the handle */
        free_handle(self->uv_handle);
    }
    if (self->weakreflist != NULL) {
        PyObject_ClearWeakRefs((PyObject *)self);
    }
    Py_TYPE(self)->tp_clear((PyObject *)self);
    Py_TYPE(self)->tp_free((PyObject *)self);
}
Beispiel #15
0
Datei: open.c Projekt: lb1a/avfs
static int virt_close(int fd, int undersc)
{
    int res;

    if(!FD_OK(fd) || !ISVIRTUAL(fd))
        res =  real_close(fd, undersc);
    else {
        int errnosave = errno;
        res = cmd_close(SERVERFH(fd));
        real_close(__av_dtable[fd].holderfd, 1);
        free_handle(fd);
        if(res < 0) 
            errno = -res, res = -1;
        else
            errno = errnosave;
    }

    return res;
}
END_TEST

START_TEST (test_handle)
{
    OMX_ERRORTYPE omx_error;
    OMX_HANDLETYPE omx_handle;

    omx_error = init ();
    fail_if (omx_error != OMX_ErrorNone);

    omx_error = get_handle (&omx_handle, "OMX.check.dummy", NULL, NULL);
    fail_if (omx_error != OMX_ErrorNone);

    omx_error = free_handle (omx_handle);
    fail_if (omx_error != OMX_ErrorNone);

    omx_error = deinit ();
    fail_if (omx_error != OMX_ErrorNone);
}
Beispiel #17
0
extern hsm_fs_ctxt_t *
HsmInitFsysContext(
const	char		*mountpoint,
	int		dumpversion)
{
	dmf_fs_ctxt_t	*dmf_fs_ctxtp;
	void		*fshanp;
	size_t		fshlen;
	dm_fsid_t	fsid;
	int		error;

	if (dumpversion != HSM_API_VERSION_1) {
		return NULL;		/* we can't handle this version */
	}

	/* Get the filesystem's DMAPI fsid for later use in building file
	   handles in HsmInitFileContext.  We use path_to_handle() because
	   dm_path_to_handle() doesn't work if the filesystem isn't mounted
	   with -o dmi.
	*/

	if (path_to_fshandle((char *)mountpoint, &fshanp, &fshlen)) {
		return NULL;
	}
	error = dm_handle_to_fsid(fshanp, fshlen, &fsid);
	free_handle(fshanp, fshlen);
	if (error) {
		return NULL;
	}

	/* Malloc space for a filesystem context, and initialize any fields
	   needed later by other routines.
	*/

	if ((dmf_fs_ctxtp = malloc(sizeof(dmf_fs_ctxt_t))) == NULL) {
		return NULL;
	}
	dmf_fs_ctxtp->dumpversion = dumpversion;
	dmf_fs_ctxtp->fsid = fsid;

	return (hsm_fs_ctxt_t *)dmf_fs_ctxtp;
}
Beispiel #18
0
static int
vfs_xfs_fd_to_handle(int fd, vfs_file_handle_t *fh)
{
        void *data;
        size_t sz;
        int rv = 0;

        if (fd_to_handle(fd, &data, &sz) < 0)
                return -1;

        if (sz >= fh->handle_bytes) {
                errno = E2BIG;
                rv = -1;
        } else {
                memcpy(fh->handle, data, sz);
                fh->handle_bytes = sz;
        }
        free_handle(data, sz);
        return rv;
}
Beispiel #19
0
status_t GraphicBuffer::unflatten(void const* buffer, size_t size,
        int fds[], size_t count)
{
    if (size < kFlattenFdsOffset*sizeof(int)) return NO_MEMORY;

    int const* buf = static_cast<int const*>(buffer);
    if (buf[0] != 'GBFR') return BAD_TYPE;

    const size_t numFds  = buf[6];
    const size_t numInts = buf[7];

    const size_t sizeNeeded = (kFlattenFdsOffset + numInts) * sizeof(int);
    if (size < sizeNeeded) return NO_MEMORY;

    size_t fdCountNeeded = 0;
    if (count < fdCountNeeded) return NO_MEMORY;

    if (handle) {
        // free previous handle if any
        free_handle();
    }

    if (numFds || numInts) {
        width  = buf[1];
        height = buf[2];
        stride = buf[3];
        format = buf[4];
        usage  = buf[5];
        transform = buf[8];
        native_handle* h = native_handle_create(numFds, numInts);
        memcpy(h->data,          fds,     numFds*sizeof(int));
        memcpy(h->data + numFds, &buf[kFlattenFdsOffset], numInts*sizeof(int));
        handle = h;
    } else {
        width = height = stride = format = usage = 0;
        handle = NULL;
    }

    mOwner = ownHandle;
    return NO_ERROR;
}
Beispiel #20
0
static struct ocmem_buf *__ocmem_allocate_range(int id, unsigned long min,
		unsigned long max, unsigned long step, bool block, bool wait)
{
	struct ocmem_handle *handle = NULL;
	int ret = 0;

	handle = generate_handle();
	if (!handle) {
		pr_err("ocmem: Unable to generate handle\n");
		return NULL;
	}

	mutex_lock(&handle->handle_mutex);
	ret = process_allocate(id, handle, min, max, step, block, wait);
	mutex_unlock(&handle->handle_mutex);
	if (ret) {
		pr_err("ocmem allocation failed\n");
		free_handle(handle);
		return NULL;
	} else
		return handle_to_buffer(handle);
}
Beispiel #21
0
int vfs_fd_to_handle(int fd, struct fsal_filesystem *fs,
		     vfs_file_handle_t *fh)
{
	void *data;
	size_t sz;
	int rv = 0;

	if (fd_to_handle(fd, &data, &sz) < 0)
		return -1;

	if (sz >= fh->handle_len) {
		errno = E2BIG;
		rv = -1;
	} else {
		memcpy(fh->handle_data, data, sz);
		fh->handle_len = sz;

		LogXFSHandle(fh);
	}
	free_handle(data, sz);
	return rv;
}
END_TEST

START_TEST (test_idle)
{
    CustomData *custom_data;
    OMX_ERRORTYPE omx_error;
    OMX_HANDLETYPE omx_handle;

    custom_data = custom_data_new ();

    omx_error = init ();
    fail_if (omx_error != OMX_ErrorNone);

    omx_error = get_handle (&omx_handle, "OMX.check.dummy", custom_data, &callbacks);
    fail_if (omx_error != OMX_ErrorNone);

    custom_data->omx_handle = omx_handle;

    change_state (custom_data, OMX_StateIdle);

    /* allocate_buffers */

    wait_for_state (custom_data, OMX_StateIdle);

    change_state (custom_data, OMX_StateLoaded);

    /* free_buffers */

    wait_for_state (custom_data, OMX_StateLoaded);

    omx_error = free_handle (omx_handle);
    fail_if (omx_error != OMX_ErrorNone);

    omx_error = deinit ();
    fail_if (omx_error != OMX_ErrorNone);

    custom_data_free (custom_data);
}
Beispiel #23
0
static int xfs_fsal_inode2handle(int fd, ino_t ino, vfs_file_handle_t *fh)
{
	xfs_bstat_t bstat;
	xfs_handle_t *hdl = (xfs_handle_t *) fh->handle_data;
	void *data;
	size_t sz;

	if (fh->handle_len < sizeof(*hdl)) {
		errno = E2BIG;
		return -1;
	}

	/* Get the information pertinent to this inode, and
	 * the file handle for the reference fd.
	 */
	if ((xfs_fsal_bulkstat_inode(fd, ino, &bstat) < 0) ||
	    (fd_to_handle(fd, &data, &sz) < 0))
		return -1;

	/* Copy the fsid from the reference fd */
	memcpy(&hdl->ha_fsid, data, sizeof(xfs_fsid_t));

	/* Fill in the rest of the handle with the information
	 * pertinent to this inode.
	 */
	hdl->ha_fid.fid_len = sizeof(xfs_handle_t) -
			      sizeof(xfs_fsid_t) -
			      sizeof(hdl->ha_fid.fid_len);
	hdl->ha_fid.fid_pad = 0;
	hdl->ha_fid.fid_gen = bstat.bs_gen;
	hdl->ha_fid.fid_ino = bstat.bs_ino;

	fh->handle_len = sizeof(*hdl);

	free_handle(data, sz);
	return 0;
}
Beispiel #24
0
void StdRedirects::close() noexcept
{
    free_handle(m_handleOwned[REDIR_STDIN]);
    free_handle(m_handleOwned[REDIR_STDOUT]);
    free_handle(m_handleOwned[REDIR_STDERR]);
}
Beispiel #25
0
		Registration::~Registration()
		{
			free_handle(_handle);
		}
GraphicBuffer::~GraphicBuffer()
{
    if (handle) {
        free_handle();
    }
}