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
Levin Zimmermann
go-fuse
Commits
ddde0e88
Commit
ddde0e88
authored
Jan 27, 2011
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Run gofmt.
parent
eb2b2511
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
61 additions
and
64 deletions
+61
-64
example/main.go
example/main.go
+1
-1
examplelib/dummyfuse.go
examplelib/dummyfuse.go
+1
-2
examplelib/passthrough.go
examplelib/passthrough.go
+3
-3
examplelib/passthrough_test.go
examplelib/passthrough_test.go
+7
-7
examplelib/stackfs.go
examplelib/stackfs.go
+0
-2
examplelib/stackfs_test.go
examplelib/stackfs_test.go
+1
-1
fuse/bufferpool.go
fuse/bufferpool.go
+5
-6
fuse/bufferpool_test.go
fuse/bufferpool_test.go
+9
-9
fuse/direntry.go
fuse/direntry.go
+3
-2
fuse/fuse.go
fuse/fuse.go
+4
-4
fuse/pathfilesystem.go
fuse/pathfilesystem.go
+27
-27
No files found.
example/main.go
View file @
ddde0e88
...
...
@@ -39,7 +39,7 @@ func main() {
state
.
Loop
(
*
threaded
)
fmt
.
Println
(
"Finished"
,
state
.
Stats
())
for
v
:=
range
(
expvar
.
Iter
()
)
{
for
v
:=
range
expvar
.
Iter
(
)
{
if
strings
.
HasPrefix
(
v
.
Key
,
"mount"
)
{
fmt
.
Printf
(
"%v: %v
\n
"
,
v
.
Key
,
v
.
Value
)
}
...
...
examplelib/dummyfuse.go
View file @
ddde0e88
...
...
@@ -201,7 +201,7 @@ func (self *DummyPathFuse) OpenDir(name string) (stream chan fuse.DirEntry, stat
return
nil
,
fuse
.
ENOSYS
}
func
(
self
*
DummyPathFuse
)
Mount
(
conn
*
fuse
.
PathFileSystemConnector
)
(
fuse
.
Status
)
{
func
(
self
*
DummyPathFuse
)
Mount
(
conn
*
fuse
.
PathFileSystemConnector
)
fuse
.
Status
{
return
fuse
.
OK
}
...
...
@@ -219,4 +219,3 @@ func (self *DummyPathFuse) Create(name string, flags uint32, mode uint32) (file
func
(
self
*
DummyPathFuse
)
Utimens
(
name
string
,
AtimeNs
uint64
,
CtimeNs
uint64
)
(
code
fuse
.
Status
)
{
return
fuse
.
ENOSYS
}
examplelib/passthrough.go
View file @
ddde0e88
...
...
@@ -25,7 +25,7 @@ func NewPassThroughFuse(root string) (out *PassThroughFuse) {
return
out
}
func
(
self
*
PassThroughFuse
)
Mount
(
conn
*
fuse
.
PathFileSystemConnector
)
(
fuse
.
Status
)
{
func
(
self
*
PassThroughFuse
)
Mount
(
conn
*
fuse
.
PathFileSystemConnector
)
fuse
.
Status
{
return
fuse
.
OK
}
...
...
@@ -77,8 +77,8 @@ func (self *PassThroughFuse) OpenDir(name string) (stream chan fuse.DirEntry, st
}
close
(
output
)
f
.
Close
()
}()
}()
return
output
,
fuse
.
OK
}
...
...
examplelib/passthrough_test.go
View file @
ddde0e88
...
...
@@ -53,7 +53,7 @@ func (self *testCase) Setup(t *testing.T) {
self
.
origFile
=
path
.
Join
(
self
.
origDir
,
name
)
self
.
origSubdir
=
path
.
Join
(
self
.
origDir
,
subdir
)
self
.
origSubfile
=
path
.
Join
(
self
.
origSubdir
,
"subfile"
)
pfs
:=
NewPassThroughFuse
(
self
.
origDir
)
self
.
connector
=
fuse
.
NewPathFileSystemConnector
(
pfs
)
self
.
connector
.
Debug
=
true
...
...
@@ -603,13 +603,13 @@ func TestRecursiveMount(t *testing.T) {
f
,
err
:=
os
.
Open
(
path
.
Join
(
ts
.
mountPoint
,
"hello.txt"
),
os
.
O_WRONLY
|
os
.
O_CREATE
,
0777
)
if
err
!=
nil
{
t
.
Errorf
(
"open write err %v"
,
err
)
}
f
.
WriteString
(
"bla"
)
f
.
Close
()
pfs2
:=
NewPassThroughFuse
(
ts
.
origDir
)
code
:=
ts
.
connector
.
Mount
(
"/hello.txt"
,
pfs2
)
if
code
!=
fuse
.
EINVAL
{
...
...
@@ -621,12 +621,12 @@ func TestRecursiveMount(t *testing.T) {
if
err
!=
nil
{
t
.
Errorf
(
"mkdir"
)
}
code
=
ts
.
connector
.
Mount
(
"/mnt"
,
pfs2
)
if
code
!=
fuse
.
OK
{
t
.
Errorf
(
"mkdir"
)
}
_
,
err
=
os
.
Lstat
(
submnt
)
if
err
!=
nil
{
t
.
Error
(
"lstat submount"
,
err
)
...
...
@@ -635,7 +635,7 @@ func TestRecursiveMount(t *testing.T) {
if
err
!=
nil
{
t
.
Error
(
"lstat submount/file"
,
err
)
}
f
,
err
=
os
.
Open
(
path
.
Join
(
submnt
,
"hello.txt"
),
os
.
O_RDONLY
,
0
)
if
err
!=
nil
{
t
.
Error
(
"open submount/file"
,
err
)
...
...
@@ -649,7 +649,7 @@ func TestRecursiveMount(t *testing.T) {
// The close takes some time to propagate through FUSE.
time
.
Sleep
(
1e9
)
code
=
ts
.
connector
.
Unmount
(
"/mnt"
)
if
code
!=
fuse
.
OK
{
t
.
Error
(
"umount failed."
,
code
)
...
...
examplelib/stackfs.go
View file @
ddde0e88
...
...
@@ -601,7 +601,6 @@ func (self *SubmountFileSystem) ReleaseDir(header *fuse.InHeader, f fuse.RawFuse
}
////////////////////////////////////////////////////////////////
type
SubmountFileSystemTopDir
struct
{
...
...
@@ -638,4 +637,3 @@ func (self *SubmountFileSystemTopDir) ReleaseDir() {
func
(
self
*
SubmountFileSystemTopDir
)
FsyncDir
(
input
*
fuse
.
FsyncIn
)
(
code
fuse
.
Status
)
{
return
fuse
.
ENOENT
}
examplelib/stackfs_test.go
View file @
ddde0e88
...
...
@@ -43,7 +43,7 @@ func (self *stackFsTestCase) Setup(t *testing.T) {
fs1
:=
fuse
.
NewPathFileSystemConnector
(
NewPassThroughFuse
(
self
.
origDir1
))
fs2
:=
fuse
.
NewPathFileSystemConnector
(
NewPassThroughFuse
(
self
.
origDir2
))
self
.
fs
=
NewSubmountFileSystem
()
attr
:=
fuse
.
Attr
{
...
...
fuse/bufferpool.go
View file @
ddde0e88
...
...
@@ -25,7 +25,7 @@ func IntToExponent(z int) uint {
}
if
z
>
(
1
<<
exp
)
{
exp
++
exp
++
}
return
exp
}
...
...
@@ -38,7 +38,7 @@ func NewBufferPool() *BufferPool {
func
(
self
*
BufferPool
)
String
()
string
{
s
:=
""
for
exp
,
bufs
:=
range
(
self
.
buffersByExponent
)
{
for
exp
,
bufs
:=
range
self
.
buffersByExponent
{
s
=
s
+
fmt
.
Sprintf
(
"%d = %d
\n
"
,
exp
,
len
(
bufs
))
}
return
s
...
...
@@ -50,11 +50,11 @@ func (self *BufferPool) getBuffer(sz int) []byte {
self
.
lock
.
Lock
()
defer
self
.
lock
.
Unlock
()
if
(
len
(
self
.
buffersByExponent
)
<=
int
(
exponent
)
)
{
if
len
(
self
.
buffersByExponent
)
<=
int
(
exponent
)
{
return
nil
}
bufferList
:=
self
.
buffersByExponent
[
exponent
]
if
(
len
(
bufferList
)
==
0
)
{
if
len
(
bufferList
)
==
0
{
return
nil
}
...
...
@@ -69,7 +69,7 @@ func (self *BufferPool) getBuffer(sz int) []byte {
}
func
(
self
*
BufferPool
)
addBuffer
(
slice
[]
byte
)
{
if
cap
(
slice
)
&
(
PAGESIZE
-
1
)
!=
0
{
if
cap
(
slice
)
&
(
PAGESIZE
-
1
)
!=
0
{
return
}
...
...
@@ -106,4 +106,3 @@ func (self *BufferPool) GetBuffer(size uint32) []byte {
return
make
([]
byte
,
size
,
rounded
)
}
fuse/bufferpool_test.go
View file @
ddde0e88
...
...
@@ -5,7 +5,7 @@ import (
"fmt"
)
func
TestIntToExponent
(
t
*
testing
.
T
)
{
func
TestIntToExponent
(
t
*
testing
.
T
)
{
e
:=
IntToExponent
(
1
)
if
e
!=
0
{
t
.
Error
(
"1"
,
e
)
...
...
@@ -24,10 +24,10 @@ func TestIntToExponent(t *testing.T) {
}
}
func
TestBufferPool
(
t
*
testing
.
T
)
{
func
TestBufferPool
(
t
*
testing
.
T
)
{
bp
:=
NewBufferPool
()
b
:=
bp
.
getBuffer
(
PAGESIZE
-
1
)
b
:=
bp
.
getBuffer
(
PAGESIZE
-
1
)
if
b
!=
nil
{
t
.
Error
(
"bp 0"
)
}
...
...
@@ -36,10 +36,10 @@ func TestBufferPool(t *testing.T) {
t
.
Error
(
"bp 1"
)
}
s
:=
make
([]
byte
,
PAGESIZE
-
1
)
s
:=
make
([]
byte
,
PAGESIZE
-
1
)
bp
.
addBuffer
(
s
)
b
=
bp
.
getBuffer
(
PAGESIZE
-
1
)
b
=
bp
.
getBuffer
(
PAGESIZE
-
1
)
if
b
!=
nil
{
t
.
Error
(
"bp 3"
)
}
...
...
@@ -57,21 +57,21 @@ func TestBufferPool(t *testing.T) {
}
bp
.
addBuffer
(
make
([]
byte
,
3
*
PAGESIZE
))
b
=
bp
.
getBuffer
(
2
*
PAGESIZE
)
b
=
bp
.
getBuffer
(
2
*
PAGESIZE
)
if
b
!=
nil
{
t
.
Error
(
"should fail."
)
}
b
=
bp
.
getBuffer
(
4
*
PAGESIZE
)
b
=
bp
.
getBuffer
(
4
*
PAGESIZE
)
if
b
!=
nil
{
t
.
Error
(
"should fail."
)
}
bp
.
addBuffer
(
make
([]
byte
,
4
*
PAGESIZE
))
fmt
.
Println
(
bp
)
b
=
bp
.
getBuffer
(
2
*
PAGESIZE
)
b
=
bp
.
getBuffer
(
2
*
PAGESIZE
)
if
b
!=
nil
{
t
.
Error
(
"should fail."
)
}
b
=
bp
.
getBuffer
(
4
*
PAGESIZE
)
b
=
bp
.
getBuffer
(
4
*
PAGESIZE
)
if
b
==
nil
{
t
.
Error
(
"4*ps should succeed."
)
}
...
...
fuse/direntry.go
View file @
ddde0e88
...
...
@@ -7,6 +7,7 @@ import (
"fmt"
"bytes"
)
var
_
=
fmt
.
Print
// For PathFileSystemConnector. The connector determines inodes.
type
DirEntry
struct
{
...
...
@@ -64,8 +65,8 @@ func (de *DirEntryList) Bytes() []byte {
////////////////////////////////////////////////////////////////
type
FuseDir
struct
{
stream
chan
DirEntry
leftOver
DirEntry
stream
chan
DirEntry
leftOver
DirEntry
connector
*
PathFileSystemConnector
parentIno
uint64
}
...
...
fuse/fuse.go
View file @
ddde0e88
...
...
@@ -196,10 +196,10 @@ func (self *MountState) Stats() string {
var
lines
[]
string
// TODO - bufferpool should use expvar.
lines
=
append
(
lines
,
lines
=
append
(
lines
,
fmt
.
Sprintf
(
"buffers: %v"
,
self
.
buffers
.
String
()))
for
v
:=
range
(
expvar
.
Iter
()
)
{
for
v
:=
range
expvar
.
Iter
(
)
{
if
strings
.
HasPrefix
(
v
.
Key
,
"mount"
)
{
lines
=
append
(
lines
,
fmt
.
Sprintf
(
"%v: %v
\n
"
,
v
.
Key
,
v
.
Value
))
}
...
...
@@ -221,7 +221,7 @@ func (self *MountState) syncWrite(packet [][]byte) {
if
err
!=
nil
{
self
.
Error
(
os
.
NewError
(
fmt
.
Sprintf
(
"writer: Writev %v failed, err: %v"
,
packet
,
err
)))
}
for
_
,
v
:=
range
(
packet
)
{
for
_
,
v
:=
range
packet
{
self
.
buffers
.
addBuffer
(
v
)
}
}
...
...
fuse/pathfilesystem.go
View file @
ddde0e88
...
...
@@ -11,20 +11,20 @@ import (
type
mountData
struct
{
// If non-nil the file system mounted here.
fs
PathFilesystem
fs
PathFilesystem
// If yes, we are looking to unmount the mounted fs.
unmountPending
bool
openFiles
int
openDirs
int
subMounts
int
openFiles
int
openDirs
int
subMounts
int
}
func
newMount
(
fs
PathFilesystem
)
*
mountData
{
return
&
mountData
{
fs
:
fs
}
}
// TODO should rename to dentry?
type
inodeData
struct
{
Parent
*
inodeData
...
...
@@ -32,7 +32,7 @@ type inodeData struct {
Name
string
LookupCount
int
Type
uint32
Type
uint32
// Number of inodeData that have this as parent.
RefCount
int
...
...
@@ -65,7 +65,7 @@ func (self *inodeData) GetPath() (path string, mount *mountData) {
if
inode
==
nil
{
panic
(
"did not find parent with mount"
)
}
fullPath
:=
strings
.
Join
(
components
[
j
:
],
"/"
)
mount
=
inode
.
mount
if
mount
.
unmountPending
{
...
...
@@ -109,9 +109,9 @@ type PathFileSystemConnector struct {
inodePathMap
map
[
string
]
*
inodeData
inodePathMapByInode
map
[
uint64
]
*
inodeData
nextFreeInode
uint64
options
PathFileSystemConnectorOptions
Debug
bool
Debug
bool
}
// Must be called with lock held.
...
...
@@ -148,7 +148,7 @@ func (self *PathFileSystemConnector) lookup(key string) *inodeData {
defer
self
.
lock
.
RUnlock
()
return
self
.
inodePathMap
[
key
]
}
func
(
self
*
PathFileSystemConnector
)
lookupUpdate
(
nodeId
uint64
,
name
string
)
*
inodeData
{
key
:=
inodeDataKey
(
nodeId
,
name
)
data
:=
self
.
lookup
(
key
)
...
...
@@ -259,16 +259,16 @@ func (self *PathFileSystemConnector) unlinkUpdate(nodeid uint64, name string) {
func
(
self
*
PathFileSystemConnector
)
findInode
(
fullPath
string
)
*
inodeData
{
fullPath
=
strings
.
TrimLeft
(
path
.
Clean
(
fullPath
),
"/"
)
comps
:=
strings
.
Split
(
fullPath
,
"/"
,
-
1
)
self
.
lock
.
RLock
()
defer
self
.
lock
.
RUnlock
()
node
:=
self
.
inodePathMapByInode
[
FUSE_ROOT_ID
]
for
i
,
component
:=
range
(
comps
)
{
for
i
,
component
:=
range
comps
{
if
len
(
component
)
==
0
{
continue
}
key
:=
inodeDataKey
(
node
.
NodeId
,
component
)
node
=
self
.
inodePathMap
[
key
]
if
node
==
nil
{
...
...
@@ -290,7 +290,7 @@ func NewPathFileSystemConnector(fs PathFilesystem) (out *PathFileSystemConnector
rootData
:=
new
(
inodeData
)
rootData
.
NodeId
=
FUSE_ROOT_ID
rootData
.
Type
=
ModeToType
(
S_IFDIR
)
out
.
inodePathMap
[
rootData
.
Key
()]
=
rootData
out
.
inodePathMapByInode
[
FUSE_ROOT_ID
]
=
rootData
out
.
nextFreeInode
=
FUSE_ROOT_ID
+
1
...
...
@@ -318,10 +318,10 @@ func (self *PathFileSystemConnector) Mount(path string, fs PathFilesystem) Statu
return
EBUSY
}
if
node
.
Type
&
ModeToType
(
S_IFDIR
)
==
0
{
if
node
.
Type
&
ModeToType
(
S_IFDIR
)
==
0
{
return
EINVAL
}
code
:=
fs
.
Mount
(
self
)
if
code
!=
OK
{
if
self
.
Debug
{
...
...
@@ -329,7 +329,7 @@ func (self *PathFileSystemConnector) Mount(path string, fs PathFilesystem) Statu
}
return
code
}
if
self
.
Debug
{
log
.
Println
(
"Mount: "
,
fs
,
"on"
,
path
,
node
)
}
...
...
@@ -340,7 +340,7 @@ func (self *PathFileSystemConnector) Mount(path string, fs PathFilesystem) Statu
_
,
parentMount
:=
node
.
Parent
.
GetPath
()
parentMount
.
subMounts
++
}
return
OK
}
...
...
@@ -355,7 +355,7 @@ func (self *PathFileSystemConnector) Unmount(path string) Status {
panic
(
path
)
}
if
mount
.
openFiles
+
mount
.
openDirs
+
mount
.
subMounts
>
0
{
if
mount
.
openFiles
+
mount
.
openDirs
+
mount
.
subMounts
>
0
{
log
.
Println
(
"busy: "
,
mount
)
return
EBUSY
}
...
...
@@ -404,7 +404,7 @@ func (self *PathFileSystemConnector) Lookup(header *InHeader, name string) (out
fullPath
=
path
.
Join
(
fullPath
,
name
)
attr
,
err
:=
mount
.
fs
.
GetAttr
(
fullPath
)
if
err
==
ENOENT
&&
self
.
options
.
NegativeTimeout
>
0.0
{
return
NegativeEntry
(
self
.
options
.
NegativeTimeout
),
OK
}
...
...
@@ -416,7 +416,7 @@ func (self *PathFileSystemConnector) Lookup(header *InHeader, name string) (out
data
:=
self
.
lookupUpdate
(
header
.
NodeId
,
name
)
data
.
LookupCount
++
data
.
Type
=
ModeToType
(
attr
.
Mode
)
out
=
new
(
EntryOut
)
out
.
NodeId
=
data
.
NodeId
out
.
Generation
=
1
// where to get the generation?
...
...
@@ -537,7 +537,7 @@ func (self *PathFileSystemConnector) Mknod(header *InHeader, input *MknodIn, nam
fullPath
,
mount
:=
self
.
GetPath
(
header
.
NodeId
)
if
mount
==
nil
{
return
nil
,
ENOENT
}
}
fullPath
=
path
.
Join
(
fullPath
,
name
)
err
:=
mount
.
fs
.
Mknod
(
fullPath
,
input
.
Mode
,
uint32
(
input
.
Rdev
))
if
err
!=
OK
{
...
...
@@ -550,7 +550,7 @@ func (self *PathFileSystemConnector) Mkdir(header *InHeader, input *MkdirIn, nam
fullPath
,
mount
:=
self
.
GetPath
(
header
.
NodeId
)
if
mount
==
nil
{
return
nil
,
ENOENT
}
}
err
:=
mount
.
fs
.
Mkdir
(
path
.
Join
(
fullPath
,
name
),
input
.
Mode
)
if
err
!=
OK
{
return
nil
,
err
...
...
@@ -563,7 +563,7 @@ func (self *PathFileSystemConnector) Unlink(header *InHeader, name string) (code
fullPath
,
mount
:=
self
.
GetPath
(
header
.
NodeId
)
if
mount
==
nil
{
return
ENOENT
}
}
code
=
mount
.
fs
.
Unlink
(
path
.
Join
(
fullPath
,
name
))
// Like fuse.c, we update our internal tables.
...
...
@@ -586,7 +586,7 @@ func (self *PathFileSystemConnector) Symlink(header *InHeader, pointedTo string,
fullPath
,
mount
:=
self
.
GetPath
(
header
.
NodeId
)
if
mount
==
nil
{
return
nil
,
ENOENT
}
}
err
:=
mount
.
fs
.
Symlink
(
pointedTo
,
path
.
Join
(
fullPath
,
linkName
))
if
err
!=
OK
{
return
nil
,
err
...
...
@@ -605,7 +605,7 @@ func (self *PathFileSystemConnector) Rename(header *InHeader, input *RenameIn, o
if
mount
!=
oldMount
{
return
EXDEV
}
oldPath
=
path
.
Join
(
oldPath
,
oldName
)
newPath
=
path
.
Join
(
newPath
,
newName
)
code
=
mount
.
fs
.
Rename
(
oldPath
,
newPath
)
...
...
@@ -648,7 +648,7 @@ func (self *PathFileSystemConnector) Access(header *InHeader, input *AccessIn) (
p
,
mount
:=
self
.
GetPath
(
header
.
NodeId
)
if
mount
==
nil
{
return
ENOENT
}
}
return
mount
.
fs
.
Access
(
p
,
input
.
Mask
)
}
...
...
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