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) }
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 }
// 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] }
// 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 }
// 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) }
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 }
// 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 }
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 }
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 }
// 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) }
// 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)) }
func (s *SyncFile) Read(buf []byte, off int64) (n int, err error) { return syscall.Pread(int(s.fp.Fd()), buf, off) }