Beispiel #1
0
int vn_fromfd(int fd, char *path, int flags, struct vnode **vpp, boolean_t fromfd)
{
	vnode_t *vp;

	*vpp = vp = kmem_cache_alloc(vnode_cache, KM_SLEEP);
	memset(vp, 0, sizeof(vnode_t));

	if (fstat64(fd, &vp->v_stat) == -1) {
		close(fd);
		return (errno);
	}

	(void) fcntl(fd, F_SETFD, FD_CLOEXEC);

	vp->v_fd = fd;
	if(S_ISBLK(vp->v_stat.st_mode)) {
		/* LINUX */
		if(ioctl(fd, BLKGETSIZE64, &vp->v_size) != 0)
			return errno;
	} else
		vp->v_size = vp->v_stat.st_size;
	vp->v_path = strdup(path);

	vp->v_type = VNON;

	if(fromfd)
		vn_setops(vp, fd_fvnodeops);
	else
		vn_setops(vp, root_fvnodeops);

	if(S_ISREG(vp->v_stat.st_mode)) {
		vp->v_type = VREG;
		if (flags & FREAD)
			atomic_add_32(&((*vpp)->v_rdcnt), 1);
		if (flags & FWRITE)
			atomic_add_32(&((*vpp)->v_wrcnt), 1);
	} else if(S_ISDIR(vp->v_stat.st_mode))
		vp->v_type = VDIR;
	else if(S_ISCHR(vp->v_stat.st_mode))
		vp->v_type = VCHR;
	else if(S_ISBLK(vp->v_stat.st_mode))
		vp->v_type = VBLK;
	else if(S_ISFIFO(vp->v_stat.st_mode))
		vp->v_type = VFIFO;
	else if(S_ISLNK(vp->v_stat.st_mode))
		vp->v_type = VLNK;
	else if(S_ISSOCK(vp->v_stat.st_mode))
		vp->v_type = VSOCK;

	VERIFY(vp->v_type != VNON);

	zmutex_init(&vp->v_lock);
	rwst_init(&vp->v_vfsmhlock.ve_lock, NULL, RW_DEFAULT, NULL);

	vp->v_count = 1;
	vp->v_vfsp = rootvfs;

	/*fprintf(stderr, "VNode %p created at vn_open (%s)\n", *vpp, path);*/
	return (0);
}
Beispiel #2
0
void ztst_mutex(){
  zmutex_t mtx;
  zmutex_init(&mtx);
  zmutex_lock(&mtx);
  zmutex_unlock(&mtx);
  zmutex_uninit(&mtx);
#ifdef ZSYS_POSIX
  zmutex_lock(&mtx);
  zmutex_unlock(&mtx);
#endif
}
struct sys_sem *
sys_sem_new_internal(XaxMachinery *xm, u8_t count)
{
	struct sys_sem *sem;


	sem = (struct sys_sem *) cheesy_malloc(&xm->arena, sizeof(struct sys_sem));
	if (sem != NULL) {
		sem->xm = xm;
		sem->c = count;
		zcond_init(&sem->zcond);
		zmutex_init(&sem->zmutex);
		sem->verbose = false;	// default no debug msgs
	}
	return sem;
}
Beispiel #4
0
static int zthr_listpush(zthr_t* attr){
  int ret = ZEOK;
  if( NULL == zg_thr_head ){
    // first thread not need lock, and init list
    if( ZEOK != (ret = zmutex_init(&zg_thr_mtx)))return ret;
    zg_thr_head = attr;
    attr->next = NULL;
    ++zg_thr_name;
  }else{
    zmutex_lock(&zg_thr_mtx);
    attr->next = zg_thr_head;
    zg_thr_head = attr;
    ++zg_thr_name;
    zmutex_unlock(&zg_thr_mtx);
  }
  return ret;
}