Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go-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
go-fuse
Commits
f2ebdfe7
Commit
f2ebdfe7
authored
Jun 23, 2013
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Hide DefaultNodeFileSystem and DefaultFsNode to reduce API clutter.
parent
4ed8a459
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
93 additions
and
72 deletions
+93
-72
fuse/api.go
fuse/api.go
+2
-1
fuse/defaultfile.go
fuse/defaultfile.go
+3
-7
fuse/defaultnode.go
fuse/defaultnode.go
+48
-45
fuse/defaultraw.go
fuse/defaultraw.go
+1
-1
fuse/files.go
fuse/files.go
+0
-2
fuse/memnode.go
fuse/memnode.go
+14
-4
fuse/pathfs/pathfs.go
fuse/pathfs/pathfs.go
+13
-2
fuse/test/mount_test.go
fuse/test/mount_test.go
+1
-1
zipfs/memtree.go
zipfs/memtree.go
+9
-6
zipfs/zipfs.go
zipfs/zipfs.go
+2
-3
No files found.
fuse/api.go
View file @
f2ebdfe7
...
...
@@ -43,7 +43,8 @@ type NodeFileSystem interface {
type
FsNode
interface
{
// Inode and SetInode are basic getter/setters. They are
// called by the FileSystemConnector. You get them for free by
// embedding DefaultFsNode.
// embedding the result of NewDefaultFsNode() in your node
// struct.
Inode
()
*
Inode
SetInode
(
node
*
Inode
)
...
...
fuse/defaultfile.go
View file @
f2ebdfe7
package
fuse
import
(
"log"
"time"
"github.com/hanwen/go-fuse/raw"
)
var
_
=
log
.
Println
var
_
=
(
File
)((
*
defaultFile
)(
nil
))
type
defaultFile
struct
{}
// DefaultFile returns ENOSYS for every operation.
// NewDefaultFile returns a File instance that returns ENOSYS for
// every operation.
func
NewDefaultFile
()
File
{
return
&
defaultFile
{}
return
(
*
defaultFile
)(
nil
)
}
func
(
f
*
defaultFile
)
SetInode
(
*
Inode
)
{
...
...
fuse/defaultnode.go
View file @
f2ebdfe7
package
fuse
import
(
"log"
"time"
)
var
_
=
log
.
Println
// NewDefaultNodeFileSystem returns a dummy implementation of
// NodeFileSystem, for embedding in structs.
func
NewDefaultNodeFileSystem
()
NodeFileSystem
{
return
(
*
defaultNodeFileSystem
)(
nil
)
}
type
D
efaultNodeFileSystem
struct
{
type
d
efaultNodeFileSystem
struct
{
}
func
(
fs
*
D
efaultNodeFileSystem
)
OnUnmount
()
{
func
(
fs
*
d
efaultNodeFileSystem
)
OnUnmount
()
{
}
func
(
fs
*
D
efaultNodeFileSystem
)
OnMount
(
conn
*
FileSystemConnector
)
{
func
(
fs
*
d
efaultNodeFileSystem
)
OnMount
(
conn
*
FileSystemConnector
)
{
}
func
(
fs
*
D
efaultNodeFileSystem
)
Root
()
FsNode
{
return
new
(
DefaultFsNode
)
func
(
fs
*
d
efaultNodeFileSystem
)
Root
()
FsNode
{
return
NewDefaultFsNode
(
)
}
func
(
fs
*
D
efaultNodeFileSystem
)
String
()
string
{
return
"
D
efaultNodeFileSystem"
func
(
fs
*
d
efaultNodeFileSystem
)
String
()
string
{
return
"
d
efaultNodeFileSystem"
}
func
(
fs
*
D
efaultNodeFileSystem
)
SetDebug
(
dbg
bool
)
{
func
(
fs
*
d
efaultNodeFileSystem
)
SetDebug
(
dbg
bool
)
{
}
// NewDefaultFsNode returns an implementation of FsNode that returns
// ENOSYS for all operations.
func
NewDefaultFsNode
()
FsNode
{
return
&
defaultFsNode
{}
}
////////////////////////////////////////////////////////////////
// FsNode default
type
DefaultFsNode
struct
{
type
defaultFsNode
struct
{
inode
*
Inode
}
var
_
=
FsNode
((
*
DefaultFsNode
)(
nil
))
func
(
n
*
DefaultFsNode
)
StatFs
()
*
StatfsOut
{
func
(
n
*
defaultFsNode
)
StatFs
()
*
StatfsOut
{
return
nil
}
func
(
n
*
D
efaultFsNode
)
SetInode
(
node
*
Inode
)
{
func
(
n
*
d
efaultFsNode
)
SetInode
(
node
*
Inode
)
{
n
.
inode
=
node
}
func
(
n
*
D
efaultFsNode
)
Deletable
()
bool
{
func
(
n
*
d
efaultFsNode
)
Deletable
()
bool
{
return
true
}
func
(
n
*
D
efaultFsNode
)
Inode
()
*
Inode
{
func
(
n
*
d
efaultFsNode
)
Inode
()
*
Inode
{
return
n
.
inode
}
func
(
n
*
D
efaultFsNode
)
OnForget
()
{
func
(
n
*
d
efaultFsNode
)
OnForget
()
{
}
func
(
n
*
D
efaultFsNode
)
Lookup
(
out
*
Attr
,
name
string
,
context
*
Context
)
(
node
FsNode
,
code
Status
)
{
func
(
n
*
d
efaultFsNode
)
Lookup
(
out
*
Attr
,
name
string
,
context
*
Context
)
(
node
FsNode
,
code
Status
)
{
return
nil
,
ENOENT
}
func
(
n
*
D
efaultFsNode
)
Access
(
mode
uint32
,
context
*
Context
)
(
code
Status
)
{
func
(
n
*
d
efaultFsNode
)
Access
(
mode
uint32
,
context
*
Context
)
(
code
Status
)
{
return
ENOSYS
}
func
(
n
*
D
efaultFsNode
)
Readlink
(
c
*
Context
)
([]
byte
,
Status
)
{
func
(
n
*
d
efaultFsNode
)
Readlink
(
c
*
Context
)
([]
byte
,
Status
)
{
return
nil
,
ENOSYS
}
func
(
n
*
D
efaultFsNode
)
Mknod
(
name
string
,
mode
uint32
,
dev
uint32
,
context
*
Context
)
(
newNode
FsNode
,
code
Status
)
{
func
(
n
*
d
efaultFsNode
)
Mknod
(
name
string
,
mode
uint32
,
dev
uint32
,
context
*
Context
)
(
newNode
FsNode
,
code
Status
)
{
return
nil
,
ENOSYS
}
func
(
n
*
D
efaultFsNode
)
Mkdir
(
name
string
,
mode
uint32
,
context
*
Context
)
(
newNode
FsNode
,
code
Status
)
{
func
(
n
*
d
efaultFsNode
)
Mkdir
(
name
string
,
mode
uint32
,
context
*
Context
)
(
newNode
FsNode
,
code
Status
)
{
return
nil
,
ENOSYS
}
func
(
n
*
D
efaultFsNode
)
Unlink
(
name
string
,
context
*
Context
)
(
code
Status
)
{
func
(
n
*
d
efaultFsNode
)
Unlink
(
name
string
,
context
*
Context
)
(
code
Status
)
{
return
ENOSYS
}
func
(
n
*
D
efaultFsNode
)
Rmdir
(
name
string
,
context
*
Context
)
(
code
Status
)
{
func
(
n
*
d
efaultFsNode
)
Rmdir
(
name
string
,
context
*
Context
)
(
code
Status
)
{
return
ENOSYS
}
func
(
n
*
D
efaultFsNode
)
Symlink
(
name
string
,
content
string
,
context
*
Context
)
(
newNode
FsNode
,
code
Status
)
{
func
(
n
*
d
efaultFsNode
)
Symlink
(
name
string
,
content
string
,
context
*
Context
)
(
newNode
FsNode
,
code
Status
)
{
return
nil
,
ENOSYS
}
func
(
n
*
D
efaultFsNode
)
Rename
(
oldName
string
,
newParent
FsNode
,
newName
string
,
context
*
Context
)
(
code
Status
)
{
func
(
n
*
d
efaultFsNode
)
Rename
(
oldName
string
,
newParent
FsNode
,
newName
string
,
context
*
Context
)
(
code
Status
)
{
return
ENOSYS
}
func
(
n
*
D
efaultFsNode
)
Link
(
name
string
,
existing
FsNode
,
context
*
Context
)
(
newNode
FsNode
,
code
Status
)
{
func
(
n
*
d
efaultFsNode
)
Link
(
name
string
,
existing
FsNode
,
context
*
Context
)
(
newNode
FsNode
,
code
Status
)
{
return
nil
,
ENOSYS
}
func
(
n
*
D
efaultFsNode
)
Create
(
name
string
,
flags
uint32
,
mode
uint32
,
context
*
Context
)
(
file
File
,
newNode
FsNode
,
code
Status
)
{
func
(
n
*
d
efaultFsNode
)
Create
(
name
string
,
flags
uint32
,
mode
uint32
,
context
*
Context
)
(
file
File
,
newNode
FsNode
,
code
Status
)
{
return
nil
,
nil
,
ENOSYS
}
func
(
n
*
D
efaultFsNode
)
Open
(
flags
uint32
,
context
*
Context
)
(
file
File
,
code
Status
)
{
func
(
n
*
d
efaultFsNode
)
Open
(
flags
uint32
,
context
*
Context
)
(
file
File
,
code
Status
)
{
return
nil
,
ENOSYS
}
func
(
n
*
D
efaultFsNode
)
Flush
(
file
File
,
openFlags
uint32
,
context
*
Context
)
(
code
Status
)
{
func
(
n
*
d
efaultFsNode
)
Flush
(
file
File
,
openFlags
uint32
,
context
*
Context
)
(
code
Status
)
{
return
ENOSYS
}
func
(
n
*
D
efaultFsNode
)
OpenDir
(
context
*
Context
)
([]
DirEntry
,
Status
)
{
func
(
n
*
d
efaultFsNode
)
OpenDir
(
context
*
Context
)
([]
DirEntry
,
Status
)
{
ch
:=
n
.
Inode
()
.
Children
()
s
:=
make
([]
DirEntry
,
0
,
len
(
ch
))
for
name
,
child
:=
range
ch
{
...
...
@@ -118,23 +121,23 @@ func (n *DefaultFsNode) OpenDir(context *Context) ([]DirEntry, Status) {
return
s
,
OK
}
func
(
n
*
D
efaultFsNode
)
GetXAttr
(
attribute
string
,
context
*
Context
)
(
data
[]
byte
,
code
Status
)
{
func
(
n
*
d
efaultFsNode
)
GetXAttr
(
attribute
string
,
context
*
Context
)
(
data
[]
byte
,
code
Status
)
{
return
nil
,
ENOSYS
}
func
(
n
*
D
efaultFsNode
)
RemoveXAttr
(
attr
string
,
context
*
Context
)
Status
{
func
(
n
*
d
efaultFsNode
)
RemoveXAttr
(
attr
string
,
context
*
Context
)
Status
{
return
ENOSYS
}
func
(
n
*
D
efaultFsNode
)
SetXAttr
(
attr
string
,
data
[]
byte
,
flags
int
,
context
*
Context
)
Status
{
func
(
n
*
d
efaultFsNode
)
SetXAttr
(
attr
string
,
data
[]
byte
,
flags
int
,
context
*
Context
)
Status
{
return
ENOSYS
}
func
(
n
*
D
efaultFsNode
)
ListXAttr
(
context
*
Context
)
(
attrs
[]
string
,
code
Status
)
{
func
(
n
*
d
efaultFsNode
)
ListXAttr
(
context
*
Context
)
(
attrs
[]
string
,
code
Status
)
{
return
nil
,
ENOSYS
}
func
(
n
*
D
efaultFsNode
)
GetAttr
(
out
*
Attr
,
file
File
,
context
*
Context
)
(
code
Status
)
{
func
(
n
*
d
efaultFsNode
)
GetAttr
(
out
*
Attr
,
file
File
,
context
*
Context
)
(
code
Status
)
{
if
n
.
Inode
()
.
IsDir
()
{
out
.
Mode
=
S_IFDIR
|
0755
}
else
{
...
...
@@ -143,22 +146,22 @@ func (n *DefaultFsNode) GetAttr(out *Attr, file File, context *Context) (code St
return
OK
}
func
(
n
*
D
efaultFsNode
)
Chmod
(
file
File
,
perms
uint32
,
context
*
Context
)
(
code
Status
)
{
func
(
n
*
d
efaultFsNode
)
Chmod
(
file
File
,
perms
uint32
,
context
*
Context
)
(
code
Status
)
{
return
ENOSYS
}
func
(
n
*
D
efaultFsNode
)
Chown
(
file
File
,
uid
uint32
,
gid
uint32
,
context
*
Context
)
(
code
Status
)
{
func
(
n
*
d
efaultFsNode
)
Chown
(
file
File
,
uid
uint32
,
gid
uint32
,
context
*
Context
)
(
code
Status
)
{
return
ENOSYS
}
func
(
n
*
D
efaultFsNode
)
Truncate
(
file
File
,
size
uint64
,
context
*
Context
)
(
code
Status
)
{
func
(
n
*
d
efaultFsNode
)
Truncate
(
file
File
,
size
uint64
,
context
*
Context
)
(
code
Status
)
{
return
ENOSYS
}
func
(
n
*
D
efaultFsNode
)
Utimens
(
file
File
,
atime
*
time
.
Time
,
mtime
*
time
.
Time
,
context
*
Context
)
(
code
Status
)
{
func
(
n
*
d
efaultFsNode
)
Utimens
(
file
File
,
atime
*
time
.
Time
,
mtime
*
time
.
Time
,
context
*
Context
)
(
code
Status
)
{
return
ENOSYS
}
func
(
n
*
D
efaultFsNode
)
Fallocate
(
file
File
,
off
uint64
,
size
uint64
,
mode
uint32
,
context
*
Context
)
(
code
Status
)
{
func
(
n
*
d
efaultFsNode
)
Fallocate
(
file
File
,
off
uint64
,
size
uint64
,
mode
uint32
,
context
*
Context
)
(
code
Status
)
{
return
ENOSYS
}
fuse/defaultraw.go
View file @
f2ebdfe7
...
...
@@ -9,7 +9,7 @@ import (
// NewDefaultRawFileSystem returns ENOSYS (not implemented) for all
// operations.
func
NewDefaultRawFileSystem
()
RawFileSystem
{
return
&
defaultRawFileSystem
{}
return
(
*
defaultRawFileSystem
)(
nil
)
}
type
defaultRawFileSystem
struct
{}
...
...
fuse/files.go
View file @
f2ebdfe7
...
...
@@ -56,8 +56,6 @@ type devNullFile struct {
File
}
var
_
=
(
File
)((
*
devNullFile
)(
nil
))
// NewDevNullFile returns a file that accepts any write, and always
// returns EOF for reads.
func
NewDevNullFile
()
*
devNullFile
{
...
...
fuse/memnode.go
View file @
f2ebdfe7
...
...
@@ -12,7 +12,6 @@ import (
var
_
=
log
.
Println
type
MemNodeFs
struct
{
DefaultNodeFileSystem
backingStorePrefix
string
root
*
memNode
...
...
@@ -28,9 +27,19 @@ func (fs *MemNodeFs) Root() FsNode {
return
fs
.
root
}
func
(
fs
*
MemNodeFs
)
SetDebug
(
bool
)
{
}
func
(
fs
*
MemNodeFs
)
OnMount
(
*
FileSystemConnector
)
{
}
func
(
fs
*
MemNodeFs
)
OnUnmount
()
{
}
func
(
fs
*
MemNodeFs
)
newNode
()
*
memNode
{
fs
.
mutex
.
Lock
()
n
:=
&
memNode
{
FsNode
:
NewDefaultFsNode
(),
fs
:
fs
,
id
:
fs
.
nextFree
,
}
...
...
@@ -43,8 +52,9 @@ func (fs *MemNodeFs) newNode() *memNode {
}
func
NewMemNodeFs
(
prefix
string
)
*
MemNodeFs
{
me
:=
&
MemNodeFs
{}
me
.
backingStorePrefix
=
prefix
me
:=
&
MemNodeFs
{
backingStorePrefix
:
prefix
,
}
me
.
root
=
me
.
newNode
()
return
me
}
...
...
@@ -55,7 +65,7 @@ func (fs *MemNodeFs) Filename(n *Inode) string {
}
type
memNode
struct
{
Default
FsNode
FsNode
fs
*
MemNodeFs
id
int
...
...
fuse/pathfs/pathfs.go
View file @
f2ebdfe7
...
...
@@ -199,8 +199,7 @@ type pathInode struct {
// This is to correctly resolve hardlinks of the underlying
// real filesystem.
clientInode
uint64
fuse
.
DefaultFsNode
inode
*
fuse
.
Inode
}
// Drop all known client inodes. Must have the treeLock.
...
...
@@ -211,6 +210,18 @@ func (n *pathInode) forgetClientInodes() {
}
}
func
(
fs
*
pathInode
)
Deletable
()
bool
{
return
true
}
func
(
n
*
pathInode
)
Inode
()
*
fuse
.
Inode
{
return
n
.
inode
}
func
(
n
*
pathInode
)
SetInode
(
node
*
fuse
.
Inode
)
{
n
.
inode
=
node
}
// Reread all client nodes below this node. Must run outside the treeLock.
func
(
n
*
pathInode
)
updateClientInodes
()
{
n
.
GetAttr
(
&
fuse
.
Attr
{},
nil
,
nil
)
...
...
fuse/test/mount_test.go
View file @
f2ebdfe7
...
...
@@ -19,7 +19,7 @@ func TestMountOnExisting(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
nfs
:=
&
fuse
.
DefaultNodeFileSystem
{}
nfs
:=
fuse
.
NewDefaultNodeFileSystem
()
code
:=
ts
.
connector
.
Mount
(
ts
.
rootNode
(),
"mnt"
,
nfs
,
nil
)
if
code
!=
fuse
.
EBUSY
{
t
.
Fatal
(
"expect EBUSY:"
,
code
)
...
...
zipfs/memtree.go
View file @
f2ebdfe7
...
...
@@ -2,8 +2,9 @@ package zipfs
import
(
"fmt"
"github.com/hanwen/go-fuse/fuse"
"strings"
"github.com/hanwen/go-fuse/fuse"
)
type
MemFile
interface
{
...
...
@@ -12,7 +13,7 @@ type MemFile interface {
}
type
memNode
struct
{
fuse
.
Default
FsNode
fuse
.
FsNode
file
MemFile
}
...
...
@@ -20,15 +21,17 @@ type memNode struct {
// loaded in memory completely at startup, it does not need to inode
// discovery through Lookup() at serve time.
type
MemTreeFs
struct
{
fuse
.
Default
NodeFileSystem
fuse
.
NodeFileSystem
root
memNode
files
map
[
string
]
MemFile
Name
string
}
func
NewMemTreeFs
()
*
MemTreeFs
{
d
:=
new
(
MemTreeFs
)
return
d
return
&
MemTreeFs
{
NodeFileSystem
:
fuse
.
NewDefaultNodeFileSystem
(),
root
:
memNode
{
FsNode
:
fuse
.
NewDefaultFsNode
()},
}
}
func
(
fs
*
MemTreeFs
)
String
()
string
{
...
...
@@ -110,7 +113,7 @@ func (n *MemTreeFs) addFile(name string, f MemFile) {
for
i
,
c
:=
range
comps
{
child
:=
node
.
GetChild
(
c
)
if
child
==
nil
{
fsnode
:=
&
memNode
{}
fsnode
:=
&
memNode
{
FsNode
:
fuse
.
NewDefaultFsNode
()
}
if
i
==
len
(
comps
)
-
1
{
fsnode
.
file
=
f
}
...
...
zipfs/zipfs.go
View file @
f2ebdfe7
...
...
@@ -61,9 +61,8 @@ func NewZipTree(name string) (map[string]MemFile, error) {
}
func
NewArchiveFileSystem
(
name
string
)
(
mfs
*
MemTreeFs
,
err
error
)
{
mfs
=
&
MemTreeFs
{
Name
:
fmt
.
Sprintf
(
"fs(%s)"
,
name
),
}
mfs
=
NewMemTreeFs
()
mfs
.
Name
=
fmt
.
Sprintf
(
"fs(%s)"
,
name
)
if
strings
.
HasSuffix
(
name
,
".zip"
)
{
mfs
.
files
,
err
=
NewZipTree
(
name
)
...
...
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