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
eeac7182
Commit
eeac7182
authored
Mar 25, 2015
by
Aaron Jacobs
Browse files
Options
Browse Files
Download
Plain Diff
Use the FileSystem interface in the samples.
parents
54d3fee5
e1e43843
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
314 deletions
+91
-314
samples/cachingfs/caching_fs.go
samples/cachingfs/caching_fs.go
+16
-55
samples/cachingfs/caching_fs_test.go
samples/cachingfs/caching_fs_test.go
+2
-1
samples/flushfs/flush_fs.go
samples/flushfs/flush_fs.go
+24
-85
samples/hellofs/hello_fs.go
samples/hellofs/hello_fs.go
+19
-62
samples/memfs/fs.go
samples/memfs/fs.go
+30
-111
No files found.
samples/cachingfs/caching_fs.go
View file @
eeac7182
...
@@ -16,12 +16,12 @@ package cachingfs
...
@@ -16,12 +16,12 @@ package cachingfs
import
(
import
(
"fmt"
"fmt"
"io"
"os"
"os"
"time"
"time"
"github.com/jacobsa/fuse"
"github.com/jacobsa/fuse"
"github.com/jacobsa/fuse/fuseops"
"github.com/jacobsa/fuse/fuseops"
"github.com/jacobsa/fuse/fuseutil"
"github.com/jacobsa/gcloud/syncutil"
"github.com/jacobsa/gcloud/syncutil"
)
)
...
@@ -42,7 +42,7 @@ const (
...
@@ -42,7 +42,7 @@ const (
// requests. It also exposes methods for renumbering inodes and updating mtimes
// requests. It also exposes methods for renumbering inodes and updating mtimes
// that are useful in testing that these durations are honored.
// that are useful in testing that these durations are honored.
type
CachingFS
interface
{
type
CachingFS
interface
{
fuse
.
Server
fuse
util
.
FileSystem
// Return the current inode ID of the file/directory with the given name.
// Return the current inode ID of the file/directory with the given name.
FooID
()
fuseops
.
InodeID
FooID
()
fuseops
.
InodeID
...
@@ -99,6 +99,8 @@ const (
...
@@ -99,6 +99,8 @@ const (
)
)
type
cachingFS
struct
{
type
cachingFS
struct
{
fuseutil
.
NotImplementedFileSystem
/////////////////////////
/////////////////////////
// Constant data
// Constant data
/////////////////////////
/////////////////////////
...
@@ -232,53 +234,18 @@ func (fs *cachingFS) SetMtime(mtime time.Time) {
...
@@ -232,53 +234,18 @@ func (fs *cachingFS) SetMtime(mtime time.Time) {
fs
.
mtime
=
mtime
fs
.
mtime
=
mtime
}
}
// LOCKS_EXCLUDED(fs.mu)
func
(
fs
*
cachingFS
)
ServeOps
(
c
*
fuse
.
Connection
)
{
for
{
op
,
err
:=
c
.
ReadOp
()
if
err
==
io
.
EOF
{
break
}
if
err
!=
nil
{
panic
(
err
)
}
switch
typed
:=
op
.
(
type
)
{
case
*
fuseops
.
InitOp
:
fs
.
init
(
typed
)
case
*
fuseops
.
LookUpInodeOp
:
fs
.
lookUpInode
(
typed
)
case
*
fuseops
.
GetInodeAttributesOp
:
fs
.
getInodeAttributes
(
typed
)
case
*
fuseops
.
OpenDirOp
:
fs
.
openDir
(
typed
)
case
*
fuseops
.
OpenFileOp
:
fs
.
openFile
(
typed
)
default
:
typed
.
Respond
(
fuse
.
ENOSYS
)
}
}
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
//
Op
methods
//
FileSystem
methods
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
func
(
fs
*
cachingFS
)
init
(
op
*
fuseops
.
InitOp
)
{
func
(
fs
*
cachingFS
)
Init
(
op
.
Respond
(
nil
)
op
*
fuseops
.
InitOp
)
(
err
error
)
{
return
}
}
// LOCKS_EXCLUDED(fs.mu)
// LOCKS_EXCLUDED(fs.mu)
func
(
fs
*
cachingFS
)
lookUpInode
(
op
*
fuseops
.
LookUpInodeOp
)
{
func
(
fs
*
cachingFS
)
LookUpInode
(
var
err
error
op
*
fuseops
.
LookUpInodeOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
fs
.
mu
.
Lock
()
fs
.
mu
.
Lock
()
defer
fs
.
mu
.
Unlock
()
defer
fs
.
mu
.
Unlock
()
...
@@ -331,10 +298,8 @@ func (fs *cachingFS) lookUpInode(op *fuseops.LookUpInodeOp) {
...
@@ -331,10 +298,8 @@ func (fs *cachingFS) lookUpInode(op *fuseops.LookUpInodeOp) {
}
}
// LOCKS_EXCLUDED(fs.mu)
// LOCKS_EXCLUDED(fs.mu)
func
(
fs
*
cachingFS
)
getInodeAttributes
(
op
*
fuseops
.
GetInodeAttributesOp
)
{
func
(
fs
*
cachingFS
)
GetInodeAttributes
(
var
err
error
op
*
fuseops
.
GetInodeAttributesOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
fs
.
mu
.
Lock
()
fs
.
mu
.
Lock
()
defer
fs
.
mu
.
Unlock
()
defer
fs
.
mu
.
Unlock
()
...
@@ -362,16 +327,12 @@ func (fs *cachingFS) getInodeAttributes(op *fuseops.GetInodeAttributesOp) {
...
@@ -362,16 +327,12 @@ func (fs *cachingFS) getInodeAttributes(op *fuseops.GetInodeAttributesOp) {
return
return
}
}
func
(
fs
*
cachingFS
)
openDir
(
op
*
fuseops
.
OpenDirOp
)
{
func
(
fs
*
cachingFS
)
OpenDir
(
var
err
error
op
*
fuseops
.
OpenDirOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
return
return
}
}
func
(
fs
*
cachingFS
)
openFile
(
op
*
fuseops
.
OpenFileOp
)
{
func
(
fs
*
cachingFS
)
OpenFile
(
var
err
error
op
*
fuseops
.
OpenFileOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
return
return
}
}
samples/cachingfs/caching_fs_test.go
View file @
eeac7182
...
@@ -23,6 +23,7 @@ import (
...
@@ -23,6 +23,7 @@ import (
"time"
"time"
"github.com/googlecloudplatform/gcsfuse/timeutil"
"github.com/googlecloudplatform/gcsfuse/timeutil"
"github.com/jacobsa/fuse/fuseutil"
"github.com/jacobsa/fuse/samples"
"github.com/jacobsa/fuse/samples"
"github.com/jacobsa/fuse/samples/cachingfs"
"github.com/jacobsa/fuse/samples/cachingfs"
.
"github.com/jacobsa/oglematchers"
.
"github.com/jacobsa/oglematchers"
...
@@ -54,7 +55,7 @@ func (t *cachingFSTest) setUp(
...
@@ -54,7 +55,7 @@ func (t *cachingFSTest) setUp(
t
.
fs
,
err
=
cachingfs
.
NewCachingFS
(
lookupEntryTimeout
,
getattrTimeout
)
t
.
fs
,
err
=
cachingfs
.
NewCachingFS
(
lookupEntryTimeout
,
getattrTimeout
)
AssertEq
(
nil
,
err
)
AssertEq
(
nil
,
err
)
t
.
Server
=
t
.
fs
t
.
Server
=
fuseutil
.
NewFileSystemServer
(
t
.
fs
)
// Mount it.
// Mount it.
t
.
SampleTest
.
SetUp
(
ti
)
t
.
SampleTest
.
SetUp
(
ti
)
...
...
samples/flushfs/flush_fs.go
View file @
eeac7182
...
@@ -16,12 +16,12 @@ package flushfs
...
@@ -16,12 +16,12 @@ package flushfs
import
(
import
(
"fmt"
"fmt"
"io"
"os"
"os"
"sync"
"sync"
"github.com/jacobsa/fuse"
"github.com/jacobsa/fuse"
"github.com/jacobsa/fuse/fuseops"
"github.com/jacobsa/fuse/fuseops"
"github.com/jacobsa/fuse/fuseutil"
)
)
// Create a file system whose sole contents are a file named "foo" and a
// Create a file system whose sole contents are a file named "foo" and a
...
@@ -35,11 +35,12 @@ import (
...
@@ -35,11 +35,12 @@ import (
func
NewFileSystem
(
func
NewFileSystem
(
reportFlush
func
(
string
)
error
,
reportFlush
func
(
string
)
error
,
reportFsync
func
(
string
)
error
)
(
server
fuse
.
Server
,
err
error
)
{
reportFsync
func
(
string
)
error
)
(
server
fuse
.
Server
,
err
error
)
{
server
=
&
flushFS
{
fs
:
=
&
flushFS
{
reportFlush
:
reportFlush
,
reportFlush
:
reportFlush
,
reportFsync
:
reportFsync
,
reportFsync
:
reportFsync
,
}
}
server
=
fuseutil
.
NewFileSystemServer
(
fs
)
return
return
}
}
...
@@ -49,6 +50,8 @@ const (
...
@@ -49,6 +50,8 @@ const (
)
)
type
flushFS
struct
{
type
flushFS
struct
{
fuseutil
.
NotImplementedFileSystem
reportFlush
func
(
string
)
error
reportFlush
func
(
string
)
error
reportFsync
func
(
string
)
error
reportFsync
func
(
string
)
error
...
@@ -85,67 +88,17 @@ func (fs *flushFS) barAttributes() fuseops.InodeAttributes {
...
@@ -85,67 +88,17 @@ func (fs *flushFS) barAttributes() fuseops.InodeAttributes {
}
}
}
}
// LOCKS_REQUIRED(fs.mu)
func
(
fs
*
flushFS
)
ServeOps
(
c
*
fuse
.
Connection
)
{
for
{
op
,
err
:=
c
.
ReadOp
()
if
err
==
io
.
EOF
{
break
}
if
err
!=
nil
{
panic
(
err
)
}
switch
typed
:=
op
.
(
type
)
{
case
*
fuseops
.
InitOp
:
fs
.
init
(
typed
)
case
*
fuseops
.
LookUpInodeOp
:
fs
.
lookUpInode
(
typed
)
case
*
fuseops
.
GetInodeAttributesOp
:
fs
.
getInodeAttributes
(
typed
)
case
*
fuseops
.
OpenFileOp
:
fs
.
openFile
(
typed
)
case
*
fuseops
.
ReadFileOp
:
fs
.
readFile
(
typed
)
case
*
fuseops
.
WriteFileOp
:
fs
.
writeFile
(
typed
)
case
*
fuseops
.
SyncFileOp
:
fs
.
syncFile
(
typed
)
case
*
fuseops
.
FlushFileOp
:
fs
.
flushFile
(
typed
)
case
*
fuseops
.
OpenDirOp
:
fs
.
openDir
(
typed
)
default
:
typed
.
Respond
(
fuse
.
ENOSYS
)
}
}
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
//
Op
methods
//
FileSystem
methods
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
func
(
fs
*
flushFS
)
init
(
op
*
fuseops
.
InitOp
)
{
func
(
fs
*
flushFS
)
Init
(
var
err
error
op
*
fuseops
.
InitOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
return
return
}
}
func
(
fs
*
flushFS
)
lookUpInode
(
op
*
fuseops
.
LookUpInodeOp
)
{
func
(
fs
*
flushFS
)
LookUpInode
(
var
err
error
op
*
fuseops
.
LookUpInodeOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
fs
.
mu
.
Lock
()
fs
.
mu
.
Lock
()
defer
fs
.
mu
.
Unlock
()
defer
fs
.
mu
.
Unlock
()
...
@@ -177,10 +130,8 @@ func (fs *flushFS) lookUpInode(op *fuseops.LookUpInodeOp) {
...
@@ -177,10 +130,8 @@ func (fs *flushFS) lookUpInode(op *fuseops.LookUpInodeOp) {
return
return
}
}
func
(
fs
*
flushFS
)
getInodeAttributes
(
op
*
fuseops
.
GetInodeAttributesOp
)
{
func
(
fs
*
flushFS
)
GetInodeAttributes
(
var
err
error
op
*
fuseops
.
GetInodeAttributesOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
fs
.
mu
.
Lock
()
fs
.
mu
.
Lock
()
defer
fs
.
mu
.
Unlock
()
defer
fs
.
mu
.
Unlock
()
...
@@ -203,10 +154,8 @@ func (fs *flushFS) getInodeAttributes(op *fuseops.GetInodeAttributesOp) {
...
@@ -203,10 +154,8 @@ func (fs *flushFS) getInodeAttributes(op *fuseops.GetInodeAttributesOp) {
}
}
}
}
func
(
fs
*
flushFS
)
openFile
(
op
*
fuseops
.
OpenFileOp
)
{
func
(
fs
*
flushFS
)
OpenFile
(
var
err
error
op
*
fuseops
.
OpenFileOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
fs
.
mu
.
Lock
()
fs
.
mu
.
Lock
()
defer
fs
.
mu
.
Unlock
()
defer
fs
.
mu
.
Unlock
()
...
@@ -219,10 +168,8 @@ func (fs *flushFS) openFile(op *fuseops.OpenFileOp) {
...
@@ -219,10 +168,8 @@ func (fs *flushFS) openFile(op *fuseops.OpenFileOp) {
return
return
}
}
func
(
fs
*
flushFS
)
readFile
(
op
*
fuseops
.
ReadFileOp
)
{
func
(
fs
*
flushFS
)
ReadFile
(
var
err
error
op
*
fuseops
.
ReadFileOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
fs
.
mu
.
Lock
()
fs
.
mu
.
Lock
()
defer
fs
.
mu
.
Unlock
()
defer
fs
.
mu
.
Unlock
()
...
@@ -238,10 +185,8 @@ func (fs *flushFS) readFile(op *fuseops.ReadFileOp) {
...
@@ -238,10 +185,8 @@ func (fs *flushFS) readFile(op *fuseops.ReadFileOp) {
return
return
}
}
func
(
fs
*
flushFS
)
writeFile
(
op
*
fuseops
.
WriteFileOp
)
{
func
(
fs
*
flushFS
)
WriteFile
(
var
err
error
op
*
fuseops
.
WriteFileOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
fs
.
mu
.
Lock
()
fs
.
mu
.
Lock
()
defer
fs
.
mu
.
Unlock
()
defer
fs
.
mu
.
Unlock
()
...
@@ -263,10 +208,8 @@ func (fs *flushFS) writeFile(op *fuseops.WriteFileOp) {
...
@@ -263,10 +208,8 @@ func (fs *flushFS) writeFile(op *fuseops.WriteFileOp) {
return
return
}
}
func
(
fs
*
flushFS
)
syncFile
(
op
*
fuseops
.
SyncFileOp
)
{
func
(
fs
*
flushFS
)
SyncFile
(
var
err
error
op
*
fuseops
.
SyncFileOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
fs
.
mu
.
Lock
()
fs
.
mu
.
Lock
()
defer
fs
.
mu
.
Unlock
()
defer
fs
.
mu
.
Unlock
()
...
@@ -274,10 +217,8 @@ func (fs *flushFS) syncFile(op *fuseops.SyncFileOp) {
...
@@ -274,10 +217,8 @@ func (fs *flushFS) syncFile(op *fuseops.SyncFileOp) {
return
return
}
}
func
(
fs
*
flushFS
)
flushFile
(
op
*
fuseops
.
FlushFileOp
)
{
func
(
fs
*
flushFS
)
FlushFile
(
var
err
error
op
*
fuseops
.
FlushFileOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
fs
.
mu
.
Lock
()
fs
.
mu
.
Lock
()
defer
fs
.
mu
.
Unlock
()
defer
fs
.
mu
.
Unlock
()
...
@@ -285,10 +226,8 @@ func (fs *flushFS) flushFile(op *fuseops.FlushFileOp) {
...
@@ -285,10 +226,8 @@ func (fs *flushFS) flushFile(op *fuseops.FlushFileOp) {
return
return
}
}
func
(
fs
*
flushFS
)
openDir
(
op
*
fuseops
.
OpenDirOp
)
{
func
(
fs
*
flushFS
)
OpenDir
(
var
err
error
op
*
fuseops
.
OpenDirOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
fs
.
mu
.
Lock
()
fs
.
mu
.
Lock
()
defer
fs
.
mu
.
Unlock
()
defer
fs
.
mu
.
Unlock
()
...
...
samples/hellofs/hello_fs.go
View file @
eeac7182
...
@@ -33,54 +33,18 @@ import (
...
@@ -33,54 +33,18 @@ import (
//
//
// Each file contains the string "Hello, world!".
// Each file contains the string "Hello, world!".
func
NewHelloFS
(
clock
timeutil
.
Clock
)
(
server
fuse
.
Server
,
err
error
)
{
func
NewHelloFS
(
clock
timeutil
.
Clock
)
(
server
fuse
.
Server
,
err
error
)
{
server
=
&
helloFS
{
fs
:
=
&
helloFS
{
Clock
:
clock
,
Clock
:
clock
,
}
}
server
=
fuseutil
.
NewFileSystemServer
(
fs
)
return
return
}
}
type
helloFS
struct
{
type
helloFS
struct
{
Clock
timeutil
.
Clock
fuseutil
.
NotImplementedFileSystem
}
func
(
fs
*
helloFS
)
ServeOps
(
c
*
fuse
.
Connection
)
{
for
{
op
,
err
:=
c
.
ReadOp
()
if
err
==
io
.
EOF
{
break
}
if
err
!=
nil
{
panic
(
err
)
}
switch
typed
:=
op
.
(
type
)
{
case
*
fuseops
.
InitOp
:
fs
.
init
(
typed
)
case
*
fuseops
.
LookUpInodeOp
:
fs
.
lookUpInode
(
typed
)
case
*
fuseops
.
GetInodeAttributesOp
:
fs
.
getInodeAttributes
(
typed
)
case
*
fuseops
.
OpenDirOp
:
fs
.
openDir
(
typed
)
case
*
fuseops
.
ReadDirOp
:
fs
.
readDir
(
typed
)
case
*
fuseops
.
OpenFileOp
:
Clock
timeutil
.
Clock
fs
.
openFile
(
typed
)
case
*
fuseops
.
ReadFileOp
:
fs
.
readFile
(
typed
)
default
:
typed
.
Respond
(
fuse
.
ENOSYS
)
}
}
}
}
const
(
const
(
...
@@ -183,14 +147,11 @@ func (fs *helloFS) patchAttributes(
...
@@ -183,14 +147,11 @@ func (fs *helloFS) patchAttributes(
attr
.
Crtime
=
now
attr
.
Crtime
=
now
}
}
func
(
fs
*
helloFS
)
init
(
op
*
fuseops
.
InitOp
)
{
func
(
fs
*
helloFS
)
Init
(
op
*
fuseops
.
InitOp
)
(
err
error
)
{
op
.
Respond
(
nil
)
return
}
}
func
(
fs
*
helloFS
)
lookUpInode
(
op
*
fuseops
.
LookUpInodeOp
)
{
func
(
fs
*
helloFS
)
LookUpInode
(
op
*
fuseops
.
LookUpInodeOp
)
(
err
error
)
{
var
err
error
defer
func
()
{
op
.
Respond
(
err
)
}()
// Find the info for the parent.
// Find the info for the parent.
parentInfo
,
ok
:=
gInodeInfo
[
op
.
Parent
]
parentInfo
,
ok
:=
gInodeInfo
[
op
.
Parent
]
if
!
ok
{
if
!
ok
{
...
@@ -214,10 +175,8 @@ func (fs *helloFS) lookUpInode(op *fuseops.LookUpInodeOp) {
...
@@ -214,10 +175,8 @@ func (fs *helloFS) lookUpInode(op *fuseops.LookUpInodeOp) {
return
return
}
}
func
(
fs
*
helloFS
)
getInodeAttributes
(
op
*
fuseops
.
GetInodeAttributesOp
)
{
func
(
fs
*
helloFS
)
GetInodeAttributes
(
var
err
error
op
*
fuseops
.
GetInodeAttributesOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
// Find the info for this inode.
// Find the info for this inode.
info
,
ok
:=
gInodeInfo
[
op
.
Inode
]
info
,
ok
:=
gInodeInfo
[
op
.
Inode
]
if
!
ok
{
if
!
ok
{
...
@@ -234,15 +193,14 @@ func (fs *helloFS) getInodeAttributes(op *fuseops.GetInodeAttributesOp) {
...
@@ -234,15 +193,14 @@ func (fs *helloFS) getInodeAttributes(op *fuseops.GetInodeAttributesOp) {
return
return
}
}
func
(
fs
*
helloFS
)
openDir
(
op
*
fuseops
.
OpenDirOp
)
{
func
(
fs
*
helloFS
)
OpenDir
(
op
*
fuseops
.
OpenDirOp
)
(
err
error
)
{
// Allow opening any directory.
// Allow opening any directory.
op
.
Respond
(
nil
)
return
}
}
func
(
fs
*
helloFS
)
readDir
(
op
*
fuseops
.
ReadDirOp
)
{
func
(
fs
*
helloFS
)
ReadDir
(
var
err
error
op
*
fuseops
.
ReadDirOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
// Find the info for this inode.
// Find the info for this inode.
info
,
ok
:=
gInodeInfo
[
op
.
Inode
]
info
,
ok
:=
gInodeInfo
[
op
.
Inode
]
if
!
ok
{
if
!
ok
{
...
@@ -277,15 +235,14 @@ func (fs *helloFS) readDir(op *fuseops.ReadDirOp) {
...
@@ -277,15 +235,14 @@ func (fs *helloFS) readDir(op *fuseops.ReadDirOp) {
return
return
}
}
func
(
fs
*
helloFS
)
openFile
(
op
*
fuseops
.
OpenFileOp
)
{
func
(
fs
*
helloFS
)
OpenFile
(
op
*
fuseops
.
OpenFileOp
)
(
err
error
)
{
// Allow opening any file.
// Allow opening any file.
op
.
Respond
(
nil
)
return
}
}
func
(
fs
*
helloFS
)
readFile
(
op
*
fuseops
.
ReadFileOp
)
{
func
(
fs
*
helloFS
)
ReadFile
(
var
err
error
op
*
fuseops
.
ReadFileOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
// Let io.ReaderAt deal with the semantics.
// Let io.ReaderAt deal with the semantics.
reader
:=
strings
.
NewReader
(
"Hello, world!"
)
reader
:=
strings
.
NewReader
(
"Hello, world!"
)
...
...
samples/memfs/fs.go
View file @
eeac7182
...
@@ -28,6 +28,8 @@ import (
...
@@ -28,6 +28,8 @@ import (
)
)
type
memFS
struct
{
type
memFS
struct
{
fuseutil
.
NotImplementedFileSystem
/////////////////////////
/////////////////////////
// Dependencies
// Dependencies
/////////////////////////
/////////////////////////
...
@@ -86,70 +88,13 @@ func NewMemFS(
...
@@ -86,70 +88,13 @@ func NewMemFS(
// Set up invariant checking.
// Set up invariant checking.
fs
.
mu
=
syncutil
.
NewInvariantMutex
(
fs
.
checkInvariants
)
fs
.
mu
=
syncutil
.
NewInvariantMutex
(
fs
.
checkInvariants
)
return
f
s
return
f
useutil
.
NewFileSystemServer
(
fs
)
}
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// Helpers
// Helpers
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
func
(
fs
*
memFS
)
ServeOps
(
c
*
fuse
.
Connection
)
{
for
{
op
,
err
:=
c
.
ReadOp
()
if
err
==
io
.
EOF
{
break
}
if
err
!=
nil
{
panic
(
err
)
}
switch
typed
:=
op
.
(
type
)
{
case
*
fuseops
.
InitOp
:
fs
.
init
(
typed
)
case
*
fuseops
.
LookUpInodeOp
:
fs
.
lookUpInode
(
typed
)
case
*
fuseops
.
GetInodeAttributesOp
:
fs
.
getInodeAttributes
(
typed
)
case
*
fuseops
.
SetInodeAttributesOp
:
fs
.
setInodeAttributes
(
typed
)
case
*
fuseops
.
MkDirOp
:
fs
.
mkDir
(
typed
)
case
*
fuseops
.
CreateFileOp
:
fs
.
createFile
(
typed
)
case
*
fuseops
.
RmDirOp
:
fs
.
rmDir
(
typed
)
case
*
fuseops
.
UnlinkOp
:
fs
.
unlink
(
typed
)
case
*
fuseops
.
OpenDirOp
:
fs
.
openDir
(
typed
)
case
*
fuseops
.
ReadDirOp
:
fs
.
readDir
(
typed
)
case
*
fuseops
.
OpenFileOp
:
fs
.
openFile
(
typed
)
case
*
fuseops
.
ReadFileOp
:
fs
.
readFile
(
typed
)
case
*
fuseops
.
WriteFileOp
:
fs
.
writeFile
(
typed
)
default
:
typed
.
Respond
(
fuse
.
ENOSYS
)
}
}
}
func
(
fs
*
memFS
)
checkInvariants
()
{
func
(
fs
*
memFS
)
checkInvariants
()
{
// Check reserved inodes.
// Check reserved inodes.
for
i
:=
0
;
i
<
fuseops
.
RootInodeID
;
i
++
{
for
i
:=
0
;
i
<
fuseops
.
RootInodeID
;
i
++
{
...
@@ -251,20 +196,16 @@ func (fs *memFS) deallocateInode(id fuseops.InodeID) {
...
@@ -251,20 +196,16 @@ func (fs *memFS) deallocateInode(id fuseops.InodeID) {
}
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
//
Op
methods
//
FileSystem
methods
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
func
(
fs
*
memFS
)
init
(
op
*
fuseops
.
InitOp
)
{
func
(
fs
*
memFS
)
Init
(
var
err
error
op
*
fuseops
.
InitOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
return
return
}
}
func
(
fs
*
memFS
)
lookUpInode
(
op
*
fuseops
.
LookUpInodeOp
)
{
func
(
fs
*
memFS
)
LookUpInode
(
var
err
error
op
*
fuseops
.
LookUpInodeOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
fs
.
mu
.
RLock
()
fs
.
mu
.
RLock
()
defer
fs
.
mu
.
RUnlock
()
defer
fs
.
mu
.
RUnlock
()
...
@@ -295,10 +236,8 @@ func (fs *memFS) lookUpInode(op *fuseops.LookUpInodeOp) {
...
@@ -295,10 +236,8 @@ func (fs *memFS) lookUpInode(op *fuseops.LookUpInodeOp) {
return
return
}
}
func
(
fs
*
memFS
)
getInodeAttributes
(
op
*
fuseops
.
GetInodeAttributesOp
)
{
func
(
fs
*
memFS
)
GetInodeAttributes
(
var
err
error
op
*
fuseops
.
GetInodeAttributesOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
fs
.
mu
.
RLock
()
fs
.
mu
.
RLock
()
defer
fs
.
mu
.
RUnlock
()
defer
fs
.
mu
.
RUnlock
()
...
@@ -316,10 +255,8 @@ func (fs *memFS) getInodeAttributes(op *fuseops.GetInodeAttributesOp) {
...
@@ -316,10 +255,8 @@ func (fs *memFS) getInodeAttributes(op *fuseops.GetInodeAttributesOp) {
return
return
}
}
func
(
fs
*
memFS
)
setInodeAttributes
(
op
*
fuseops
.
SetInodeAttributesOp
)
{
func
(
fs
*
memFS
)
SetInodeAttributes
(
var
err
error
op
*
fuseops
.
SetInodeAttributesOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
fs
.
mu
.
RLock
()
fs
.
mu
.
RLock
()
defer
fs
.
mu
.
RUnlock
()
defer
fs
.
mu
.
RUnlock
()
...
@@ -340,10 +277,8 @@ func (fs *memFS) setInodeAttributes(op *fuseops.SetInodeAttributesOp) {
...
@@ -340,10 +277,8 @@ func (fs *memFS) setInodeAttributes(op *fuseops.SetInodeAttributesOp) {
return
return
}
}
func
(
fs
*
memFS
)
mkDir
(
op
*
fuseops
.
MkDirOp
)
{
func
(
fs
*
memFS
)
MkDir
(
var
err
error
op
*
fuseops
.
MkDirOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
fs
.
mu
.
Lock
()
fs
.
mu
.
Lock
()
defer
fs
.
mu
.
Unlock
()
defer
fs
.
mu
.
Unlock
()
...
@@ -379,10 +314,8 @@ func (fs *memFS) mkDir(op *fuseops.MkDirOp) {
...
@@ -379,10 +314,8 @@ func (fs *memFS) mkDir(op *fuseops.MkDirOp) {
return
return
}
}
func
(
fs
*
memFS
)
createFile
(
op
*
fuseops
.
CreateFileOp
)
{
func
(
fs
*
memFS
)
CreateFile
(
var
err
error
op
*
fuseops
.
CreateFileOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
fs
.
mu
.
Lock
()
fs
.
mu
.
Lock
()
defer
fs
.
mu
.
Unlock
()
defer
fs
.
mu
.
Unlock
()
...
@@ -425,10 +358,8 @@ func (fs *memFS) createFile(op *fuseops.CreateFileOp) {
...
@@ -425,10 +358,8 @@ func (fs *memFS) createFile(op *fuseops.CreateFileOp) {
return
return
}
}
func
(
fs
*
memFS
)
rmDir
(
op
*
fuseops
.
RmDirOp
)
{
func
(
fs
*
memFS
)
RmDir
(
var
err
error
op
*
fuseops
.
RmDirOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
fs
.
mu
.
Lock
()
fs
.
mu
.
Lock
()
defer
fs
.
mu
.
Unlock
()
defer
fs
.
mu
.
Unlock
()
...
@@ -462,10 +393,8 @@ func (fs *memFS) rmDir(op *fuseops.RmDirOp) {
...
@@ -462,10 +393,8 @@ func (fs *memFS) rmDir(op *fuseops.RmDirOp) {
return
return
}
}
func
(
fs
*
memFS
)
unlink
(
op
*
fuseops
.
UnlinkOp
)
{
func
(
fs
*
memFS
)
Unlink
(
var
err
error
op
*
fuseops
.
UnlinkOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
fs
.
mu
.
Lock
()
fs
.
mu
.
Lock
()
defer
fs
.
mu
.
Unlock
()
defer
fs
.
mu
.
Unlock
()
...
@@ -493,10 +422,8 @@ func (fs *memFS) unlink(op *fuseops.UnlinkOp) {
...
@@ -493,10 +422,8 @@ func (fs *memFS) unlink(op *fuseops.UnlinkOp) {
return
return
}
}
func
(
fs
*
memFS
)
openDir
(
op
*
fuseops
.
OpenDirOp
)
{
func
(
fs
*
memFS
)
OpenDir
(
var
err
error
op
*
fuseops
.
OpenDirOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
fs
.
mu
.
RLock
()
fs
.
mu
.
RLock
()
defer
fs
.
mu
.
RUnlock
()
defer
fs
.
mu
.
RUnlock
()
...
@@ -513,10 +440,8 @@ func (fs *memFS) openDir(op *fuseops.OpenDirOp) {
...
@@ -513,10 +440,8 @@ func (fs *memFS) openDir(op *fuseops.OpenDirOp) {
return
return
}
}
func
(
fs
*
memFS
)
readDir
(
op
*
fuseops
.
ReadDirOp
)
{
func
(
fs
*
memFS
)
ReadDir
(
var
err
error
op
*
fuseops
.
ReadDirOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
fs
.
mu
.
RLock
()
fs
.
mu
.
RLock
()
defer
fs
.
mu
.
RUnlock
()
defer
fs
.
mu
.
RUnlock
()
...
@@ -534,10 +459,8 @@ func (fs *memFS) readDir(op *fuseops.ReadDirOp) {
...
@@ -534,10 +459,8 @@ func (fs *memFS) readDir(op *fuseops.ReadDirOp) {
return
return
}
}
func
(
fs
*
memFS
)
openFile
(
op
*
fuseops
.
OpenFileOp
)
{
func
(
fs
*
memFS
)
OpenFile
(
var
err
error
op
*
fuseops
.
OpenFileOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
fs
.
mu
.
RLock
()
fs
.
mu
.
RLock
()
defer
fs
.
mu
.
RUnlock
()
defer
fs
.
mu
.
RUnlock
()
...
@@ -554,10 +477,8 @@ func (fs *memFS) openFile(op *fuseops.OpenFileOp) {
...
@@ -554,10 +477,8 @@ func (fs *memFS) openFile(op *fuseops.OpenFileOp) {
return
return
}
}
func
(
fs
*
memFS
)
readFile
(
op
*
fuseops
.
ReadFileOp
)
{
func
(
fs
*
memFS
)
ReadFile
(
var
err
error
op
*
fuseops
.
ReadFileOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
fs
.
mu
.
RLock
()
fs
.
mu
.
RLock
()
defer
fs
.
mu
.
RUnlock
()
defer
fs
.
mu
.
RUnlock
()
...
@@ -578,10 +499,8 @@ func (fs *memFS) readFile(op *fuseops.ReadFileOp) {
...
@@ -578,10 +499,8 @@ func (fs *memFS) readFile(op *fuseops.ReadFileOp) {
return
return
}
}
func
(
fs
*
memFS
)
writeFile
(
op
*
fuseops
.
WriteFileOp
)
{
func
(
fs
*
memFS
)
WriteFile
(
var
err
error
op
*
fuseops
.
WriteFileOp
)
(
err
error
)
{
defer
func
()
{
op
.
Respond
(
err
)
}()
fs
.
mu
.
RLock
()
fs
.
mu
.
RLock
()
defer
fs
.
mu
.
RUnlock
()
defer
fs
.
mu
.
RUnlock
()
...
...
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