当前位置: 首页>>代码示例>>C++>>正文


C++ VOP_READ函数代码示例

本文整理汇总了C++中VOP_READ函数的典型用法代码示例。如果您正苦于以下问题:C++ VOP_READ函数的具体用法?C++ VOP_READ怎么用?C++ VOP_READ使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了VOP_READ函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sys_read

int sys_read(int fd, void *buf, size_t buflen) {
    struct fd* tmp;
    if (!buf || buf == NULL || !valid_address_check(curproc->p_addrspace, (vaddr_t)buf)){      // else if invalid buffer
        errno = EFAULT;
        return -1;
    }
    if (fd < 0 || fd >= MAX_fd_table){       // if fd < 0 || fd > MAX_fd_table or 
        errno = EBADF;
        return -1;
    }
	else if (fd == STDOUT_FILENO || fd == STDERR_FILENO){      // fd == STDOUT_FILENO || STDERR_FILENO
            errno = EIO;
            return -1;
        }
        else if (fd >= 3 && fd < MAX_fd_table){
            tmp = curproc->fd_table[fd];
            if (tmp == NULL || (tmp->file_flag & O_WRONLY)){        // or if file is not readable
                errno = EBADF;  // error
                return -1;
            }
        }

        struct uio u;
        struct iovec iov;
        struct addrspace *as ;
        as = as_create();

        iov.iov_ubase = buf;
        iov.iov_len = buflen;

        u.uio_iov = &iov;
        u.uio_iovcnt = 1;
        u.uio_offset = tmp->offset;
        u.uio_resid = buflen;
        u.uio_segflg = UIO_USERSPACE;
        u.uio_rw = UIO_READ;
        u.uio_space = curproc_getas();
	
	if (fd == STDIN_FILENO){
		struct vnode *vn;
		char *console = NULL; // console string ("con:")
            console = kstrdup("con:"); // set to console
            vfs_open(console,O_RDONLY,0,&vn); // open the console vnode
            kfree(console); // free the console
            int result = VOP_READ(vn,&u);
            if(result < 0){
                    errno = EIO; //A hardware I/O error occurred writing the data
                    return -1;
            }
	} else{
	        int retval = VOP_READ(tmp->file, &u);
		if (retval < 0){
			errno = EIO;
			return -1;
		}
	}
	return buflen - u.uio_resid ;
}
开发者ID:y3046308,项目名称:os-group-project,代码行数:58,代码来源:filesystem.c

示例2: ToMem

static int ToMem(u_int32_t flatloc, vaddr_t vaddr)
{
    assert(lock_do_i_hold(&vmlock));
    assert((vaddr & 0xfffff000) == vaddr);
    assert((flatloc & 0xfffff000) == flatloc);
    
    struct uio ku;
    int result;
    u_int32_t bitmaploc, diskloc, diskindex;
    bitmaploc = flatloc/PAGE_SIZE;
    
    assert (bitmap_isset(diskmap, bitmaploc));
    
    diskindex = flatloc / DISKSPACE;
    diskloc = flatloc - diskindex * DISKSPACE;
    
    mk_kuio(&ku, (void*)vaddr , PAGE_SIZE, diskloc, UIO_READ);
    result = VOP_READ(disk[diskindex], &ku);
    if (result) {
        panic(strerror(result));
    }
    
    bitmap_unmark(diskmap, bitmaploc);
    return result;
}
开发者ID:john-yan,项目名称:OS161,代码行数:25,代码来源:addrspace.c

示例3: vdsp_is_iso

