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
94244f10
Commit
94244f10
authored
Dec 30, 2010
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Run Gofmt.
parent
736b11e3
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
57 additions
and
61 deletions
+57
-61
example/main.go
example/main.go
+2
-3
examplelib/dummyfuse.go
examplelib/dummyfuse.go
+3
-2
examplelib/passthrough.go
examplelib/passthrough.go
+6
-7
examplelib/passthrough_test.go
examplelib/passthrough_test.go
+12
-14
fuse/fuse.go
fuse/fuse.go
+3
-4
fuse/misc.go
fuse/misc.go
+1
-1
fuse/pathfilesystem.go
fuse/pathfilesystem.go
+25
-25
fuse/types.go
fuse/types.go
+5
-5
No files found.
example/main.go
View file @
94244f10
...
...
@@ -13,12 +13,12 @@ func main() {
debug
:=
flag
.
Bool
(
"debug"
,
false
,
"print debugging messages."
)
threaded
:=
flag
.
Bool
(
"threaded"
,
true
,
"switch off threading; print debugging messages."
)
flag
.
Parse
()
if
flag
.
NArg
()
<
2
{
if
flag
.
NArg
()
<
2
{
// TODO - where to get program name?
fmt
.
Println
(
"usage: main ORIGINAL MOUNTPOINT"
)
os
.
Exit
(
2
)
}
orig
:=
flag
.
Arg
(
0
)
pt
:=
examplelib
.
NewPassThroughFuse
(
orig
)
fs
:=
fuse
.
NewPathFileSystemConnector
(
pt
)
...
...
@@ -31,4 +31,3 @@ func main() {
fmt
.
Printf
(
"Mounted %s on %s (threaded=%v, debug=%v)
\n
"
,
orig
,
mountPoint
,
*
threaded
,
*
debug
)
state
.
Loop
(
*
threaded
)
}
examplelib/dummyfuse.go
View file @
94244f10
package
examplelib
import
(
"github.com/hanwen/go-fuse/fuse"
)
)
// Declare dummy methods, for cut & paste convenience.
type
DummyFuse
struct
{}
...
...
@@ -200,5 +201,5 @@ func (self *DummyPathFuse) Utimens(name string, AtimeNs uint64, CtimeNs uint64)
}
func
(
self
*
DummyPathFuse
)
SetOptions
(
*
fuse
.
PathFileSystemConnectorOptions
)
{
}
examplelib/passthrough.go
View file @
94244f10
...
...
@@ -173,10 +173,10 @@ func (self *PassThroughFile) Fsync(*fuse.FsyncIn) (code fuse.Status) {
type
PassThroughDir
struct
{
directoryChannel
chan
*
os
.
FileInfo
directoryError
os
.
Error
shipped
int
exported
int
leftOver
*
os
.
FileInfo
directoryError
os
.
Error
shipped
int
exported
int
leftOver
*
os
.
FileInfo
}
func
NewPassThroughDir
(
file
*
os
.
File
)
*
PassThroughDir
{
...
...
@@ -214,7 +214,7 @@ func (self *PassThroughDir) ReadDir(input *fuse.ReadIn) (*fuse.DirEntryList, fus
}
self
.
leftOver
=
nil
}
for
{
fi
:=
<-
self
.
directoryChannel
if
fi
==
nil
{
...
...
@@ -223,7 +223,7 @@ func (self *PassThroughDir) ReadDir(input *fuse.ReadIn) (*fuse.DirEntryList, fus
if
!
list
.
AddString
(
fi
.
Name
,
fuse
.
FUSE_UNKNOWN_INO
,
fi
.
Mode
)
{
self
.
leftOver
=
fi
break
}
}
}
return
list
,
fuse
.
OsErrorToFuseError
(
self
.
directoryError
)
}
...
...
@@ -235,4 +235,3 @@ func (self *PassThroughDir) ReleaseDir() {
func
(
self
*
PassThroughDir
)
FsyncDir
(
input
*
fuse
.
FsyncIn
)
(
code
fuse
.
Status
)
{
return
fuse
.
ENOSYS
}
examplelib/passthrough_test.go
View file @
94244f10
...
...
@@ -396,9 +396,9 @@ func (self *testCase) testReaddir() {
self
.
tester
.
Errorf
(
"readdir err %v"
,
err
)
}
wanted
:=
map
[
string
]
bool
{
wanted
:=
map
[
string
]
bool
{
"hello.txt"
:
true
,
"subdir"
:
true
,
"subdir"
:
true
,
}
if
len
(
wanted
)
!=
len
(
infos
)
{
self
.
tester
.
Errorf
(
"Length mismatch %v"
,
infos
)
...
...
@@ -437,7 +437,7 @@ func (self *testCase) testFSync() {
func
(
self
*
testCase
)
testLargeRead
()
{
name
:=
path
.
Join
(
self
.
origDir
,
"large"
)
f
,
err
:=
os
.
Open
(
name
,
os
.
O_WRONLY
|
os
.
O_CREATE
,
0777
)
f
,
err
:=
os
.
Open
(
name
,
os
.
O_WRONLY
|
os
.
O_CREATE
,
0777
)
if
err
!=
nil
{
self
.
tester
.
Errorf
(
"open write err %v"
,
err
)
}
...
...
@@ -469,10 +469,10 @@ func (self *testCase) testLargeRead() {
readSlice
:=
make
([]
byte
,
len
(
slice
))
m
,
err
:=
g
.
Read
(
readSlice
)
if
m
!=
n
{
self
.
tester
.
Errorf
(
"read mismatch %v %v"
,
m
,
n
)
self
.
tester
.
Errorf
(
"read mismatch %v %v"
,
m
,
n
)
}
for
i
,
v
:=
range
(
readSlice
)
{
if
(
slice
[
i
]
!=
v
)
{
for
i
,
v
:=
range
readSlice
{
if
slice
[
i
]
!=
v
{
self
.
tester
.
Errorf
(
"char mismatch %v %v %v"
,
i
,
slice
[
i
],
v
)
break
}
...
...
@@ -506,8 +506,7 @@ func (self *testCase) testLargeRead() {
}
g
.
Close
()
os
.
Remove
(
name
)
os
.
Remove
(
name
)
}
func
randomLengthString
(
length
int
)
string
{
...
...
@@ -541,7 +540,7 @@ func (self *testCase) testLargeDirRead() {
nameSet
[
base
]
=
true
f
,
err
:=
os
.
Open
(
name
,
os
.
O_WRONLY
|
os
.
O_CREATE
,
0777
)
f
,
err
:=
os
.
Open
(
name
,
os
.
O_WRONLY
|
os
.
O_CREATE
,
0777
)
if
err
!=
nil
{
self
.
tester
.
Errorf
(
"open write err %v"
,
err
)
break
...
...
@@ -552,13 +551,13 @@ func (self *testCase) testLargeDirRead() {
names
[
i
]
=
name
}
dir
,
err
:=
os
.
Open
(
path
.
Join
(
self
.
mountPoint
,
"readdirSubdir"
),
os
.
O_RDONLY
,
0
)
dir
,
err
:=
os
.
Open
(
path
.
Join
(
self
.
mountPoint
,
"readdirSubdir"
),
os
.
O_RDONLY
,
0
)
if
err
!=
nil
{
self
.
tester
.
Errorf
(
"dirread %v"
,
err
)
}
// Chunked read.
total
:=
0
readSet
:=
make
(
map
[
string
]
bool
)
readSet
:=
make
(
map
[
string
]
bool
)
for
{
namesRead
,
err
:=
dir
.
Readdirnames
(
200
)
if
err
!=
nil
{
...
...
@@ -568,7 +567,7 @@ func (self *testCase) testLargeDirRead() {
if
len
(
namesRead
)
==
0
{
break
}
for
_
,
v
:=
range
(
namesRead
)
{
for
_
,
v
:=
range
namesRead
{
readSet
[
v
]
=
true
}
total
+=
len
(
namesRead
)
...
...
@@ -577,7 +576,7 @@ func (self *testCase) testLargeDirRead() {
if
total
!=
created
{
self
.
tester
.
Errorf
(
"readdir mismatch got %v wanted %v"
,
total
,
created
)
}
for
k
,
_
:=
range
(
nameSet
)
{
for
k
,
_
:=
range
nameSet
{
_
,
ok
:=
readSet
[
k
]
if
!
ok
{
self
.
tester
.
Errorf
(
"Name %v not found in output"
,
k
)
...
...
@@ -590,7 +589,6 @@ func (self *testCase) testLargeDirRead() {
}
// Test driver.
func
TestMount
(
t
*
testing
.
T
)
{
ts
:=
new
(
testCase
)
...
...
fuse/fuse.go
View file @
94244f10
...
...
@@ -109,7 +109,7 @@ func (self *MountState) Mount(mountPoint string) os.Error {
self
.
mountFile
=
file
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
)
{
...
...
@@ -263,7 +263,6 @@ func dispatch(state *MountState, h *InHeader, arg *bytes.Buffer) (outBytes [][]b
status
=
OK
fs
:=
state
.
fileSystem
filename
:=
""
// Perhaps a map is faster?
if
h
.
Opcode
==
FUSE_UNLINK
||
h
.
Opcode
==
FUSE_RMDIR
||
...
...
@@ -380,7 +379,7 @@ func dispatch(state *MountState, h *InHeader, arg *bytes.Buffer) (outBytes [][]b
return
serialize
(
h
,
status
,
out
,
flatData
,
state
.
Debug
)
}
func
serialize
(
h
*
InHeader
,
res
Status
,
out
interface
{},
flatData
[]
byte
,
debug
bool
)
([][]
byte
)
{
func
serialize
(
h
*
InHeader
,
res
Status
,
out
interface
{},
flatData
[]
byte
,
debug
bool
)
[][]
byte
{
out_data
:=
make
([]
byte
,
0
)
b
:=
new
(
bytes
.
Buffer
)
if
out
!=
nil
&&
res
==
OK
{
...
...
@@ -395,7 +394,7 @@ func serialize(h *InHeader, res Status, out interface{}, flatData []byte, debug
var
hout
OutHeader
hout
.
Unique
=
h
.
Unique
hout
.
Status
=
-
res
hout
.
Length
=
uint32
(
len
(
out_data
)
+
SizeOfOutHeader
+
len
(
flatData
))
hout
.
Length
=
uint32
(
len
(
out_data
)
+
SizeOfOutHeader
+
len
(
flatData
))
b
=
new
(
bytes
.
Buffer
)
err
:=
binary
.
Write
(
b
,
binary
.
LittleEndian
,
&
hout
)
if
err
!=
nil
{
...
...
fuse/misc.go
View file @
94244f10
...
...
@@ -251,7 +251,7 @@ func Writev(fd int, packet [][]byte) (n int, err os.Error) {
}
iovecs
:=
make
([]
syscall
.
Iovec
,
len
(
packet
))
j
:=
0
j
:=
0
for
i
,
v
:=
range
packet
{
if
v
==
nil
||
len
(
v
)
==
0
{
continue
...
...
fuse/pathfilesystem.go
View file @
94244f10
...
...
@@ -10,13 +10,13 @@ import (
// TODO should rename to dentry?
type
inodeData
struct
{
Parent
*
inodeData
NodeId
uint64
Name
string
LookupCount
int
Parent
*
inodeData
NodeId
uint64
Name
string
LookupCount
int
// Number of inodeData that have this as parent.
RefCount
int
RefCount
int
}
// Should implement some hash table method instead?
...
...
@@ -48,8 +48,8 @@ func (self *inodeData) GetPath() string {
}
type
PathFileSystemConnectorOptions
struct
{
EntryTimeout
float64
AttrTimeout
float64
EntryTimeout
float64
AttrTimeout
float64
NegativeTimeout
float64
}
...
...
@@ -57,8 +57,8 @@ type PathFileSystemConnector struct {
fileSystem
PathFilesystem
// Protects the hashmap, its contents and the nextFreeInode counter.
lock
sync
.
RWMutex
lock
sync
.
RWMutex
// Invariants
// - For all values, (RefCount > 0 || LookupCount > 0).
// - For all values, value = inodePathMap[value.Key()]
...
...
@@ -71,7 +71,7 @@ type PathFileSystemConnector struct {
// > 0.
inodePathMap
map
[
string
]
*
inodeData
inodePathMapByInode
map
[
uint64
]
*
inodeData
nextFreeInode
uint64
nextFreeInode
uint64
options
PathFileSystemConnectorOptions
}
...
...
@@ -82,11 +82,11 @@ func (self *PathFileSystemConnector) setParent(data *inodeData, parentId uint64)
if
data
.
Parent
==
newParent
{
return
}
if
newParent
==
nil
{
panic
(
"Unknown parent"
)
}
oldParent
:=
data
.
Parent
if
oldParent
!=
nil
{
self
.
unrefNode
(
oldParent
)
...
...
@@ -100,7 +100,7 @@ func (self *PathFileSystemConnector) setParent(data *inodeData, parentId uint64)
// Must be called with lock held.
func
(
self
*
PathFileSystemConnector
)
unrefNode
(
data
*
inodeData
)
{
data
.
RefCount
--
if
data
.
RefCount
<=
0
&&
data
.
LookupCount
<=
0
{
if
data
.
RefCount
<=
0
&&
data
.
LookupCount
<=
0
{
self
.
inodePathMapByInode
[
data
.
NodeId
]
=
nil
,
false
}
}
...
...
@@ -146,8 +146,8 @@ func (self *PathFileSystemConnector) forgetUpdate(nodeId uint64, forgetCount int
}
}
func
(
self
*
PathFileSystemConnector
)
renameUpdate
(
oldParent
uint64
,
oldName
string
,
newParent
uint64
,
newName
string
)
{
self
.
lock
.
Lock
()
func
(
self
*
PathFileSystemConnector
)
renameUpdate
(
oldParent
uint64
,
oldName
string
,
newParent
uint64
,
newName
string
)
{
self
.
lock
.
Lock
()
defer
self
.
lock
.
Unlock
()
oldKey
:=
inodeDataKey
(
oldParent
,
oldName
)
...
...
@@ -163,7 +163,7 @@ func (self *PathFileSystemConnector) renameUpdate(oldParent uint64, oldName stri
}
self
.
inodePathMap
[
oldKey
]
=
nil
,
false
self
.
setParent
(
data
,
newParent
)
data
.
Name
=
newName
newKey
:=
data
.
Key
()
...
...
@@ -182,7 +182,7 @@ func (self *PathFileSystemConnector) renameUpdate(oldParent uint64, oldName stri
self
.
setParent
(
target
,
FUSE_ROOT_ID
)
target
.
Name
=
fmt
.
Sprintf
(
"overwrittenByRename%d"
,
self
.
nextFreeInode
)
self
.
nextFreeInode
++
;
self
.
nextFreeInode
++
self
.
inodePathMap
[
target
.
Key
()]
=
target
}
...
...
@@ -225,7 +225,7 @@ func NewPathFileSystemConnector(fs PathFilesystem) (out *PathFileSystemConnector
out
.
options
.
EntryTimeout
=
1.0
fs
.
SetOptions
(
&
out
.
options
)
return
out
}
...
...
@@ -249,7 +249,7 @@ func (self *PathFileSystemConnector) Lookup(header *InHeader, name string) (out
// Hmm. - fuse.c has special case code for name == "." and "..".
// Should we have it too?
fullPath
:=
path
.
Join
(
parent
.
GetPath
(),
name
)
attr
,
err
:=
self
.
fileSystem
.
GetAttr
(
fullPath
)
if
err
==
ENOENT
&&
self
.
options
.
NegativeTimeout
>
0.0
{
...
...
@@ -315,7 +315,7 @@ func (self *PathFileSystemConnector) Open(header *InHeader, input *OpenIn) (flag
func
(
self
*
PathFileSystemConnector
)
SetAttr
(
header
*
InHeader
,
input
*
SetAttrIn
)
(
out
*
AttrOut
,
code
Status
)
{
var
err
Status
=
OK
// TODO - support Fh. (FSetAttr/FGetAttr/FTruncate.)
fullPath
:=
self
.
GetPath
(
header
.
NodeId
)
if
input
.
Valid
&
FATTR_MODE
!=
0
{
...
...
@@ -374,12 +374,12 @@ func (self *PathFileSystemConnector) Unlink(header *InHeader, name string) (code
// Like fuse.c, we update our internal tables.
self
.
unlinkUpdate
(
header
.
NodeId
,
name
)
return
code
}
func
(
self
*
PathFileSystemConnector
)
Rmdir
(
header
*
InHeader
,
name
string
)
(
code
Status
)
{
code
=
self
.
fileSystem
.
Rmdir
(
path
.
Join
(
self
.
GetPath
(
header
.
NodeId
),
name
))
code
=
self
.
fileSystem
.
Rmdir
(
path
.
Join
(
self
.
GetPath
(
header
.
NodeId
),
name
))
self
.
unlinkUpdate
(
header
.
NodeId
,
name
)
return
code
}
...
...
@@ -397,12 +397,12 @@ func (self *PathFileSystemConnector) Symlink(header *InHeader, pointedTo string,
func
(
self
*
PathFileSystemConnector
)
Rename
(
header
*
InHeader
,
input
*
RenameIn
,
oldName
string
,
newName
string
)
(
code
Status
)
{
oldPath
:=
path
.
Join
(
self
.
GetPath
(
header
.
NodeId
),
oldName
)
newPath
:=
path
.
Join
(
self
.
GetPath
(
input
.
Newdir
),
newName
)
code
=
self
.
fileSystem
.
Rename
(
oldPath
,
newPath
)
if
code
!=
OK
{
return
}
// It is conceivable that the kernel module will issue a
// forget for the old entry, and a lookup request for the new
// one, but the fuse.c updates its client-side tables on its
...
...
fuse/types.go
View file @
94244f10
...
...
@@ -38,8 +38,8 @@ const (
FUSE_BIG_WRITES
=
(
1
<<
5
)
FUSE_DONT_MASK
=
(
1
<<
6
)
FUSE_UNKNOWN_INO
=
0xffffffff
FUSE_UNKNOWN_INO
=
0xffffffff
CUSE_UNRESTRICTED_IOCTL
=
(
1
<<
0
)
FUSE_RELEASE_FLUSH
=
(
1
<<
0
)
...
...
@@ -89,7 +89,7 @@ const (
ENOENT
=
Status
(
syscall
.
ENOENT
)
ENOTDIR
=
Status
(
syscall
.
ENOTDIR
)
EACCES
=
Status
(
syscall
.
EACCES
)
EPERM
=
Status
(
syscall
.
EPERM
)
EPERM
=
Status
(
syscall
.
EPERM
)
)
type
Opcode
int
...
...
@@ -545,8 +545,8 @@ type RawFuseDir interface {
// Should make interface ?
type
DirEntryList
struct
{
buf
bytes
.
Buffer
offset
uint64
buf
bytes
.
Buffer
offset
uint64
maxSize
int
}
...
...
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