Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jacobsa-fuse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
jacobsa-fuse
Commits
96c65235
Commit
96c65235
authored
Mar 06, 2015
by
Aaron Jacobs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented memFS.ReadFile.
parent
d307babe
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
0 deletions
+49
-0
samples/memfs/fs.go
samples/memfs/fs.go
+24
-0
samples/memfs/inode.go
samples/memfs/inode.go
+25
-0
No files found.
samples/memfs/fs.go
View file @
96c65235
...
@@ -459,6 +459,28 @@ func (fs *memFS) OpenFile(
...
@@ -459,6 +459,28 @@ func (fs *memFS) OpenFile(
return
return
}
}
func
(
fs
*
memFS
)
ReadFile
(
ctx
context
.
Context
,
req
*
fuse
.
ReadFileRequest
)
(
resp
*
fuse
.
ReadFileResponse
,
err
error
)
{
resp
=
&
fuse
.
ReadFileResponse
{}
fs
.
mu
.
RLock
()
defer
fs
.
mu
.
RUnlock
()
// Find the inode in question.
inode
:=
fs
.
getInodeForReadingOrDie
(
req
.
Inode
)
defer
inode
.
mu
.
RUnlock
()
// Serve the request.
//
// TODO(jacobsa): Add tests involving EOF matching posix_test.go.
resp
.
Data
=
make
([]
byte
,
req
.
Size
)
n
,
err
:=
inode
.
ReadAt
(
resp
.
Data
,
req
.
Offset
)
resp
.
Data
=
resp
.
Data
[
:
n
]
return
}
func
(
fs
*
memFS
)
WriteFile
(
func
(
fs
*
memFS
)
WriteFile
(
ctx
context
.
Context
,
ctx
context
.
Context
,
req
*
fuse
.
WriteFileRequest
)
(
resp
*
fuse
.
WriteFileResponse
,
err
error
)
{
req
*
fuse
.
WriteFileRequest
)
(
resp
*
fuse
.
WriteFileResponse
,
err
error
)
{
...
@@ -472,6 +494,8 @@ func (fs *memFS) WriteFile(
...
@@ -472,6 +494,8 @@ func (fs *memFS) WriteFile(
defer
inode
.
mu
.
Unlock
()
defer
inode
.
mu
.
Unlock
()
// Serve the request.
// Serve the request.
//
// TODO(jacobsa): Add tests involving EOF matching posix_test.go.
_
,
err
=
inode
.
WriteAt
(
req
.
Data
,
req
.
Offset
)
_
,
err
=
inode
.
WriteAt
(
req
.
Data
,
req
.
Offset
)
return
return
...
...
samples/memfs/inode.go
View file @
96c65235
...
@@ -16,6 +16,7 @@ package memfs
...
@@ -16,6 +16,7 @@ package memfs
import
(
import
(
"fmt"
"fmt"
"io"
"os"
"os"
"github.com/jacobsa/fuse"
"github.com/jacobsa/fuse"
...
@@ -290,6 +291,30 @@ func (inode *inode) ReadDir(offset int, size int) (data []byte, err error) {
...
@@ -290,6 +291,30 @@ func (inode *inode) ReadDir(offset int, size int) (data []byte, err error) {
return
return
}
}
// Read from the file's contents. See documentation for ioutil.ReaderAt.
//
// REQUIRES: !inode.dir
// SHARED_LOCKS_REQUIRED(inode.mu)
func
(
inode
*
inode
)
ReadAt
(
p
[]
byte
,
off
int64
)
(
n
int
,
err
error
)
{
if
inode
.
dir
{
panic
(
"ReadAt called on directory."
)
}
// Ensure the offset is in range.
if
off
>
int64
(
len
(
inode
.
contents
))
{
err
=
io
.
EOF
return
}
// Read what we can.
n
=
copy
(
p
,
inode
.
contents
[
off
:
])
if
n
<
len
(
p
)
{
err
=
io
.
EOF
}
return
}
// Write to the file's contents. See documentation for ioutil.WriterAt.
// Write to the file's contents. See documentation for ioutil.WriterAt.
//
//
// REQUIRES: !inode.dir
// REQUIRES: !inode.dir
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment