From dcf4c93dfd25483778e2f353ec12028617b5b7cf Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Wed, 4 Mar 2015 15:16:29 +1100 Subject: [PATCH] Added a WriteFile method. --- file_system.go | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/file_system.go b/file_system.go index 5d8e787..df208bc 100644 --- a/file_system.go +++ b/file_system.go @@ -150,11 +150,16 @@ type FileSystem interface { ctx context.Context, req *OpenFileRequest) (*OpenFileResponse, error) - // Read data from a file previously opened with OpenFile. + // Read data from a file previously opened with CreateFile or OpenFile. ReadFile( ctx context.Context, req *ReadFileRequest) (*ReadFileResponse, error) + // Write data to a file previously opened with CreateFile or OpenFile. + WriteFile( + ctx context.Context, + req *WriteFileRequest) (*WriteFileResponse, error) + // Release a previously-minted file handle. The kernel calls this when there // are no more references to an open file: all file descriptors are closed // and all memory mappings are unmapped. @@ -437,6 +442,7 @@ type CreateFileResponse struct { // The handle may be supplied to the following methods: // // * ReadFile + // * WriteFile // * ReleaseFileHandle // // The file system must ensure this ID remains valid until a later call to @@ -602,6 +608,7 @@ type OpenFileResponse struct { // The handle may be supplied to the following methods: // // * ReadFile + // * WriteFile // * ReleaseFileHandle // // The file system must ensure this ID remains valid until a later call to @@ -613,7 +620,7 @@ type ReadFileRequest struct { Header RequestHeader // The file inode that we are reading, and the handle previously returned by - // OpenFile when opening that inode. + // CreateFile or OpenFile when opening that inode. Inode InodeID Handle HandleID @@ -634,6 +641,30 @@ type ReadFileResponse struct { Data []byte } +type WriteFileRequest struct { + Header RequestHeader + + // The file inode that we are modifying, and the handle previously returned + // by CreateFile or OpenFile when opening that inode. + Inode InodeID + Handle HandleID + + // The data to write, and the offset at which to write it. + // + // The FUSE documentation requires that exactly the number of bytes supplied + // be written, except on error (http://goo.gl/KUpwwn). This appears to be + // because it uses file mmapping machinery (http://goo.gl/SGxnaN) to write a + // page at a time. + // + // TODO(jacobsa): Figure out what the posix semantics are for extending the + // file, and document them here. + Data []byte + Offset int64 +} + +type WriteFileResponse struct { +} + type ReleaseFileHandleRequest struct { Header RequestHeader