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
c0b9bca3
Commit
c0b9bca3
authored
Mar 09, 2011
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename PassThroughFuse to LoopbackFileSystem.
parent
249e144f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
70 deletions
+36
-70
example/main.go
example/main.go
+1
-1
examplelib/Makefile
examplelib/Makefile
+1
-1
examplelib/loopback.go
examplelib/loopback.go
+29
-63
examplelib/loopback_test.go
examplelib/loopback_test.go
+2
-2
examplelib/stackfs_test.go
examplelib/stackfs_test.go
+3
-3
No files found.
example/main.go
View file @
c0b9bca3
...
@@ -23,7 +23,7 @@ func main() {
...
@@ -23,7 +23,7 @@ func main() {
}
}
orig
:=
flag
.
Arg
(
0
)
orig
:=
flag
.
Arg
(
0
)
fs
:=
examplelib
.
New
PassThroughFuse
(
orig
)
fs
:=
examplelib
.
New
LoopbackFileSystem
(
orig
)
conn
:=
fuse
.
NewPathFileSystemConnector
(
fs
)
conn
:=
fuse
.
NewPathFileSystemConnector
(
fs
)
state
:=
fuse
.
NewMountState
(
conn
)
state
:=
fuse
.
NewMountState
(
conn
)
state
.
Debug
=
*
debug
state
.
Debug
=
*
debug
...
...
examplelib/Makefile
View file @
c0b9bca3
...
@@ -5,7 +5,7 @@ TARG=github.com/hanwen/go-fuse/examplelib
...
@@ -5,7 +5,7 @@ TARG=github.com/hanwen/go-fuse/examplelib
DEPS
=
../fuse
DEPS
=
../fuse
GOFILES
=
passthrough
.go
\
GOFILES
=
loopback
.go
\
stackfs.go
\
stackfs.go
\
zipfs.go
\
zipfs.go
\
multizip.go
\
multizip.go
\
...
...
examplelib/
passthrough
.go
→
examplelib/
loopback
.go
View file @
c0b9bca3
...
@@ -14,24 +14,24 @@ import (
...
@@ -14,24 +14,24 @@ import (
var
_
=
fmt
.
Println
var
_
=
fmt
.
Println
type
PassThroughFuse
struct
{
type
LoopbackFileSystem
struct
{
root
string
root
string
fuse
.
DefaultPathFilesystem
fuse
.
DefaultPathFilesystem
}
}
func
New
PassThroughFuse
(
root
string
)
(
out
*
PassThroughFuse
)
{
func
New
LoopbackFileSystem
(
root
string
)
(
out
*
LoopbackFileSystem
)
{
out
=
new
(
PassThroughFuse
)
out
=
new
(
LoopbackFileSystem
)
out
.
root
=
root
out
.
root
=
root
return
out
return
out
}
}
func
(
me
*
PassThroughFuse
)
GetPath
(
relPath
string
)
string
{
func
(
me
*
LoopbackFileSystem
)
GetPath
(
relPath
string
)
string
{
return
path
.
Join
(
me
.
root
,
relPath
)
return
path
.
Join
(
me
.
root
,
relPath
)
}
}
func
(
me
*
PassThroughFuse
)
GetAttr
(
name
string
)
(
*
fuse
.
Attr
,
fuse
.
Status
)
{
func
(
me
*
LoopbackFileSystem
)
GetAttr
(
name
string
)
(
*
fuse
.
Attr
,
fuse
.
Status
)
{
fullPath
:=
me
.
GetPath
(
name
)
fullPath
:=
me
.
GetPath
(
name
)
fi
,
err
:=
os
.
Lstat
(
fullPath
)
fi
,
err
:=
os
.
Lstat
(
fullPath
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -43,7 +43,7 @@ func (me *PassThroughFuse) GetAttr(name string) (*fuse.Attr, fuse.Status) {
...
@@ -43,7 +43,7 @@ func (me *PassThroughFuse) GetAttr(name string) (*fuse.Attr, fuse.Status) {
return
out
,
fuse
.
OK
return
out
,
fuse
.
OK
}
}
func
(
me
*
PassThroughFuse
)
OpenDir
(
name
string
)
(
stream
chan
fuse
.
DirEntry
,
status
fuse
.
Status
)
{
func
(
me
*
LoopbackFileSystem
)
OpenDir
(
name
string
)
(
stream
chan
fuse
.
DirEntry
,
status
fuse
.
Status
)
{
// What other ways beyond O_RDONLY are there to open
// What other ways beyond O_RDONLY are there to open
// directories?
// directories?
f
,
err
:=
os
.
Open
(
me
.
GetPath
(
name
),
os
.
O_RDONLY
,
0
)
f
,
err
:=
os
.
Open
(
me
.
GetPath
(
name
),
os
.
O_RDONLY
,
0
)
...
@@ -76,75 +76,75 @@ func (me *PassThroughFuse) OpenDir(name string) (stream chan fuse.DirEntry, stat
...
@@ -76,75 +76,75 @@ func (me *PassThroughFuse) OpenDir(name string) (stream chan fuse.DirEntry, stat
return
output
,
fuse
.
OK
return
output
,
fuse
.
OK
}
}
func
(
me
*
PassThroughFuse
)
Open
(
name
string
,
flags
uint32
)
(
fuseFile
fuse
.
RawFuseFile
,
status
fuse
.
Status
)
{
func
(
me
*
LoopbackFileSystem
)
Open
(
name
string
,
flags
uint32
)
(
fuseFile
fuse
.
RawFuseFile
,
status
fuse
.
Status
)
{
f
,
err
:=
os
.
Open
(
me
.
GetPath
(
name
),
int
(
flags
),
0
)
f
,
err
:=
os
.
Open
(
me
.
GetPath
(
name
),
int
(
flags
),
0
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fuse
.
OsErrorToFuseError
(
err
)
return
nil
,
fuse
.
OsErrorToFuseError
(
err
)
}
}
return
&
PassThrough
File
{
file
:
f
},
fuse
.
OK
return
&
Loopback
File
{
file
:
f
},
fuse
.
OK
}
}
func
(
me
*
PassThroughFuse
)
Chmod
(
path
string
,
mode
uint32
)
(
code
fuse
.
Status
)
{
func
(
me
*
LoopbackFileSystem
)
Chmod
(
path
string
,
mode
uint32
)
(
code
fuse
.
Status
)
{
err
:=
os
.
Chmod
(
me
.
GetPath
(
path
),
mode
)
err
:=
os
.
Chmod
(
me
.
GetPath
(
path
),
mode
)
return
fuse
.
OsErrorToFuseError
(
err
)
return
fuse
.
OsErrorToFuseError
(
err
)
}
}
func
(
me
*
PassThroughFuse
)
Chown
(
path
string
,
uid
uint32
,
gid
uint32
)
(
code
fuse
.
Status
)
{
func
(
me
*
LoopbackFileSystem
)
Chown
(
path
string
,
uid
uint32
,
gid
uint32
)
(
code
fuse
.
Status
)
{
return
fuse
.
OsErrorToFuseError
(
os
.
Chown
(
me
.
GetPath
(
path
),
int
(
uid
),
int
(
gid
)))
return
fuse
.
OsErrorToFuseError
(
os
.
Chown
(
me
.
GetPath
(
path
),
int
(
uid
),
int
(
gid
)))
}
}
func
(
me
*
PassThroughFuse
)
Truncate
(
path
string
,
offset
uint64
)
(
code
fuse
.
Status
)
{
func
(
me
*
LoopbackFileSystem
)
Truncate
(
path
string
,
offset
uint64
)
(
code
fuse
.
Status
)
{
return
fuse
.
OsErrorToFuseError
(
os
.
Truncate
(
me
.
GetPath
(
path
),
int64
(
offset
)))
return
fuse
.
OsErrorToFuseError
(
os
.
Truncate
(
me
.
GetPath
(
path
),
int64
(
offset
)))
}
}
func
(
me
*
PassThroughFuse
)
Utimens
(
path
string
,
AtimeNs
uint64
,
MtimeNs
uint64
)
(
code
fuse
.
Status
)
{
func
(
me
*
LoopbackFileSystem
)
Utimens
(
path
string
,
AtimeNs
uint64
,
MtimeNs
uint64
)
(
code
fuse
.
Status
)
{
return
fuse
.
OsErrorToFuseError
(
os
.
Chtimes
(
me
.
GetPath
(
path
),
int64
(
AtimeNs
),
int64
(
MtimeNs
)))
return
fuse
.
OsErrorToFuseError
(
os
.
Chtimes
(
me
.
GetPath
(
path
),
int64
(
AtimeNs
),
int64
(
MtimeNs
)))
}
}
func
(
me
*
PassThroughFuse
)
Readlink
(
name
string
)
(
out
string
,
code
fuse
.
Status
)
{
func
(
me
*
LoopbackFileSystem
)
Readlink
(
name
string
)
(
out
string
,
code
fuse
.
Status
)
{
f
,
err
:=
os
.
Readlink
(
me
.
GetPath
(
name
))
f
,
err
:=
os
.
Readlink
(
me
.
GetPath
(
name
))
return
f
,
fuse
.
OsErrorToFuseError
(
err
)
return
f
,
fuse
.
OsErrorToFuseError
(
err
)
}
}
func
(
me
*
PassThroughFuse
)
Mknod
(
name
string
,
mode
uint32
,
dev
uint32
)
(
code
fuse
.
Status
)
{
func
(
me
*
LoopbackFileSystem
)
Mknod
(
name
string
,
mode
uint32
,
dev
uint32
)
(
code
fuse
.
Status
)
{
return
fuse
.
Status
(
syscall
.
Mknod
(
me
.
GetPath
(
name
),
mode
,
int
(
dev
)))
return
fuse
.
Status
(
syscall
.
Mknod
(
me
.
GetPath
(
name
),
mode
,
int
(
dev
)))
}
}
func
(
me
*
PassThroughFuse
)
Mkdir
(
path
string
,
mode
uint32
)
(
code
fuse
.
Status
)
{
func
(
me
*
LoopbackFileSystem
)
Mkdir
(
path
string
,
mode
uint32
)
(
code
fuse
.
Status
)
{
return
fuse
.
OsErrorToFuseError
(
os
.
Mkdir
(
me
.
GetPath
(
path
),
mode
))
return
fuse
.
OsErrorToFuseError
(
os
.
Mkdir
(
me
.
GetPath
(
path
),
mode
))
}
}
func
(
me
*
PassThroughFuse
)
Unlink
(
name
string
)
(
code
fuse
.
Status
)
{
func
(
me
*
LoopbackFileSystem
)
Unlink
(
name
string
)
(
code
fuse
.
Status
)
{
return
fuse
.
OsErrorToFuseError
(
os
.
Remove
(
me
.
GetPath
(
name
)))
return
fuse
.
OsErrorToFuseError
(
os
.
Remove
(
me
.
GetPath
(
name
)))
}
}
func
(
me
*
PassThroughFuse
)
Rmdir
(
name
string
)
(
code
fuse
.
Status
)
{
func
(
me
*
LoopbackFileSystem
)
Rmdir
(
name
string
)
(
code
fuse
.
Status
)
{
return
fuse
.
OsErrorToFuseError
(
os
.
Remove
(
me
.
GetPath
(
name
)))
return
fuse
.
OsErrorToFuseError
(
os
.
Remove
(
me
.
GetPath
(
name
)))
}
}
func
(
me
*
PassThroughFuse
)
Symlink
(
pointedTo
string
,
linkName
string
)
(
code
fuse
.
Status
)
{
func
(
me
*
LoopbackFileSystem
)
Symlink
(
pointedTo
string
,
linkName
string
)
(
code
fuse
.
Status
)
{
return
fuse
.
OsErrorToFuseError
(
os
.
Symlink
(
pointedTo
,
me
.
GetPath
(
linkName
)))
return
fuse
.
OsErrorToFuseError
(
os
.
Symlink
(
pointedTo
,
me
.
GetPath
(
linkName
)))
}
}
func
(
me
*
PassThroughFuse
)
Rename
(
oldPath
string
,
newPath
string
)
(
code
fuse
.
Status
)
{
func
(
me
*
LoopbackFileSystem
)
Rename
(
oldPath
string
,
newPath
string
)
(
code
fuse
.
Status
)
{
err
:=
os
.
Rename
(
me
.
GetPath
(
oldPath
),
me
.
GetPath
(
newPath
))
err
:=
os
.
Rename
(
me
.
GetPath
(
oldPath
),
me
.
GetPath
(
newPath
))
return
fuse
.
OsErrorToFuseError
(
err
)
return
fuse
.
OsErrorToFuseError
(
err
)
}
}
func
(
me
*
PassThroughFuse
)
Link
(
orig
string
,
newName
string
)
(
code
fuse
.
Status
)
{
func
(
me
*
LoopbackFileSystem
)
Link
(
orig
string
,
newName
string
)
(
code
fuse
.
Status
)
{
return
fuse
.
OsErrorToFuseError
(
os
.
Link
(
me
.
GetPath
(
orig
),
me
.
GetPath
(
newName
)))
return
fuse
.
OsErrorToFuseError
(
os
.
Link
(
me
.
GetPath
(
orig
),
me
.
GetPath
(
newName
)))
}
}
func
(
me
*
PassThroughFuse
)
Access
(
name
string
,
mode
uint32
)
(
code
fuse
.
Status
)
{
func
(
me
*
LoopbackFileSystem
)
Access
(
name
string
,
mode
uint32
)
(
code
fuse
.
Status
)
{
return
fuse
.
Status
(
syscall
.
Access
(
me
.
GetPath
(
name
),
mode
))
return
fuse
.
Status
(
syscall
.
Access
(
me
.
GetPath
(
name
),
mode
))
}
}
func
(
me
*
PassThroughFuse
)
Create
(
path
string
,
flags
uint32
,
mode
uint32
)
(
fuseFile
fuse
.
RawFuseFile
,
code
fuse
.
Status
)
{
func
(
me
*
LoopbackFileSystem
)
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
)
f
,
err
:=
os
.
Open
(
me
.
GetPath
(
path
),
int
(
flags
)
|
os
.
O_CREAT
,
mode
)
return
&
PassThrough
File
{
file
:
f
},
fuse
.
OsErrorToFuseError
(
err
)
return
&
Loopback
File
{
file
:
f
},
fuse
.
OsErrorToFuseError
(
err
)
}
}
func
(
me
*
PassThroughFuse
)
SetOptions
(
options
*
fuse
.
PathFileSystemConnectorOptions
)
{
func
(
me
*
LoopbackFileSystem
)
SetOptions
(
options
*
fuse
.
PathFileSystemConnectorOptions
)
{
options
.
NegativeTimeout
=
100.0
options
.
NegativeTimeout
=
100.0
options
.
AttrTimeout
=
100.0
options
.
AttrTimeout
=
100.0
options
.
EntryTimeout
=
100.0
options
.
EntryTimeout
=
100.0
...
@@ -152,13 +152,13 @@ func (me *PassThroughFuse) SetOptions(options *fuse.PathFileSystemConnectorOptio
...
@@ -152,13 +152,13 @@ func (me *PassThroughFuse) SetOptions(options *fuse.PathFileSystemConnectorOptio
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
type
PassThrough
File
struct
{
type
Loopback
File
struct
{
file
*
os
.
File
file
*
os
.
File
fuse
.
DefaultRawFuseFile
fuse
.
DefaultRawFuseFile
}
}
func
(
me
*
PassThrough
File
)
Read
(
input
*
fuse
.
ReadIn
,
buffers
*
fuse
.
BufferPool
)
([]
byte
,
fuse
.
Status
)
{
func
(
me
*
Loopback
File
)
Read
(
input
*
fuse
.
ReadIn
,
buffers
*
fuse
.
BufferPool
)
([]
byte
,
fuse
.
Status
)
{
slice
:=
buffers
.
AllocBuffer
(
input
.
Size
)
slice
:=
buffers
.
AllocBuffer
(
input
.
Size
)
n
,
err
:=
me
.
file
.
ReadAt
(
slice
,
int64
(
input
.
Offset
))
n
,
err
:=
me
.
file
.
ReadAt
(
slice
,
int64
(
input
.
Offset
))
...
@@ -169,49 +169,15 @@ func (me *PassThroughFile) Read(input *fuse.ReadIn, buffers *fuse.BufferPool) ([
...
@@ -169,49 +169,15 @@ func (me *PassThroughFile) Read(input *fuse.ReadIn, buffers *fuse.BufferPool) ([
return
slice
[
:
n
],
fuse
.
OsErrorToFuseError
(
err
)
return
slice
[
:
n
],
fuse
.
OsErrorToFuseError
(
err
)
}
}
func
(
me
*
PassThrough
File
)
Write
(
input
*
fuse
.
WriteIn
,
data
[]
byte
)
(
uint32
,
fuse
.
Status
)
{
func
(
me
*
Loopback
File
)
Write
(
input
*
fuse
.
WriteIn
,
data
[]
byte
)
(
uint32
,
fuse
.
Status
)
{
n
,
err
:=
me
.
file
.
WriteAt
(
data
,
int64
(
input
.
Offset
))
n
,
err
:=
me
.
file
.
WriteAt
(
data
,
int64
(
input
.
Offset
))
return
uint32
(
n
),
fuse
.
OsErrorToFuseError
(
err
)
return
uint32
(
n
),
fuse
.
OsErrorToFuseError
(
err
)
}
}
func
(
me
*
PassThrough
File
)
Release
()
{
func
(
me
*
Loopback
File
)
Release
()
{
me
.
file
.
Close
()
me
.
file
.
Close
()
}
}
func
(
me
*
PassThrough
File
)
Fsync
(
*
fuse
.
FsyncIn
)
(
code
fuse
.
Status
)
{
func
(
me
*
Loopback
File
)
Fsync
(
*
fuse
.
FsyncIn
)
(
code
fuse
.
Status
)
{
return
fuse
.
Status
(
syscall
.
Fsync
(
me
.
file
.
Fd
()))
return
fuse
.
Status
(
syscall
.
Fsync
(
me
.
file
.
Fd
()))
}
}
////////////////////////////////////////////////////////////////
type
PassThroughDir
struct
{
directoryChannel
chan
*
os
.
FileInfo
directoryError
os
.
Error
shipped
int
exported
int
leftOver
*
os
.
FileInfo
}
func
NewPassThroughDir
(
file
*
os
.
File
)
*
PassThroughDir
{
me
:=
new
(
PassThroughDir
)
me
.
directoryChannel
=
make
(
chan
*
os
.
FileInfo
,
500
)
go
func
()
{
for
{
want
:=
500
infos
,
err
:=
file
.
Readdir
(
want
)
for
i
,
_
:=
range
infos
{
me
.
directoryChannel
<-
&
infos
[
i
]
}
if
len
(
infos
)
<
want
{
break
}
if
err
!=
nil
{
me
.
directoryError
=
err
break
}
}
close
(
me
.
directoryChannel
)
file
.
Close
()
}()
return
me
}
examplelib/
passthrough
_test.go
→
examplelib/
loopback
_test.go
View file @
c0b9bca3
...
@@ -54,7 +54,7 @@ func (me *testCase) Setup(t *testing.T) {
...
@@ -54,7 +54,7 @@ func (me *testCase) Setup(t *testing.T) {
me
.
origSubdir
=
path
.
Join
(
me
.
origDir
,
subdir
)
me
.
origSubdir
=
path
.
Join
(
me
.
origDir
,
subdir
)
me
.
origSubfile
=
path
.
Join
(
me
.
origSubdir
,
"subfile"
)
me
.
origSubfile
=
path
.
Join
(
me
.
origSubdir
,
"subfile"
)
pfs
:=
New
PassThroughFuse
(
me
.
origDir
)
pfs
:=
New
LoopbackFileSystem
(
me
.
origDir
)
me
.
connector
=
fuse
.
NewPathFileSystemConnector
(
pfs
)
me
.
connector
=
fuse
.
NewPathFileSystemConnector
(
pfs
)
me
.
connector
.
Debug
=
true
me
.
connector
.
Debug
=
true
me
.
state
=
fuse
.
NewMountState
(
me
.
connector
)
me
.
state
=
fuse
.
NewMountState
(
me
.
connector
)
...
@@ -530,7 +530,7 @@ func TestRecursiveMount(t *testing.T) {
...
@@ -530,7 +530,7 @@ func TestRecursiveMount(t *testing.T) {
f
.
WriteString
(
"bla"
)
f
.
WriteString
(
"bla"
)
f
.
Close
()
f
.
Close
()
pfs2
:=
New
PassThroughFuse
(
ts
.
origDir
)
pfs2
:=
New
LoopbackFileSystem
(
ts
.
origDir
)
code
:=
ts
.
connector
.
Mount
(
"/hello.txt"
,
pfs2
)
code
:=
ts
.
connector
.
Mount
(
"/hello.txt"
,
pfs2
)
if
code
!=
fuse
.
EINVAL
{
if
code
!=
fuse
.
EINVAL
{
t
.
Error
(
"expect EINVAL"
,
code
)
t
.
Error
(
"expect EINVAL"
,
code
)
...
...
examplelib/stackfs_test.go
View file @
c0b9bca3
...
@@ -41,8 +41,8 @@ func (me *stackFsTestCase) Setup(t *testing.T) {
...
@@ -41,8 +41,8 @@ func (me *stackFsTestCase) Setup(t *testing.T) {
os
.
Mkdir
(
me
.
origDir2
,
0700
)
os
.
Mkdir
(
me
.
origDir2
,
0700
)
os
.
Mkdir
(
me
.
mountDir
,
0700
)
os
.
Mkdir
(
me
.
mountDir
,
0700
)
fs1
:=
fuse
.
NewPathFileSystemConnector
(
New
PassThroughFuse
(
me
.
origDir1
))
fs1
:=
fuse
.
NewPathFileSystemConnector
(
New
LoopbackFileSystem
(
me
.
origDir1
))
fs2
:=
fuse
.
NewPathFileSystemConnector
(
New
PassThroughFuse
(
me
.
origDir2
))
fs2
:=
fuse
.
NewPathFileSystemConnector
(
New
LoopbackFileSystem
(
me
.
origDir2
))
me
.
fs
=
NewSubmountFileSystem
()
me
.
fs
=
NewSubmountFileSystem
()
...
@@ -154,7 +154,7 @@ func (me *stackFsTestCase) testAddRemove() {
...
@@ -154,7 +154,7 @@ func (me *stackFsTestCase) testAddRemove() {
Mode
:
0755
,
Mode
:
0755
,
}
}
conn
:=
fuse
.
NewPathFileSystemConnector
(
New
PassThroughFuse
(
me
.
origDir1
))
conn
:=
fuse
.
NewPathFileSystemConnector
(
New
LoopbackFileSystem
(
me
.
origDir1
))
ok
:=
me
.
fs
.
AddFileSystem
(
"sub1"
,
conn
,
attr
)
ok
:=
me
.
fs
.
AddFileSystem
(
"sub1"
,
conn
,
attr
)
if
ok
{
if
ok
{
me
.
tester
.
Errorf
(
"AddFileSystem should fail"
)
me
.
tester
.
Errorf
(
"AddFileSystem should fail"
)
...
...
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