int
vdsp_is_iso(struct vdsp_softc *sc)
{
	struct proc *p = curproc;
	struct iovec iov;
	struct uio uio;
	struct iso_volume_descriptor *vdp;
	int err;

	if (sc->sc_vp == NULL)
		return (0);

	vdp = malloc(sizeof(*vdp), M_DEVBUF, M_WAITOK);

	iov.iov_base = vdp;
	iov.iov_len = sizeof(*vdp);
	uio.uio_iov = &iov;
	uio.uio_iovcnt = 1;
	uio.uio_offset = 16 * ISO_DEFAULT_BLOCK_SIZE;
	uio.uio_resid = sizeof(*vdp);
	uio.uio_segflg = UIO_SYSSPACE;
	uio.uio_rw = UIO_READ;
	uio.uio_procp = p;

	vn_lock(sc->sc_vp, LK_EXCLUSIVE | LK_RETRY, p);
	err = VOP_READ(sc->sc_vp, &uio, 0, p->p_ucred);
	VOP_UNLOCK(sc->sc_vp, 0, p);

	if (err == 0 && memcmp(vdp->id, ISO_STANDARD_ID, sizeof(vdp->id)))
		err = ENOENT;

	free(vdp, M_DEVBUF, 0);
	return (err == 0);
}
开发者ID:DavidAlphaFox,项目名称:openbsd-kernel,代码行数:34,代码来源:vdsp.c

示例4: vnode_pager_input_old

/*
 * old style vnode pager input routine
 */
static int
vnode_pager_input_old(vm_object_t object, vm_page_t m)
{
	struct uio auio;
	struct iovec aiov;
	int error;
	int size;
	struct sf_buf *sf;
	struct vnode *vp;

	VM_OBJECT_ASSERT_WLOCKED(object);
	error = 0;

	/*
	 * Return failure if beyond current EOF
	 */
	if (IDX_TO_OFF(m->pindex) >= object->un_pager.vnp.vnp_size) {
		return VM_PAGER_BAD;
	} else {
		size = PAGE_SIZE;
		if (IDX_TO_OFF(m->pindex) + size > object->un_pager.vnp.vnp_size)
			size = object->un_pager.vnp.vnp_size - IDX_TO_OFF(m->pindex);
		vp = object->handle;
		VM_OBJECT_WUNLOCK(object);

		/*
		 * Allocate a kernel virtual address and initialize so that
		 * we can use VOP_READ/WRITE routines.
		 */
		sf = sf_buf_alloc(m, 0);

		aiov.iov_base = (caddr_t)sf_buf_kva(sf);
		aiov.iov_len = size;
		auio.uio_iov = &aiov;
		auio.uio_iovcnt = 1;
		auio.uio_offset = IDX_TO_OFF(m->pindex);
		auio.uio_segflg = UIO_SYSSPACE;
		auio.uio_rw = UIO_READ;
		auio.uio_resid = size;
		auio.uio_td = curthread;

		error = VOP_READ(vp, &auio, 0, curthread->td_ucred);
		if (!error) {
			int count = size - auio.uio_resid;

			if (count == 0)
				error = EINVAL;
			else if (count != PAGE_SIZE)
				bzero((caddr_t)sf_buf_kva(sf) + count,
				    PAGE_SIZE - count);
		}
		sf_buf_free(sf);

		VM_OBJECT_WLOCK(object);
	}
	KASSERT(m->dirty == 0, ("vnode_pager_input_old: page %p is dirty", m));
	if (!error)
		m->valid = VM_PAGE_BITS_ALL;
	return error ? VM_PAGER_ERROR : VM_PAGER_OK;
}
开发者ID:kwitaszczyk,项目名称:freebsd,代码行数:63,代码来源:vnode_pager.c

示例5: sys_read

int sys_read(int fid, void* buffer, size_t nbytes, int* retval) {
	if(!buffer || buffer == NULL) {
		return EFAULT;
	}

	struct openfile* readfile = (struct openfile*)ftGet(curthread->ft,fid);
	
	if (readfile == NULL) {
		return EBADF;
	}

	struct uio userio;
	mk_kuio(&userio, buffer,nbytes,readfile->offset,UIO_READ);

	int error = VOP_READ(readfile->data,&userio);

	if (error) {
		return error;
	}

	readfile->offset = userio.uio_offset;

	*retval = userio.uio_resid;

	return 0;
}
开发者ID:nyanzebra,项目名称:Operating-Systems,代码行数:26,代码来源:read.c

示例6: read_seg_from_swap

