本文整理汇总了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)
}
示例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
}
示例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]
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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))
}
示例12: Read
func (s *SyncFile) Read(buf []byte, off int64) (n int, err error) {
return syscall.Pread(int(s.fp.Fd()), buf, off)
}