當前位置: 首頁>>代碼示例>>Golang>>正文


Golang fuse.ReadResultData函數代碼示例

本文整理匯總了Golang中github.com/hanwen/go-fuse/fuse.ReadResultData函數的典型用法代碼示例。如果您正苦於以下問題:Golang ReadResultData函數的具體用法?Golang ReadResultData怎麽用?Golang ReadResultData使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了ReadResultData函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Read

// implements nodefs.File
func (this *hookFile) Read(dest []byte, off int64) (fuse.ReadResult, fuse.Status) {
	hook, hookEnabled := this.hook.(HookOnRead)
	var prehookBuf, posthookBuf []byte
	var prehookErr, posthookErr error
	var prehooked, posthooked bool
	var prehookCtx HookContext

	if hookEnabled {
		prehookBuf, prehookErr, prehooked, prehookCtx = hook.PreRead(this.name, int64(len(dest)), off)
		if prehooked {
			log.WithFields(log.Fields{
				"this": this,
				// "prehookBuf": prehookBuf,
				"prehookErr": prehookErr,
				"prehookCtx": prehookCtx,
			}).Debug("Read: Prehooked")
			return fuse.ReadResultData(prehookBuf), fuse.ToStatus(prehookErr)
		}
	}

	lowerRR, lowerCode := this.file.Read(dest, off)
	if hookEnabled {
		lowerRRBuf, lowerRRBufStatus := lowerRR.Bytes(make([]byte, lowerRR.Size()))
		if lowerRRBufStatus != fuse.OK {
			log.WithField("error", lowerRRBufStatus).Panic("lowerRR.Bytes() should not cause an error")
		}
		posthookBuf, posthookErr, posthooked = hook.PostRead(int32(lowerCode), lowerRRBuf, prehookCtx)
		if posthooked {
			if len(posthookBuf) != len(lowerRRBuf) {
				log.WithFields(log.Fields{
					"this": this,
					// "posthookBuf": posthookBuf,
					"posthookErr":    posthookErr,
					"posthookBufLen": len(posthookBuf),
					"lowerRRBufLen":  len(lowerRRBuf),
					"destLen":        len(dest),
				}).Warn("Read: Posthooked, but posthookBuf length != lowerrRRBuf length. You may get a strange behavior.")
			}

			log.WithFields(log.Fields{
				"this": this,
				// "posthookBuf": posthookBuf,
				"posthookErr": posthookErr,
			}).Debug("Read: Posthooked")
			return fuse.ReadResultData(posthookBuf), fuse.ToStatus(posthookErr)
		}
	}

	return lowerRR, lowerCode
}
開發者ID:osrg,項目名稱:hookfs,代碼行數:51,代碼來源:file.go

示例2: Read

func (node *AppendFSNode) Read(file nodefs.File, dest []byte, off int64, context *fuse.Context) (fuse.ReadResult, fuse.Status) {
	ret := fuse.OK
	dataFile, err := os.Open(node.fs.dataFilePath)
	if err != nil {
		ret = fuse.EIO
	}
	node.metadataMutex.RLock()
	start, end := int(off), int(off)+len(dest)-1
	entries := node.contentRanges.InRange(start, end)
	for _, entry := range entries {
		readStart, readEnd := max(entry.Min, start), min(entry.Max, end)+1
		blockStart, blockEnd := readStart-int(off), readEnd-int(off)
		blockDest := dest[blockStart:blockEnd]
		if fse, ok := entry.Data.(fileSegmentEntry); ok {
			readPos := int64(fse.base + readStart)
			//fmt.Printf("fileOffset: %d, blockStart: %d, blockEnd: %d, readPos: %d, min: %d, max: %d\n",
			//fse.fileOffset, blockStart, blockEnd, readPos, entry.Min, entry.Max)
			_, err = dataFile.ReadAt(blockDest, readPos)
			if err != nil {
				fmt.Printf("Read error\n")
				ret = fuse.EIO
			}

		}
	}
	node.metadataMutex.RUnlock()
	err = dataFile.Close()
	if err != nil {
		ret = fuse.EIO
	}
	if ret != fuse.OK {
		return nil, ret
	}
	return fuse.ReadResultData(dest), ret
}
開發者ID:e-tothe-ipi,項目名稱:appendfs,代碼行數:35,代碼來源:appendfsnode.go