char* read_seg_from_swap(vaddr_t vaddr){
	kprintf("About to read segment from swap. given vaddress: %lu \n", (unsigned long)vaddr);
	char buf[SEG_SZ];
		
	struct iovec iov;
	struct uio u;

	int i, result, segNum= -1;
	
	for(i=0;i<TABLE_SZ;i++){
		if(addrptr[i]!=-1 && vaddr>=addrptr[i] && vaddr<addrptr[i]+SEG_SZ){
			segNum = i;
		}
	}

	
	if(segNum==-1){}//kprintf("segment not found\n");}
	else kprintf("found seg no %d \n",segNum);
	
	u.uio_iovcnt = 1;
	u.uio_resid = SEG_SZ;          // amount to read from the file
	u.uio_offset = offset[segNum];
	//u.uio_segflg = is_executable ? UIO_USERISPACE : UIO_USERSPACE;
	u.uio_rw = UIO_READ;
	u.uio_space = curthread->t_addrspace;

	uio_kinit(&iov, &u, buf, SEG_SZ, 0, UIO_READ);
	result = VOP_READ(swap_file, &u);
	return buf;

}
开发者ID:siddug,项目名称:os161-vm,代码行数:31,代码来源:swap.c

示例7: swapin

/*
 * Swapin()
 * -----------------------
 * 1. Sanity checks: We can't swap the pages holding the page table itself. 
 *    So, check if the paddr lie outside of coremap or not.
 * 2. We use mk_kuio to intiate a read from disk to physical memory.
 * 3. Remove the mapping of the page in the swaparea and unmark the swapmap 
 *    bitmap.
 * 4. Read into the page from disk.
 */
void swapin(u_int32_t paddr, u_int32_t chunk)
{
    /*
     * sanity check: make sure that we are not touching kernel space or the page
     * table itself .That is the page should be within the coremap memory 
     * starting from coremap_base
     */    
    assert(paddr >= coremap_base);
    
    int spl=splhigh();
    /*
     * Initialize the read I/O into kernel buffer of size PAGE_SIZE starting 
     * from paddr from the swaparea starting from offset indexed by chunk.
     */    
    struct uio swap_uio;
    mk_kuio(&swap_uio, /*kernel buffer*/(void*)PADDR_TO_KVADDR(paddr & PAGE_FRAME), 
                       /*Size of the buffer to read into*/PAGE_SIZE, 
                       /*Starting offset of the swap area for read out */chunk, UIO_READ);        
    
    /*
     * Remove the mapping of the chunk to page in the swaparea and unmark the 
     * swap_memmap bitmap to free the chunk.
     */
    remove_spage(chunk);
    splx(spl);
    
    //Now we read the page from memory into kernel buffer pointed with paddr
    int result=VOP_READ(swap_fp, &swap_uio);
    if(result) 
        panic("VM: SWAPIN Failed");    
}
开发者ID:zrzahid,项目名称:os161-kernel,代码行数:41,代码来源:vm.c

示例8: swaponepageout

static void swaponepageout(struct page* pg, paddr_t phyaddr) {
	int swapPageindex = pg->pt_pagebase;
	struct iovec iov;
	struct uio kuio;
	iov.iov_kbase = (void*) PADDR_TO_KVADDR(phyaddr);
	iov.iov_len = PAGE_SIZE; // length of the memory space
	kuio.uio_iov = &iov;
	kuio.uio_iovcnt = 1;
	kuio.uio_resid = PAGE_SIZE; // amount to write to the file
	kuio.uio_space = NULL;
	kuio.uio_offset = swap_map[swapPageindex].se_paddr * PAGE_SIZE;
	kuio.uio_segflg = UIO_SYSSPACE;
	kuio.uio_rw = UIO_READ;
	// 4. write them to disk
	int result = VOP_READ(swap_vnode, &kuio);
	if (result) {
		// release lock on the vnode
		panic("READ FAILED!\n");
		return;
	}

	swap_map[swapPageindex].se_used = SWAP_PAGE_FREE;
	kprintf("Swap out:\tswap= %x,\tpage=%x \n",swapPageindex,pg->pt_virtbase);
	pg->pt_state = PT_STATE_MAPPED;
	pg->pt_pagebase = phyaddr / PAGE_SIZE;


}
开发者ID:barrylanceleo,项目名称:Operating-system-abstractions-in-OS161,代码行数:28,代码来源:myvm.c

