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
8c5c22a9
Commit
8c5c22a9
authored
Jun 22, 2013
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Hide LoopBackFileSystem type to reduce API clutter.
parent
c6e90c78
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
33 deletions
+33
-33
fuse/pathfs/loopback.go
fuse/pathfs/loopback.go
+25
-25
fuse/pathfs/loopback_linux.go
fuse/pathfs/loopback_linux.go
+5
-5
fuse/test/cache_test.go
fuse/test/cache_test.go
+3
-3
No files found.
fuse/pathfs/loopback.go
View file @
8c5c22a9
...
...
@@ -15,26 +15,26 @@ import (
var
_
=
fmt
.
Println
var
_
=
log
.
Println
// A FUSE filesystem that shunts all request to an underlying file
// system. Its main purpose is to provide test coverage without
// having to build an actual synthetic filesystem.
type
LoopbackFileSystem
struct
{
type
loopbackFileSystem
struct
{
Root
string
DefaultFileSystem
}
func
NewLoopbackFileSystem
(
root
string
)
(
out
*
LoopbackFileSystem
)
{
out
=
new
(
LoopbackFileSystem
)
// A FUSE filesystem that shunts all request to an underlying file
// system. Its main purpose is to provide test coverage without
// having to build a synthetic filesystem.
func
NewLoopbackFileSystem
(
root
string
)
(
out
*
loopbackFileSystem
)
{
out
=
new
(
loopbackFileSystem
)
out
.
Root
=
root
return
out
}
func
(
fs
*
L
oopbackFileSystem
)
GetPath
(
relPath
string
)
string
{
func
(
fs
*
l
oopbackFileSystem
)
GetPath
(
relPath
string
)
string
{
return
filepath
.
Join
(
fs
.
Root
,
relPath
)
}
func
(
fs
*
L
oopbackFileSystem
)
GetAttr
(
name
string
,
context
*
fuse
.
Context
)
(
a
*
fuse
.
Attr
,
code
fuse
.
Status
)
{
func
(
fs
*
l
oopbackFileSystem
)
GetAttr
(
name
string
,
context
*
fuse
.
Context
)
(
a
*
fuse
.
Attr
,
code
fuse
.
Status
)
{
fullPath
:=
fs
.
GetPath
(
name
)
var
err
error
=
nil
st
:=
syscall
.
Stat_t
{}
...
...
@@ -54,9 +54,9 @@ func (fs *LoopbackFileSystem) GetAttr(name string, context *fuse.Context) (a *fu
return
a
,
fuse
.
OK
}
var
_
=
(
FileSystem
)((
*
L
oopbackFileSystem
)(
nil
))
var
_
=
(
FileSystem
)((
*
l
oopbackFileSystem
)(
nil
))
func
(
fs
*
L
oopbackFileSystem
)
OpenDir
(
name
string
,
context
*
fuse
.
Context
)
(
stream
[]
fuse
.
DirEntry
,
status
fuse
.
Status
)
{
func
(
fs
*
l
oopbackFileSystem
)
OpenDir
(
name
string
,
context
*
fuse
.
Context
)
(
stream
[]
fuse
.
DirEntry
,
status
fuse
.
Status
)
{
// What other ways beyond O_RDONLY are there to open
// directories?
f
,
err
:=
os
.
Open
(
fs
.
GetPath
(
name
))
...
...
@@ -92,7 +92,7 @@ func (fs *LoopbackFileSystem) OpenDir(name string, context *fuse.Context) (strea
return
output
,
fuse
.
OK
}
func
(
fs
*
L
oopbackFileSystem
)
Open
(
name
string
,
flags
uint32
,
context
*
fuse
.
Context
)
(
fuseFile
fuse
.
File
,
status
fuse
.
Status
)
{
func
(
fs
*
l
oopbackFileSystem
)
Open
(
name
string
,
flags
uint32
,
context
*
fuse
.
Context
)
(
fuseFile
fuse
.
File
,
status
fuse
.
Status
)
{
f
,
err
:=
os
.
OpenFile
(
fs
.
GetPath
(
name
),
int
(
flags
),
0
)
if
err
!=
nil
{
return
nil
,
fuse
.
ToStatus
(
err
)
...
...
@@ -100,20 +100,20 @@ func (fs *LoopbackFileSystem) Open(name string, flags uint32, context *fuse.Cont
return
&
fuse
.
LoopbackFile
{
File
:
f
},
fuse
.
OK
}
func
(
fs
*
L
oopbackFileSystem
)
Chmod
(
path
string
,
mode
uint32
,
context
*
fuse
.
Context
)
(
code
fuse
.
Status
)
{
func
(
fs
*
l
oopbackFileSystem
)
Chmod
(
path
string
,
mode
uint32
,
context
*
fuse
.
Context
)
(
code
fuse
.
Status
)
{
err
:=
os
.
Chmod
(
fs
.
GetPath
(
path
),
os
.
FileMode
(
mode
))
return
fuse
.
ToStatus
(
err
)
}
func
(
fs
*
L
oopbackFileSystem
)
Chown
(
path
string
,
uid
uint32
,
gid
uint32
,
context
*
fuse
.
Context
)
(
code
fuse
.
Status
)
{
func
(
fs
*
l
oopbackFileSystem
)
Chown
(
path
string
,
uid
uint32
,
gid
uint32
,
context
*
fuse
.
Context
)
(
code
fuse
.
Status
)
{
return
fuse
.
ToStatus
(
os
.
Chown
(
fs
.
GetPath
(
path
),
int
(
uid
),
int
(
gid
)))
}
func
(
fs
*
L
oopbackFileSystem
)
Truncate
(
path
string
,
offset
uint64
,
context
*
fuse
.
Context
)
(
code
fuse
.
Status
)
{
func
(
fs
*
l
oopbackFileSystem
)
Truncate
(
path
string
,
offset
uint64
,
context
*
fuse
.
Context
)
(
code
fuse
.
Status
)
{
return
fuse
.
ToStatus
(
os
.
Truncate
(
fs
.
GetPath
(
path
),
int64
(
offset
)))
}
func
(
fs
*
L
oopbackFileSystem
)
Utimens
(
path
string
,
Atime
*
time
.
Time
,
Mtime
*
time
.
Time
,
context
*
fuse
.
Context
)
(
code
fuse
.
Status
)
{
func
(
fs
*
l
oopbackFileSystem
)
Utimens
(
path
string
,
Atime
*
time
.
Time
,
Mtime
*
time
.
Time
,
context
*
fuse
.
Context
)
(
code
fuse
.
Status
)
{
var
a
time
.
Time
if
Atime
!=
nil
{
a
=
*
Atime
...
...
@@ -125,46 +125,46 @@ func (fs *LoopbackFileSystem) Utimens(path string, Atime *time.Time, Mtime *time
return
fuse
.
ToStatus
(
os
.
Chtimes
(
fs
.
GetPath
(
path
),
a
,
m
))
}
func
(
fs
*
L
oopbackFileSystem
)
Readlink
(
name
string
,
context
*
fuse
.
Context
)
(
out
string
,
code
fuse
.
Status
)
{
func
(
fs
*
l
oopbackFileSystem
)
Readlink
(
name
string
,
context
*
fuse
.
Context
)
(
out
string
,
code
fuse
.
Status
)
{
f
,
err
:=
os
.
Readlink
(
fs
.
GetPath
(
name
))
return
f
,
fuse
.
ToStatus
(
err
)
}
func
(
fs
*
L
oopbackFileSystem
)
Mknod
(
name
string
,
mode
uint32
,
dev
uint32
,
context
*
fuse
.
Context
)
(
code
fuse
.
Status
)
{
func
(
fs
*
l
oopbackFileSystem
)
Mknod
(
name
string
,
mode
uint32
,
dev
uint32
,
context
*
fuse
.
Context
)
(
code
fuse
.
Status
)
{
return
fuse
.
ToStatus
(
syscall
.
Mknod
(
fs
.
GetPath
(
name
),
mode
,
int
(
dev
)))
}
func
(
fs
*
L
oopbackFileSystem
)
Mkdir
(
path
string
,
mode
uint32
,
context
*
fuse
.
Context
)
(
code
fuse
.
Status
)
{
func
(
fs
*
l
oopbackFileSystem
)
Mkdir
(
path
string
,
mode
uint32
,
context
*
fuse
.
Context
)
(
code
fuse
.
Status
)
{
return
fuse
.
ToStatus
(
os
.
Mkdir
(
fs
.
GetPath
(
path
),
os
.
FileMode
(
mode
)))
}
// Don't use os.Remove, it removes twice (unlink followed by rmdir).
func
(
fs
*
L
oopbackFileSystem
)
Unlink
(
name
string
,
context
*
fuse
.
Context
)
(
code
fuse
.
Status
)
{
func
(
fs
*
l
oopbackFileSystem
)
Unlink
(
name
string
,
context
*
fuse
.
Context
)
(
code
fuse
.
Status
)
{
return
fuse
.
ToStatus
(
syscall
.
Unlink
(
fs
.
GetPath
(
name
)))
}
func
(
fs
*
L
oopbackFileSystem
)
Rmdir
(
name
string
,
context
*
fuse
.
Context
)
(
code
fuse
.
Status
)
{
func
(
fs
*
l
oopbackFileSystem
)
Rmdir
(
name
string
,
context
*
fuse
.
Context
)
(
code
fuse
.
Status
)
{
return
fuse
.
ToStatus
(
syscall
.
Rmdir
(
fs
.
GetPath
(
name
)))
}
func
(
fs
*
L
oopbackFileSystem
)
Symlink
(
pointedTo
string
,
linkName
string
,
context
*
fuse
.
Context
)
(
code
fuse
.
Status
)
{
func
(
fs
*
l
oopbackFileSystem
)
Symlink
(
pointedTo
string
,
linkName
string
,
context
*
fuse
.
Context
)
(
code
fuse
.
Status
)
{
return
fuse
.
ToStatus
(
os
.
Symlink
(
pointedTo
,
fs
.
GetPath
(
linkName
)))
}
func
(
fs
*
L
oopbackFileSystem
)
Rename
(
oldPath
string
,
newPath
string
,
context
*
fuse
.
Context
)
(
codee
fuse
.
Status
)
{
func
(
fs
*
l
oopbackFileSystem
)
Rename
(
oldPath
string
,
newPath
string
,
context
*
fuse
.
Context
)
(
codee
fuse
.
Status
)
{
err
:=
os
.
Rename
(
fs
.
GetPath
(
oldPath
),
fs
.
GetPath
(
newPath
))
return
fuse
.
ToStatus
(
err
)
}
func
(
fs
*
L
oopbackFileSystem
)
Link
(
orig
string
,
newName
string
,
context
*
fuse
.
Context
)
(
code
fuse
.
Status
)
{
func
(
fs
*
l
oopbackFileSystem
)
Link
(
orig
string
,
newName
string
,
context
*
fuse
.
Context
)
(
code
fuse
.
Status
)
{
return
fuse
.
ToStatus
(
os
.
Link
(
fs
.
GetPath
(
orig
),
fs
.
GetPath
(
newName
)))
}
func
(
fs
*
L
oopbackFileSystem
)
Access
(
name
string
,
mode
uint32
,
context
*
fuse
.
Context
)
(
code
fuse
.
Status
)
{
func
(
fs
*
l
oopbackFileSystem
)
Access
(
name
string
,
mode
uint32
,
context
*
fuse
.
Context
)
(
code
fuse
.
Status
)
{
return
fuse
.
ToStatus
(
syscall
.
Access
(
fs
.
GetPath
(
name
),
mode
))
}
func
(
fs
*
L
oopbackFileSystem
)
Create
(
path
string
,
flags
uint32
,
mode
uint32
,
context
*
fuse
.
Context
)
(
fuseFile
fuse
.
File
,
code
fuse
.
Status
)
{
func
(
fs
*
l
oopbackFileSystem
)
Create
(
path
string
,
flags
uint32
,
mode
uint32
,
context
*
fuse
.
Context
)
(
fuseFile
fuse
.
File
,
code
fuse
.
Status
)
{
f
,
err
:=
os
.
OpenFile
(
fs
.
GetPath
(
path
),
int
(
flags
)
|
os
.
O_CREATE
,
os
.
FileMode
(
mode
))
return
&
fuse
.
LoopbackFile
{
File
:
f
},
fuse
.
ToStatus
(
err
)
}
fuse/pathfs/loopback_linux.go
View file @
8c5c22a9
...
...
@@ -7,7 +7,7 @@ import (
"github.com/hanwen/go-fuse/fuse"
)
func
(
fs
*
L
oopbackFileSystem
)
StatFs
(
name
string
)
*
fuse
.
StatfsOut
{
func
(
fs
*
l
oopbackFileSystem
)
StatFs
(
name
string
)
*
fuse
.
StatfsOut
{
s
:=
syscall
.
Statfs_t
{}
err
:=
syscall
.
Statfs
(
fs
.
GetPath
(
name
),
&
s
)
if
err
==
nil
{
...
...
@@ -25,21 +25,21 @@ func (fs *LoopbackFileSystem) StatFs(name string) *fuse.StatfsOut {
return
nil
}
func
(
fs
*
L
oopbackFileSystem
)
ListXAttr
(
name
string
,
context
*
fuse
.
Context
)
([]
string
,
fuse
.
Status
)
{
func
(
fs
*
l
oopbackFileSystem
)
ListXAttr
(
name
string
,
context
*
fuse
.
Context
)
([]
string
,
fuse
.
Status
)
{
data
,
errNo
:=
ListXAttr
(
fs
.
GetPath
(
name
))
return
data
,
fuse
.
Status
(
errNo
)
}
func
(
fs
*
L
oopbackFileSystem
)
RemoveXAttr
(
name
string
,
attr
string
,
context
*
fuse
.
Context
)
fuse
.
Status
{
func
(
fs
*
l
oopbackFileSystem
)
RemoveXAttr
(
name
string
,
attr
string
,
context
*
fuse
.
Context
)
fuse
.
Status
{
return
fuse
.
Status
(
Removexattr
(
fs
.
GetPath
(
name
),
attr
))
}
func
(
fs
*
L
oopbackFileSystem
)
String
()
string
{
func
(
fs
*
l
oopbackFileSystem
)
String
()
string
{
return
fmt
.
Sprintf
(
"LoopbackFs(%s)"
,
fs
.
Root
)
}
func
(
fs
*
L
oopbackFileSystem
)
GetXAttr
(
name
string
,
attr
string
,
context
*
fuse
.
Context
)
([]
byte
,
fuse
.
Status
)
{
func
(
fs
*
l
oopbackFileSystem
)
GetXAttr
(
name
string
,
attr
string
,
context
*
fuse
.
Context
)
([]
byte
,
fuse
.
Status
)
{
data
:=
make
([]
byte
,
1024
)
data
,
errNo
:=
GetXAttr
(
fs
.
GetPath
(
name
),
attr
,
data
)
...
...
fuse/test/cache_test.go
View file @
8c5c22a9
...
...
@@ -16,11 +16,11 @@ import (
var
_
=
log
.
Println
type
cacheFs
struct
{
*
pathfs
.
Loopback
FileSystem
pathfs
.
FileSystem
}
func
(
fs
*
cacheFs
)
Open
(
name
string
,
flags
uint32
,
context
*
fuse
.
Context
)
(
fuseFile
fuse
.
File
,
status
fuse
.
Status
)
{
f
,
c
:=
fs
.
Loopback
FileSystem
.
Open
(
name
,
flags
,
context
)
f
,
c
:=
fs
.
FileSystem
.
Open
(
name
,
flags
,
context
)
if
!
c
.
Ok
()
{
return
f
,
c
}
...
...
@@ -40,7 +40,7 @@ func setupCacheTest(t *testing.T) (string, *pathfs.PathNodeFs, func()) {
os
.
Mkdir
(
dir
+
"/orig"
,
0755
)
fs
:=
&
cacheFs
{
LoopbackFileSystem
:
pathfs
.
NewLoopbackFileSystem
(
dir
+
"/orig"
),
pathfs
.
NewLoopbackFileSystem
(
dir
+
"/orig"
),
}
pfs
:=
pathfs
.
NewPathNodeFs
(
fs
,
nil
)
state
,
conn
,
err
:=
fuse
.
MountNodeFileSystem
(
dir
+
"/mnt"
,
pfs
,
nil
)
...
...
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