示例3: Read

func (n *nodeReadNode) Read(file File, dest []byte, off int64, context *fuse.Context) (fuse.ReadResult, fuse.Status) {
	e := off + int64(len(dest))
	if int(e) > len(n.data) {
		e = int64(len(n.data))
	}
	return fuse.ReadResultData(n.data[off:int(e)]), fuse.OK
}
開發者ID:carriercomm,項目名稱:go-fuse,代碼行數:7,代碼來源:fileless_test.go

示例4: Read

func (f *memoryFile) Read(dest []byte, off int64) (fuse.ReadResult, fuse.Status) {
	b := f.blob.Contents()
	end := off + int64(len(dest))
	if end > int64(len(b)) {
		end = int64(len(b))
	}
	return fuse.ReadResultData(b[off:end]), fuse.OK
}
開發者ID:hanwen,項目名稱:gitfs,代碼行數:8,代碼來源:fs.go

示例5: Read

func (f *MutableDataFile) Read(buf []byte, off int64) (fuse.ReadResult, fuse.Status) {
	end := int(off) + len(buf)
	if end > len(f.data) {
		end = len(f.data)
	}

	return fuse.ReadResultData(f.data[off:end]), fuse.OK
}
開發者ID:Richardphp,項目名稱:noms,代碼行數:8,代碼來源:fsetattr_test.go

示例6: Read

func (f *dataFile) Read(buf []byte, off int64) (res fuse.ReadResult, code fuse.Status) {
	end := int(off) + int(len(buf))
	if end > len(f.data) {
		end = len(f.data)
	}

	return fuse.ReadResultData(f.data[off:end]), fuse.OK
}
開發者ID:jszwedko,項目名稱:ec2-metadatafs,代碼行數:8,代碼來源:files.go

示例7: Read

func (f *CFile) Read(buf []byte, off int64) (res fuse.ReadResult, code fuse.Status) {
	log.Printf("Reading data from %s, len: %v", f.name, len(buf))
	l, buf, _, err := f.client.Read(ctx.TODO(), f.name, off, int64(len(buf)), 0)
	if err != nil {
		log.Fatalf("Failed to read")
	}
	log.Printf("Read Data from %s %v, %v", f.name, buf, l)
	return fuse.ReadResultData(buf), fuse.OK
}
開發者ID:c-fs,項目名稱:cfuse,代碼行數:9,代碼來源:main.go

示例8: Read

func (m *MFile) Read(dest []byte, off int64) (fuse.ReadResult, fuse.Status) {
	m.obj.Lock()
	defer m.obj.Unlock()
	n, e := m.file.ReadAt(dest, off)
	if e == io.EOF {
		e = nil
	}
	return fuse.ReadResultData(dest[:n]), fuse.ToStatus(e)
}
開發者ID:maxymania,項目名稱:metaclusterfs,代碼行數:9,代碼來源:file.go

示例9: Read

// Read - FUSE call
func (f *virtualFile) Read(buf []byte, off int64) (resultData fuse.ReadResult, status fuse.Status) {
	if off >= int64(len(f.content)) {
		return nil, fuse.OK
	}
	end := int(off) + len(buf)
	if end > len(f.content) {
		end = len(f.content)
	}
	return fuse.ReadResultData(f.content[off:end]), fuse.OK
}
開發者ID:rfjakob,項目名稱:gocryptfs,代碼行數:11,代碼來源:virtualfile.go

示例10: Read

func (node *inMemNode) Read(file nodefs.File, dest []byte, off int64, context *fuse.Context) (fuse.ReadResult, fuse.Status) {
	if int(off) > len(node.contents) {
		return nil, fuse.EIO
	}
	if len(dest) > len(node.contents)-int(off) {
		dest = dest[:len(node.contents)-int(off)]
	}
	copy(dest, node.contents[off:])
	return fuse.ReadResultData(dest), fuse.OK
}
開發者ID:e-tothe-ipi,項目名稱:inmemfs,代碼行數:10,代碼來源:main.go

示例11: Read