示例9: vdsp_readlabel

void
vdsp_readlabel(struct vdsp_softc *sc)
{
	struct proc *p = curproc;
	struct iovec iov;
	struct uio uio;
	int err;

	if (sc->sc_vp == NULL)
		return;

	sc->sc_label = malloc(sizeof(*sc->sc_label), M_DEVBUF, M_WAITOK);

	iov.iov_base = sc->sc_label;
	iov.iov_len = sizeof(*sc->sc_label);
	uio.uio_iov = &iov;
	uio.uio_iovcnt = 1;
	uio.uio_offset = 0;
	uio.uio_resid = sizeof(*sc->sc_label);
	uio.uio_segflg = UIO_SYSSPACE;
	uio.uio_rw = UIO_READ;
	uio.uio_procp = p;

	vn_lock(sc->sc_vp, LK_EXCLUSIVE | LK_RETRY, p);
	err = VOP_READ(sc->sc_vp, &uio, 0, p->p_ucred);
	VOP_UNLOCK(sc->sc_vp, 0, p);
	if (err) {
		free(sc->sc_label, M_DEVBUF, 0);
		sc->sc_label = NULL;
	}
}
开发者ID:DavidAlphaFox,项目名称:openbsd-kernel,代码行数:31,代码来源:vdsp.c

示例10: kobj_read_file_vnode

int
kobj_read_file_vnode(struct _buf *file, char *buf, unsigned size, unsigned off)
{
	struct vnode *vp = file->ptr;
	struct thread *td = curthread;
	struct uio auio;
	struct iovec aiov;
	int error, vfslocked;

	bzero(&aiov, sizeof(aiov));
	bzero(&auio, sizeof(auio));

	aiov.iov_base = buf;
	aiov.iov_len = size;

	auio.uio_iov = &aiov;
	auio.uio_offset = (off_t)off;
	auio.uio_segflg = UIO_SYSSPACE;
	auio.uio_rw = UIO_READ;
	auio.uio_iovcnt = 1;
	auio.uio_resid = size;
	auio.uio_td = td;

	vfslocked = VFS_LOCK_GIANT(vp->v_mount);
	vn_lock(vp, LK_SHARED | LK_RETRY);
	error = VOP_READ(vp, &auio, IO_UNIT | IO_SYNC, td->td_ucred);
	VOP_UNLOCK(vp, 0);
	VFS_UNLOCK_GIANT(vfslocked);
	return (error != 0 ? -1 : size - auio.uio_resid);
}
开发者ID:edgar-pek,项目名称:PerspicuOS,代码行数:30,代码来源:opensolaris_kobj.c

示例11: sys_read

