コード例 #1
0
ファイル: hello_fs.go プロジェクト: BanzaiMan/gcsfuse
func (fs *helloFS) ReadFile(
	op *fuseops.ReadFileOp) (err error) {
	// Let io.ReaderAt deal with the semantics.
	reader := strings.NewReader("Hello, world!")

	op.Data = make([]byte, op.Size)
	n, err := reader.ReadAt(op.Data, op.Offset)
	op.Data = op.Data[:n]

	// Special case: FUSE doesn't expect us to return io.EOF.
	if err == io.EOF {
		err = nil
	}

	return
}
コード例 #2
0
ファイル: memfs.go プロジェクト: BanzaiMan/gcsfuse
func (fs *memFS) ReadFile(
	op *fuseops.ReadFileOp) (err error) {
	fs.mu.Lock()
	defer fs.mu.Unlock()

	// Find the inode in question.
	inode := fs.getInodeOrDie(op.Inode)

	// Serve the request.
	op.Data = make([]byte, op.Size)
	n, err := inode.ReadAt(op.Data, op.Offset)
	op.Data = op.Data[:n]

	// Don't return EOF errors; we just indicate EOF to fuse using a short read.
	if err == io.EOF {
		err = nil
	}

	return
}
コード例 #3
0
ファイル: flush_fs.go プロジェクト: BanzaiMan/gcsfuse
func (fs *flushFS) ReadFile(
	op *fuseops.ReadFileOp) (err error) {
	fs.mu.Lock()
	defer fs.mu.Unlock()

	// Ensure the offset is in range.
	if op.Offset > int64(len(fs.fooContents)) {
		return
	}

	// Read what we can.
	op.Data = make([]byte, op.Size)
	copy(op.Data, fs.fooContents[op.Offset:])

	return
}