func (h *Handler) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error { logex.Struct(*req) resp.Data = make([]byte, req.Size) n, err := h.file.ReadAt(resp.Data, req.Offset) resp.Data = resp.Data[:n] return err }
func (f *File) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error { f.RLock() defer f.RUnlock() log.Trace("File Read, req=%#v, topic=%s, partitionId=%d", req, f.topic, f.partitionId) resp.Data = resp.Data[:req.Size] resp.Data = f.content[req.Offset : req.Size+int(req.Offset)] return nil }
func (e fuseFile) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error { // TODO ReadAt is more strict about not giving partial reads // than we care about, but i like the lack of cursor resp.Data = resp.Data[0:cap(resp.Data)] n, err := e.rat.ReadAt(resp.Data, req.Offset) resp.Data = resp.Data[:n] if err != nil && err != io.EOF { return err } return nil }
func readContent(node *TreeEntry, ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) (err error) { var p []byte = make([]byte, req.Size) // see if we already have an open body if node.HttpResponse == nil { fmt.Printf("starting to download %s\n", node.E.Name) b, _ := json.Marshal(node.Metadata) fmt.Println(string(b)) // get the reader node.HttpResponse, err = DownloadContent(node.CustomId, apiClient, endpointCfg) if err != nil { return err } } cnt, err := readBytes(node.HttpResponse.Body, p, req.Size) if err == io.EOF { fmt.Println("GOT EOF!!!") err = nil defer func() { node.HttpResponse.Body.Close() node.HttpResponse = nil }() } resp.Data = p[:cnt] return }
// Responds on FUSE Read request func (this *ZipFileHandle) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error { this.lock.Lock() defer this.lock.Unlock() for req.Offset != this.offset { // Since file is opened in fuse.OpenNonSeekable mode, we expect kernel to issue sequential reads. // However kernel might issue multiple read-ahead requests, one after another, but and they might be // reordered by underlying bazil/fuse library because it fans out each request to a separate concurrent goroutine. // If we got offset which isn't expected, this means that "wrong" goroutine grabbed the lock, // in this case yielding for other instance of concurrent go-routine. // This is a temporary workaround, we'll need to find better solution // TODO: consider addressing this at bazil/fuse, by adding per-handle request serialization feature which preserves ordering this.lock.Unlock() time.Sleep(time.Duration(rand.Int31n(10)) * time.Millisecond) this.lock.Lock() } // reading requested bytes buffer := make([]byte, req.Size) nr, err := io.ReadFull(this.ContentStream, buffer) this.offset += int64(nr) if err == io.EOF || err == io.ErrUnexpectedEOF { // EOF isn't an error from the FUSE's point of view err = nil } resp.Data = buffer[:nr] return err }
func (f *file) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error { debug.Log("file.Read", "Read(%v), file size %v", req.Size, f.node.Size) offset := req.Offset // Skip blobs before the offset startContent := 0 for offset > int64(f.sizes[startContent]) { offset -= int64(f.sizes[startContent]) startContent++ } dst := resp.Data[0:req.Size] readBytes := 0 remainingBytes := req.Size for i := startContent; remainingBytes > 0 && i < len(f.sizes); i++ { blob, err := f.getBlobAt(i) if err != nil { return err } if offset > 0 { blob = blob[offset:len(blob)] offset = 0 } copied := copy(dst, blob) remainingBytes -= copied readBytes += copied dst = dst[copied:] } resp.Data = resp.Data[:readBytes] return nil }
func (fh FileHandle) Read(ctx context.Context, req *bfuse.ReadRequest, resp *bfuse.ReadResponse) error { /* Header: Conn *Conn `json:"-"` // connection this request was received on ID RequestID // unique ID for request Node NodeID // file or directory the request is about Uid uint32 // user ID of process making request Gid uint32 // group ID of process making request Pid uint32 // process ID of process making request Handle HandleID Offset int64 Size int */ log.Printf("Read offset %d size %d", req.Offset, req.Size) if fh.h == nil { return EBADF } resp.Data = resp.Data[:req.Size] if err := fh.h.PRead(req.Offset, resp.Data); err != nil { return err } return nil }
func (fh FileHandle) Read(ctx context.Context, req *bfuse.ReadRequest, resp *bfuse.ReadResponse) error { logger.Debugf(mylog, "Read offset %d size %d", req.Offset, req.Size) if fh.h == nil { return EBADF } resp.Data = resp.Data[:req.Size] n, err := fh.h.ReadAt(resp.Data, req.Offset) if err != nil { return err } resp.Data = resp.Data[:n] return nil }
func (f *file) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error { off := req.Offset // Skip blobs before the offset startContent := 0 for off > int64(f.sizes[startContent]) { off -= int64(f.sizes[startContent]) startContent++ } content := make([]byte, req.Size) allContent := content for i := startContent; i < len(f.sizes); i++ { blob, err := f.getBlobAt(i) if err != nil { return err } blob = blob[off:] off = 0 var copied int if len(blob) > len(content) { copied = copy(content[0:], blob[:len(content)]) } else { copied = copy(content[0:], blob) } content = content[copied:] if len(content) == 0 { break } } resp.Data = allContent return nil }
func (h *handle) Read(ctx context.Context, request *fuse.ReadRequest, response *fuse.ReadResponse) (retErr error) { defer func() { if retErr == nil { protolion.Debug(&FileRead{&h.f.Node, string(response.Data), errorToString(retErr)}) } else { protolion.Error(&FileRead{&h.f.Node, string(response.Data), errorToString(retErr)}) } }() var buffer bytes.Buffer if err := h.f.fs.apiClient.GetFileUnsafe( h.f.File.Commit.Repo.Name, h.f.File.Commit.ID, h.f.File.Path, request.Offset, int64(request.Size), h.f.fs.getFromCommitID(h.f.getRepoOrAliasName()), h.f.Shard, h.f.fs.handleID, &buffer, ); err != nil { if grpc.Code(err) == codes.NotFound { // ENOENT from read(2) is weird, let's call this EINVAL // instead. return fuse.Errno(syscall.EINVAL) } return err } response.Data = buffer.Bytes() return nil }
func (fn fileNode) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error { torrentfsReadRequests.Add(1) if req.Dir { panic("read on directory") } size := req.Size fileLeft := int64(fn.size) - req.Offset if fileLeft < 0 { fileLeft = 0 } if fileLeft < int64(size) { size = int(fileLeft) } resp.Data = resp.Data[:size] if len(resp.Data) == 0 { return nil } torrentOff := fn.TorrentOffset + req.Offset n, err := readFull(ctx, fn.FS, fn.t, torrentOff, resp.Data) if err != nil { return err } if n != size { panic(fmt.Sprintf("%d < %d", n, size)) } return nil }
// io func (f *FuseDevice) Read(fReq *fuse.ReadRequest, fResp *fuse.ReadResponse, i fs.Intr) fuse.Error { println("read request, bufsize: ", cap(fResp.Data), fReq.Size) // FIXME: handle aborted reads req := newReadReq() f.device.readReqs <- req resp := <-*req if resp.err != nil { fResp.Data = fResp.Data[:0] } else { n := copy(fResp.Data[:fReq.Size], resp.input) fResp.Data = fResp.Data[:n] println("return on read: ", fResp.Data, resp.err) } return resp.err }
func (f *file) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error { debug.Log("Read(%v, %v, %v), file size %v", f.node.Name, req.Size, req.Offset, f.node.Size) offset := req.Offset if uint64(offset) > f.node.Size { debug.Log("Read(%v): offset is greater than file size: %v > %v", f.node.Name, req.Offset, f.node.Size) return errors.New("offset greater than files size") } // handle special case: file is empty if f.node.Size == 0 { resp.Data = resp.Data[:0] return nil } // Skip blobs before the offset startContent := 0 for offset > int64(f.sizes[startContent]) { offset -= int64(f.sizes[startContent]) startContent++ } dst := resp.Data[0:req.Size] readBytes := 0 remainingBytes := req.Size for i := startContent; remainingBytes > 0 && i < len(f.sizes); i++ { blob, err := f.getBlobAt(i) if err != nil { return err } if offset > 0 { blob = blob[offset:len(blob)] offset = 0 } copied := copy(dst, blob) remainingBytes -= copied readBytes += copied dst = dst[copied:] } resp.Data = resp.Data[:readBytes] return nil }
func (f *file) Read(ctx context.Context, request *fuse.ReadRequest, response *fuse.ReadResponse) error { buffer := bytes.NewBuffer(make([]byte, 0, request.Size)) if err := pfsutil.GetFile(f.fs.apiClient, f.fs.repositoryName, f.commitID, f.path, request.Offset, int64(request.Size), buffer); err != nil { return err } response.Data = buffer.Bytes() return nil }
func (fh *FileHandle) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error { glog.Infof("Entered Read.\n") //TODO: Check if we need to add something here for playlists and drop directories. if fh.r == nil { if fh.f.name == ".description" { glog.Info("Reading description file\n") if len(fh.f.artist) < 1 { return fuse.ENOENT } _, err := store.GetArtistPath(fh.f.artist) if err != nil { return err } if len(fh.f.album) > 1 { _, err = store.GetAlbumPath(fh.f.artist, fh.f.album) if err != nil { return err } } descBytes, err := store.GetDescription(fh.f.artist, fh.f.album, fh.f.name) if err != nil { return err } resp.Data = []byte(descBytes) return nil } glog.Info("There is no file handler.\n") return fuse.EIO } glog.Infof("Reading file: %s.\n", fh.r.Name()) if _, err := fh.r.Seek(req.Offset, 0); err != nil { return err } buf := make([]byte, req.Size) n, err := fh.r.Read(buf) resp.Data = buf[:n] if err != nil && err != io.EOF { glog.Error(err) return err } return nil }
func (n Node) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error { if fp := n.handleManager.GetHandle(req.Handle); fp != nil { resp.Data = make([]byte, req.Size) _, err := fp.ReadAt(resp.Data, req.Offset) return err } return syscall.EBADF }
//handleReader interface func (o *openFileHandle) Read(request *fuse.ReadRequest, response *fuse.ReadResponse, intr fs.Intr) fuse.Error { log.Printf("request: %+v\nobject: %+v", request, o) start := request.Offset stop := start + int64(request.Size) bufptr := o.buffer if stop > int64(len(bufptr)-1) { stop = int64(len(bufptr)) } if stop == start { log.Printf("no bytes read") response.Data = []byte{} //new gives you a pointer return nil } slice := bufptr[start:stop] response.Data = slice //address of buffer goes to response log.Printf("FileHandle data:%s", response.Data) return nil }
func (f File) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error { data, err := f.m.GetFileData(f.folder, f.path, req.Offset, req.Size) if err != nil { return err } resp.Data = data return err }
func (f *file) Read(ctx context.Context, request *fuse.ReadRequest, response *fuse.ReadResponse) (retErr error) { defer func() { protolog.Info(&FileRead{&f.Node, errorToString(retErr)}) }() buffer := bytes.NewBuffer(make([]byte, 0, request.Size)) if err := pfsutil.GetFile(f.fs.apiClient, f.RepoName, f.CommitID, f.Path, request.Offset, int64(request.Size), buffer); err != nil { return err } response.Data = buffer.Bytes() return nil }
func (f *File) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error { f.RLock() defer f.RUnlock() log.Printf("(*File) Read, req=%q, path=%s", req, filepath.Base(f.path)) if f.handler == nil { log.Println("Read: File should be open, aborting request") return fuse.ENOTSUP } resp.Data = resp.Data[:req.Size] n, err := f.handler.ReadAt(resp.Data, req.Offset) if err != nil && err != io.EOF { log.Println("Read ERR: ", err) return err } resp.Data = resp.Data[:n] return nil }
// Read gets a swift object data for a request within the current context. // The request size is always honored. We open the file on the first write. func (fh *ObjectHandle) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) (err error) { if fh.rd == nil { fh.rd, err = newReader(fh) if err != nil { return err } } fh.rd.Seek(req.Offset, 0) resp.Data = make([]byte, req.Size) io.ReadFull(fh.rd, resp.Data) return nil }
// HandleRead handles a read request assuming that data is the entire file content. // It adjusts the amount returned in resp according to req.Offset and req.Size. func HandleRead(req *fuse.ReadRequest, resp *fuse.ReadResponse, data []byte) { if req.Offset >= int64(len(data)) { data = nil } else { data = data[req.Offset:] } if len(data) > req.Size { data = data[:req.Size] } n := copy(resp.Data[:req.Size], data) resp.Data = resp.Data[:n] }
func (f *file) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error { f.mu.Lock() defer f.mu.Unlock() if req.Offset < 0 { panic("unreachable") } if req.Offset > maxInt64 { log.Printf("offset is past int64 max: %d", req.Offset) return fuse.EIO } resp.Data = resp.Data[:req.Size] n, err := f.blob.ReadAt(resp.Data, int64(req.Offset)) if err != nil && err != io.EOF { log.Printf("read error: %v", err) return fuse.EIO } resp.Data = resp.Data[:n] return nil }
func (s staticFileNode) Read(ctx context.Context, req *fuse.ReadRequest, res *fuse.ReadResponse) error { if req.Offset > int64(len(s)) { return nil } s = s[req.Offset:] size := req.Size if size > len(s) { size = len(s) } res.Data = make([]byte, size) copy(res.Data, s) return nil }
// Read implements the fs.HandleReader interface for File. func (f *File) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) (err error) { f.folder.fs.log.CDebugf(ctx, "File Read") defer func() { f.folder.reportErr(ctx, libkbfs.ReadMode, err) }() n, err := f.folder.fs.config.KBFSOps().Read( ctx, f.node, resp.Data[:cap(resp.Data)], req.Offset) if err != nil { return err } resp.Data = resp.Data[:n] return nil }
func (f *LinkedFile) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error { fi, err := f.fileHandle() if err != nil { log.Println(err) return err } d := make([]byte, req.Size) _, err = fi.ReadAt(d, req.Offset) if err != nil && err != io.EOF { return err } resp.Data = d return nil }
func (s *stat) Read(ctx context.Context, req *fuse.ReadRequest, res *fuse.ReadResponse) error { c := s.content() if req.Offset > int64(len(c)) { return nil } c = c[req.Offset:] size := req.Size if size > len(c) { size = len(c) } res.Data = make([]byte, size) copy(res.Data, c) return nil }
func (h *FileHandle) Read(req *fuse.ReadRequest, resp *fuse.ReadResponse, intr fs.Intr) fuse.Error { _, err := h.file.Seek(req.Offset, os.SEEK_SET) if err != nil { return err } buf := make([]byte, req.Size) n, err := h.file.Read(buf) if err != io.EOF && err != nil { return err } resp.Data = buf[:n] return nil }
func (h *fileHandler) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error { if _, err := h.reader.Seek(req.Offset, os.SEEK_SET); err != nil { logrus.Debugf("Error seeking: %v", err) return err } n, err := h.reader.Read(resp.Data[:req.Size]) if err != nil { logrus.Debugf("Read error: %v", err) return err } resp.Data = resp.Data[:n] return nil }
func (f *FileHandle) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error { err := f.fs.PrepareForRead(f.path, f.etag, f.file.Name(), uint64(req.Offset), uint64(req.Size), nil) if err != nil { fmt.Printf("PrepareForRead failed: %s\n", err.Error()) return err } buffer := make([]byte, req.Size) n, err := f.file.ReadAt(buffer, req.Offset) if err != nil { return err } // TODO: check, did caller allocate Data before this call? resp.Data = buffer[:n] return err }