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


Golang syscall.Pread函数代码示例

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


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

示例1: Pread64

func (k *PosixKernel) Pread64(fd co.Fd, buf co.Obuf, size co.Len, offset int64) uint64 {
	p := make([]byte, size)
	n, err := syscall.Pread(int(fd), p, offset)
	if err != nil {
		return Errno(err)
	}
	if err := buf.Pack(p); err != nil {
		return UINT64_MAX // FIXME
	}
	return uint64(n)
}
开发者ID:lunixbochs,项目名称:usercorn,代码行数:11,代码来源:io.go

示例2: ReadInt16

func (b Bone) ReadInt16(addr int) (uint16, error) {
	data := make([]byte, 2)
	count, err := syscall.Pread(int(b), data, int64(addr))
	if err != nil {
		return 0, err
	}
	if count != 2 {
		return 0, errors.New("wrong number of bytes read")
	}
	val := (uint16(data[1]) << 8) | uint16(data[0])
	return val, nil
}
开发者ID:enjenye,项目名称:beaglebone,代码行数:12,代码来源:beaglebone.go

示例3: Bytes

// Reads raw bytes from file descriptor if necessary, using the passed
// buffer as storage.
func (r *ReadResultFd) Bytes(buf []byte) []byte {
	sz := r.Sz
	if len(buf) < sz {
		sz = len(buf)
	}

	n, err := syscall.Pread(int(r.Fd), buf[:sz], r.Off)
	if err == io.EOF {
		err = nil
	}
	// TODO - error handling?
	return buf[:n]
}
开发者ID:SoftwareMaven,项目名称:go-fuse,代码行数:15,代码来源:read.go

示例4: ReadAt

// ReadAt reads len(b) bytes from the File starting at byte offset off.
// It returns the number of bytes read and the Error, if any.
// EOF is signaled by a zero count with err set to EOF.
// ReadAt always returns a non-nil Error when n != len(b).
func (file *File) ReadAt(b []byte, off int64) (n int, err Error) {
	if file == nil {
		return 0, EINVAL
	}
	for len(b) > 0 {
		m, e := syscall.Pread(file.fd, b, off)
		n += m
		if e != 0 {
			err = &PathError{"read", file.name, Errno(e)}
			break
		}
		b = b[m:len(b)]
		off += int64(m)
	}
	return
}
开发者ID:edisonwsk,项目名称:golang-on-cygwin,代码行数:20,代码来源:file.go

示例5: Bytes

// Reads raw bytes from file descriptor if necessary, using the passed
// buffer as storage.
func (r *ReadResultFd) Bytes(buf []byte) ([]byte, Status) {
	sz := r.Sz
	if len(buf) < sz {
		sz = len(buf)
	}

	n, err := syscall.Pread(int(r.Fd), buf[:sz], r.Off)
	if err == io.EOF {
		err = nil
	}

	if n < 0 {
		n = 0
	}

	return buf[:n], ToStatus(err)
}
开发者ID:thomasf,项目名称:go-fuse,代码行数:19,代码来源:read.go

示例6: Read

func (constor *Constor) Read(input *fuse.ReadIn, buf []byte) (fuse.ReadResult, fuse.Status) {
	constor.log("%d", input.Fh)
	ptr := uintptr(input.Fh)
	inode, err := constor.inodemap.findInode(input.NodeId)
	if err != nil {
		constor.error("%s", err)
		return nil, fuse.ToStatus(err)
	}
	offset := input.Offset

	F := constor.getfd(ptr)

	if F == nil {
		constor.error("F == nil")
		return nil, fuse.EIO
	}

	if (F.layer != inode.layer) && (inode.layer == 0) {
		syscall.Close(F.fd)
		path, err := constor.dentrymap.getPath(inode.ino)
		if err != nil {
			constor.error("%s", err)
			return nil, fuse.ToStatus(err)
		}
		pathl := Path.Join(constor.layers[0] + path)
		fd, err := syscall.Open(pathl, F.flags, 0)
		if err != nil {
			constor.error("%s", err)
			return nil, fuse.ToStatus(err)
		}
		F.fd = fd
		F.layer = 0
		constor.log("reset fd for %s", path)
	}

	fd := F.fd
	_, err = syscall.Pread(fd, buf, int64(offset))
	if err != nil {
		constor.error("%s", err)
		return nil, fuse.ToStatus(err)
	}
	return fuse.ReadResultData(buf), fuse.OK
}
开发者ID:krishnasrinivas,项目名称:constor,代码行数:43,代码来源:main.go

