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
83798dc7
Commit
83798dc7
authored
Sep 05, 2011
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Run gofmt.
parent
50a64bf6
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
115 additions
and
120 deletions
+115
-120
fuse/api.go
fuse/api.go
+19
-19
fuse/cache_test.go
fuse/cache_test.go
+1
-0
fuse/default.go
fuse/default.go
+1
-0
fuse/defaultfile.go
fuse/defaultfile.go
+1
-0
fuse/defaultnode.go
fuse/defaultnode.go
+10
-12
fuse/direntry.go
fuse/direntry.go
+3
-3
fuse/fsconnector.go
fuse/fsconnector.go
+4
-4
fuse/fsetattr_test.go
fuse/fsetattr_test.go
+3
-3
fuse/fsmount.go
fuse/fsmount.go
+5
-4
fuse/fsops.go
fuse/fsops.go
+8
-10
fuse/inode.go
fuse/inode.go
+12
-12
fuse/loopback_test.go
fuse/loopback_test.go
+20
-20
fuse/pathfs.go
fuse/pathfs.go
+17
-20
unionfs/unionfs_test.go
unionfs/unionfs_test.go
+2
-3
zipfs/memtree.go
zipfs/memtree.go
+5
-6
zipfs/tarfs.go
zipfs/tarfs.go
+3
-3
zipfs/zipfs.go
zipfs/zipfs.go
+1
-1
No files found.
fuse/api.go
View file @
83798dc7
...
@@ -27,42 +27,42 @@ type FsNode interface {
...
@@ -27,42 +27,42 @@ type FsNode interface {
// The following are called by the FileSystemConnector
// The following are called by the FileSystemConnector
Inode
()
*
Inode
Inode
()
*
Inode
SetInode
(
node
*
Inode
)
SetInode
(
node
*
Inode
)
RmChild
(
name
string
,
child
FsNode
)
RmChild
(
name
string
,
child
FsNode
)
AddChild
(
name
string
,
child
FsNode
)
AddChild
(
name
string
,
child
FsNode
)
Lookup
(
name
string
)
(
fi
*
os
.
FileInfo
,
node
FsNode
,
code
Status
)
Lookup
(
name
string
)
(
fi
*
os
.
FileInfo
,
node
FsNode
,
code
Status
)
// Misc.
// Misc.
Access
(
mode
uint32
,
context
*
Context
)
(
code
Status
)
Access
(
mode
uint32
,
context
*
Context
)
(
code
Status
)
Readlink
(
c
*
Context
)
([]
byte
,
Status
)
Readlink
(
c
*
Context
)
([]
byte
,
Status
)
// Namespace operations
// Namespace operations
Mknod
(
name
string
,
mode
uint32
,
dev
uint32
,
context
*
Context
)
(
fi
*
os
.
FileInfo
,
newNode
FsNode
,
code
Status
)
Mknod
(
name
string
,
mode
uint32
,
dev
uint32
,
context
*
Context
)
(
fi
*
os
.
FileInfo
,
newNode
FsNode
,
code
Status
)
Mkdir
(
name
string
,
mode
uint32
,
context
*
Context
)
(
fi
*
os
.
FileInfo
,
newNode
FsNode
,
code
Status
)
Mkdir
(
name
string
,
mode
uint32
,
context
*
Context
)
(
fi
*
os
.
FileInfo
,
newNode
FsNode
,
code
Status
)
Unlink
(
name
string
,
context
*
Context
)
(
code
Status
)
Unlink
(
name
string
,
context
*
Context
)
(
code
Status
)
Rmdir
(
name
string
,
context
*
Context
)
(
code
Status
)
Rmdir
(
name
string
,
context
*
Context
)
(
code
Status
)
Symlink
(
name
string
,
content
string
,
context
*
Context
)
(
fi
*
os
.
FileInfo
,
newNode
FsNode
,
code
Status
)
Symlink
(
name
string
,
content
string
,
context
*
Context
)
(
fi
*
os
.
FileInfo
,
newNode
FsNode
,
code
Status
)
Rename
(
oldName
string
,
newParent
FsNode
,
newName
string
,
context
*
Context
)
(
code
Status
)
Rename
(
oldName
string
,
newParent
FsNode
,
newName
string
,
context
*
Context
)
(
code
Status
)
Link
(
name
string
,
existing
FsNode
,
context
*
Context
)
(
fi
*
os
.
FileInfo
,
newNode
FsNode
,
code
Status
)
Link
(
name
string
,
existing
FsNode
,
context
*
Context
)
(
fi
*
os
.
FileInfo
,
newNode
FsNode
,
code
Status
)
// Files
// Files
Create
(
name
string
,
flags
uint32
,
mode
uint32
,
context
*
Context
)
(
file
File
,
fi
*
os
.
FileInfo
,
newNode
FsNode
,
code
Status
)
Create
(
name
string
,
flags
uint32
,
mode
uint32
,
context
*
Context
)
(
file
File
,
fi
*
os
.
FileInfo
,
newNode
FsNode
,
code
Status
)
Open
(
flags
uint32
,
context
*
Context
)
(
file
File
,
code
Status
)
Open
(
flags
uint32
,
context
*
Context
)
(
file
File
,
code
Status
)
Flush
(
file
File
,
openFlags
uint32
,
context
*
Context
)
(
code
Status
)
Flush
(
file
File
,
openFlags
uint32
,
context
*
Context
)
(
code
Status
)
OpenDir
(
context
*
Context
)
(
chan
DirEntry
,
Status
)
OpenDir
(
context
*
Context
)
(
chan
DirEntry
,
Status
)
// XAttrs
// XAttrs
GetXAttr
(
attribute
string
,
context
*
Context
)
(
data
[]
byte
,
code
Status
)
GetXAttr
(
attribute
string
,
context
*
Context
)
(
data
[]
byte
,
code
Status
)
RemoveXAttr
(
attr
string
,
context
*
Context
)
Status
RemoveXAttr
(
attr
string
,
context
*
Context
)
Status
SetXAttr
(
attr
string
,
data
[]
byte
,
flags
int
,
context
*
Context
)
Status
SetXAttr
(
attr
string
,
data
[]
byte
,
flags
int
,
context
*
Context
)
Status
ListXAttr
(
context
*
Context
)
(
attrs
[]
string
,
code
Status
)
ListXAttr
(
context
*
Context
)
(
attrs
[]
string
,
code
Status
)
// Attributes
// Attributes
GetAttr
(
file
File
,
context
*
Context
)
(
fi
*
os
.
FileInfo
,
code
Status
)
GetAttr
(
file
File
,
context
*
Context
)
(
fi
*
os
.
FileInfo
,
code
Status
)
Chmod
(
file
File
,
perms
uint32
,
context
*
Context
)
(
code
Status
)
Chmod
(
file
File
,
perms
uint32
,
context
*
Context
)
(
code
Status
)
Chown
(
file
File
,
uid
uint32
,
gid
uint32
,
context
*
Context
)
(
code
Status
)
Chown
(
file
File
,
uid
uint32
,
gid
uint32
,
context
*
Context
)
(
code
Status
)
Truncate
(
file
File
,
size
uint64
,
context
*
Context
)
(
code
Status
)
Truncate
(
file
File
,
size
uint64
,
context
*
Context
)
(
code
Status
)
Utimens
(
file
File
,
atime
uint64
,
mtime
uint64
,
context
*
Context
)
(
code
Status
)
Utimens
(
file
File
,
atime
uint64
,
mtime
uint64
,
context
*
Context
)
(
code
Status
)
}
}
...
...
fuse/cache_test.go
View file @
83798dc7
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
"os"
"os"
"testing"
"testing"
)
)
var
_
=
log
.
Println
var
_
=
log
.
Println
type
cacheFs
struct
{
type
cacheFs
struct
{
...
...
fuse/default.go
View file @
83798dc7
package
fuse
package
fuse
import
(
import
(
"os"
"os"
)
)
...
...
fuse/defaultfile.go
View file @
83798dc7
package
fuse
package
fuse
import
(
import
(
"os"
"os"
)
)
...
...
fuse/defaultnode.go
View file @
83798dc7
package
fuse
package
fuse
import
(
import
(
"os"
"os"
)
)
...
@@ -44,8 +45,7 @@ func (me *DefaultFsNode) RmChild(name string, child FsNode) {
...
@@ -44,8 +45,7 @@ func (me *DefaultFsNode) RmChild(name string, child FsNode) {
func
(
me
*
DefaultFsNode
)
AddChild
(
name
string
,
child
FsNode
)
{
func
(
me
*
DefaultFsNode
)
AddChild
(
name
string
,
child
FsNode
)
{
}
}
func
(
me
*
DefaultFsNode
)
Lookup
(
name
string
)
(
fi
*
os
.
FileInfo
,
node
FsNode
,
code
Status
)
{
func
(
me
*
DefaultFsNode
)
Lookup
(
name
string
)
(
fi
*
os
.
FileInfo
,
node
FsNode
,
code
Status
)
{
return
nil
,
nil
,
ENOSYS
return
nil
,
nil
,
ENOSYS
}
}
...
@@ -85,35 +85,34 @@ func (me *DefaultFsNode) Create(name string, flags uint32, mode uint32, context
...
@@ -85,35 +85,34 @@ func (me *DefaultFsNode) Create(name string, flags uint32, mode uint32, context
return
nil
,
nil
,
nil
,
ENOSYS
return
nil
,
nil
,
nil
,
ENOSYS
}
}
func
(
me
*
DefaultFsNode
)
Open
(
flags
uint32
,
context
*
Context
)
(
file
File
,
code
Status
)
{
func
(
me
*
DefaultFsNode
)
Open
(
flags
uint32
,
context
*
Context
)
(
file
File
,
code
Status
)
{
return
nil
,
ENOSYS
return
nil
,
ENOSYS
}
}
func
(
me
*
DefaultFsNode
)
Flush
(
file
File
,
openFlags
uint32
,
context
*
Context
)
(
code
Status
)
{
func
(
me
*
DefaultFsNode
)
Flush
(
file
File
,
openFlags
uint32
,
context
*
Context
)
(
code
Status
)
{
return
ENOSYS
return
ENOSYS
}
}
func
(
me
*
DefaultFsNode
)
OpenDir
(
context
*
Context
)
(
chan
DirEntry
,
Status
)
{
func
(
me
*
DefaultFsNode
)
OpenDir
(
context
*
Context
)
(
chan
DirEntry
,
Status
)
{
return
nil
,
ENOSYS
return
nil
,
ENOSYS
}
}
func
(
me
*
DefaultFsNode
)
GetXAttr
(
attribute
string
,
context
*
Context
)
(
data
[]
byte
,
code
Status
)
{
func
(
me
*
DefaultFsNode
)
GetXAttr
(
attribute
string
,
context
*
Context
)
(
data
[]
byte
,
code
Status
)
{
return
nil
,
ENOSYS
return
nil
,
ENOSYS
}
}
func
(
me
*
DefaultFsNode
)
RemoveXAttr
(
attr
string
,
context
*
Context
)
Status
{
func
(
me
*
DefaultFsNode
)
RemoveXAttr
(
attr
string
,
context
*
Context
)
Status
{
return
ENOSYS
return
ENOSYS
}
}
func
(
me
*
DefaultFsNode
)
SetXAttr
(
attr
string
,
data
[]
byte
,
flags
int
,
context
*
Context
)
Status
{
func
(
me
*
DefaultFsNode
)
SetXAttr
(
attr
string
,
data
[]
byte
,
flags
int
,
context
*
Context
)
Status
{
return
ENOSYS
return
ENOSYS
}
}
func
(
me
*
DefaultFsNode
)
ListXAttr
(
context
*
Context
)
(
attrs
[]
string
,
code
Status
)
{
func
(
me
*
DefaultFsNode
)
ListXAttr
(
context
*
Context
)
(
attrs
[]
string
,
code
Status
)
{
return
nil
,
ENOSYS
return
nil
,
ENOSYS
}
}
func
(
me
*
DefaultFsNode
)
GetAttr
(
file
File
,
context
*
Context
)
(
fi
*
os
.
FileInfo
,
code
Status
)
{
func
(
me
*
DefaultFsNode
)
GetAttr
(
file
File
,
context
*
Context
)
(
fi
*
os
.
FileInfo
,
code
Status
)
{
return
nil
,
ENOSYS
return
nil
,
ENOSYS
}
}
...
@@ -126,11 +125,10 @@ func (me *DefaultFsNode) Chown(file File, uid uint32, gid uint32, context *Conte
...
@@ -126,11 +125,10 @@ func (me *DefaultFsNode) Chown(file File, uid uint32, gid uint32, context *Conte
return
ENOSYS
return
ENOSYS
}
}
func
(
me
*
DefaultFsNode
)
Truncate
(
file
File
,
size
uint64
,
context
*
Context
)
(
code
Status
)
{
func
(
me
*
DefaultFsNode
)
Truncate
(
file
File
,
size
uint64
,
context
*
Context
)
(
code
Status
)
{
return
ENOSYS
return
ENOSYS
}
}
func
(
me
*
DefaultFsNode
)
Utimens
(
file
File
,
atime
uint64
,
mtime
uint64
,
context
*
Context
)
(
code
Status
)
{
func
(
me
*
DefaultFsNode
)
Utimens
(
file
File
,
atime
uint64
,
mtime
uint64
,
context
*
Context
)
(
code
Status
)
{
return
ENOSYS
return
ENOSYS
}
}
fuse/direntry.go
View file @
83798dc7
...
@@ -76,9 +76,9 @@ type rawDir interface {
...
@@ -76,9 +76,9 @@ type rawDir interface {
}
}
type
connectorDir
struct
{
type
connectorDir
struct
{
extra
[]
DirEntry
extra
[]
DirEntry
stream
chan
DirEntry
stream
chan
DirEntry
leftOver
DirEntry
leftOver
DirEntry
lastOffset
uint64
lastOffset
uint64
}
}
...
...
fuse/fsconnector.go
View file @
83798dc7
...
@@ -150,10 +150,10 @@ func (me *FileSystemConnector) considerDropInode(n *Inode) (drop bool) {
...
@@ -150,10 +150,10 @@ func (me *FileSystemConnector) considerDropInode(n *Inode) (drop bool) {
if
n
==
me
.
rootNode
||
n
.
mountPoint
!=
nil
{
if
n
==
me
.
rootNode
||
n
.
mountPoint
!=
nil
{
return
false
return
false
}
}
n
.
openFilesMutex
.
Lock
()
n
.
openFilesMutex
.
Lock
()
defer
n
.
openFilesMutex
.
Unlock
()
defer
n
.
openFilesMutex
.
Unlock
()
return
len
(
n
.
openFiles
)
==
0
return
len
(
n
.
openFiles
)
==
0
}
}
func
(
me
*
FileSystemConnector
)
renameUpdate
(
oldParent
*
Inode
,
oldName
string
,
newParent
*
Inode
,
newName
string
)
{
func
(
me
*
FileSystemConnector
)
renameUpdate
(
oldParent
*
Inode
,
oldName
string
,
newParent
*
Inode
,
newName
string
)
{
...
@@ -164,7 +164,7 @@ func (me *FileSystemConnector) renameUpdate(oldParent *Inode, oldName string, ne
...
@@ -164,7 +164,7 @@ func (me *FileSystemConnector) renameUpdate(oldParent *Inode, oldName string, ne
if
oldParent
.
mount
!=
newParent
.
mount
{
if
oldParent
.
mount
!=
newParent
.
mount
{
panic
(
"Cross mount rename"
)
panic
(
"Cross mount rename"
)
}
}
node
:=
oldParent
.
rmChild
(
oldName
)
node
:=
oldParent
.
rmChild
(
oldName
)
if
node
==
nil
{
if
node
==
nil
{
panic
(
"Source of rename does not exist"
)
panic
(
"Source of rename does not exist"
)
...
@@ -175,7 +175,7 @@ func (me *FileSystemConnector) renameUpdate(oldParent *Inode, oldName string, ne
...
@@ -175,7 +175,7 @@ func (me *FileSystemConnector) renameUpdate(oldParent *Inode, oldName string, ne
func
(
me
*
FileSystemConnector
)
unlinkUpdate
(
parent
*
Inode
,
name
string
)
{
func
(
me
*
FileSystemConnector
)
unlinkUpdate
(
parent
*
Inode
,
name
string
)
{
defer
me
.
verify
()
defer
me
.
verify
()
parent
.
treeLock
.
Lock
()
parent
.
treeLock
.
Lock
()
defer
parent
.
treeLock
.
Unlock
()
defer
parent
.
treeLock
.
Unlock
()
...
...
fuse/fsetattr_test.go
View file @
83798dc7
...
@@ -125,7 +125,7 @@ func setupFAttrTest(fs FileSystem) (dir string, clean func()) {
...
@@ -125,7 +125,7 @@ func setupFAttrTest(fs FileSystem) (dir string, clean func()) {
state
,
_
,
err
:=
MountPathFileSystem
(
dir
,
fs
,
nil
)
state
,
_
,
err
:=
MountPathFileSystem
(
dir
,
fs
,
nil
)
CheckSuccess
(
err
)
CheckSuccess
(
err
)
state
.
Debug
=
true
state
.
Debug
=
true
go
state
.
Loop
(
false
)
go
state
.
Loop
(
false
)
// Trigger INIT.
// Trigger INIT.
...
@@ -133,7 +133,7 @@ func setupFAttrTest(fs FileSystem) (dir string, clean func()) {
...
@@ -133,7 +133,7 @@ func setupFAttrTest(fs FileSystem) (dir string, clean func()) {
if
state
.
KernelSettings
()
.
Flags
&
CAP_FILE_OPS
==
0
{
if
state
.
KernelSettings
()
.
Flags
&
CAP_FILE_OPS
==
0
{
log
.
Println
(
"Mount does not support file operations"
)
log
.
Println
(
"Mount does not support file operations"
)
}
}
return
dir
,
func
()
{
return
dir
,
func
()
{
if
state
.
Unmount
()
==
nil
{
if
state
.
Unmount
()
==
nil
{
os
.
RemoveAll
(
dir
)
os
.
RemoveAll
(
dir
)
...
@@ -145,7 +145,7 @@ func TestFSetAttr(t *testing.T) {
...
@@ -145,7 +145,7 @@ func TestFSetAttr(t *testing.T) {
fs
:=
&
FSetAttrFs
{}
fs
:=
&
FSetAttrFs
{}
dir
,
clean
:=
setupFAttrTest
(
fs
)
dir
,
clean
:=
setupFAttrTest
(
fs
)
defer
clean
()
defer
clean
()
fn
:=
dir
+
"/file"
fn
:=
dir
+
"/file"
f
,
err
:=
os
.
OpenFile
(
fn
,
os
.
O_CREATE
|
os
.
O_WRONLY
,
0755
)
f
,
err
:=
os
.
OpenFile
(
fn
,
os
.
O_CREATE
|
os
.
O_WRONLY
,
0755
)
CheckSuccess
(
err
)
CheckSuccess
(
err
)
...
...
fuse/fsmount.go
View file @
83798dc7
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"sync"
"sync"
"unsafe"
"unsafe"
)
)
var
_
=
log
.
Println
var
_
=
log
.
Println
// openedFile stores either an open dir or an open file.
// openedFile stores either an open dir or an open file.
...
@@ -57,7 +58,7 @@ func (me *fileSystemMount) fileInfoToEntry(fi *os.FileInfo) (out *EntryOut) {
...
@@ -57,7 +58,7 @@ func (me *fileSystemMount) fileInfoToEntry(fi *os.FileInfo) (out *EntryOut) {
}
}
return
out
return
out
}
}
func
(
me
*
fileSystemMount
)
fileInfoToAttr
(
fi
*
os
.
FileInfo
,
out
*
AttrOut
)
{
func
(
me
*
fileSystemMount
)
fileInfoToAttr
(
fi
*
os
.
FileInfo
,
out
*
AttrOut
)
{
CopyFileInfo
(
fi
,
&
out
.
Attr
)
CopyFileInfo
(
fi
,
&
out
.
Attr
)
SplitNs
(
me
.
options
.
AttrTimeout
,
&
out
.
AttrValid
,
&
out
.
AttrValidNsec
)
SplitNs
(
me
.
options
.
AttrTimeout
,
&
out
.
AttrValid
,
&
out
.
AttrValidNsec
)
...
@@ -94,9 +95,9 @@ func (me *fileSystemMount) registerFileHandle(node *Inode, dir rawDir, f File, f
...
@@ -94,9 +95,9 @@ func (me *fileSystemMount) registerFileHandle(node *Inode, dir rawDir, f File, f
node
.
openFilesMutex
.
Lock
()
node
.
openFilesMutex
.
Lock
()
defer
node
.
openFilesMutex
.
Unlock
()
defer
node
.
openFilesMutex
.
Unlock
()
b
:=
&
openedFile
{
b
:=
&
openedFile
{
dir
:
dir
,
dir
:
dir
,
file
:
f
,
file
:
f
,
OpenFlags
:
flags
,
OpenFlags
:
flags
,
}
}
withFlags
,
ok
:=
f
.
(
*
WithFlags
)
withFlags
,
ok
:=
f
.
(
*
WithFlags
)
...
...
fuse/fsops.go
View file @
83798dc7
...
@@ -11,7 +11,6 @@ import (
...
@@ -11,7 +11,6 @@ import (
var
_
=
log
.
Println
var
_
=
log
.
Println
func
(
me
*
FileSystemConnector
)
Init
(
fsInit
*
RawFsInit
)
{
func
(
me
*
FileSystemConnector
)
Init
(
fsInit
*
RawFsInit
)
{
me
.
fsInit
=
*
fsInit
me
.
fsInit
=
*
fsInit
}
}
...
@@ -60,12 +59,12 @@ func (me *FileSystemConnector) internalLookup(parent *Inode, name string, lookup
...
@@ -60,12 +59,12 @@ func (me *FileSystemConnector) internalLookup(parent *Inode, name string, lookup
}
}
if
child
!=
nil
&&
code
.
Ok
()
{
if
child
!=
nil
&&
code
.
Ok
()
{
out
=
parent
.
mount
.
fileInfoToEntry
(
fi
)
out
=
parent
.
mount
.
fileInfoToEntry
(
fi
)
out
.
NodeId
=
child
.
nodeId
out
.
NodeId
=
child
.
nodeId
out
.
Generation
=
1
out
.
Generation
=
1
return
out
,
OK
,
child
return
out
,
OK
,
child
}
}
fi
,
fsNode
,
code
:=
parent
.
fsInode
.
Lookup
(
name
)
fi
,
fsNode
,
code
:=
parent
.
fsInode
.
Lookup
(
name
)
if
code
==
ENOENT
&&
mount
.
options
.
NegativeTimeout
>
0.0
{
if
code
==
ENOENT
&&
mount
.
options
.
NegativeTimeout
>
0.0
{
return
NegativeEntry
(
mount
.
options
.
NegativeTimeout
),
OK
,
nil
return
NegativeEntry
(
mount
.
options
.
NegativeTimeout
),
OK
,
nil
...
@@ -74,7 +73,7 @@ func (me *FileSystemConnector) internalLookup(parent *Inode, name string, lookup
...
@@ -74,7 +73,7 @@ func (me *FileSystemConnector) internalLookup(parent *Inode, name string, lookup
return
nil
,
code
,
nil
return
nil
,
code
,
nil
}
}
out
,
_
=
me
.
createChild
(
parent
,
name
,
fi
,
fsNode
)
out
,
_
=
me
.
createChild
(
parent
,
name
,
fi
,
fsNode
)
return
out
,
OK
,
node
return
out
,
OK
,
node
}
}
...
@@ -91,7 +90,7 @@ func (me *FileSystemConnector) GetAttr(header *InHeader, input *GetAttrIn) (out
...
@@ -91,7 +90,7 @@ func (me *FileSystemConnector) GetAttr(header *InHeader, input *GetAttrIn) (out
f
=
opened
.
file
f
=
opened
.
file
}
}
}
}
fi
,
code
:=
node
.
fsInode
.
GetAttr
(
f
,
&
header
.
Context
)
fi
,
code
:=
node
.
fsInode
.
GetAttr
(
f
,
&
header
.
Context
)
if
!
code
.
Ok
()
{
if
!
code
.
Ok
()
{
return
nil
,
code
return
nil
,
code
...
@@ -101,7 +100,7 @@ func (me *FileSystemConnector) GetAttr(header *InHeader, input *GetAttrIn) (out
...
@@ -101,7 +100,7 @@ func (me *FileSystemConnector) GetAttr(header *InHeader, input *GetAttrIn) (out
node
.
mount
.
fileInfoToAttr
(
fi
,
out
)
node
.
mount
.
fileInfoToAttr
(
fi
,
out
)
return
out
,
OK
return
out
,
OK
}
}
func
(
me
*
FileSystemConnector
)
OpenDir
(
header
*
InHeader
,
input
*
OpenIn
)
(
flags
uint32
,
handle
uint64
,
code
Status
)
{
func
(
me
*
FileSystemConnector
)
OpenDir
(
header
*
InHeader
,
input
*
OpenIn
)
(
flags
uint32
,
handle
uint64
,
code
Status
)
{
node
:=
me
.
getInodeData
(
header
.
NodeId
)
node
:=
me
.
getInodeData
(
header
.
NodeId
)
stream
,
err
:=
node
.
fsInode
.
OpenDir
(
&
header
.
Context
)
stream
,
err
:=
node
.
fsInode
.
OpenDir
(
&
header
.
Context
)
...
@@ -115,7 +114,7 @@ func (me *FileSystemConnector) OpenDir(header *InHeader, input *OpenIn) (flags u
...
@@ -115,7 +114,7 @@ func (me *FileSystemConnector) OpenDir(header *InHeader, input *OpenIn) (flags u
}
}
de
.
extra
=
append
(
de
.
extra
,
DirEntry
{
S_IFDIR
,
"."
},
DirEntry
{
S_IFDIR
,
".."
})
de
.
extra
=
append
(
de
.
extra
,
DirEntry
{
S_IFDIR
,
"."
},
DirEntry
{
S_IFDIR
,
".."
})
h
,
opened
:=
node
.
mount
.
registerFileHandle
(
node
,
de
,
nil
,
input
.
Flags
)
h
,
opened
:=
node
.
mount
.
registerFileHandle
(
node
,
de
,
nil
,
input
.
Flags
)
// TODO - implement seekable directories
// TODO - implement seekable directories
opened
.
FuseFlags
|=
FOPEN_NONSEEKABLE
opened
.
FuseFlags
|=
FOPEN_NONSEEKABLE
return
opened
.
FuseFlags
,
h
,
OK
return
opened
.
FuseFlags
,
h
,
OK
...
@@ -238,7 +237,6 @@ func (me *FileSystemConnector) Symlink(header *InHeader, pointedTo string, linkN
...
@@ -238,7 +237,6 @@ func (me *FileSystemConnector) Symlink(header *InHeader, pointedTo string, linkN
return
out
,
code
return
out
,
code
}
}
func
(
me
*
FileSystemConnector
)
Rename
(
header
*
InHeader
,
input
*
RenameIn
,
oldName
string
,
newName
string
)
(
code
Status
)
{
func
(
me
*
FileSystemConnector
)
Rename
(
header
*
InHeader
,
input
*
RenameIn
,
oldName
string
,
newName
string
)
(
code
Status
)
{
oldParent
:=
me
.
getInodeData
(
header
.
NodeId
)
oldParent
:=
me
.
getInodeData
(
header
.
NodeId
)
isMountPoint
:=
me
.
lookupMount
(
oldParent
,
oldName
,
0
)
!=
nil
isMountPoint
:=
me
.
lookupMount
(
oldParent
,
oldName
,
0
)
!=
nil
...
@@ -265,7 +263,7 @@ func (me *FileSystemConnector) Link(header *InHeader, input *LinkIn, name string
...
@@ -265,7 +263,7 @@ func (me *FileSystemConnector) Link(header *InHeader, input *LinkIn, name string
if
existing
.
mount
!=
parent
.
mount
{
if
existing
.
mount
!=
parent
.
mount
{
return
nil
,
EXDEV
return
nil
,
EXDEV
}
}
fi
,
fsInode
,
code
:=
parent
.
fsInode
.
Link
(
name
,
existing
.
fsInode
,
&
header
.
Context
)
fi
,
fsInode
,
code
:=
parent
.
fsInode
.
Link
(
name
,
existing
.
fsInode
,
&
header
.
Context
)
if
!
code
.
Ok
()
{
if
!
code
.
Ok
()
{
return
nil
,
code
return
nil
,
code
...
@@ -323,7 +321,7 @@ func (me *FileSystemConnector) GetXAttr(header *InHeader, attribute string) (dat
...
@@ -323,7 +321,7 @@ func (me *FileSystemConnector) GetXAttr(header *InHeader, attribute string) (dat
func
(
me
*
FileSystemConnector
)
RemoveXAttr
(
header
*
InHeader
,
attr
string
)
Status
{
func
(
me
*
FileSystemConnector
)
RemoveXAttr
(
header
*
InHeader
,
attr
string
)
Status
{
node
:=
me
.
getInodeData
(
header
.
NodeId
)
node
:=
me
.
getInodeData
(
header
.
NodeId
)
return
node
.
fsInode
.
RemoveXAttr
(
attr
,
&
header
.
Context
)
return
node
.
fsInode
.
RemoveXAttr
(
attr
,
&
header
.
Context
)
}
}
func
(
me
*
FileSystemConnector
)
SetXAttr
(
header
*
InHeader
,
input
*
SetXAttrIn
,
attr
string
,
data
[]
byte
)
Status
{
func
(
me
*
FileSystemConnector
)
SetXAttr
(
header
*
InHeader
,
input
*
SetXAttrIn
,
attr
string
,
data
[]
byte
)
Status
{
node
:=
me
.
getInodeData
(
header
.
NodeId
)
node
:=
me
.
getInodeData
(
header
.
NodeId
)
...
...
fuse/inode.go
View file @
83798dc7
...
@@ -25,9 +25,9 @@ type Inode struct {
...
@@ -25,9 +25,9 @@ type Inode struct {
treeLock
*
sync
.
RWMutex
treeLock
*
sync
.
RWMutex
// All data below is protected by treeLock.
// All data below is protected by treeLock.
fsInode
FsNode
fsInode
FsNode
children
map
[
string
]
*
Inode
children
map
[
string
]
*
Inode
// Contains directories that function as mounts. The entries
// Contains directories that function as mounts. The entries
// are duplicated in children.
// are duplicated in children.
...
@@ -49,7 +49,7 @@ type Inode struct {
...
@@ -49,7 +49,7 @@ type Inode struct {
// LockTree() Locks the mutex used for tree operations, and returns the
// LockTree() Locks the mutex used for tree operations, and returns the
// unlock function.
// unlock function.
func
(
me
*
Inode
)
LockTree
()
(
func
()
)
{
func
(
me
*
Inode
)
LockTree
()
func
(
)
{
// TODO - this API is tricky.
// TODO - this API is tricky.
me
.
treeLock
.
Lock
()
me
.
treeLock
.
Lock
()
return
func
()
{
me
.
treeLock
.
Unlock
()
}
return
func
()
{
me
.
treeLock
.
Unlock
()
}
...
@@ -59,9 +59,9 @@ func (me *Inode) LockTree() (func()) {
...
@@ -59,9 +59,9 @@ func (me *Inode) LockTree() (func()) {
func
(
me
*
Inode
)
AnyFile
()
(
file
File
)
{
func
(
me
*
Inode
)
AnyFile
()
(
file
File
)
{
me
.
openFilesMutex
.
Lock
()
me
.
openFilesMutex
.
Lock
()
defer
me
.
openFilesMutex
.
Unlock
()
defer
me
.
openFilesMutex
.
Unlock
()
for
_
,
f
:=
range
me
.
openFiles
{
for
_
,
f
:=
range
me
.
openFiles
{
if
file
==
nil
||
f
.
OpenFlags
&
O_ANYWRITE
!=
0
{
if
file
==
nil
||
f
.
OpenFlags
&
O_ANYWRITE
!=
0
{
file
=
f
.
file
file
=
f
.
file
}
}
}
}
...
@@ -82,14 +82,14 @@ func (me *Inode) Children() (out map[string]*Inode) {
...
@@ -82,14 +82,14 @@ func (me *Inode) Children() (out map[string]*Inode) {
func
(
me
*
Inode
)
FsNode
()
FsNode
{
func
(
me
*
Inode
)
FsNode
()
FsNode
{
return
me
.
fsInode
return
me
.
fsInode
}
}
// Returns an open writable file for the given Inode.
// Returns an open writable file for the given Inode.
func
(
me
*
Inode
)
WritableFiles
()
(
files
[]
File
)
{
func
(
me
*
Inode
)
WritableFiles
()
(
files
[]
File
)
{
me
.
openFilesMutex
.
Lock
()
me
.
openFilesMutex
.
Lock
()
defer
me
.
openFilesMutex
.
Unlock
()
defer
me
.
openFilesMutex
.
Unlock
()
for
_
,
f
:=
range
me
.
openFiles
{
for
_
,
f
:=
range
me
.
openFiles
{
if
f
.
OpenFlags
&
O_ANYWRITE
!=
0
{
if
f
.
OpenFlags
&
O_ANYWRITE
!=
0
{
files
=
append
(
files
,
f
.
file
)
files
=
append
(
files
,
f
.
file
)
}
}
}
}
...
@@ -111,12 +111,12 @@ func (me *Inode) CreateChild(name string, isDir bool, fsi FsNode) *Inode {
...
@@ -111,12 +111,12 @@ func (me *Inode) CreateChild(name string, isDir bool, fsi FsNode) *Inode {
}
}
ch
=
me
.
connector
.
newInode
(
isDir
)
ch
=
me
.
connector
.
newInode
(
isDir
)
ch
.
fsInode
=
fsi
ch
.
fsInode
=
fsi
fsi
.
SetInode
(
ch
)
fsi
.
SetInode
(
ch
)
ch
.
mount
=
me
.
mount
ch
.
mount
=
me
.
mount
ch
.
treeLock
=
me
.
treeLock
ch
.
treeLock
=
me
.
treeLock
ch
.
lookupCount
=
1
ch
.
lookupCount
=
1
ch
.
connector
=
me
.
connector
ch
.
connector
=
me
.
connector
me
.
addChild
(
name
,
ch
)
me
.
addChild
(
name
,
ch
)
return
ch
return
ch
}
}
...
@@ -124,7 +124,7 @@ func (me *Inode) CreateChild(name string, isDir bool, fsi FsNode) *Inode {
...
@@ -124,7 +124,7 @@ func (me *Inode) CreateChild(name string, isDir bool, fsi FsNode) *Inode {
func
(
me
*
Inode
)
GetChild
(
name
string
)
(
child
*
Inode
)
{
func
(
me
*
Inode
)
GetChild
(
name
string
)
(
child
*
Inode
)
{
me
.
treeLock
.
Lock
()
me
.
treeLock
.
Lock
()
defer
me
.
treeLock
.
Unlock
()
defer
me
.
treeLock
.
Unlock
()
return
me
.
children
[
name
]
return
me
.
children
[
name
]
}
}
...
@@ -217,7 +217,7 @@ func (me *Inode) verify(cur *fileSystemMount) {
...
@@ -217,7 +217,7 @@ func (me *Inode) verify(cur *fileSystemMount) {
me
.
mountPoint
,
name
,
me
.
children
))
me
.
mountPoint
,
name
,
me
.
children
))
}
}
}
}
for
_
,
ch
:=
range
me
.
children
{
for
_
,
ch
:=
range
me
.
children
{
if
ch
==
nil
{
if
ch
==
nil
{
panic
(
"Found nil child."
)
panic
(
"Found nil child."
)
...
...
fuse/loopback_test.go
View file @
83798dc7
...
@@ -27,13 +27,13 @@ type testCase struct {
...
@@ -27,13 +27,13 @@ type testCase struct {
orig
string
orig
string
mnt
string
mnt
string
mountFile
string
mountFile
string
mountSubdir
string
mountSubdir
string
origFile
string
origFile
string
origSubdir
string
origSubdir
string
tester
*
testing
.
T
tester
*
testing
.
T
state
*
MountState
state
*
MountState
connector
*
FileSystemConnector
connector
*
FileSystemConnector
}
}
const
testTtl
=
0.1
const
testTtl
=
0.1
...
@@ -682,17 +682,17 @@ func TestOriginalIsSymlink(t *testing.T) {
...
@@ -682,17 +682,17 @@ func TestOriginalIsSymlink(t *testing.T) {
}
}
func
TestDoubleOpen
(
t
*
testing
.
T
)
{
func
TestDoubleOpen
(
t
*
testing
.
T
)
{
ts
:=
NewTestCase
(
t
)
ts
:=
NewTestCase
(
t
)
defer
ts
.
Cleanup
()
defer
ts
.
Cleanup
()
err
:=
ioutil
.
WriteFile
(
ts
.
orig
+
"/file"
,
[]
byte
(
"blabla"
),
0644
)
err
:=
ioutil
.
WriteFile
(
ts
.
orig
+
"/file"
,
[]
byte
(
"blabla"
),
0644
)
CheckSuccess
(
err
)
CheckSuccess
(
err
)
roFile
,
err
:=
os
.
Open
(
ts
.
mnt
+
"/file"
)
roFile
,
err
:=
os
.
Open
(
ts
.
mnt
+
"/file"
)
CheckSuccess
(
err
)
CheckSuccess
(
err
)
defer
roFile
.
Close
()
defer
roFile
.
Close
()
rwFile
,
err
:=
os
.
OpenFile
(
ts
.
mnt
+
"/file"
,
os
.
O_WRONLY
|
os
.
O_TRUNC
,
0666
)
rwFile
,
err
:=
os
.
OpenFile
(
ts
.
mnt
+
"/file"
,
os
.
O_WRONLY
|
os
.
O_TRUNC
,
0666
)
CheckSuccess
(
err
)
CheckSuccess
(
err
)
defer
rwFile
.
Close
()
defer
rwFile
.
Close
()
}
}
fuse/pathfs.go
View file @
83798dc7
...
@@ -27,10 +27,10 @@ func (me *PathNodeFs) StatFs() *StatfsOut {
...
@@ -27,10 +27,10 @@ func (me *PathNodeFs) StatFs() *StatfsOut {
func
NewPathNodeFs
(
fs
FileSystem
)
*
PathNodeFs
{
func
NewPathNodeFs
(
fs
FileSystem
)
*
PathNodeFs
{
root
:=
new
(
pathInode
)
root
:=
new
(
pathInode
)
root
.
fs
=
fs
root
.
fs
=
fs
me
:=
&
PathNodeFs
{
me
:=
&
PathNodeFs
{
fs
:
fs
,
fs
:
fs
,
root
:
root
,
root
:
root
,
}
}
root
.
ifs
=
me
root
.
ifs
=
me
return
me
return
me
...
@@ -40,15 +40,14 @@ func (me *PathNodeFs) Root() FsNode {
...
@@ -40,15 +40,14 @@ func (me *PathNodeFs) Root() FsNode {
return
me
.
root
return
me
.
root
}
}
// This is a combination of dentry (entry in the file/directory and
// This is a combination of dentry (entry in the file/directory and
// the inode). This structure is used to implement glue for FSes where
// the inode). This structure is used to implement glue for FSes where
// there is a one-to-one mapping of paths and inodes, ie. FSes that
// there is a one-to-one mapping of paths and inodes, ie. FSes that
// disallow hardlinks.
// disallow hardlinks.
type
pathInode
struct
{
type
pathInode
struct
{
ifs
*
PathNodeFs
ifs
*
PathNodeFs
fs
FileSystem
fs
FileSystem
Name
string
Name
string
// This is nil at the root of the mount.
// This is nil at the root of the mount.
Parent
*
pathInode
Parent
*
pathInode
...
@@ -95,7 +94,7 @@ func (me *pathInode) RmChild(name string, child FsNode) {
...
@@ -95,7 +94,7 @@ func (me *pathInode) RmChild(name string, child FsNode) {
func
(
me
*
pathInode
)
Readlink
(
c
*
Context
)
([]
byte
,
Status
)
{
func
(
me
*
pathInode
)
Readlink
(
c
*
Context
)
([]
byte
,
Status
)
{
path
:=
me
.
GetPath
()
path
:=
me
.
GetPath
()
val
,
err
:=
me
.
fs
.
Readlink
(
path
,
c
)
val
,
err
:=
me
.
fs
.
Readlink
(
path
,
c
)
return
[]
byte
(
val
),
err
return
[]
byte
(
val
),
err
}
}
...
@@ -148,7 +147,7 @@ func (me *pathInode) Mknod(name string, mode uint32, dev uint32, context *Contex
...
@@ -148,7 +147,7 @@ func (me *pathInode) Mknod(name string, mode uint32, dev uint32, context *Contex
}
}
return
return
}
}
func
(
me
*
pathInode
)
Mkdir
(
name
string
,
mode
uint32
,
context
*
Context
)
(
fi
*
os
.
FileInfo
,
newNode
FsNode
,
code
Status
)
{
func
(
me
*
pathInode
)
Mkdir
(
name
string
,
mode
uint32
,
context
*
Context
)
(
fi
*
os
.
FileInfo
,
newNode
FsNode
,
code
Status
)
{
code
=
me
.
fs
.
Mkdir
(
filepath
.
Join
(
me
.
GetPath
(),
name
),
mode
,
context
)
code
=
me
.
fs
.
Mkdir
(
filepath
.
Join
(
me
.
GetPath
(),
name
),
mode
,
context
)
if
code
.
Ok
()
{
if
code
.
Ok
()
{
...
@@ -179,12 +178,11 @@ func (me *pathInode) Symlink(name string, content string, context *Context) (fi
...
@@ -179,12 +178,11 @@ func (me *pathInode) Symlink(name string, content string, context *Context) (fi
return
return
}
}
func
(
me
*
pathInode
)
Rename
(
oldName
string
,
newParent
FsNode
,
newName
string
,
context
*
Context
)
(
code
Status
)
{
func
(
me
*
pathInode
)
Rename
(
oldName
string
,
newParent
FsNode
,
newName
string
,
context
*
Context
)
(
code
Status
)
{
p
:=
newParent
.
(
*
pathInode
)
p
:=
newParent
.
(
*
pathInode
)
oldPath
:=
filepath
.
Join
(
me
.
GetPath
(),
oldName
)
oldPath
:=
filepath
.
Join
(
me
.
GetPath
(),
oldName
)
newPath
:=
filepath
.
Join
(
p
.
GetPath
(),
newName
)
newPath
:=
filepath
.
Join
(
p
.
GetPath
(),
newName
)
return
me
.
fs
.
Rename
(
oldPath
,
newPath
,
context
)
return
me
.
fs
.
Rename
(
oldPath
,
newPath
,
context
)
}
}
...
@@ -202,7 +200,7 @@ func (me *pathInode) Link(name string, existing FsNode, context *Context) (fi *o
...
@@ -202,7 +200,7 @@ func (me *pathInode) Link(name string, existing FsNode, context *Context) (fi *o
}
}
newNode
=
me
.
createChild
(
name
)
newNode
=
me
.
createChild
(
name
)
}
}
return
return
}
}
func
(
me
*
pathInode
)
Create
(
name
string
,
flags
uint32
,
mode
uint32
,
context
*
Context
)
(
file
File
,
fi
*
os
.
FileInfo
,
newNode
FsNode
,
code
Status
)
{
func
(
me
*
pathInode
)
Create
(
name
string
,
flags
uint32
,
mode
uint32
,
context
*
Context
)
(
file
File
,
fi
*
os
.
FileInfo
,
newNode
FsNode
,
code
Status
)
{
...
@@ -211,11 +209,11 @@ func (me *pathInode) Create(name string, flags uint32, mode uint32, context *Con
...
@@ -211,11 +209,11 @@ func (me *pathInode) Create(name string, flags uint32, mode uint32, context *Con
if
code
.
Ok
()
{
if
code
.
Ok
()
{
newNode
=
me
.
createChild
(
name
)
newNode
=
me
.
createChild
(
name
)
fi
=
&
os
.
FileInfo
{
fi
=
&
os
.
FileInfo
{
Mode
:
S_IFREG
|
mode
,
Mode
:
S_IFREG
|
mode
,
// TODO - ctime, mtime, atime?
// TODO - ctime, mtime, atime?
}
}
}
}
return
return
}
}
func
(
me
*
pathInode
)
createChild
(
name
string
)
*
pathInode
{
func
(
me
*
pathInode
)
createChild
(
name
string
)
*
pathInode
{
...
@@ -247,7 +245,7 @@ func (me *pathInode) GetAttr(file File, context *Context) (fi *os.FileInfo, code
...
@@ -247,7 +245,7 @@ func (me *pathInode) GetAttr(file File, context *Context) (fi *os.FileInfo, code
// called on a deleted files.
// called on a deleted files.
file
=
me
.
inode
.
AnyFile
()
file
=
me
.
inode
.
AnyFile
()
}
}
if
file
!=
nil
{
if
file
!=
nil
{
fi
,
code
=
file
.
GetAttr
()
fi
,
code
=
file
.
GetAttr
()
}
}
...
@@ -255,12 +253,12 @@ func (me *pathInode) GetAttr(file File, context *Context) (fi *os.FileInfo, code
...
@@ -255,12 +253,12 @@ func (me *pathInode) GetAttr(file File, context *Context) (fi *os.FileInfo, code
if
file
==
nil
||
code
==
ENOSYS
{
if
file
==
nil
||
code
==
ENOSYS
{
fi
,
code
=
me
.
fs
.
GetAttr
(
me
.
GetPath
(),
context
)
fi
,
code
=
me
.
fs
.
GetAttr
(
me
.
GetPath
(),
context
)
}
}
if
fi
!=
nil
&&
!
fi
.
IsDirectory
()
&&
fi
.
Nlink
==
0
{
if
fi
!=
nil
&&
!
fi
.
IsDirectory
()
&&
fi
.
Nlink
==
0
{
fi
.
Nlink
=
1
fi
.
Nlink
=
1
}
}
return
fi
,
code
return
fi
,
code
}
}
func
(
me
*
pathInode
)
Chmod
(
file
File
,
perms
uint32
,
context
*
Context
)
(
code
Status
)
{
func
(
me
*
pathInode
)
Chmod
(
file
File
,
perms
uint32
,
context
*
Context
)
(
code
Status
)
{
files
:=
me
.
inode
.
WritableFiles
()
files
:=
me
.
inode
.
WritableFiles
()
...
@@ -271,14 +269,13 @@ func (me *pathInode) Chmod(file File, perms uint32, context *Context) (code Stat
...
@@ -271,14 +269,13 @@ func (me *pathInode) Chmod(file File, perms uint32, context *Context) (code Stat
break
break
}
}
}
}
if
len
(
files
)
==
0
||
code
==
ENOSYS
{
if
len
(
files
)
==
0
||
code
==
ENOSYS
{
code
=
me
.
fs
.
Chmod
(
me
.
GetPath
(),
perms
,
context
)
code
=
me
.
fs
.
Chmod
(
me
.
GetPath
(),
perms
,
context
)
}
}
return
code
return
code
}
}
func
(
me
*
pathInode
)
Chown
(
file
File
,
uid
uint32
,
gid
uint32
,
context
*
Context
)
(
code
Status
)
{
func
(
me
*
pathInode
)
Chown
(
file
File
,
uid
uint32
,
gid
uint32
,
context
*
Context
)
(
code
Status
)
{
files
:=
me
.
inode
.
WritableFiles
()
files
:=
me
.
inode
.
WritableFiles
()
for
_
,
f
:=
range
files
{
for
_
,
f
:=
range
files
{
...
...
unionfs/unionfs_test.go
View file @
83798dc7
...
@@ -893,7 +893,7 @@ func TestDoubleOpen(t *testing.T) {
...
@@ -893,7 +893,7 @@ func TestDoubleOpen(t *testing.T) {
roFile
,
err
:=
os
.
Open
(
wd
+
"/mount/file"
)
roFile
,
err
:=
os
.
Open
(
wd
+
"/mount/file"
)
CheckSuccess
(
err
)
CheckSuccess
(
err
)
defer
roFile
.
Close
()
defer
roFile
.
Close
()
rwFile
,
err
:=
os
.
OpenFile
(
wd
+
"/mount/file"
,
os
.
O_WRONLY
|
os
.
O_TRUNC
,
0666
)
rwFile
,
err
:=
os
.
OpenFile
(
wd
+
"/mount/file"
,
os
.
O_WRONLY
|
os
.
O_TRUNC
,
0666
)
CheckSuccess
(
err
)
CheckSuccess
(
err
)
defer
rwFile
.
Close
()
defer
rwFile
.
Close
()
...
@@ -910,7 +910,7 @@ func TestDoubleOpen(t *testing.T) {
...
@@ -910,7 +910,7 @@ func TestDoubleOpen(t *testing.T) {
CheckSuccess
(
err
)
CheckSuccess
(
err
)
b
:=
make
([]
byte
,
100
)
b
:=
make
([]
byte
,
100
)
roFile
.
Seek
(
0
,
0
)
roFile
.
Seek
(
0
,
0
)
n
,
err
:=
roFile
.
Read
(
b
)
n
,
err
:=
roFile
.
Read
(
b
)
CheckSuccess
(
err
)
CheckSuccess
(
err
)
...
@@ -921,4 +921,3 @@ func TestDoubleOpen(t *testing.T) {
...
@@ -921,4 +921,3 @@ func TestDoubleOpen(t *testing.T) {
}
}
}
}
}
}
zipfs/memtree.go
View file @
83798dc7
...
@@ -17,14 +17,13 @@ type memNode struct {
...
@@ -17,14 +17,13 @@ type memNode struct {
file
MemFile
file
MemFile
}
}
// MemTreeFs creates a tree of internal Inodes. Since the tree is
// MemTreeFs creates a tree of internal Inodes. Since the tree is
// loaded in memory completely at startup, it does not need to inode
// loaded in memory completely at startup, it does not need to inode
// discovery through Lookup() at serve time.
// discovery through Lookup() at serve time.
type
MemTreeFs
struct
{
type
MemTreeFs
struct
{
fuse
.
DefaultNodeFileSystem
fuse
.
DefaultNodeFileSystem
root
memNode
root
memNode
files
map
[
string
]
MemFile
files
map
[
string
]
MemFile
}
}
func
NewMemTreeFs
()
*
MemTreeFs
{
func
NewMemTreeFs
()
*
MemTreeFs
{
...
@@ -55,7 +54,7 @@ func (me *memNode) Print(indent int) {
...
@@ -55,7 +54,7 @@ func (me *memNode) Print(indent int) {
fmt
.
Println
(
s
+
k
+
":"
)
fmt
.
Println
(
s
+
k
+
":"
)
mn
,
ok
:=
v
.
FsNode
()
.
(
*
memNode
)
mn
,
ok
:=
v
.
FsNode
()
.
(
*
memNode
)
if
ok
{
if
ok
{
mn
.
Print
(
indent
+
2
)
mn
.
Print
(
indent
+
2
)
}
}
}
else
{
}
else
{
fmt
.
Println
(
s
+
k
)
fmt
.
Println
(
s
+
k
)
...
@@ -96,7 +95,7 @@ func (me *memNode) Open(flags uint32, context *fuse.Context) (fuseFile fuse.File
...
@@ -96,7 +95,7 @@ func (me *memNode) Open(flags uint32, context *fuse.Context) (fuseFile fuse.File
func
(
me
*
memNode
)
GetAttr
(
file
fuse
.
File
,
context
*
fuse
.
Context
)
(
*
os
.
FileInfo
,
fuse
.
Status
)
{
func
(
me
*
memNode
)
GetAttr
(
file
fuse
.
File
,
context
*
fuse
.
Context
)
(
*
os
.
FileInfo
,
fuse
.
Status
)
{
if
me
.
Inode
()
.
IsDir
()
{
if
me
.
Inode
()
.
IsDir
()
{
return
&
os
.
FileInfo
{
return
&
os
.
FileInfo
{
Mode
:
fuse
.
S_IFDIR
|
0777
,
Mode
:
fuse
.
S_IFDIR
|
0777
,
},
fuse
.
OK
},
fuse
.
OK
}
}
...
@@ -114,7 +113,7 @@ func (me *MemTreeFs) addFile(name string, f MemFile) {
...
@@ -114,7 +113,7 @@ func (me *MemTreeFs) addFile(name string, f MemFile) {
if
i
==
len
(
comps
)
-
1
{
if
i
==
len
(
comps
)
-
1
{
fsnode
.
file
=
f
fsnode
.
file
=
f
}
}
ch
=
node
.
CreateChild
(
c
,
fsnode
.
file
==
nil
,
fsnode
)
ch
=
node
.
CreateChild
(
c
,
fsnode
.
file
==
nil
,
fsnode
)
}
}
node
=
ch
node
=
ch
...
...
zipfs/tarfs.go
View file @
83798dc7
...
@@ -44,7 +44,7 @@ func (me *TarFile) Data() []byte {
...
@@ -44,7 +44,7 @@ func (me *TarFile) Data() []byte {
return
me
.
data
return
me
.
data
}
}
func
NewTarTree
(
r
io
.
Reader
)
(
map
[
string
]
MemFile
)
{
func
NewTarTree
(
r
io
.
Reader
)
map
[
string
]
MemFile
{
files
:=
map
[
string
]
MemFile
{}
files
:=
map
[
string
]
MemFile
{}
tr
:=
tar
.
NewReader
(
r
)
tr
:=
tar
.
NewReader
(
r
)
...
@@ -80,8 +80,8 @@ func NewTarTree(r io.Reader) (map[string]MemFile) {
...
@@ -80,8 +80,8 @@ func NewTarTree(r io.Reader) (map[string]MemFile) {
io
.
Copy
(
buf
,
tr
)
io
.
Copy
(
buf
,
tr
)
files
[
hdr
.
Name
]
=
&
TarFile
{
files
[
hdr
.
Name
]
=
&
TarFile
{
Header
:
*
hdr
,
Header
:
*
hdr
,
data
:
buf
.
Bytes
(),
data
:
buf
.
Bytes
(),
}
}
}
}
return
files
return
files
...
...
zipfs/zipfs.go
View file @
83798dc7
...
@@ -33,7 +33,7 @@ func (me *ZipFile) Data() []byte {
...
@@ -33,7 +33,7 @@ func (me *ZipFile) Data() []byte {
panic
(
err
)
panic
(
err
)
}
}
dest
:=
bytes
.
NewBuffer
(
make
([]
byte
,
0
,
me
.
UncompressedSize
))
dest
:=
bytes
.
NewBuffer
(
make
([]
byte
,
0
,
me
.
UncompressedSize
))
_
,
err
=
io
.
Copyn
(
dest
,
rc
,
int64
(
me
.
UncompressedSize
))
_
,
err
=
io
.
Copyn
(
dest
,
rc
,
int64
(
me
.
UncompressedSize
))
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
panic
(
err
)
...
...
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