func (f *file) Read(buf []byte, offset int64) (fuse.ReadResult, fuse.Status) {
	logrus.Debugf("Read: %s", string(f.kv.Value))

	end := int(offset) + len(buf)
	if end > len(f.kv.Value) {
		end = len(f.kv.Value)
	}

	copy(buf, f.kv.Value[offset:end])
	return fuse.ReadResultData(buf), fuse.OK
}
開發者ID:cpuguy83,項目名稱:kvfs,代碼行數:11,代碼來源:file.go

示例12: Read

func (f *OssFile) Read(buf []byte, off int64) (fuse.ReadResult, fuse.Status) {
	log.Printf("Start to call read method!off:%d \n", off)
	f.lock.Lock()
	defer f.lock.Unlock()
	if f.bufFile == nil {
		f.bufFile = &BufFile{off: off, data: nil, size: int(f.size), endOff: int64(0), bucket: f.bucket,
			cacheSize: 1500000, lock: &sync.Mutex{}}
	}
	num, err := readFromBuf(f.bufFile, buf, off, f.size, f.ossClient, f.fileName, 0)

	log.Printf("Has read from Buf %d num bytes \n", num)
	if err != nil {
		return nil, fuse.EINVAL
	} else {
		if num <= len(buf) {
			readResultDatas := fuse.ReadResultData(buf[:num])
			return readResultDatas, fuse.OK
		} else {
			log.Printf("Error!!! num %d,len:%d,off:%d \n", num, len(buf), off)
			return fuse.ReadResultData(buf[:len(buf)]), fuse.OK
		}
	}
}
開發者ID:fantasycool,項目名稱:gz-oss,代碼行數:23,代碼來源:file.go

示例13: Read

func (nfile nomsFile) Read(dest []byte, off int64) (fuse.ReadResult, fuse.Status) {
	nfile.node.nLock.Lock()
	defer nfile.node.nLock.Unlock()

	file := nfile.node.inode.Get("contents")

	d.Chk.Equal(nodeType(nfile.node.inode), "File")

	ref := file.(types.Struct).Get("data").(types.Ref)
	blob := nfile.fs.ds.Database().ReadValue(ref.TargetHash()).(types.Blob)

	br := blob.Reader()

	_, err := br.Seek(off, 0)
	if err != nil {
		return nil, fuse.EIO
	}
	n, err := br.Read(dest)
	if err != nil {
		return fuse.ReadResultData(dest[:n]), fuse.EIO
	}

	return fuse.ReadResultData(dest[:n]), fuse.OK
}
開發者ID:Richardphp,項目名稱:noms,代碼行數:24,代碼來源:nomsfs.go

示例14: Read

func (f *etcdFile) Read(buf []byte, off int64) (fuse.ReadResult, fuse.Status) {
	res, err := f.etcdClient.Get(f.path, false, false)

	if err != nil {
		log.Println("Error:", err)
		return nil, fuse.EIO
	}

	end := int(off) + int(len(buf))
	if end > len(res.Node.Value) {
		end = len(res.Node.Value)
	}

	data := []byte(res.Node.Value)
	return fuse.ReadResultData(data[off:end]), fuse.OK
}
開發者ID:roberto-reale,項目名稱:etcd-fs,代碼行數:16,代碼來源:file.go

示例15: Read

func (f *androidFile) Read(dest []byte, off int64) (fuse.ReadResult, fuse.Status) {
	if off > f.node.Size {
		// ENXIO = no such address.
		return nil, fuse.Status(int(syscall.ENXIO))
	}

	if off+int64(len(dest)) > f.node.Size {
		dest = dest[:f.node.Size-off]
	}
	b := bytes.NewBuffer(dest[:0])
	err := f.node.fs.dev.AndroidGetPartialObject64(f.node.Handle(), b, off, uint32(len(dest)))
	if err != nil {
		log.Println("AndroidGetPartialObject64 failed:", err)
		return nil, fuse.EIO
	}

	return fuse.ReadResultData(dest[:b.Len()]), fuse.OK
}
開發者ID:YoshikuniShiku,項目名稱:go-mtpfs,代碼行數:18,代碼來源:android.go


注:本文中的github.com/hanwen/go-fuse/fuse.ReadResultData函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。