示例7: ReadAt

// ReadAt reads len(b) bytes from the File starting at byte offset off.
// It returns the number of bytes read and the Error, if any.
// EOF is signaled by a zero count with err set to EOF.
// ReadAt always returns a non-nil Error when n != len(b).
func (file *File) ReadAt(b []byte, off int64) (n int, err Error) {
	if file == nil {
		return 0, EINVAL
	}
	for len(b) > 0 {
		m, e := syscall.Pread(file.fd, b, off)
		if m == 0 && !iserror(e) {
			return n, EOF
		}
		if iserror(e) {
			err = &PathError{"read", file.name, Errno(e)}
			break
		}
		n += m
		b = b[m:]
		off += int64(m)
	}
	return
}
开发者ID:richlowe,项目名称:gcc,代码行数:23,代码来源:file.go

示例8: Read

func (constor *Constor) Read(input *fuse.ReadIn, buf []byte) (fuse.ReadResult, fuse.Status) {
	constor.log("%d %d", input.Fh, len(buf))
	ptr := uintptr(input.Fh)
	inode := constor.inodemap.findInodePtr(input.NodeId)
	if inode == nil {
		constor.error("inode == nil")
		return nil, fuse.ENOENT
	}
	offset := input.Offset

	F := constor.getfd(ptr)

	if F == nil {
		constor.error("F == nil")
		return nil, fuse.EIO
	}

	if (F.layer != inode.layer) && (inode.layer == 0) {
		syscall.Close(F.fd)
		path := constor.getPath(0, inode.id)
		fd, err := syscall.Open(path, F.flags, 0)
		if err != nil {
			constor.error("open failed %s : %s", path, err)
			return nil, fuse.ToStatus(err)
		}
		F.fd = fd
		F.layer = 0
		constor.log("reset fd for %s", path)
	}
	if (F.layer != inode.layer) && (inode.layer >= 0) {
		constor.error("%s : %d", F.id, inode.layer)
		return nil, fuse.EBADF
	}
	fd := F.fd
	n, err := syscall.Pread(fd, buf, int64(offset))
	if err != nil && err != io.EOF {
		constor.error("%s", err)
		return nil, fuse.ToStatus(err)
	}
	return fuse.ReadResultData(buf[:n]), fuse.OK
}
开发者ID:krishnasrinivas,项目名称:confs,代码行数:41,代码来源:main.go

示例9: ReadAt

func (r *Reader) ReadAt(p []byte, off int64) (int, error) {
	//TODO: check if buffer is already conformant in case user wants to
	//      optimize
	l := len(p)
	start := off

	// offset from start of block
	offset := int(start % r.xfer)
	start -= int64(offset)
	l += offset

	// Make sure you read complete blocks
	remainder := int64(l) % r.xfer
	l += int(r.xfer - remainder)

	buff, err := NewAlignedBuffer(r.align, l)
	if err != nil {
		return -1, err
	}
	defer buff.Close()

	slice := buff.CreateSlice()

	bread, err := syscall.Pread(int(r.file.Fd()), slice, start)
	if err != nil {
		return -1, err
	}

	bread -= offset
	if bread > len(p) {
		bread = len(p)
	}

	copy(p, slice[offset:offset+bread])
	return bread, nil
}
开发者ID:ficoos,项目名称:godirect,代码行数:36,代码来源:reader.go

示例10: pread

// pread reads len(b) bytes from the File starting at byte offset off.
// It returns the number of bytes read and the error, if any.
// EOF is signaled by a zero count with err set to nil.
func (f *File) pread(b []byte, off int64) (n int, err error) {
	return syscall.Pread(f.fd, b, off)
}
开发者ID:kostyll,项目名称:gccpy,代码行数:6,代码来源:file_plan9.go

示例11: pread

// pread reads len(b) bytes from the File starting at byte offset off.
// It returns the number of bytes read and the error, if any.
// EOF is signaled by a zero count with err set to nil.
func (f *File) pread(b []byte, off int64) (n int, err error) {
	if needsMaxRW && len(b) > maxRW {
		b = b[:maxRW]
	}
	return fixCount(syscall.Pread(f.fd, b, off))
}
开发者ID:kuangchanglang,项目名称:go,代码行数:9,代码来源:file_unix.go

示例12: Read

func (s *SyncFile) Read(buf []byte, off int64) (n int, err error) {
	return syscall.Pread(int(s.fp.Fd()), buf, off)
}
开发者ID:lovefcaaa,项目名称:split,代码行数:3,代码来源:syncio.go


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