int sys_read(int fd, userptr_t buf, size_t nbytes, int * retval){
	
	int err;	
	/* Step 1: Check if the fd value is valid and that the file handle has been opened */
	
	if (fd >= OPEN_MAX || fd <= -1) {	// out of bounds of the file table array
		return EBADF;
	} else { // if within the range of the file table
		if (curthread->t_fdtable[fd] == NULL) {		// if entry corresponding to the fd number is NULL, then return bad fd error
			return EBADF;
		}
	}
		/* Now, checking for "is file handle allowed to be written into? " */
	
	struct fhandle * fdesc;
	fdesc = curthread->t_fdtable[fd];
	
	if (fdesc->flags == O_WRONLY) {
		return EBADF;
	} 
	
	/* Step 2: Check if the buffer location is valid in userspace */
	if (buf == NULL) {
		return EFAULT;
	}
	
	/* Synchronizing the read operation */
	lock_acquire(fdesc->lock);
	
	/* Step 4: Initialize iovec and uio with uio_kinit and correct arguments */
	struct iovec iov;
	struct uio user;
	
	/* get the file handle from the file table and initialize uio with the uio_kinit method using fhandle's offset value also*/
	iov.iov_kbase = buf;
	iov.iov_len = nbytes;
	user.uio_iov = &iov;
	user.uio_iovcnt = 1;
	user.uio_offset = fdesc->offset;
	user.uio_resid = nbytes;
	user.uio_rw = UIO_READ;
	user.uio_segflg = UIO_USERSPACE;
	user.uio_space = curthread->t_addrspace;
	
	/* use VOP_READ to read from the file */
	err = VOP_READ(fdesc->vn, &user);
	if (err) {
		return err;
	}
	
	/* Calculate the amount of bytes written and return success to user (indicated by 0)*/
	*retval = nbytes - user.uio_resid;
	fdesc->offset = user.uio_offset; 	// advance offset by amount of bytes read	
	
	/* releasing the lock*/
	lock_release(fdesc->lock);

	return 0;	
}
开发者ID:flightno23,项目名称:OS161,代码行数:59,代码来源:fileOperations.c

示例12: as_define_stack

int
as_define_stack(struct addrspace *as, vaddr_t *stackptr)
{
	struct page *p;
	size_t npages;
	size_t curpage;
	struct uio ku;
	vaddr_t maxvaddr;
	vaddr_t lowerbound;
	int i;
	int result;
	unsigned int rval;
	vaddr_t stacktop;

	*stackptr = USERTOP;

	/* Do Stack ASLR */
	if (randvnode!=NULL)
	{
		mk_kuio(&ku, &rval, 4, 0, UIO_READ);

		result = VOP_READ(randvnode, &ku);
		if (result)
			return result;

		maxvaddr = (vaddr_t) 0;
		for(i=0;i<array_getnum(as->pages);i++)
		{
			p = (struct page *) array_getguy(as->pages, i);
			if (p->vaddr>maxvaddr)
				maxvaddr = p->vaddr;
		}
		
		lowerbound = maxvaddr + ((STACKSIZE * PAGE_SIZE) + PAGE_SIZE);
		rval %= USERTOP - (USERTOP - lowerbound);
		*stackptr = (lowerbound + rval) & PAGE_FRAME;
	}

	npages = (size_t) STACKSIZE;
	stacktop = *stackptr - PAGE_SIZE * npages;

	for(curpage=0;curpage<npages;curpage++)
	{
		p = (struct page *) kmalloc(sizeof(struct page));
		if (p==NULL)
			return ENOMEM;

		p->vaddr = stacktop + curpage * PAGE_SIZE;
		p->perms = P_R_B | P_W_B;
		array_add(as->pages, p);


		addpage(p->vaddr, curthread->t_pid, p->perms & P_R_B, 
			p->perms & P_W_B, p->perms & P_X_B, NULL);
	}

	return 0;
}
开发者ID:NickStephens,项目名称:os161,代码行数:58,代码来源:addrspace.c

示例13: load_each_segment

static
int
load_each_segment(struct vnode *v, off_t offset, vaddr_t vaddr, paddr_t paddr, 
                  size_t memsize, size_t filesize,
                  int is_executable, int first_read)
{
	struct uio u;
	int result;
	size_t fillamt;
    int spl;
    
	if (filesize > memsize) {
		kprintf("ELF: warning: segment filesize > segment memsize\n");
		filesize = memsize;
	}
    
	DEBUG(DB_EXEC, "ELF: Loading %lu bytes to 0x%lx\n", 
	      (unsigned long) filesize, (unsigned long) vaddr);
    
    if(first_read == 0){
        
        u.uio_iovec.iov_ubase = (userptr_t)vaddr;
        u.uio_iovec.iov_len = memsize;   // length of the memory space
        u.uio_resid = filesize;          // amount to actually read
        u.uio_offset = offset;
        u.uio_segflg = is_executable ? UIO_USERISPACE : UIO_USERSPACE;
        u.uio_rw = UIO_READ;
        u.uio_space = curthread->t_vmspace;
        
    }else{
        
        return 0;
    }
	
    result = VOP_READ(v, &u);
    
	if (result) {
        
		return result;
	}
	if (u.uio_resid != 0) {
		/* short read; problem with executable? */
		kprintf("ELF: short read on segment - file truncated?\n");
		return ENOEXEC;
	}
    
    /* Fill the rest of the memory space (if any) with zeros */
	fillamt = memsize - filesize;
	if (fillamt > 0) {
		DEBUG(DB_EXEC, "ELF: Zero-filling %lu more bytes\n", 
		      (unsigned long) fillamt);
		u.uio_resid += fillamt;
		result = uiomovezeros(fillamt, &u);
	}
	return result;
}
开发者ID:cecabusa,项目名称:cs350_os161,代码行数:56,代码来源:vm.c

