Define reader
This commit is contained in:
		
							
								
								
									
										35
									
								
								fuse/main.go
									
									
									
									
									
								
							
							
						
						
									
										35
									
								
								fuse/main.go
									
									
									
									
									
								
							| @@ -106,6 +106,41 @@ func (n *ITNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (* | ||||
| 	return nil, syscall.ENOENT | ||||
| } | ||||
|  | ||||
| type bytesFileHandle struct { | ||||
| 	content []byte | ||||
| } | ||||
| var _ = (fs.FileReader)((*bytesFileHandle)(nil)) | ||||
|  | ||||
| func (fh *bytesFileHandle) Read(ctx context.Context, dest []byte, off int64) (fuse.ReadResult, syscall.Errno) { | ||||
| 	end := off + int64(len(dest)) | ||||
| 	if end > int64(len(fh.content)) { | ||||
| 		end = int64(len(fh.content)) | ||||
| 	} | ||||
| 	return fuse.ReadResultData(fh.content[off:end]), 0 | ||||
| } | ||||
|  | ||||
| var _ = (fs.NodeOpener)((*ITNode)(nil)) | ||||
| func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle, fuseFlags uint32, errno syscall.Errno) { | ||||
| 	switch f.kind { | ||||
| 	case 3: | ||||
| 		// Device file | ||||
|  | ||||
| 		// disallow writes | ||||
| 		if fuseFlags&(syscall.O_RDWR|syscall.O_WRONLY) != 0 { | ||||
| 			return nil, 0, syscall.EROFS | ||||
| 		} | ||||
|  | ||||
| 		for _, value := range properties { | ||||
| 			if value.Ino == f.Ino { | ||||
| 				fh = &bytesFileHandle{ | ||||
| 					content: []byte(value.name), | ||||
| 				} | ||||
| 				return fh, fuse.FOPEN_DIRECT_IO, 0 | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return nil, 0, syscall.EROFS | ||||
| } | ||||
|  | ||||
| func main() { | ||||
| 	// This is where we'll mount the FS | ||||
|   | ||||
		Reference in New Issue
	
	Block a user