/* API: Initialize the audio device parameters with default values for the * specified device. */ PJ_DEF(pj_status_t) pjmedia_aud_dev_default_param(pjmedia_aud_dev_index id, pjmedia_aud_param *param) { pjmedia_aud_dev_factory *f; unsigned index; pj_status_t status; PJ_ASSERT_RETURN(param && id!=PJMEDIA_AUD_INVALID_DEV, PJ_EINVAL); //PJ_ASSERT_RETURN(aud_subsys.pf, PJMEDIA_EAUD_INIT); // DEAN don't assertion if (!aud_subsys.pf) return PJMEDIA_EAUD_INIT; status = lookup_dev(id, &f, &index); if (status != PJ_SUCCESS) return status; status = f->op->default_param(f, index, param); if (status != PJ_SUCCESS) return status; /* Normalize device IDs */ make_global_index(f->sys.drv_idx, ¶m->rec_id); make_global_index(f->sys.drv_idx, ¶m->play_id); return PJ_SUCCESS; }
/* API: Get device information. */ PJ_DEF(pj_status_t) pjmedia_vid_dev_get_info(pjmedia_vid_dev_index id, pjmedia_vid_dev_info *info) { pjmedia_vid_dev_factory *f; unsigned index; pj_status_t status; PJ_ASSERT_RETURN(info, PJ_EINVAL); PJ_ASSERT_RETURN(vid_subsys.pf, PJMEDIA_EVID_INIT); if (id <= PJMEDIA_VID_INVALID_DEV) return PJMEDIA_EVID_INVDEV; status = lookup_dev(id, &f, &index); if (status != PJ_SUCCESS) return status; status = f->op->get_dev_info(f, index, info); /* Make sure device ID is the real ID (not PJMEDIA_VID_DEFAULT_*_DEV) */ info->id = index; make_global_index(f->sys.drv_idx, &info->id); return status; }
void * acc_hostptr (void *d) { splay_tree_key n; void *h; void *offset; goacc_lazy_initialize (); struct goacc_thread *thr = goacc_thread (); struct gomp_device_descr *acc_dev = thr->dev; if (thr->dev->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM) return d; gomp_mutex_lock (&acc_dev->lock); n = lookup_dev (acc_dev->openacc.data_environ, d, 1); if (!n) { gomp_mutex_unlock (&acc_dev->lock); return NULL; } offset = d - n->tgt->tgt_start + n->tgt_offset; h = n->host_start + offset; gomp_mutex_unlock (&acc_dev->lock); return h; }
/* API: Initialize the video device parameters with default values for the * specified device. */ PJ_DEF(pj_status_t) pjmedia_vid_dev_default_param(pj_pool_t *pool, pjmedia_vid_dev_index id, pjmedia_vid_dev_param *param) { pjmedia_vid_dev_factory *f; unsigned index; pj_status_t status; PJ_ASSERT_RETURN(param, PJ_EINVAL); PJ_ASSERT_RETURN(vid_subsys.pf, PJMEDIA_EVID_INIT); if (id <= PJMEDIA_VID_INVALID_DEV) return PJMEDIA_EVID_INVDEV; status = lookup_dev(id, &f, &index); if (status != PJ_SUCCESS) return status; status = f->op->default_param(pool, f, index, param); if (status != PJ_SUCCESS) return status; /* Normalize device IDs */ make_global_index(f->sys.drv_idx, ¶m->cap_id); make_global_index(f->sys.drv_idx, ¶m->rend_id); return PJ_SUCCESS; }
/* API: Set the value of a specific capability of the video stream. */ PJ_DEF(pj_status_t) pjmedia_vid_dev_stream_set_cap( pjmedia_vid_dev_stream *strm, pjmedia_vid_dev_cap cap, const void *value) { /* For fast switching, device global index needs to be converted to * local index before forwarding the request to the device stream. */ if (cap == PJMEDIA_VID_DEV_CAP_SWITCH) { pjmedia_vid_dev_factory *f; unsigned local_idx; pj_status_t status; pjmedia_vid_dev_switch_param p = *(pjmedia_vid_dev_switch_param*)value; status = lookup_dev(p.target_id, &f, &local_idx); if (status != PJ_SUCCESS) return status; /* Make sure that current & target devices share the same factory */ if (f->sys.drv_idx != strm->sys.drv_idx) return PJMEDIA_EVID_INVDEV; p.target_id = local_idx; return strm->op->set_cap(strm, cap, &p); } return strm->op->set_cap(strm, cap, value); }
/* OpenACC 2.0a (3.2.16) doesn't specify what to do in the event the device address is mapped. We choose to check if it mapped, and if it is, to unmap it. */ void acc_free (void *d) { splay_tree_key k; if (!d) return; struct goacc_thread *thr = goacc_thread (); assert (thr && thr->dev); struct gomp_device_descr *acc_dev = thr->dev; gomp_mutex_lock (&acc_dev->lock); /* We don't have to call lazy open here, as the ptr value must have been returned by acc_malloc. It's not permitted to pass NULL in (unless you got that null from acc_malloc). */ if ((k = lookup_dev (acc_dev->openacc.data_environ, d, 1))) { void *offset; offset = d - k->tgt->tgt_start + k->tgt_offset; gomp_mutex_unlock (&acc_dev->lock); acc_unmap_data ((void *)(k->host_start + offset)); } else gomp_mutex_unlock (&acc_dev->lock); acc_dev->free_func (acc_dev->target_id, d); }
void acc_map_data (void *h, void *d, size_t s) { struct target_mem_desc *tgt; size_t mapnum = 1; void *hostaddrs = h; void *devaddrs = d; size_t sizes = s; unsigned short kinds = GOMP_MAP_ALLOC; goacc_lazy_initialize (); struct goacc_thread *thr = goacc_thread (); struct gomp_device_descr *acc_dev = thr->dev; if (acc_dev->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM) { if (d != h) gomp_fatal ("cannot map data on shared-memory system"); tgt = gomp_map_vars (NULL, 0, NULL, NULL, NULL, NULL, true, GOMP_MAP_VARS_OPENACC); } else { struct goacc_thread *thr = goacc_thread (); if (!d || !h || !s) gomp_fatal ("[%p,+%d]->[%p,+%d] is a bad map", (void *)h, (int)s, (void *)d, (int)s); gomp_mutex_lock (&acc_dev->lock); if (lookup_host (acc_dev, h, s)) { gomp_mutex_unlock (&acc_dev->lock); gomp_fatal ("host address [%p, +%d] is already mapped", (void *)h, (int)s); } if (lookup_dev (thr->dev->openacc.data_environ, d, s)) { gomp_mutex_unlock (&acc_dev->lock); gomp_fatal ("device address [%p, +%d] is already mapped", (void *)d, (int)s); } gomp_mutex_unlock (&acc_dev->lock); tgt = gomp_map_vars (acc_dev, mapnum, &hostaddrs, &devaddrs, &sizes, &kinds, true, GOMP_MAP_VARS_OPENACC); } gomp_mutex_lock (&acc_dev->lock); tgt->prev = acc_dev->openacc.data_environ; acc_dev->openacc.data_environ = tgt; gomp_mutex_unlock (&acc_dev->lock); }
static void dio_config( void ) { comedi_t *dev = lookup_dev( *sp++ ); unsigned int subdev = *sp++; unsigned int chan = *sp++; unsigned int data = *sp++; int c = comedi_dio_config( dev, subdev, chan, data ); if( c < 1 ) comedi_perror( "<dio> " ); }
int main(int argc, char *argv[]) { int i, j, nfn, fd, ret; u_int mask; ds_ioctl_arg_t arg; #if (!defined(__BEOS__) && !defined(__ANTARES__)) major = lookup_dev("pcmcia"); if (major < 0) { fprintf(stderr, "no pcmcia driver in /proc/devices\n"); exit(EXIT_FAILURE); } #endif for (i = 0; i < MAX_SOCKS; i++) { fd = open_sock(i); if (fd < 0) break; arg.tuple.TupleDataMax = sizeof(arg.tuple_parse.data); arg.tuple.Attributes = TUPLE_RETURN_COMMON; arg.tuple.DesiredTuple = CISTPL_LONGLINK_MFC; arg.tuple.TupleOffset = 0; if (ioctl(fd, DS_GET_FIRST_TUPLE, &arg) == 0) { ioctl(fd, DS_GET_TUPLE_DATA, &arg); ioctl(fd, DS_PARSE_TUPLE, &arg); nfn = arg.tuple_parse.parse.longlink_mfc.nfn; } else { nfn = 1; arg.tuple.DesiredTuple = CISTPL_DEVICE; ret = ioctl(fd, DS_GET_FIRST_TUPLE, &arg); if (ret != 0) { if (errno != ENODEV) perror("ioctl()"); continue; } } arg.tuple.DesiredTuple = CISTPL_CONFIG; for (j = 0; j < nfn; j++) { printf("Socket %d function %d:\n", i, j); if (ioctl(fd, DS_GET_NEXT_TUPLE, &arg) != 0) { printf(" no config tuple: %s\n\n", strerror(errno)); continue; } ioctl(fd, DS_GET_TUPLE_DATA, &arg); ioctl(fd, DS_PARSE_TUPLE, &arg); printf(" Config register base = %#4.4x, mask = %#4.4x\n", arg.tuple_parse.parse.config.base, arg.tuple_parse.parse.config.rmask[0]); mask = arg.tuple_parse.parse.config.rmask[0]; dump_all(fd, j, (nfn > 1), mask); } } return 0; }
static void dio_read( void ) { comedi_t *dev = lookup_dev( *sp++ ); unsigned int subdev = *sp++; unsigned int chan = *sp++; unsigned int data; int c = comedi_dio_read( dev, subdev, chan, &data ); if( c < 1 ) comedi_perror( "@dio " ); *--sp = data; }
static void dio_bitfield( void ) { comedi_t *dev = lookup_dev( *sp++ ); unsigned int subdev = *sp++; unsigned int mask = *sp++; unsigned int data = *sp++; int c = comedi_dio_bitfield( dev, subdev, mask, &data ); if( c < 0 ) comedi_perror( "!@dio " ); *--sp = data; }
static void data_write( void ) { comedi_t *dev = lookup_dev( *sp++ ); unsigned int subdev = *sp++; unsigned int chan = *sp++; unsigned int range = *sp++; unsigned int aref = *sp++; lsampl_t data = *sp++; int c = comedi_data_write( dev, subdev, chan, range, aref, data ); if( c < 1 ) comedi_perror( "!daq " ); }
static void data_read( void ) { comedi_t *dev = lookup_dev( *sp++ ); unsigned int subdev = *sp++; unsigned int chan = *sp++; unsigned int range = *sp++; unsigned int aref = *sp++; lsampl_t data; int c = comedi_data_read( dev, subdev, chan, range, aref, &data ); if( c < 1 ) comedi_perror( "@daq " ); *--sp = data; }
/* API: Get device information. */ PJ_DEF(pj_status_t) pjmedia_aud_dev_get_info(pjmedia_aud_dev_index id, pjmedia_aud_dev_info *info) { pjmedia_aud_dev_factory *f; unsigned index; pj_status_t status; PJ_ASSERT_RETURN(info && id!=PJMEDIA_AUD_INVALID_DEV, PJ_EINVAL); PJ_ASSERT_RETURN(aud_subsys.pf, PJMEDIA_EAUD_INIT); status = lookup_dev(id, &f, &index); if (status != PJ_SUCCESS) return status; return f->op->get_dev_info(f, index, info); }
/* OpenACC 2.0a (3.2.16) doesn't specify what to do in the event the device address is mapped. We choose to check if it mapped, and if it is, to unmap it. */ void acc_free (void *d) { splay_tree_key k; if (!d) return; struct goacc_thread *thr = goacc_thread (); assert (thr && thr->dev); struct gomp_device_descr *acc_dev = thr->dev; if (acc_dev->capabilities & GOMP_OFFLOAD_CAP_SHARED_MEM) return free (d); gomp_mutex_lock (&acc_dev->lock); /* We don't have to call lazy open here, as the ptr value must have been returned by acc_malloc. It's not permitted to pass NULL in (unless you got that null from acc_malloc). */ if ((k = lookup_dev (acc_dev->openacc.data_environ, d, 1))) { void *offset; offset = d - k->tgt->tgt_start + k->tgt_offset; gomp_mutex_unlock (&acc_dev->lock); acc_unmap_data ((void *)(k->host_start + offset)); } else gomp_mutex_unlock (&acc_dev->lock); if (!acc_dev->free_func (acc_dev->target_id, d)) gomp_fatal ("error in freeing device memory in %s", __FUNCTION__); }
/* API: Open video stream object using the specified parameters. */ PJ_DEF(pj_status_t) pjmedia_vid_dev_stream_create( pjmedia_vid_dev_param *prm, const pjmedia_vid_dev_cb *cb, void *user_data, pjmedia_vid_dev_stream **p_vid_strm) { pjmedia_vid_dev_factory *cap_f=NULL, *rend_f=NULL, *f=NULL; pj_status_t status; PJ_ASSERT_RETURN(prm && prm->dir && p_vid_strm, PJ_EINVAL); PJ_ASSERT_RETURN(vid_subsys.pf, PJMEDIA_EVID_INIT); PJ_ASSERT_RETURN(prm->dir==PJMEDIA_DIR_CAPTURE || prm->dir==PJMEDIA_DIR_RENDER || prm->dir==PJMEDIA_DIR_CAPTURE_RENDER, PJ_EINVAL); /* Normalize cap_id */ if (prm->dir & PJMEDIA_DIR_CAPTURE) { unsigned index; if (prm->cap_id < 0) prm->cap_id = PJMEDIA_VID_DEFAULT_CAPTURE_DEV; status = lookup_dev(prm->cap_id, &cap_f, &index); if (status != PJ_SUCCESS) return status; prm->cap_id = index; f = cap_f; } /* Normalize rend_id */ if (prm->dir & PJMEDIA_DIR_RENDER) { unsigned index; if (prm->rend_id < 0) prm->rend_id = PJMEDIA_VID_DEFAULT_RENDER_DEV; status = lookup_dev(prm->rend_id, &rend_f, &index); if (status != PJ_SUCCESS) return status; prm->rend_id = index; f = rend_f; } PJ_ASSERT_RETURN(f != NULL, PJ_EBUG); /* For now, cap_id and rend_id must belong to the same factory */ PJ_ASSERT_RETURN((prm->dir != PJMEDIA_DIR_CAPTURE_RENDER) || (cap_f == rend_f), PJMEDIA_EVID_INVDEV); /* Create the stream */ status = f->op->create_stream(f, prm, cb, user_data, p_vid_strm); if (status != PJ_SUCCESS) return status; /* Assign factory id to the stream */ (*p_vid_strm)->sys.drv_idx = f->sys.drv_idx; return PJ_SUCCESS; }
static struct closefd vfs_fsal_open_and_stat(struct fsal_export *exp, struct vfs_fsal_obj_handle *myself, struct stat *stat, int open_flags, fsal_errors_t *fsal_error) { struct fsal_obj_handle *obj_hdl = &myself->obj_handle; struct closefd cfd = { .fd = -1, .close_fd = false }; int retval = 0; vfs_file_handle_t *fh = NULL; vfs_alloc_handle(fh); const char *func = "unknown"; struct vfs_filesystem *vfs_fs = myself->obj_handle.fs->private; switch (obj_hdl->type) { case SOCKET_FILE: case CHARACTER_FILE: case BLOCK_FILE: cfd.fd = vfs_open_by_handle(vfs_fs, myself->u.unopenable.dir, O_PATH | O_NOACCESS, fsal_error); if (cfd.fd < 0) { LogDebug(COMPONENT_FSAL, "Failed with %s open_flags 0x%08x", strerror(-cfd.fd), O_PATH | O_NOACCESS); return cfd; } cfd.close_fd = true; retval = fstatat(cfd.fd, myself->u.unopenable.name, stat, AT_SYMLINK_NOFOLLOW); func = "fstatat"; break; case REGULAR_FILE: if (myself->u.file.openflags == FSAL_O_CLOSED) { /* no file open at the moment */ cfd.fd = vfs_fsal_open(myself, open_flags, fsal_error); if (cfd.fd < 0) { LogDebug(COMPONENT_FSAL, "Failed with %s open_flags 0x%08x", strerror(-cfd.fd), open_flags); return cfd; } cfd.close_fd = true; } else { cfd.fd = myself->u.file.fd; } retval = fstat(cfd.fd, stat); func = "fstat"; break; case SYMBOLIC_LINK: open_flags |= (O_PATH | O_RDWR | O_NOFOLLOW); goto vfos_open; case FIFO_FILE: open_flags |= O_NONBLOCK; /* fall through */ case DIRECTORY: default: vfos_open: cfd.fd = vfs_fsal_open(myself, open_flags, fsal_error); if (cfd.fd < 0) { LogDebug(COMPONENT_FSAL, "Failed with %s open_flags 0x%08x", strerror(-cfd.fd), open_flags); return cfd; } cfd.close_fd = true; retval = vfs_stat_by_handle(cfd.fd, myself->handle, stat, open_flags); func = "vfs_stat_by_handle"; break; } if (retval < 0) { retval = errno; if (cfd.close_fd) { int rc; rc = close(cfd.fd); if (rc < 0) { rc = errno; LogDebug(COMPONENT_FSAL, "close failed with %s", strerror(rc)); } } if (retval == ENOENT) retval = ESTALE; *fsal_error = posix2fsal_error(retval); LogDebug(COMPONENT_FSAL, "%s failed with %s", func, strerror(retval)); cfd.fd = -retval; cfd.close_fd = false; return cfd; } return cfd; } static fsal_status_t getattrs(struct fsal_obj_handle *obj_hdl) { struct vfs_fsal_obj_handle *myself; struct closefd cfd = { .fd = -1, .close_fd = false }; struct stat stat; fsal_errors_t fsal_error = ERR_FSAL_NO_ERROR; fsal_status_t st; int retval = 0; myself = container_of(obj_hdl, struct vfs_fsal_obj_handle, obj_handle); if (obj_hdl->fsal != obj_hdl->fs->fsal) { LogDebug(COMPONENT_FSAL, "FSAL %s getattr for handle belonging to FSAL %s, ignoring", obj_hdl->fsal->name, obj_hdl->fs->fsal != NULL ? obj_hdl->fs->fsal->name : "(none)"); goto out; } cfd = vfs_fsal_open_and_stat(op_ctx->fsal_export, myself, &stat, O_RDONLY, &fsal_error); if (cfd.fd >= 0) { st = posix2fsal_attributes(&stat, &obj_hdl->attributes); if (cfd.close_fd) close(cfd.fd); if (FSAL_IS_ERROR(st)) { FSAL_CLEAR_MASK(obj_hdl->attributes.mask); FSAL_SET_MASK(obj_hdl->attributes.mask, ATTR_RDATTR_ERR); fsal_error = st.major; retval = st.minor; } else { obj_hdl->attributes.fsid = obj_hdl->fs->fsid; } } else { LogDebug(COMPONENT_FSAL, "Failed with %s, fsal_error %s", strerror(-cfd.fd), fsal_error == ERR_FSAL_STALE ? "ERR_FSAL_STALE" : "other"); if (obj_hdl->type == SYMBOLIC_LINK && cfd.fd == -EPERM) { /* You cannot open_by_handle (XFS on linux) a symlink * and it throws an EPERM error for it. * open_by_handle_at does not throw that error for * symlinks so we play a game here. Since there is * not much we can do with symlinks anyway, * say that we did it but don't actually * do anything. In this case, return the stat we got * at lookup time. If you *really* want to tweek things * like owners, get a modern linux kernel... */ fsal_error = ERR_FSAL_NO_ERROR; goto out; } retval = -cfd.fd; } out: return fsalstat(fsal_error, retval); } /* * NOTE: this is done under protection of the attributes rwlock * in the cache entry. */ static fsal_status_t setattrs(struct fsal_obj_handle *obj_hdl, struct attrlist *attrs) { struct vfs_fsal_obj_handle *myself; struct closefd cfd = { .fd = -1, .close_fd = false }; struct stat stat; fsal_errors_t fsal_error = ERR_FSAL_NO_ERROR; int retval = 0; int open_flags = O_RDONLY; /* apply umask, if mode attribute is to be changed */ if (FSAL_TEST_MASK(attrs->mask, ATTR_MODE)) attrs->mode &= ~op_ctx->fsal_export->exp_ops. fs_umask(op_ctx->fsal_export); myself = container_of(obj_hdl, struct vfs_fsal_obj_handle, obj_handle); if (obj_hdl->fsal != obj_hdl->fs->fsal) { LogDebug(COMPONENT_FSAL, "FSAL %s operation for handle belonging to FSAL %s, return EXDEV", obj_hdl->fsal->name, obj_hdl->fs->fsal != NULL ? obj_hdl->fs->fsal->name : "(none)"); retval = EXDEV; fsal_error = posix2fsal_error(retval); goto hdlerr; } /* This is yet another "you can't get there from here". If this object * is a socket (AF_UNIX), an fd on the socket s useless _period_. * If it is for a symlink, without O_PATH, you will get an ELOOP error * and (f)chmod doesn't work for a symlink anyway - not that it matters * because access checking is not done on the symlink but the final * target. * AF_UNIX sockets are also ozone material. If the socket is already * active listeners et al, you can manipulate the mode etc. If it is * just sitting there as in you made it with a mknod. * (one of those leaky abstractions...) * or the listener forgot to unlink it, it is lame duck. */ if (FSAL_TEST_MASK(attrs->mask, ATTR_SIZE)) open_flags = O_RDWR; cfd = vfs_fsal_open_and_stat(op_ctx->fsal_export, myself, &stat, open_flags, &fsal_error); if (cfd.fd < 0) { if (obj_hdl->type == SYMBOLIC_LINK && cfd.fd == -EPERM) { /* You cannot open_by_handle (XFS) a symlink and it * throws an EPERM error for it. open_by_handle_at * does not throw that error for symlinks so we play a * game here. Since there is not much we can do with * symlinks anyway, say that we did it * but don't actually do anything. * If you *really* want to tweek things * like owners, get a modern linux kernel... */ fsal_error = ERR_FSAL_NO_ERROR; goto out; } return fsalstat(fsal_error, cfd.fd); } /** TRUNCATE **/ if (FSAL_TEST_MASK(attrs->mask, ATTR_SIZE)) { if (obj_hdl->type != REGULAR_FILE) { fsal_error = ERR_FSAL_INVAL; goto fileerr; } retval = ftruncate(cfd.fd, attrs->filesize); if (retval != 0) { /* XXX ESXi volume creation pattern reliably * reaches this point and reliably can successfully * ftruncate on reopen. I don't know yet if fd if * we failed to handle a previous error, or what. * I don't see a prior failed op in wireshark. */ if (retval == -1 /* bad fd */) { vfs_close(obj_hdl); if (cfd.close_fd) close(cfd.fd); cfd = vfs_fsal_open_and_stat( op_ctx->fsal_export, myself, &stat, open_flags, &fsal_error); retval = ftruncate(cfd.fd, attrs->filesize); if (retval != 0) goto fileerr; } else goto fileerr; } } /** CHMOD **/ if (FSAL_TEST_MASK(attrs->mask, ATTR_MODE)) { /* The POSIX chmod call doesn't affect the symlink object, but * the entry it points to. So we must ignore it. */ if (!S_ISLNK(stat.st_mode)) { if (vfs_unopenable_type(obj_hdl->type)) retval = fchmodat(cfd.fd, myself->u.unopenable.name, fsal2unix_mode(attrs->mode), 0); else retval = fchmod(cfd.fd, fsal2unix_mode(attrs->mode)); if (retval != 0) goto fileerr; } } /** CHOWN **/ if (FSAL_TEST_MASK(attrs->mask, ATTR_OWNER | ATTR_GROUP)) { uid_t user = FSAL_TEST_MASK(attrs->mask, ATTR_OWNER) ? (int)attrs->owner : -1; gid_t group = FSAL_TEST_MASK(attrs->mask, ATTR_GROUP) ? (int)attrs->group : -1; if (vfs_unopenable_type(obj_hdl->type)) retval = fchownat(cfd.fd, myself->u.unopenable.name, user, group, AT_SYMLINK_NOFOLLOW); else if (obj_hdl->type == SYMBOLIC_LINK) retval = fchownat(cfd.fd, "", user, group, AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH); else retval = fchown(cfd.fd, user, group); if (retval) goto fileerr; } /** UTIME **/ if (FSAL_TEST_MASK (attrs->mask, ATTR_ATIME | ATTR_MTIME | ATTR_ATIME_SERVER | ATTR_MTIME_SERVER)) { struct timespec timebuf[2]; if (obj_hdl->type == SYMBOLIC_LINK) goto out; /* Setting time on symlinks is illegal */ /* Atime */ if (FSAL_TEST_MASK(attrs->mask, ATTR_ATIME_SERVER)) { timebuf[0].tv_sec = 0; timebuf[0].tv_nsec = UTIME_NOW; } else if (FSAL_TEST_MASK(attrs->mask, ATTR_ATIME)) { timebuf[0] = attrs->atime; } else { timebuf[0].tv_sec = 0; timebuf[0].tv_nsec = UTIME_OMIT; } /* Mtime */ if (FSAL_TEST_MASK(attrs->mask, ATTR_MTIME_SERVER)) { timebuf[1].tv_sec = 0; timebuf[1].tv_nsec = UTIME_NOW; } else if (FSAL_TEST_MASK(attrs->mask, ATTR_MTIME)) { timebuf[1] = attrs->mtime; } else { timebuf[1].tv_sec = 0; timebuf[1].tv_nsec = UTIME_OMIT; } if (vfs_unopenable_type(obj_hdl->type)) retval = vfs_utimesat(cfd.fd, myself->u.unopenable.name, timebuf, AT_SYMLINK_NOFOLLOW); else retval = vfs_utimes(cfd.fd, timebuf); if (retval != 0) goto fileerr; } goto out; fileerr: retval = errno; fsal_error = posix2fsal_error(retval); out: if (cfd.close_fd) close(cfd.fd); hdlerr: return fsalstat(fsal_error, retval); } /* file_unlink * unlink the named file in the directory */ static fsal_status_t file_unlink(struct fsal_obj_handle *dir_hdl, const char *name) { struct vfs_fsal_obj_handle *myself; fsal_errors_t fsal_error = ERR_FSAL_NO_ERROR; struct stat stat; int fd; int retval = 0; myself = container_of(dir_hdl, struct vfs_fsal_obj_handle, obj_handle); if (dir_hdl->fsal != dir_hdl->fs->fsal) { LogDebug(COMPONENT_FSAL, "FSAL %s operation for handle belonging to FSAL %s, return EXDEV", dir_hdl->fsal->name, dir_hdl->fs->fsal != NULL ? dir_hdl->fs->fsal->name : "(none)"); retval = EXDEV; fsal_error = posix2fsal_error(retval); goto out; } fd = vfs_fsal_open(myself, O_PATH | O_NOACCESS, &fsal_error); if (fd < 0) { retval = -fd; goto out; } retval = fstatat(fd, name, &stat, AT_SYMLINK_NOFOLLOW); if (retval < 0) { retval = errno; LogDebug(COMPONENT_FSAL, "fstatat %s failed %s", name, strerror(retval)); if (retval == ENOENT) fsal_error = ERR_FSAL_STALE; else fsal_error = posix2fsal_error(retval); goto errout; } fsal_set_credentials(op_ctx->creds); retval = unlinkat(fd, name, (S_ISDIR(stat.st_mode)) ? AT_REMOVEDIR : 0); if (retval < 0) { retval = errno; if (retval == ENOENT) fsal_error = ERR_FSAL_STALE; else fsal_error = posix2fsal_error(retval); } fsal_restore_ganesha_credentials(); errout: close(fd); out: return fsalstat(fsal_error, retval); } /* handle_digest * fill in the opaque f/s file handle part. * we zero the buffer to length first. This MAY already be done above * at which point, remove memset here because the caller is zeroing * the whole struct. */ static fsal_status_t handle_digest(const struct fsal_obj_handle *obj_hdl, fsal_digesttype_t output_type, struct gsh_buffdesc *fh_desc) { const struct vfs_fsal_obj_handle *myself; myself = container_of(obj_hdl, struct vfs_fsal_obj_handle, obj_handle); if (obj_hdl->fsal != obj_hdl->fs->fsal) { /* Log, but allow digest */ LogDebug(COMPONENT_FSAL, "FSAL %s operation for handle belonging to FSAL %s", obj_hdl->fsal->name, obj_hdl->fs->fsal != NULL ? obj_hdl->fs->fsal->name : "(none)"); } switch (output_type) { case FSAL_DIGEST_NFSV3: case FSAL_DIGEST_NFSV4: if (fh_desc->len < myself->handle->handle_len) { LogMajor(COMPONENT_FSAL, "Space too small for handle. need %d, have %lu", (int) myself->handle->handle_len, fh_desc->len); return fsalstat(ERR_FSAL_TOOSMALL, 0); } memcpy(fh_desc->addr, myself->handle->handle_data, myself->handle->handle_len); break; default: return fsalstat(ERR_FSAL_SERVERFAULT, 0); } fh_desc->len = myself->handle->handle_len; return fsalstat(ERR_FSAL_NO_ERROR, 0); } /** * handle_to_key * return a handle descriptor into the handle in this object handle * @TODO reminder. make sure things like hash keys don't point here * after the handle is released. */ static void handle_to_key(struct fsal_obj_handle *obj_hdl, struct gsh_buffdesc *fh_desc) { struct vfs_fsal_obj_handle *myself; myself = container_of(obj_hdl, struct vfs_fsal_obj_handle, obj_handle); fh_desc->addr = myself->handle->handle_data; fh_desc->len = myself->handle->handle_len; } /* * release * release our export first so they know we are gone */ static void release(struct fsal_obj_handle *obj_hdl) { struct vfs_fsal_obj_handle *myself; object_file_type_t type = obj_hdl->type; myself = container_of(obj_hdl, struct vfs_fsal_obj_handle, obj_handle); if (type == REGULAR_FILE) { fsal_status_t st = vfs_close(obj_hdl); if (FSAL_IS_ERROR(st)) { LogCrit(COMPONENT_FSAL, "Could not close hdl 0x%p, error %s(%d)", obj_hdl, strerror(st.minor), st.minor); } } fsal_obj_handle_fini(obj_hdl); if (type == SYMBOLIC_LINK) { if (myself->u.symlink.link_content != NULL) gsh_free(myself->u.symlink.link_content); } else if (vfs_unopenable_type(type)) { if (myself->u.unopenable.name != NULL) gsh_free(myself->u.unopenable.name); if (myself->u.unopenable.dir != NULL) gsh_free(myself->u.unopenable.dir); } gsh_free(myself); } void vfs_handle_ops_init(struct fsal_obj_ops *ops) { ops->release = release; ops->lookup = lookup; ops->readdir = read_dirents; ops->create = create; ops->mkdir = makedir; ops->mknode = makenode; ops->symlink = makesymlink; ops->readlink = readsymlink; ops->test_access = fsal_test_access; ops->getattrs = getattrs; ops->setattrs = setattrs; ops->link = linkfile; ops->rename = renamefile; ops->unlink = file_unlink; ops->open = vfs_open; ops->status = vfs_status; ops->read = vfs_read; ops->write = vfs_write; ops->commit = vfs_commit; ops->lock_op = vfs_lock_op; ops->close = vfs_close; ops->lru_cleanup = vfs_lru_cleanup; ops->handle_digest = handle_digest; ops->handle_to_key = handle_to_key; /* xattr related functions */ ops->list_ext_attrs = vfs_list_ext_attrs; ops->getextattr_id_by_name = vfs_getextattr_id_by_name; ops->getextattr_value_by_name = vfs_getextattr_value_by_name; ops->getextattr_value_by_id = vfs_getextattr_value_by_id; ops->setextattr_value = vfs_setextattr_value; ops->setextattr_value_by_id = vfs_setextattr_value_by_id; ops->getextattr_attrs = vfs_getextattr_attrs; ops->remove_extattr_by_id = vfs_remove_extattr_by_id; ops->remove_extattr_by_name = vfs_remove_extattr_by_name; } /* export methods that create object handles */ /* lookup_path * modeled on old api except we don't stuff attributes. * KISS */ fsal_status_t vfs_lookup_path(struct fsal_export *exp_hdl, const char *path, struct fsal_obj_handle **handle) { int dir_fd = -1; struct stat stat; struct vfs_fsal_obj_handle *hdl; fsal_errors_t fsal_error = ERR_FSAL_NO_ERROR; int retval = 0; struct fsal_filesystem *fs; struct fsal_dev__ dev; vfs_file_handle_t *fh = NULL; vfs_alloc_handle(fh); *handle = NULL; /* poison it */ dir_fd = open_dir_by_path_walk(-1, path, &stat); if (dir_fd < 0) { LogCrit(COMPONENT_FSAL, "Could not open directory for path %s", path); retval = -dir_fd; goto errout; } dev = posix2fsal_devt(stat.st_dev); fs = lookup_dev(&dev); if (fs == NULL) { LogInfo(COMPONENT_FSAL, "Could not find file system for path %s", path); retval = ENOENT; goto errout; } if (fs->fsal != exp_hdl->fsal) { LogInfo(COMPONENT_FSAL, "File system for path %s did not belong to FSAL %s", path, exp_hdl->fsal->name); retval = EACCES; goto errout; } LogDebug(COMPONENT_FSAL, "filesystem %s for path %s", fs->path, path); retval = vfs_fd_to_handle(dir_fd, fs, fh); if (retval < 0) { retval = errno; LogCrit(COMPONENT_FSAL, "Could not get handle for path %s, error %s", path, strerror(retval)); goto errout; } /* allocate an obj_handle and fill it up */ hdl = alloc_handle(-1, fh, fs, &stat, NULL, "", exp_hdl); if (hdl == NULL) { retval = ENOMEM; LogCrit(COMPONENT_FSAL, "Could not allocate handle for path %s", path); goto errout; } close(dir_fd); *handle = &hdl->obj_handle; return fsalstat(ERR_FSAL_NO_ERROR, 0); errout: if (dir_fd >= 0) close(dir_fd); fsal_error = posix2fsal_error(retval); return fsalstat(fsal_error, retval); } fsal_status_t vfs_check_handle(struct fsal_export *exp_hdl, struct gsh_buffdesc *hdl_desc, struct fsal_filesystem **fs, vfs_file_handle_t *fh, bool *dummy) { fsal_errors_t fsal_error = ERR_FSAL_NO_ERROR; int retval = 0; struct fsal_fsid__ fsid; enum fsid_type fsid_type; *fs = NULL; if (!vfs_valid_handle(hdl_desc)) return fsalstat(ERR_FSAL_BADHANDLE, 0); memcpy(fh->handle_data, hdl_desc->addr, hdl_desc->len); fh->handle_len = hdl_desc->len; *dummy = vfs_is_dummy_handle(fh); retval = vfs_extract_fsid(fh, &fsid_type, &fsid); if (retval == 0) { *fs = lookup_fsid(&fsid, fsid_type); if (*fs == NULL) { LogInfo(COMPONENT_FSAL, "Could not map " "fsid=0x%016"PRIx64".0x%016"PRIx64 " to filesytem", fsid.major, fsid.minor); retval = ESTALE; fsal_error = posix2fsal_error(retval); goto errout; } if (((*fs)->fsal != exp_hdl->fsal) && !(*dummy)) { LogInfo(COMPONENT_FSAL, "fsid=0x%016"PRIx64".0x%016"PRIx64 " in handle not a %s filesystem", fsid.major, fsid.minor, exp_hdl->fsal->name); retval = ESTALE; fsal_error = posix2fsal_error(retval); goto errout; } LogDebug(COMPONENT_FSAL, "Found filesystem %s for handle for FSAL %s", (*fs)->path, (*fs)->fsal != NULL ? (*fs)->fsal->name : "(none)"); } else { LogDebug(COMPONENT_FSAL, "Could not map handle to fsid"); fsal_error = ERR_FSAL_BADHANDLE; goto errout; } errout: return fsalstat(fsal_error, retval); }
pjmedia_vid_dev_get_local_index(pjmedia_vid_dev_index id, pjmedia_vid_dev_factory **p_f, unsigned *p_local_index) { return lookup_dev(id, p_f, p_local_index); }
static fsal_status_t lookup(struct fsal_obj_handle *parent, const char *path, struct fsal_obj_handle **handle) { struct vfs_fsal_obj_handle *parent_hdl, *hdl; fsal_errors_t fsal_error = ERR_FSAL_NO_ERROR; int retval, dirfd; struct stat stat; vfs_file_handle_t *fh = NULL; vfs_alloc_handle(fh); fsal_dev_t dev; struct fsal_filesystem *fs; bool xfsal = false; *handle = NULL; /* poison it first */ parent_hdl = container_of(parent, struct vfs_fsal_obj_handle, obj_handle); if (!parent->obj_ops.handle_is(parent, DIRECTORY)) { LogCrit(COMPONENT_FSAL, "Parent handle is not a directory. hdl = 0x%p", parent); return fsalstat(ERR_FSAL_NOTDIR, 0); } if (parent->fsal != parent->fs->fsal) { LogDebug(COMPONENT_FSAL, "FSAL %s operation for handle belonging to FSAL %s, return EXDEV", parent->fsal->name, parent->fs->fsal != NULL ? parent->fs->fsal->name : "(none)"); retval = EXDEV; goto hdlerr; } fs = parent->fs; dirfd = vfs_fsal_open(parent_hdl, O_PATH | O_NOACCESS, &fsal_error); if (dirfd < 0) return fsalstat(fsal_error, -dirfd); retval = fstatat(dirfd, path, &stat, AT_SYMLINK_NOFOLLOW); if (retval < 0) { retval = errno; goto direrr; } dev = posix2fsal_devt(stat.st_dev); if ((dev.minor != parent_hdl->dev.minor) || (dev.major != parent_hdl->dev.major)) { /* XDEV */ fs = lookup_dev(&dev); if (fs == NULL) { LogDebug(COMPONENT_FSAL, "Lookup of %s crosses filesystem boundary to " "unknown file system dev=%"PRIu64".%"PRIu64, path, dev.major, dev.minor); retval = EXDEV; goto direrr; } if (fs->fsal != parent->fsal) { xfsal = true; LogDebug(COMPONENT_FSAL, "Lookup of %s crosses filesystem boundary to file system %s into FSAL %s", path, fs->path, fs->fsal != NULL ? fs->fsal->name : "(none)"); } else { LogDebug(COMPONENT_FSAL, "Lookup of %s crosses filesystem boundary to file system %s", path, fs->path); } } if (xfsal || vfs_name_to_handle(dirfd, fs, path, fh) < 0) { retval = errno; if (((retval == ENOTTY) || (retval == EOPNOTSUPP) || (retval == ENOTSUP) || xfsal) && (fs != parent->fs)) { /* Crossed device into territory not handled by * this FSAL (XFS or VFS). Need to invent a handle. * The made up handle will be JUST the fsid, we * do not expect to see the handle on the wire, and * this handle will not be valid for any form of this * FSAL. */ LogDebug(COMPONENT_FSAL, "vfs_name_to_handle %s, inventing FSAL %s handle for FSAL %s filesystem %s", xfsal ? "skipped" : "failed", parent->fsal->name, fs->fsal != NULL ? fs->fsal->name : "(none)", path); retval = vfs_encode_dummy_handle(fh, fs); if (retval < 0) { retval = errno; goto direrr; } retval = 0; } else { /* Some other error */ goto direrr; } } /* allocate an obj_handle and fill it up */ hdl = alloc_handle(dirfd, fh, fs, &stat, parent_hdl->handle, path, op_ctx->fsal_export); close(dirfd); if (hdl == NULL) { retval = ENOMEM; goto hdlerr; } *handle = &hdl->obj_handle; return fsalstat(ERR_FSAL_NO_ERROR, 0); direrr: close(dirfd); hdlerr: fsal_error = posix2fsal_error(retval); return fsalstat(fsal_error, retval); }
/* API: Open audio stream object using the specified parameters. */ PJ_DEF(pj_status_t) pjmedia_aud_stream_create(const pjmedia_aud_param *prm, pjmedia_aud_rec_cb rec_cb, pjmedia_aud_play_cb play_cb, void *user_data, pjmedia_aud_stream **p_aud_strm) { pjmedia_aud_dev_factory *rec_f=NULL, *play_f=NULL, *f=NULL; pjmedia_aud_param param; pj_status_t status; PJ_ASSERT_RETURN(prm && prm->dir && p_aud_strm, PJ_EINVAL); //PJ_ASSERT_RETURN(aud_subsys.pf, PJMEDIA_EAUD_INIT); // DEAN don't assertion if (!aud_subsys.pf) return PJMEDIA_EAUD_INIT; PJ_ASSERT_RETURN(prm->dir==PJMEDIA_DIR_CAPTURE || prm->dir==PJMEDIA_DIR_PLAYBACK || prm->dir==PJMEDIA_DIR_CAPTURE_PLAYBACK, PJ_EINVAL); /* Must make copy of param because we're changing device ID */ pj_memcpy(¶m, prm, sizeof(param)); /* Normalize rec_id */ if (param.dir & PJMEDIA_DIR_CAPTURE) { unsigned index; if (param.rec_id < 0) param.rec_id = PJMEDIA_AUD_DEFAULT_CAPTURE_DEV; status = lookup_dev(param.rec_id, &rec_f, &index); if (status != PJ_SUCCESS) return status; param.rec_id = index; f = rec_f; } /* Normalize play_id */ if (param.dir & PJMEDIA_DIR_PLAYBACK) { unsigned index; if (param.play_id < 0) param.play_id = PJMEDIA_AUD_DEFAULT_PLAYBACK_DEV; status = lookup_dev(param.play_id, &play_f, &index); if (status != PJ_SUCCESS) return status; param.play_id = index; f = play_f; } PJ_ASSERT_RETURN(f != NULL, PJ_EBUG); /* For now, rec_id and play_id must belong to the same factory */ PJ_ASSERT_RETURN((param.dir != PJMEDIA_DIR_CAPTURE_PLAYBACK) || (rec_f == play_f), PJMEDIA_EAUD_INVDEV); /* Create the stream */ status = f->op->create_stream(f, ¶m, rec_cb, play_cb, user_data, p_aud_strm); if (status != PJ_SUCCESS) return status; /* Assign factory id to the stream */ (*p_aud_strm)->sys.drv_idx = f->sys.drv_idx; return PJ_SUCCESS; }
int dm_query_device(const char *name, char **device, uint64_t *size, uint64_t *skip, uint64_t *offset, char **cipher, int *key_size, char **key, int *read_only, int *suspended, char **uuid) { struct dm_task *dmt; struct dm_info dmi; uint64_t start, length, val64; char *target_type, *params, *rcipher, *key_, *rdevice, *endp, buffer[3], *tmp_uuid; void *next = NULL; int i, r = -EINVAL; if (!(dmt = dm_task_create(DM_DEVICE_TABLE))) goto out; if (!dm_task_set_name(dmt, name)) goto out; r = -ENODEV; if (!dm_task_run(dmt)) goto out; r = -EINVAL; if (!dm_task_get_info(dmt, &dmi)) goto out; if (!dmi.exists) { r = -ENODEV; goto out; } next = dm_get_next_target(dmt, next, &start, &length, &target_type, ¶ms); if (!target_type || strcmp(target_type, DM_CRYPT_TARGET) != 0 || start != 0 || next) goto out; if (size) *size = length; rcipher = strsep(¶ms, " "); /* cipher */ if (cipher) *cipher = strdup(rcipher); /* skip */ key_ = strsep(¶ms, " "); if (!params) goto out; val64 = strtoull(params, ¶ms, 10); if (*params != ' ') goto out; params++; if (skip) *skip = val64; /* device */ rdevice = strsep(¶ms, " "); if (device) *device = lookup_dev(rdevice); /*offset */ if (!params) goto out; val64 = strtoull(params, ¶ms, 10); if (*params) goto out; if (offset) *offset = val64; /* key_size */ if (key_size) *key_size = strlen(key_) / 2; /* key */ if (key_size && key) { *key = safe_alloc(*key_size); if (!*key) { r = -ENOMEM; goto out; } buffer[2] = '\0'; for(i = 0; i < *key_size; i++) { memcpy(buffer, &key_[i * 2], 2); (*key)[i] = strtoul(buffer, &endp, 16); if (endp != &buffer[2]) { safe_free(key); *key = NULL; goto out; } } } memset(key_, 0, strlen(key_)); if (read_only) *read_only = dmi.read_only; if (suspended) *suspended = dmi.suspended; if (uuid && (tmp_uuid = (char*)dm_task_get_uuid(dmt)) && !strncmp(tmp_uuid, DM_UUID_PREFIX, DM_UUID_PREFIX_LEN)) *uuid = strdup(tmp_uuid + DM_UUID_PREFIX_LEN); r = (dmi.open_count > 0); out: if (dmt) dm_task_destroy(dmt); return r; }
int cl_setup_promisc(struct netdev *nd) { char buf[1024]={0}; struct ifconf ifc; struct ifreq *ifr; int if_cnt; int yes; struct sockaddr_ll sll; /* set netlink socket */ nd->nd_fd = socket(PF_PACKET,SOCK_RAW,htons(ETH_P_ALL)); if(nd->nd_fd == -1) { perrx("socket:PF_PACKET"); return -1; } memset(&ifc,0,sizeof(ifc)); memset(&ifr,0,sizeof(ifr)); ifc.ifc_len = sizeof(buf); ifc.ifc_buf = buf; if(ioctl(nd->nd_fd,SIOCGIFCONF,&ifc) < 0) { perrx("ioctl:SIOCGIFCONF"); return -1; } /* list all network interfaces then look for the desired one */ ifr = ifc.ifc_req; if_cnt =ifc.ifc_len / sizeof(struct ifreq); ifr = lookup_dev(ifr,&if_cnt,nd); if(ifr == NULL) { perrx("Couldn't get device name \n"); return -1; } #ifdef IFCONF printfd(2,"interface index : %d\n",ifr->ifr_ifindex); printfd(2,"interface address : "IPFMT"\n", ipfmt((int)(((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr.s_addr))); printfd(2,"interface netmask : "IPFMT"\n", ipfmt((int)(((struct sockaddr_in *)&ifr->ifr_netmask)->sin_addr.s_addr))); #endif /* make sure that the interface is UP & RUNNING */ ifr->ifr_flags |= IFF_PROMISC; ifr->ifr_flags |= IFF_UP |IFF_RUNNING; if(ioctl(nd->nd_fd, SIOCSIFFLAGS, ifr) < 0) { perrx("ioctl:SIOCGIFCONF"); return -1; } /* get interface index */ if (ioctl(nd->nd_fd,SIOCGIFINDEX,ifr)==-1) { perrx("SIOCGIFINDEX"); } if (setsockopt(nd->nd_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) == -1) { perrx("setsockopt:SO_REUSEADDR"); return -1; } /* No need for this if (setsockopt(nd->nd_fd, SOL_SOCKET, SO_BINDTODEVICE, ifr->ifr_name, IFNAMSIZ-1) == -1) { perrx("SO_BINDTODEVICE"); return -1; } */ memset(&sll,0,sizeof(sll)); sll.sll_family = AF_PACKET; sll.sll_ifindex = ifr->ifr_ifindex; sll.sll_protocol = htons(ETH_P_ALL); if(bind(nd->nd_fd,(struct sockaddr*)&sll,sizeof(sll)) == -1) { perrx("bind"); return -1; } nd->nd_ops->xmit(nd,NULL); return 0; }