示例14: smb_vop_read

int
smb_vop_read(vnode_t *vp, uio_t *uiop, cred_t *cr)
{
	int error;

	(void) VOP_RWLOCK(vp, V_WRITELOCK_FALSE, &smb_ct);
	error = VOP_READ(vp, uiop, 0, cr, &smb_ct);
	VOP_RWUNLOCK(vp, V_WRITELOCK_FALSE, &smb_ct);
	return (error);
}
开发者ID:MatiasNAmendola,项目名称:AuroraUX-SunOS,代码行数:10,代码来源:smb_vops.c

示例15: load_segment

/*
 * Load a segment at virtual address VADDR. The segment in memory
 * extends from VADDR up to (but not including) VADDR+MEMSIZE. The
 * segment on disk is located at file offset OFFSET and has length
 * FILESIZE.
 *
 * FILESIZE may be less than MEMSIZE; if so the remaining portion of
 * the in-memory segment should be zero-filled.
 *
 * Note that uiomove will catch it if someone tries to load an
 * executable whose load address is in kernel space. If you should
 * change this code to not use uiomove, be sure to check for this case
 * explicitly.
 */
int
load_segment(struct vnode *v, off_t offset, vaddr_t vaddr, 
	     size_t memsize, size_t filesize,
	     int is_executable)
{

	struct uio u; // Memory block
	int result;
	size_t fillamt;


	// The virtual memory has to be bigger then the file that we are loading into it
	if (filesize > memsize) {
		kprintf("ELF: warning: segment filesize > segment memsize\n");
		filesize = memsize;
	}

	DEBUG(DB_EXEC, "ELF: Loading %lu bytes to 0x%lx\n", 
	      (unsigned long) filesize, (unsigned long) vaddr);

	//u.uio_iovec.iov_ubase = (userptr_t)PADDR_TO_KVADDR(vaddr);
	u.uio_iovec.iov_ubase = (userptr_t)vaddr;
	u.uio_iovec.iov_len = memsize;   // length of the memory space
	u.uio_resid = filesize;          // amount to actually read
	u.uio_offset = offset;
	//u.uio_segflg = is_executable ? UIO_USERISPACE : UIO_USERSPACE;
	u.uio_segflg = UIO_SYSSPACE;
	u.uio_rw = UIO_READ;
	//u.uio_space = curthread->t_vmspace;
	u.uio_space = NULL;

	result = VOP_READ(v, &u);
	if (result) {
		return result;
	}

	DEBUG(1,"after read\n");

	if (u.uio_resid != 0) {
		/* short read; problem with executable? */
		kprintf("ELF: short read on segment - file truncated?\n");
		return ENOEXEC;
	}

	/* Fill the rest of the memory space (if any) with zeros */
	fillamt = memsize - filesize;
	if (fillamt > 0) {
		DEBUG(DB_EXEC, "ELF: Zero-filling %lu more bytes\n", 
		      (unsigned long) fillamt);
		u.uio_resid += fillamt;
		result = uiomovezeros(fillamt, &u);
	}
	
	return result;
}
开发者ID:gmumar,项目名称:os161,代码行数:69,代码来源:loadelf.c


注:本文中的VOP_READ函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。