Пример #1
0
// LOCKS_EXCLUDED(fs.mu)
func (fs *fileSystem) ReadFile(
	op *fuseops.ReadFileOp) (err error) {
	// Find the inode.
	fs.mu.Lock()
	in := fs.inodes[op.Inode].(*inode.FileInode)
	fs.mu.Unlock()

	in.Lock()
	defer in.Unlock()

	// Serve the request.
	op.Data, err = in.Read(op.Context(), op.Offset, op.Size)

	return
}
Пример #2
0
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
}
Пример #3
0
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
}
Пример #4
0
func (fs *InterruptFS) ReadFile(
	op *fuseops.ReadFileOp) (err error) {
	// Signal that a read has been received.
	fs.mu.Lock()
	fs.readInFlight = true
	fs.readInFlightChanged.Broadcast()
	fs.mu.Unlock()

	// Wait for cancellation.
	done := op.Context().Done()
	if done == nil {
		panic("Expected non-nil channel.")
	}

	<-done

	// Return the context's error.
	err = op.Context().Err()

	return
}
Пример #5
0
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
}
Пример #6
0
func (fs *flushFS) ReadFile(
	ctx context.Context,
	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.BytesRead = copy(op.Dst, fs.fooContents[op.Offset:])

	return
}