func (sc *serveConn) readDir(req *fuse.ReadRequest) { inode := uint64(req.Header.Node) resp := &fuse.ReadResponse{make([]byte, 0, req.Size)} var dirs []fuse.Dirent file, err := sc.db.FileByInode(inode) if err != nil { fuse.Debug(fmt.Sprintf("FileByInode(%d): %v", inode, err)) req.RespondError(fuse.EIO) return } for _, inode := range file.Children { f, err := sc.db.FileByInode(inode) if err != nil { fuse.Debug(fmt.Sprintf("child: FileByInode(%d): %v", inode, err)) req.RespondError(fuse.EIO) return } childType := fuse.DT_File if f.MimeType == driveFolderMimeType { childType = fuse.DT_Dir } dirs = append(dirs, fuse.Dirent{Inode: f.Inode, Name: f.Title, Type: childType}) } fuse.Debug(fmt.Sprintf("%+v", dirs)) var data []byte for _, dir := range dirs { data = fuse.AppendDirent(data, dir) } fuseutil.HandleRead(req, resp, data) req.Respond(resp) }
func (sc *serveConn) read(req *fuse.ReadRequest) { inode := uint64(req.Header.Node) resp := &fuse.ReadResponse{} // Lookup which fileId this request refers to f, err := sc.db.FileByInode(inode) if err != nil { debug.Printf("FileByInode(%d): %v", inode, err) req.RespondError(fuse.EIO) return } debug.Printf("Read(title: %s, offset: %d, size: %d)\n", f.Title, req.Offset, req.Size) resp.Data, err = sc.db.ReadFiledata(f.Id, req.Offset, int64(req.Size), f.FileSize) if err != nil && err != io.EOF { debug.Printf("driveCache.Read (..%v..): %v", req.Offset, err) req.RespondError(fuse.EIO) return } req.Respond(resp) }