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
7c3c1e41
Commit
7c3c1e41
authored
Feb 21, 2011
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Uniformize receiver names to 'me'.
parent
1fe92061
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
733 additions
and
733 deletions
+733
-733
examplelib/passthrough.go
examplelib/passthrough.go
+51
-51
examplelib/passthrough_test.go
examplelib/passthrough_test.go
+175
-175
examplelib/stackfs.go
examplelib/stackfs.go
+133
-133
examplelib/stackfs_test.go
examplelib/stackfs_test.go
+58
-58
examplelib/zipfs.go
examplelib/zipfs.go
+6
-6
fuse/bufferpool.go
fuse/bufferpool.go
+21
-21
fuse/datafile.go
fuse/datafile.go
+4
-4
fuse/default.go
fuse/default.go
+52
-52
fuse/direntry.go
fuse/direntry.go
+14
-14
fuse/fuse.go
fuse/fuse.go
+83
-83
fuse/pathfilesystem.go
fuse/pathfilesystem.go
+136
-136
No files found.
examplelib/passthrough.go
View file @
7c3c1e41
...
...
@@ -27,12 +27,12 @@ func NewPassThroughFuse(root string) (out *PassThroughFuse) {
return
out
}
func
(
self
*
PassThroughFuse
)
GetPath
(
relPath
string
)
string
{
return
path
.
Join
(
self
.
root
,
relPath
)
func
(
me
*
PassThroughFuse
)
GetPath
(
relPath
string
)
string
{
return
path
.
Join
(
me
.
root
,
relPath
)
}
func
(
self
*
PassThroughFuse
)
GetAttr
(
name
string
)
(
*
fuse
.
Attr
,
fuse
.
Status
)
{
fullPath
:=
self
.
GetPath
(
name
)
func
(
me
*
PassThroughFuse
)
GetAttr
(
name
string
)
(
*
fuse
.
Attr
,
fuse
.
Status
)
{
fullPath
:=
me
.
GetPath
(
name
)
fi
,
err
:=
os
.
Lstat
(
fullPath
)
if
err
!=
nil
{
return
nil
,
fuse
.
ENOENT
...
...
@@ -43,10 +43,10 @@ func (self *PassThroughFuse) GetAttr(name string) (*fuse.Attr, fuse.Status) {
return
out
,
fuse
.
OK
}
func
(
self
*
PassThroughFuse
)
OpenDir
(
name
string
)
(
stream
chan
fuse
.
DirEntry
,
status
fuse
.
Status
)
{
func
(
me
*
PassThroughFuse
)
OpenDir
(
name
string
)
(
stream
chan
fuse
.
DirEntry
,
status
fuse
.
Status
)
{
// What other ways beyond O_RDONLY are there to open
// directories?
f
,
err
:=
os
.
Open
(
self
.
GetPath
(
name
),
os
.
O_RDONLY
,
0
)
f
,
err
:=
os
.
Open
(
me
.
GetPath
(
name
),
os
.
O_RDONLY
,
0
)
if
err
!=
nil
{
return
nil
,
fuse
.
OsErrorToFuseError
(
err
)
}
...
...
@@ -76,75 +76,75 @@ func (self *PassThroughFuse) OpenDir(name string) (stream chan fuse.DirEntry, st
return
output
,
fuse
.
OK
}
func
(
self
*
PassThroughFuse
)
Open
(
name
string
,
flags
uint32
)
(
fuseFile
fuse
.
RawFuseFile
,
status
fuse
.
Status
)
{
f
,
err
:=
os
.
Open
(
self
.
GetPath
(
name
),
int
(
flags
),
0
)
func
(
me
*
PassThroughFuse
)
Open
(
name
string
,
flags
uint32
)
(
fuseFile
fuse
.
RawFuseFile
,
status
fuse
.
Status
)
{
f
,
err
:=
os
.
Open
(
me
.
GetPath
(
name
),
int
(
flags
),
0
)
if
err
!=
nil
{
return
nil
,
fuse
.
OsErrorToFuseError
(
err
)
}
return
&
PassThroughFile
{
file
:
f
},
fuse
.
OK
}
func
(
self
*
PassThroughFuse
)
Chmod
(
path
string
,
mode
uint32
)
(
code
fuse
.
Status
)
{
err
:=
os
.
Chmod
(
self
.
GetPath
(
path
),
mode
)
func
(
me
*
PassThroughFuse
)
Chmod
(
path
string
,
mode
uint32
)
(
code
fuse
.
Status
)
{
err
:=
os
.
Chmod
(
me
.
GetPath
(
path
),
mode
)
return
fuse
.
OsErrorToFuseError
(
err
)
}
func
(
self
*
PassThroughFuse
)
Chown
(
path
string
,
uid
uint32
,
gid
uint32
)
(
code
fuse
.
Status
)
{
return
fuse
.
OsErrorToFuseError
(
os
.
Chown
(
self
.
GetPath
(
path
),
int
(
uid
),
int
(
gid
)))
func
(
me
*
PassThroughFuse
)
Chown
(
path
string
,
uid
uint32
,
gid
uint32
)
(
code
fuse
.
Status
)
{
return
fuse
.
OsErrorToFuseError
(
os
.
Chown
(
me
.
GetPath
(
path
),
int
(
uid
),
int
(
gid
)))
}
func
(
self
*
PassThroughFuse
)
Truncate
(
path
string
,
offset
uint64
)
(
code
fuse
.
Status
)
{
return
fuse
.
OsErrorToFuseError
(
os
.
Truncate
(
self
.
GetPath
(
path
),
int64
(
offset
)))
func
(
me
*
PassThroughFuse
)
Truncate
(
path
string
,
offset
uint64
)
(
code
fuse
.
Status
)
{
return
fuse
.
OsErrorToFuseError
(
os
.
Truncate
(
me
.
GetPath
(
path
),
int64
(
offset
)))
}
func
(
self
*
PassThroughFuse
)
Utimens
(
path
string
,
AtimeNs
uint64
,
MtimeNs
uint64
)
(
code
fuse
.
Status
)
{
return
fuse
.
OsErrorToFuseError
(
os
.
Chtimes
(
self
.
GetPath
(
path
),
int64
(
AtimeNs
),
int64
(
MtimeNs
)))
func
(
me
*
PassThroughFuse
)
Utimens
(
path
string
,
AtimeNs
uint64
,
MtimeNs
uint64
)
(
code
fuse
.
Status
)
{
return
fuse
.
OsErrorToFuseError
(
os
.
Chtimes
(
me
.
GetPath
(
path
),
int64
(
AtimeNs
),
int64
(
MtimeNs
)))
}
func
(
self
*
PassThroughFuse
)
Readlink
(
name
string
)
(
out
string
,
code
fuse
.
Status
)
{
f
,
err
:=
os
.
Readlink
(
self
.
GetPath
(
name
))
func
(
me
*
PassThroughFuse
)
Readlink
(
name
string
)
(
out
string
,
code
fuse
.
Status
)
{
f
,
err
:=
os
.
Readlink
(
me
.
GetPath
(
name
))
return
f
,
fuse
.
OsErrorToFuseError
(
err
)
}
func
(
self
*
PassThroughFuse
)
Mknod
(
name
string
,
mode
uint32
,
dev
uint32
)
(
code
fuse
.
Status
)
{
return
fuse
.
Status
(
syscall
.
Mknod
(
self
.
GetPath
(
name
),
mode
,
int
(
dev
)))
func
(
me
*
PassThroughFuse
)
Mknod
(
name
string
,
mode
uint32
,
dev
uint32
)
(
code
fuse
.
Status
)
{
return
fuse
.
Status
(
syscall
.
Mknod
(
me
.
GetPath
(
name
),
mode
,
int
(
dev
)))
}
func
(
self
*
PassThroughFuse
)
Mkdir
(
path
string
,
mode
uint32
)
(
code
fuse
.
Status
)
{
return
fuse
.
OsErrorToFuseError
(
os
.
Mkdir
(
self
.
GetPath
(
path
),
mode
))
func
(
me
*
PassThroughFuse
)
Mkdir
(
path
string
,
mode
uint32
)
(
code
fuse
.
Status
)
{
return
fuse
.
OsErrorToFuseError
(
os
.
Mkdir
(
me
.
GetPath
(
path
),
mode
))
}
func
(
self
*
PassThroughFuse
)
Unlink
(
name
string
)
(
code
fuse
.
Status
)
{
return
fuse
.
OsErrorToFuseError
(
os
.
Remove
(
self
.
GetPath
(
name
)))
func
(
me
*
PassThroughFuse
)
Unlink
(
name
string
)
(
code
fuse
.
Status
)
{
return
fuse
.
OsErrorToFuseError
(
os
.
Remove
(
me
.
GetPath
(
name
)))
}
func
(
self
*
PassThroughFuse
)
Rmdir
(
name
string
)
(
code
fuse
.
Status
)
{
return
fuse
.
OsErrorToFuseError
(
os
.
Remove
(
self
.
GetPath
(
name
)))
func
(
me
*
PassThroughFuse
)
Rmdir
(
name
string
)
(
code
fuse
.
Status
)
{
return
fuse
.
OsErrorToFuseError
(
os
.
Remove
(
me
.
GetPath
(
name
)))
}
func
(
self
*
PassThroughFuse
)
Symlink
(
pointedTo
string
,
linkName
string
)
(
code
fuse
.
Status
)
{
return
fuse
.
OsErrorToFuseError
(
os
.
Symlink
(
pointedTo
,
self
.
GetPath
(
linkName
)))
func
(
me
*
PassThroughFuse
)
Symlink
(
pointedTo
string
,
linkName
string
)
(
code
fuse
.
Status
)
{
return
fuse
.
OsErrorToFuseError
(
os
.
Symlink
(
pointedTo
,
me
.
GetPath
(
linkName
)))
}
func
(
self
*
PassThroughFuse
)
Rename
(
oldPath
string
,
newPath
string
)
(
code
fuse
.
Status
)
{
err
:=
os
.
Rename
(
self
.
GetPath
(
oldPath
),
self
.
GetPath
(
newPath
))
func
(
me
*
PassThroughFuse
)
Rename
(
oldPath
string
,
newPath
string
)
(
code
fuse
.
Status
)
{
err
:=
os
.
Rename
(
me
.
GetPath
(
oldPath
),
me
.
GetPath
(
newPath
))
return
fuse
.
OsErrorToFuseError
(
err
)
}
func
(
self
*
PassThroughFuse
)
Link
(
orig
string
,
newName
string
)
(
code
fuse
.
Status
)
{
return
fuse
.
OsErrorToFuseError
(
os
.
Link
(
self
.
GetPath
(
orig
),
self
.
GetPath
(
newName
)))
func
(
me
*
PassThroughFuse
)
Link
(
orig
string
,
newName
string
)
(
code
fuse
.
Status
)
{
return
fuse
.
OsErrorToFuseError
(
os
.
Link
(
me
.
GetPath
(
orig
),
me
.
GetPath
(
newName
)))
}
func
(
self
*
PassThroughFuse
)
Access
(
name
string
,
mode
uint32
)
(
code
fuse
.
Status
)
{
return
fuse
.
Status
(
syscall
.
Access
(
self
.
GetPath
(
name
),
mode
))
func
(
me
*
PassThroughFuse
)
Access
(
name
string
,
mode
uint32
)
(
code
fuse
.
Status
)
{
return
fuse
.
Status
(
syscall
.
Access
(
me
.
GetPath
(
name
),
mode
))
}
func
(
self
*
PassThroughFuse
)
Create
(
path
string
,
flags
uint32
,
mode
uint32
)
(
fuseFile
fuse
.
RawFuseFile
,
code
fuse
.
Status
)
{
f
,
err
:=
os
.
Open
(
self
.
GetPath
(
path
),
int
(
flags
)
|
os
.
O_CREAT
,
mode
)
func
(
me
*
PassThroughFuse
)
Create
(
path
string
,
flags
uint32
,
mode
uint32
)
(
fuseFile
fuse
.
RawFuseFile
,
code
fuse
.
Status
)
{
f
,
err
:=
os
.
Open
(
me
.
GetPath
(
path
),
int
(
flags
)
|
os
.
O_CREAT
,
mode
)
return
&
PassThroughFile
{
file
:
f
},
fuse
.
OsErrorToFuseError
(
err
)
}
func
(
self
*
PassThroughFuse
)
SetOptions
(
options
*
fuse
.
PathFileSystemConnectorOptions
)
{
func
(
me
*
PassThroughFuse
)
SetOptions
(
options
*
fuse
.
PathFileSystemConnectorOptions
)
{
options
.
NegativeTimeout
=
100.0
options
.
AttrTimeout
=
100.0
options
.
EntryTimeout
=
100.0
...
...
@@ -158,10 +158,10 @@ type PassThroughFile struct {
fuse
.
DefaultRawFuseFile
}
func
(
self
*
PassThroughFile
)
Read
(
input
*
fuse
.
ReadIn
,
buffers
*
fuse
.
BufferPool
)
([]
byte
,
fuse
.
Status
)
{
func
(
me
*
PassThroughFile
)
Read
(
input
*
fuse
.
ReadIn
,
buffers
*
fuse
.
BufferPool
)
([]
byte
,
fuse
.
Status
)
{
slice
:=
buffers
.
AllocBuffer
(
input
.
Size
)
n
,
err
:=
self
.
file
.
ReadAt
(
slice
,
int64
(
input
.
Offset
))
n
,
err
:=
me
.
file
.
ReadAt
(
slice
,
int64
(
input
.
Offset
))
if
err
==
os
.
EOF
{
// TODO - how to signal EOF?
return
slice
[
:
n
],
fuse
.
OK
...
...
@@ -169,17 +169,17 @@ func (self *PassThroughFile) Read(input *fuse.ReadIn, buffers *fuse.BufferPool)
return
slice
[
:
n
],
fuse
.
OsErrorToFuseError
(
err
)
}
func
(
self
*
PassThroughFile
)
Write
(
input
*
fuse
.
WriteIn
,
data
[]
byte
)
(
uint32
,
fuse
.
Status
)
{
n
,
err
:=
self
.
file
.
WriteAt
(
data
,
int64
(
input
.
Offset
))
func
(
me
*
PassThroughFile
)
Write
(
input
*
fuse
.
WriteIn
,
data
[]
byte
)
(
uint32
,
fuse
.
Status
)
{
n
,
err
:=
me
.
file
.
WriteAt
(
data
,
int64
(
input
.
Offset
))
return
uint32
(
n
),
fuse
.
OsErrorToFuseError
(
err
)
}
func
(
self
*
PassThroughFile
)
Release
()
{
self
.
file
.
Close
()
func
(
me
*
PassThroughFile
)
Release
()
{
me
.
file
.
Close
()
}
func
(
self
*
PassThroughFile
)
Fsync
(
*
fuse
.
FsyncIn
)
(
code
fuse
.
Status
)
{
return
fuse
.
Status
(
syscall
.
Fsync
(
self
.
file
.
Fd
()))
func
(
me
*
PassThroughFile
)
Fsync
(
*
fuse
.
FsyncIn
)
(
code
fuse
.
Status
)
{
return
fuse
.
Status
(
syscall
.
Fsync
(
me
.
file
.
Fd
()))
}
////////////////////////////////////////////////////////////////
...
...
@@ -193,25 +193,25 @@ type PassThroughDir struct {
}
func
NewPassThroughDir
(
file
*
os
.
File
)
*
PassThroughDir
{
self
:=
new
(
PassThroughDir
)
self
.
directoryChannel
=
make
(
chan
*
os
.
FileInfo
,
500
)
me
:=
new
(
PassThroughDir
)
me
.
directoryChannel
=
make
(
chan
*
os
.
FileInfo
,
500
)
go
func
()
{
for
{
want
:=
500
infos
,
err
:=
file
.
Readdir
(
want
)
for
i
,
_
:=
range
infos
{
self
.
directoryChannel
<-
&
infos
[
i
]
me
.
directoryChannel
<-
&
infos
[
i
]
}
if
len
(
infos
)
<
want
{
break
}
if
err
!=
nil
{
self
.
directoryError
=
err
me
.
directoryError
=
err
break
}
}
close
(
self
.
directoryChannel
)
close
(
me
.
directoryChannel
)
file
.
Close
()
}()
return
self
return
me
}
examplelib/passthrough_test.go
View file @
7c3c1e41
This diff is collapsed.
Click to expand it.
examplelib/stackfs.go
View file @
7c3c1e41
This diff is collapsed.
Click to expand it.
examplelib/stackfs_test.go
View file @
7c3c1e41
...
...
@@ -29,63 +29,63 @@ type stackFsTestCase struct {
state
*
fuse
.
MountState
}
func
(
self
*
stackFsTestCase
)
Setup
(
t
*
testing
.
T
)
{
self
.
tester
=
t
func
(
me
*
stackFsTestCase
)
Setup
(
t
*
testing
.
T
)
{
me
.
tester
=
t
self
.
testDir
=
fuse
.
MakeTempDir
()
self
.
origDir1
=
path
.
Join
(
self
.
testDir
,
"orig1"
)
self
.
origDir2
=
path
.
Join
(
self
.
testDir
,
"orig2"
)
self
.
mountDir
=
path
.
Join
(
self
.
testDir
,
"mount"
)
me
.
testDir
=
fuse
.
MakeTempDir
()
me
.
origDir1
=
path
.
Join
(
me
.
testDir
,
"orig1"
)
me
.
origDir2
=
path
.
Join
(
me
.
testDir
,
"orig2"
)
me
.
mountDir
=
path
.
Join
(
me
.
testDir
,
"mount"
)
os
.
Mkdir
(
self
.
origDir1
,
0700
)
os
.
Mkdir
(
self
.
origDir2
,
0700
)
os
.
Mkdir
(
self
.
mountDir
,
0700
)
os
.
Mkdir
(
me
.
origDir1
,
0700
)
os
.
Mkdir
(
me
.
origDir2
,
0700
)
os
.
Mkdir
(
me
.
mountDir
,
0700
)
fs1
:=
fuse
.
NewPathFileSystemConnector
(
NewPassThroughFuse
(
self
.
origDir1
))
fs2
:=
fuse
.
NewPathFileSystemConnector
(
NewPassThroughFuse
(
self
.
origDir2
))
fs1
:=
fuse
.
NewPathFileSystemConnector
(
NewPassThroughFuse
(
me
.
origDir1
))
fs2
:=
fuse
.
NewPathFileSystemConnector
(
NewPassThroughFuse
(
me
.
origDir2
))
self
.
fs
=
NewSubmountFileSystem
()
me
.
fs
=
NewSubmountFileSystem
()
attr
:=
fuse
.
Attr
{
Mode
:
uint32
(
magicMode
),
}
self
.
fs
.
AddFileSystem
(
"sub1"
,
fs1
,
attr
)
self
.
fs
.
AddFileSystem
(
"sub2"
,
fs2
,
attr
)
me
.
fs
.
AddFileSystem
(
"sub1"
,
fs1
,
attr
)
me
.
fs
.
AddFileSystem
(
"sub2"
,
fs2
,
attr
)
self
.
state
=
fuse
.
NewMountState
(
self
.
fs
)
self
.
state
.
Mount
(
self
.
mountDir
)
me
.
state
=
fuse
.
NewMountState
(
me
.
fs
)
me
.
state
.
Mount
(
me
.
mountDir
)
self
.
state
.
Debug
=
true
me
.
state
.
Debug
=
true
fmt
.
Println
(
"tempdir: "
,
self
.
testDir
)
fmt
.
Println
(
"tempdir: "
,
me
.
testDir
)
// Unthreaded, but in background.
go
self
.
state
.
Loop
(
false
)
go
me
.
state
.
Loop
(
false
)
}
// Unmount and del.
func
(
self
*
stackFsTestCase
)
Cleanup
()
{
func
(
me
*
stackFsTestCase
)
Cleanup
()
{
fmt
.
Println
(
"Unmounting."
)
err
:=
self
.
state
.
Unmount
()
err
:=
me
.
state
.
Unmount
()
if
err
!=
nil
{
self
.
tester
.
Errorf
(
"Can't unmount a dir, err: %v"
,
err
)
me
.
tester
.
Errorf
(
"Can't unmount a dir, err: %v"
,
err
)
}
os
.
RemoveAll
(
self
.
testDir
)
os
.
RemoveAll
(
me
.
testDir
)
}
////////////////
func
(
self
*
stackFsTestCase
)
testReaddir
()
{
func
(
me
*
stackFsTestCase
)
testReaddir
()
{
fmt
.
Println
(
"testReaddir... "
)
dir
,
err
:=
os
.
Open
(
self
.
mountDir
,
os
.
O_RDONLY
,
0
)
dir
,
err
:=
os
.
Open
(
me
.
mountDir
,
os
.
O_RDONLY
,
0
)
if
err
!=
nil
{
self
.
tester
.
Errorf
(
"opendir err %v"
,
err
)
me
.
tester
.
Errorf
(
"opendir err %v"
,
err
)
return
}
infos
,
err
:=
dir
.
Readdir
(
10
)
if
err
!=
nil
{
self
.
tester
.
Errorf
(
"readdir err %v"
,
err
)
me
.
tester
.
Errorf
(
"readdir err %v"
,
err
)
}
wanted
:=
map
[
string
]
bool
{
...
...
@@ -93,16 +93,16 @@ func (self *stackFsTestCase) testReaddir() {
"sub2"
:
true
,
}
if
len
(
wanted
)
!=
len
(
infos
)
{
self
.
tester
.
Errorf
(
"Length mismatch %v"
,
infos
)
me
.
tester
.
Errorf
(
"Length mismatch %v"
,
infos
)
}
else
{
for
_
,
v
:=
range
infos
{
_
,
ok
:=
wanted
[
v
.
Name
]
if
!
ok
{
self
.
tester
.
Errorf
(
"Unexpected name %v"
,
v
.
Name
)
me
.
tester
.
Errorf
(
"Unexpected name %v"
,
v
.
Name
)
}
if
v
.
Mode
&
0777
!=
magicMode
{
self
.
tester
.
Errorf
(
"Unexpected mode %o, %v"
,
v
.
Mode
,
v
)
me
.
tester
.
Errorf
(
"Unexpected mode %o, %v"
,
v
.
Mode
,
v
)
}
}
}
...
...
@@ -111,11 +111,11 @@ func (self *stackFsTestCase) testReaddir() {
}
func
(
self
*
stackFsTestCase
)
testSubFs
()
{
func
(
me
*
stackFsTestCase
)
testSubFs
()
{
fmt
.
Println
(
"testSubFs... "
)
for
i
:=
1
;
i
<=
2
;
i
++
{
// orig := path.Join(
self
.testDir, fmt.Sprintf("orig%d", i))
mount
:=
path
.
Join
(
self
.
mountDir
,
fmt
.
Sprintf
(
"sub%d"
,
i
))
// orig := path.Join(
me
.testDir, fmt.Sprintf("orig%d", i))
mount
:=
path
.
Join
(
me
.
mountDir
,
fmt
.
Sprintf
(
"sub%d"
,
i
))
name
:=
"testFile"
...
...
@@ -123,13 +123,13 @@ func (self *stackFsTestCase) testSubFs() {
f
,
err
:=
os
.
Open
(
mountFile
,
os
.
O_WRONLY
,
0
)
if
err
==
nil
{
self
.
tester
.
Errorf
(
"Expected error for open write %v"
,
name
)
me
.
tester
.
Errorf
(
"Expected error for open write %v"
,
name
)
continue
}
content1
:=
"booh!"
f
,
err
=
os
.
Open
(
mountFile
,
os
.
O_WRONLY
|
os
.
O_CREATE
,
magicMode
)
if
err
!=
nil
{
self
.
tester
.
Errorf
(
"Create %v"
,
err
)
me
.
tester
.
Errorf
(
"Create %v"
,
err
)
}
f
.
Write
([]
byte
(
content1
))
...
...
@@ -137,80 +137,80 @@ func (self *stackFsTestCase) testSubFs() {
err
=
os
.
Chmod
(
mountFile
,
magicMode
)
if
err
!=
nil
{
self
.
tester
.
Errorf
(
"chmod %v"
,
err
)
me
.
tester
.
Errorf
(
"chmod %v"
,
err
)
}
fi
,
err
:=
os
.
Lstat
(
mountFile
)
if
err
!=
nil
{
self
.
tester
.
Errorf
(
"Lstat %v"
,
err
)
me
.
tester
.
Errorf
(
"Lstat %v"
,
err
)
}
else
{
if
fi
.
Mode
&
0777
!=
magicMode
{
self
.
tester
.
Errorf
(
"Mode %o"
,
fi
.
Mode
)
me
.
tester
.
Errorf
(
"Mode %o"
,
fi
.
Mode
)
}
}
g
,
err
:=
os
.
Open
(
mountFile
,
os
.
O_RDONLY
,
0
)
if
err
!=
nil
{
self
.
tester
.
Errorf
(
"Open %v"
,
err
)
me
.
tester
.
Errorf
(
"Open %v"
,
err
)
}
else
{
buf
:=
make
([]
byte
,
1024
)
n
,
err
:=
g
.
Read
(
buf
)
if
err
!=
nil
{
self
.
tester
.
Errorf
(
"read err %v"
,
err
)
me
.
tester
.
Errorf
(
"read err %v"
,
err
)
}
if
string
(
buf
[
:
n
])
!=
content1
{
self
.
tester
.
Errorf
(
"content %v"
,
buf
[
:
n
])
me
.
tester
.
Errorf
(
"content %v"
,
buf
[
:
n
])
}
g
.
Close
()
}
}
}
func
(
self
*
stackFsTestCase
)
testAddRemove
()
{
self
.
tester
.
Log
(
"testAddRemove"
)
func
(
me
*
stackFsTestCase
)
testAddRemove
()
{
me
.
tester
.
Log
(
"testAddRemove"
)
attr
:=
fuse
.
Attr
{
Mode
:
0755
,
}
conn
:=
fuse
.
NewPathFileSystemConnector
(
NewPassThroughFuse
(
self
.
origDir1
))
ok
:=
self
.
fs
.
AddFileSystem
(
"sub1"
,
conn
,
attr
)
conn
:=
fuse
.
NewPathFileSystemConnector
(
NewPassThroughFuse
(
me
.
origDir1
))
ok
:=
me
.
fs
.
AddFileSystem
(
"sub1"
,
conn
,
attr
)
if
ok
{
self
.
tester
.
Errorf
(
"AddFileSystem should fail"
)
me
.
tester
.
Errorf
(
"AddFileSystem should fail"
)
return
}
ok
=
self
.
fs
.
AddFileSystem
(
"third"
,
conn
,
attr
)
ok
=
me
.
fs
.
AddFileSystem
(
"third"
,
conn
,
attr
)
if
!
ok
{
self
.
tester
.
Errorf
(
"AddFileSystem fail"
)
me
.
tester
.
Errorf
(
"AddFileSystem fail"
)
}
conn
.
Init
(
new
(
fuse
.
InHeader
),
new
(
fuse
.
InitIn
))
fi
,
err
:=
os
.
Lstat
(
path
.
Join
(
self
.
mountDir
,
"third"
))
fi
,
err
:=
os
.
Lstat
(
path
.
Join
(
me
.
mountDir
,
"third"
))
if
err
!=
nil
{
self
.
tester
.
Errorf
(
"third lstat err %v"
,
err
)
me
.
tester
.
Errorf
(
"third lstat err %v"
,
err
)
}
else
{
if
!
fi
.
IsDirectory
()
{
self
.
tester
.
Errorf
(
"not a directory %v"
,
fi
)
me
.
tester
.
Errorf
(
"not a directory %v"
,
fi
)
}
}
fs
:=
self
.
fs
.
RemoveFileSystem
(
"third"
)
fs
:=
me
.
fs
.
RemoveFileSystem
(
"third"
)
if
fs
==
nil
{
self
.
tester
.
Errorf
(
"remove fail"
)
me
.
tester
.
Errorf
(
"remove fail"
)
}
dir
,
err
:=
os
.
Open
(
self
.
mountDir
,
os
.
O_RDONLY
,
0
)
dir
,
err
:=
os
.
Open
(
me
.
mountDir
,
os
.
O_RDONLY
,
0
)
if
err
!=
nil
{
self
.
tester
.
Errorf
(
"opendir err %v"
,
err
)
me
.
tester
.
Errorf
(
"opendir err %v"
,
err
)
return
}
infos
,
err
:=
dir
.
Readdir
(
10
)
if
len
(
infos
)
!=
2
{
self
.
tester
.
Errorf
(
"lstat expect 2 infos %v"
,
infos
)
me
.
tester
.
Errorf
(
"lstat expect 2 infos %v"
,
infos
)
}
dir
.
Close
()
_
,
err
=
os
.
Open
(
path
.
Join
(
self
.
mountDir
,
"third"
),
os
.
O_RDONLY
,
0
)
_
,
err
=
os
.
Open
(
path
.
Join
(
me
.
mountDir
,
"third"
),
os
.
O_RDONLY
,
0
)
if
err
==
nil
{
self
.
tester
.
Errorf
(
"expect enoent %v"
,
err
)
me
.
tester
.
Errorf
(
"expect enoent %v"
,
err
)
}
}
...
...
examplelib/zipfs.go
View file @
7c3c1e41
...
...
@@ -119,8 +119,8 @@ func NewZipFileFuse(name string) *ZipFileFuse {
const
zip_DIRMODE
uint32
=
fuse
.
S_IFDIR
|
0700
const
zip_FILEMODE
uint32
=
fuse
.
S_IFREG
|
0600
func
(
self
*
ZipFileFuse
)
GetAttr
(
name
string
)
(
*
fuse
.
Attr
,
fuse
.
Status
)
{
dir
,
file
:=
self
.
tree
.
Lookup
(
name
)
func
(
me
*
ZipFileFuse
)
GetAttr
(
name
string
)
(
*
fuse
.
Attr
,
fuse
.
Status
)
{
dir
,
file
:=
me
.
tree
.
Lookup
(
name
)
if
dir
==
nil
{
return
nil
,
fuse
.
ENOENT
}
...
...
@@ -136,16 +136,16 @@ func (self *ZipFileFuse) GetAttr(name string) (*fuse.Attr, fuse.Status) {
return
a
,
fuse
.
OK
}
func
(
self
*
ZipFileFuse
)
Open
(
name
string
,
flags
uint32
)
(
file
fuse
.
RawFuseFile
,
code
fuse
.
Status
)
{
_
,
zfile
:=
self
.
tree
.
Lookup
(
name
)
func
(
me
*
ZipFileFuse
)
Open
(
name
string
,
flags
uint32
)
(
file
fuse
.
RawFuseFile
,
code
fuse
.
Status
)
{
_
,
zfile
:=
me
.
tree
.
Lookup
(
name
)
if
zfile
==
nil
{
return
nil
,
fuse
.
ENOENT
}
return
NewZipFile
(
zfile
),
fuse
.
OK
}
func
(
self
*
ZipFileFuse
)
OpenDir
(
name
string
)
(
stream
chan
fuse
.
DirEntry
,
code
fuse
.
Status
)
{
zdir
,
file
:=
self
.
tree
.
Lookup
(
name
)
func
(
me
*
ZipFileFuse
)
OpenDir
(
name
string
)
(
stream
chan
fuse
.
DirEntry
,
code
fuse
.
Status
)
{
zdir
,
file
:=
me
.
tree
.
Lookup
(
name
)
if
file
!=
nil
{
return
nil
,
fuse
.
ENOSYS
}
...
...
fuse/bufferpool.go
View file @
7c3c1e41
...
...
@@ -41,37 +41,37 @@ func NewBufferPool() *BufferPool {
return
bp
}
func
(
self
*
BufferPool
)
String
()
string
{
func
(
me
*
BufferPool
)
String
()
string
{
s
:=
""
for
exp
,
bufs
:=
range
self
.
buffersByExponent
{
for
exp
,
bufs
:=
range
me
.
buffersByExponent
{
s
=
s
+
fmt
.
Sprintf
(
"%d = %d
\n
"
,
exp
,
len
(
bufs
))
}
return
s
}
func
(
self
*
BufferPool
)
getBuffer
(
exponent
uint
)
[]
byte
{
if
len
(
self
.
buffersByExponent
)
<=
int
(
exponent
)
{
func
(
me
*
BufferPool
)
getBuffer
(
exponent
uint
)
[]
byte
{
if
len
(
me
.
buffersByExponent
)
<=
int
(
exponent
)
{
return
nil
}
bufferList
:=
self
.
buffersByExponent
[
exponent
]
bufferList
:=
me
.
buffersByExponent
[
exponent
]
if
len
(
bufferList
)
==
0
{
return
nil
}
result
:=
bufferList
[
len
(
bufferList
)
-
1
]
self
.
buffersByExponent
[
exponent
]
=
self
.
buffersByExponent
[
exponent
][
:
len
(
bufferList
)
-
1
]
me
.
buffersByExponent
[
exponent
]
=
me
.
buffersByExponent
[
exponent
][
:
len
(
bufferList
)
-
1
]
return
result
}
func
(
self
*
BufferPool
)
addBuffer
(
slice
[]
byte
,
exp
uint
)
{
for
len
(
self
.
buffersByExponent
)
<=
int
(
exp
)
{
self
.
buffersByExponent
=
append
(
self
.
buffersByExponent
,
make
([][]
byte
,
0
))
func
(
me
*
BufferPool
)
addBuffer
(
slice
[]
byte
,
exp
uint
)
{
for
len
(
me
.
buffersByExponent
)
<=
int
(
exp
)
{
me
.
buffersByExponent
=
append
(
me
.
buffersByExponent
,
make
([][]
byte
,
0
))
}
self
.
buffersByExponent
[
exp
]
=
append
(
self
.
buffersByExponent
[
exp
],
slice
)
me
.
buffersByExponent
[
exp
]
=
append
(
me
.
buffersByExponent
[
exp
],
slice
)
}
func
(
self
*
BufferPool
)
AllocBuffer
(
size
uint32
)
[]
byte
{
func
(
me
*
BufferPool
)
AllocBuffer
(
size
uint32
)
[]
byte
{
sz
:=
int
(
size
)
if
sz
<
PAGESIZE
{
sz
=
PAGESIZE
...
...
@@ -82,10 +82,10 @@ func (self *BufferPool) AllocBuffer(size uint32) []byte {
exp
-=
IntToExponent
(
PAGESIZE
)
self
.
lock
.
Lock
()
defer
self
.
lock
.
Unlock
()
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
b
:=
self
.
getBuffer
(
exp
)
b
:=
me
.
getBuffer
(
exp
)
if
b
!=
nil
{
b
=
b
[
:
size
]
...
...
@@ -93,24 +93,24 @@ func (self *BufferPool) AllocBuffer(size uint32) []byte {
}
b
=
make
([]
byte
,
size
,
rounded
)
self
.
outstandingBuffers
[
uintptr
(
unsafe
.
Pointer
(
&
b
[
0
]))]
=
exp
me
.
outstandingBuffers
[
uintptr
(
unsafe
.
Pointer
(
&
b
[
0
]))]
=
exp
return
b
}
// Takes back a buffer if it was allocated through AllocBuffer. It is
// not an error to call FreeBuffer() on a slice obtained elsewhere.
func
(
self
*
BufferPool
)
FreeBuffer
(
slice
[]
byte
)
{
self
.
lock
.
Lock
()
defer
self
.
lock
.
Unlock
()
func
(
me
*
BufferPool
)
FreeBuffer
(
slice
[]
byte
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
if
cap
(
slice
)
<
PAGESIZE
{
return
}
key
:=
uintptr
(
unsafe
.
Pointer
(
&
slice
[
0
]))
exp
,
ok
:=
self
.
outstandingBuffers
[
key
]
exp
,
ok
:=
me
.
outstandingBuffers
[
key
]
if
ok
{
self
.
addBuffer
(
slice
,
exp
)
self
.
outstandingBuffers
[
key
]
=
0
,
false
me
.
addBuffer
(
slice
,
exp
)
me
.
outstandingBuffers
[
key
]
=
0
,
false
}
}
fuse/datafile.go
View file @
7c3c1e41
...
...
@@ -14,11 +14,11 @@ func NewReadOnlyFile(data []byte) *ReadOnlyFile {
return
f
}
func
(
self
*
ReadOnlyFile
)
Read
(
input
*
ReadIn
,
bp
*
BufferPool
)
([]
byte
,
Status
)
{
func
(
me
*
ReadOnlyFile
)
Read
(
input
*
ReadIn
,
bp
*
BufferPool
)
([]
byte
,
Status
)
{
end
:=
int
(
input
.
Offset
)
+
int
(
input
.
Size
)
if
end
>
len
(
self
.
data
)
{
end
=
len
(
self
.
data
)
if
end
>
len
(
me
.
data
)
{
end
=
len
(
me
.
data
)
}
return
self
.
data
[
input
.
Offset
:
end
],
OK
return
me
.
data
[
input
.
Offset
:
end
],
OK
}
fuse/default.go
View file @
7c3c1e41
This diff is collapsed.
Click to expand it.
fuse/direntry.go
View file @
7c3c1e41
...
...
@@ -25,41 +25,41 @@ func NewDirEntryList(max int) *DirEntryList {
return
&
DirEntryList
{
maxSize
:
max
}
}
func
(
d
e
*
DirEntryList
)
AddString
(
name
string
,
inode
uint64
,
mode
uint32
)
bool
{
return
d
e
.
Add
([]
byte
(
name
),
inode
,
mode
)
func
(
m
e
*
DirEntryList
)
AddString
(
name
string
,
inode
uint64
,
mode
uint32
)
bool
{
return
m
e
.
Add
([]
byte
(
name
),
inode
,
mode
)
}
func
(
d
e
*
DirEntryList
)
Add
(
name
[]
byte
,
inode
uint64
,
mode
uint32
)
bool
{
lastLen
:=
d
e
.
buf
.
Len
()
d
e
.
offset
++
func
(
m
e
*
DirEntryList
)
Add
(
name
[]
byte
,
inode
uint64
,
mode
uint32
)
bool
{
lastLen
:=
m
e
.
buf
.
Len
()
m
e
.
offset
++
dirent
:=
new
(
Dirent
)
dirent
.
Off
=
d
e
.
offset
dirent
.
Off
=
m
e
.
offset
dirent
.
Ino
=
inode
dirent
.
NameLen
=
uint32
(
len
(
name
))
dirent
.
Typ
=
ModeToType
(
mode
)
err
:=
binary
.
Write
(
&
d
e
.
buf
,
binary
.
LittleEndian
,
dirent
)
err
:=
binary
.
Write
(
&
m
e
.
buf
,
binary
.
LittleEndian
,
dirent
)
if
err
!=
nil
{
panic
(
"Serialization of Dirent failed"
)
}
d
e
.
buf
.
Write
(
name
)
m
e
.
buf
.
Write
(
name
)
padding
:=
8
-
len
(
name
)
&
7
if
padding
<
8
{
d
e
.
buf
.
Write
(
make
([]
byte
,
padding
))
m
e
.
buf
.
Write
(
make
([]
byte
,
padding
))
}
if
de
.
buf
.
Len
()
>
d
e
.
maxSize
{
d
e
.
buf
.
Truncate
(
lastLen
)
d
e
.
offset
--
if
me
.
buf
.
Len
()
>
m
e
.
maxSize
{
m
e
.
buf
.
Truncate
(
lastLen
)
m
e
.
offset
--
return
false
}
return
true
}
func
(
d
e
*
DirEntryList
)
Bytes
()
[]
byte
{
return
d
e
.
buf
.
Bytes
()
func
(
m
e
*
DirEntryList
)
Bytes
()
[]
byte
{
return
m
e
.
buf
.
Bytes
()
}
////////////////////////////////////////////////////////////////
...
...
fuse/fuse.go
View file @
7c3c1e41
...
...
@@ -60,47 +60,47 @@ type MountState struct {
operationCounts
*
expvar
.
Map
}
func
(
self
*
MountState
)
RegisterFile
(
file
RawFuseFile
)
uint64
{
self
.
openedFilesMutex
.
Lock
()
defer
self
.
openedFilesMutex
.
Unlock
()
func
(
me
*
MountState
)
RegisterFile
(
file
RawFuseFile
)
uint64
{
me
.
openedFilesMutex
.
Lock
()
defer
me
.
openedFilesMutex
.
Unlock
()
// We will be screwed if nextFree ever wraps.
self
.
nextFreeFile
++
index
:=
self
.
nextFreeFile
self
.
openedFiles
[
index
]
=
file
me
.
nextFreeFile
++
index
:=
me
.
nextFreeFile
me
.
openedFiles
[
index
]
=
file
return
index
}
func
(
self
*
MountState
)
FindFile
(
index
uint64
)
RawFuseFile
{
self
.
openedFilesMutex
.
RLock
()
defer
self
.
openedFilesMutex
.
RUnlock
()
return
self
.
openedFiles
[
index
]
func
(
me
*
MountState
)
FindFile
(
index
uint64
)
RawFuseFile
{
me
.
openedFilesMutex
.
RLock
()
defer
me
.
openedFilesMutex
.
RUnlock
()
return
me
.
openedFiles
[
index
]
}
func
(
self
*
MountState
)
UnregisterFile
(
handle
uint64
)
{
self
.
openedFilesMutex
.
Lock
()
defer
self
.
openedFilesMutex
.
Unlock
()
self
.
openedFiles
[
handle
]
=
nil
,
false
func
(
me
*
MountState
)
UnregisterFile
(
handle
uint64
)
{
me
.
openedFilesMutex
.
Lock
()
defer
me
.
openedFilesMutex
.
Unlock
()
me
.
openedFiles
[
handle
]
=
nil
,
false
}
func
(
self
*
MountState
)
RegisterDir
(
dir
RawFuseDir
)
uint64
{
self
.
openedDirsMutex
.
Lock
()
defer
self
.
openedDirsMutex
.
Unlock
()
self
.
nextFreeDir
++
index
:=
self
.
nextFreeDir
self
.
openedDirs
[
index
]
=
dir
func
(
me
*
MountState
)
RegisterDir
(
dir
RawFuseDir
)
uint64
{
me
.
openedDirsMutex
.
Lock
()
defer
me
.
openedDirsMutex
.
Unlock
()
me
.
nextFreeDir
++
index
:=
me
.
nextFreeDir
me
.
openedDirs
[
index
]
=
dir
return
index
}
func
(
self
*
MountState
)
FindDir
(
index
uint64
)
RawFuseDir
{
self
.
openedDirsMutex
.
RLock
()
defer
self
.
openedDirsMutex
.
RUnlock
()
return
self
.
openedDirs
[
index
]
func
(
me
*
MountState
)
FindDir
(
index
uint64
)
RawFuseDir
{
me
.
openedDirsMutex
.
RLock
()
defer
me
.
openedDirsMutex
.
RUnlock
()
return
me
.
openedDirs
[
index
]
}
func
(
self
*
MountState
)
UnregisterDir
(
handle
uint64
)
{
self
.
openedDirsMutex
.
Lock
()
defer
self
.
openedDirsMutex
.
Unlock
()
self
.
openedDirs
[
handle
]
=
nil
,
false
func
(
me
*
MountState
)
UnregisterDir
(
handle
uint64
)
{
me
.
openedDirsMutex
.
Lock
()
defer
me
.
openedDirsMutex
.
Unlock
()
me
.
openedDirs
[
handle
]
=
nil
,
false
}
// Mount filesystem on mountPoint.
...
...
@@ -110,48 +110,48 @@ func (self *MountState) UnregisterDir(handle uint64) {
// using channels.
//
// TODO - error handling should perhaps be user-serviceable.
func
(
self
*
MountState
)
Mount
(
mountPoint
string
)
os
.
Error
{
func
(
me
*
MountState
)
Mount
(
mountPoint
string
)
os
.
Error
{
file
,
mp
,
err
:=
mount
(
mountPoint
)
if
err
!=
nil
{
return
err
}
self
.
mountPoint
=
mp
self
.
mountFile
=
file
me
.
mountPoint
=
mp
me
.
mountFile
=
file
self
.
operationCounts
=
expvar
.
NewMap
(
fmt
.
Sprintf
(
"mount(%v)"
,
mountPoint
))
me
.
operationCounts
=
expvar
.
NewMap
(
fmt
.
Sprintf
(
"mount(%v)"
,
mountPoint
))
return
nil
}
// Normally, callers should run loop() and wait for FUSE to exit, but
// tests will want to run this in a goroutine.
func
(
self
*
MountState
)
Loop
(
threaded
bool
)
{
self
.
threaded
=
threaded
if
self
.
threaded
{
self
.
outputChannel
=
make
(
chan
[][]
byte
,
100
)
self
.
errorChannel
=
make
(
chan
os
.
Error
,
100
)
go
self
.
asyncWriterThread
()
go
self
.
DefaultErrorHandler
()
func
(
me
*
MountState
)
Loop
(
threaded
bool
)
{
me
.
threaded
=
threaded
if
me
.
threaded
{
me
.
outputChannel
=
make
(
chan
[][]
byte
,
100
)
me
.
errorChannel
=
make
(
chan
os
.
Error
,
100
)
go
me
.
asyncWriterThread
()
go
me
.
DefaultErrorHandler
()
}
self
.
loop
()
me
.
loop
()
if
self
.
threaded
{
close
(
self
.
outputChannel
)
close
(
self
.
errorChannel
)
if
me
.
threaded
{
close
(
me
.
outputChannel
)
close
(
me
.
errorChannel
)
}
}
func
(
self
*
MountState
)
Unmount
()
os
.
Error
{
func
(
me
*
MountState
)
Unmount
()
os
.
Error
{
// Todo: flush/release all files/dirs?
result
:=
unmount
(
self
.
mountPoint
)
result
:=
unmount
(
me
.
mountPoint
)
if
result
==
nil
{
self
.
mountPoint
=
""
me
.
mountPoint
=
""
}
return
result
}
func
(
self
*
MountState
)
DefaultErrorHandler
()
{
for
err
:=
range
self
.
errorChannel
{
func
(
me
*
MountState
)
DefaultErrorHandler
()
{
for
err
:=
range
me
.
errorChannel
{
if
err
==
os
.
EOF
||
err
==
nil
{
break
}
...
...
@@ -159,45 +159,45 @@ func (self *MountState) DefaultErrorHandler() {
}
}
func
(
self
*
MountState
)
Error
(
err
os
.
Error
)
{
func
(
me
*
MountState
)
Error
(
err
os
.
Error
)
{
// It is safe to do errors unthreaded, since the logger is thread-safe.
if
!
self
.
threaded
||
self
.
Debug
{
if
!
me
.
threaded
||
me
.
Debug
{
log
.
Println
(
"error: "
,
err
)
}
else
{
self
.
errorChannel
<-
err
me
.
errorChannel
<-
err
}
}
func
(
self
*
MountState
)
Write
(
packet
[][]
byte
)
{
func
(
me
*
MountState
)
Write
(
packet
[][]
byte
)
{
if
packet
==
nil
{
return
}
if
self
.
threaded
{
self
.
outputChannel
<-
packet
if
me
.
threaded
{
me
.
outputChannel
<-
packet
}
else
{
self
.
syncWrite
(
packet
)
me
.
syncWrite
(
packet
)
}
}
func
NewMountState
(
fs
RawFileSystem
)
*
MountState
{
self
:=
new
(
MountState
)
self
.
openedDirs
=
make
(
map
[
uint64
]
RawFuseDir
)
self
.
openedFiles
=
make
(
map
[
uint64
]
RawFuseFile
)
self
.
mountPoint
=
""
self
.
fileSystem
=
fs
self
.
buffers
=
NewBufferPool
()
return
self
me
:=
new
(
MountState
)
me
.
openedDirs
=
make
(
map
[
uint64
]
RawFuseDir
)
me
.
openedFiles
=
make
(
map
[
uint64
]
RawFuseFile
)
me
.
mountPoint
=
""
me
.
fileSystem
=
fs
me
.
buffers
=
NewBufferPool
()
return
me
}
// TODO - have more statistics.
func
(
self
*
MountState
)
Stats
()
string
{
func
(
me
*
MountState
)
Stats
()
string
{
var
lines
[]
string
// TODO - bufferpool should use expvar.
lines
=
append
(
lines
,
fmt
.
Sprintf
(
"buffers: %v"
,
self
.
buffers
.
String
()))
fmt
.
Sprintf
(
"buffers: %v"
,
me
.
buffers
.
String
()))
for
v
:=
range
expvar
.
Iter
()
{
if
strings
.
HasPrefix
(
v
.
Key
,
"mount"
)
{
...
...
@@ -210,19 +210,19 @@ func (self *MountState) Stats() string {
////////////////
// Private routines.
func
(
self
*
MountState
)
asyncWriterThread
()
{
for
packet
:=
range
self
.
outputChannel
{
self
.
syncWrite
(
packet
)
func
(
me
*
MountState
)
asyncWriterThread
()
{
for
packet
:=
range
me
.
outputChannel
{
me
.
syncWrite
(
packet
)
}
}
func
(
self
*
MountState
)
syncWrite
(
packet
[][]
byte
)
{
_
,
err
:=
Writev
(
self
.
mountFile
.
Fd
(),
packet
)
func
(
me
*
MountState
)
syncWrite
(
packet
[][]
byte
)
{
_
,
err
:=
Writev
(
me
.
mountFile
.
Fd
(),
packet
)
if
err
!=
nil
{
self
.
Error
(
os
.
NewError
(
fmt
.
Sprintf
(
"writer: Writev %v failed, err: %v"
,
packet
,
err
)))
me
.
Error
(
os
.
NewError
(
fmt
.
Sprintf
(
"writer: Writev %v failed, err: %v"
,
packet
,
err
)))
}
for
_
,
v
:=
range
packet
{
self
.
buffers
.
FreeBuffer
(
v
)
me
.
buffers
.
FreeBuffer
(
v
)
}
}
...
...
@@ -230,11 +230,11 @@ func (self *MountState) syncWrite(packet [][]byte) {
////////////////////////////////////////////////////////////////
// Logic for the control loop.
func
(
self
*
MountState
)
loop
()
{
func
(
me
*
MountState
)
loop
()
{
// See fuse_kern_chan_receive()
for
{
buf
:=
self
.
buffers
.
AllocBuffer
(
bufSize
)
n
,
err
:=
self
.
mountFile
.
Read
(
buf
)
buf
:=
me
.
buffers
.
AllocBuffer
(
bufSize
)
n
,
err
:=
me
.
mountFile
.
Read
(
buf
)
if
err
!=
nil
{
errNo
:=
OsErrorToFuseError
(
err
)
...
...
@@ -254,21 +254,21 @@ func (self *MountState) loop() {
}
readErr
:=
os
.
NewError
(
fmt
.
Sprintf
(
"Failed to read from fuse conn: %v"
,
err
))
self
.
Error
(
readErr
)
me
.
Error
(
readErr
)
break
}
if
self
.
threaded
{
go
self
.
handle
(
buf
[
0
:
n
])
if
me
.
threaded
{
go
me
.
handle
(
buf
[
0
:
n
])
}
else
{
self
.
handle
(
buf
[
0
:
n
])
me
.
handle
(
buf
[
0
:
n
])
}
}
self
.
mountFile
.
Close
()
me
.
mountFile
.
Close
()
}
func
(
self
*
MountState
)
handle
(
in_data
[]
byte
)
{
func
(
me
*
MountState
)
handle
(
in_data
[]
byte
)
{
r
:=
bytes
.
NewBuffer
(
in_data
)
header
:=
new
(
InHeader
)
err
:=
binary
.
Read
(
r
,
binary
.
LittleEndian
,
header
)
...
...
@@ -276,11 +276,11 @@ func (self *MountState) handle(in_data []byte) {
err
=
os
.
NewError
(
fmt
.
Sprintf
(
"MountPoint, handle: can't read a header, in_data: %v"
,
in_data
))
}
if
err
!=
nil
{
self
.
Error
(
err
)
me
.
Error
(
err
)
return
}
self
.
Write
(
dispatch
(
self
,
header
,
r
))
self
.
buffers
.
FreeBuffer
(
in_data
)
me
.
Write
(
dispatch
(
me
,
header
,
r
))
me
.
buffers
.
FreeBuffer
(
in_data
)
}
...
...
fuse/pathfilesystem.go
View file @
7c3c1e41
This diff is collapsed.
Click to expand it.
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