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
5610b3e4
Commit
5610b3e4
authored
Aug 14, 2010
by
Ivan Krasin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FileSystem.GetAttr has now easy arguments. Return value is still hard
parent
34b6d99b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
14 deletions
+49
-14
fuse/fuse.go
fuse/fuse.go
+46
-11
fuse/fuse_test.go
fuse/fuse_test.go
+3
-3
No files found.
fuse/fuse.go
View file @
5610b3e4
...
@@ -16,7 +16,7 @@ const (
...
@@ -16,7 +16,7 @@ const (
type
FileSystem
interface
{
type
FileSystem
interface
{
List
(
parent
string
)
(
names
[]
string
,
code
Error
,
err
os
.
Error
)
List
(
parent
string
)
(
names
[]
string
,
code
Error
,
err
os
.
Error
)
Lookup
(
parent
,
filename
string
)
(
out
*
Attr
,
code
Error
,
err
os
.
Error
)
Lookup
(
parent
,
filename
string
)
(
out
*
Attr
,
code
Error
,
err
os
.
Error
)
GetAttr
(
h
*
InHeader
,
in
*
GetAttrIn
)
(
out
*
AttrOut
,
code
Error
,
err
os
.
Error
)
GetAttr
(
path
string
,
id
*
Identity
,
flags
uint32
)
(
out
*
AttrOut
,
code
Error
,
err
os
.
Error
)
}
}
type
Mounted
interface
{
type
Mounted
interface
{
...
@@ -41,7 +41,7 @@ func loop(f *os.File, fs FileSystem, errors chan os.Error) {
...
@@ -41,7 +41,7 @@ func loop(f *os.File, fs FileSystem, errors chan os.Error) {
go
writer
(
f
,
toW
,
errors
)
go
writer
(
f
,
toW
,
errors
)
managerReq
:=
make
(
chan
*
managerRequest
,
100
)
managerReq
:=
make
(
chan
*
managerRequest
,
100
)
startManager
(
fs
,
managerReq
)
startManager
(
fs
,
managerReq
)
c
:=
&
managerClient
{
managerReq
}
c
:=
&
managerClient
{
managerReq
}
defer
close
(
managerReq
)
defer
close
(
managerReq
)
for
{
for
{
n
,
err
:=
f
.
Read
(
buf
)
n
,
err
:=
f
.
Read
(
buf
)
...
@@ -166,10 +166,21 @@ func getAttr(fs FileSystem, h *InHeader, r io.Reader, c *managerClient) (data []
...
@@ -166,10 +166,21 @@ func getAttr(fs FileSystem, h *InHeader, r io.Reader, c *managerClient) (data []
}
}
fmt
.
Printf
(
"FUSE_GETATTR: %v, Fh: %d
\n
"
,
in
,
in
.
Fh
)
fmt
.
Printf
(
"FUSE_GETATTR: %v, Fh: %d
\n
"
,
in
,
in
.
Fh
)
var
out
*
AttrOut
var
out
*
AttrOut
out
,
res
,
err
:=
fs
.
GetAttr
(
h
,
in
)
resp
:=
c
.
getPath
(
in
.
Fh
)
if
resp
.
err
!=
nil
{
err
=
resp
.
err
return
}
if
resp
.
code
!=
OK
{
return
serialize
(
h
,
resp
.
code
,
nil
)
}
out
,
res
,
err
:=
fs
.
GetAttr
(
resp
.
path
,
&
h
.
Identity
,
in
.
GetAttrFlags
)
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
if
out
!=
nil
{
out
.
Ino
=
h
.
NodeId
}
data
,
err
=
serialize
(
h
,
res
,
out
)
data
,
err
=
serialize
(
h
,
res
,
out
)
return
return
}
}
...
@@ -319,6 +330,7 @@ const (
...
@@ -319,6 +330,7 @@ const (
getHandleOp
=
FileOp
(
2
)
getHandleOp
=
FileOp
(
2
)
closeDirOp
=
FileOp
(
3
)
closeDirOp
=
FileOp
(
3
)
lookupOp
=
FileOp
(
4
)
lookupOp
=
FileOp
(
4
)
getPathOp
=
FileOp
(
5
)
)
)
type
managerRequest
struct
{
type
managerRequest
struct
{
...
@@ -336,17 +348,18 @@ type managerResponse struct {
...
@@ -336,17 +348,18 @@ type managerResponse struct {
err
os
.
Error
err
os
.
Error
code
Error
code
Error
attr
*
Attr
attr
*
Attr
path
string
}
}
type
dirEntry
struct
{
type
dirEntry
struct
{
nodeId
uint64
nodeId
uint64
name
string
name
string
mode
uint32
mode
uint32
}
}
type
dirRequest
struct
{
type
dirRequest
struct
{
isClose
bool
isClose
bool
nodeId
uint64
nodeId
uint64
offset
uint64
offset
uint64
resp
chan
*
dirResponse
resp
chan
*
dirResponse
}
}
...
@@ -364,7 +377,7 @@ type dirHandle struct {
...
@@ -364,7 +377,7 @@ type dirHandle struct {
type
manager
struct
{
type
manager
struct
{
fs
FileSystem
fs
FileSystem
client
*
managerClient
client
*
managerClient
dirHandles
map
[
uint64
]
*
dirHandle
dirHandles
map
[
uint64
]
*
dirHandle
cnt
uint64
cnt
uint64
nodes
map
[
uint64
]
string
nodes
map
[
uint64
]
string
...
@@ -375,7 +388,7 @@ type manager struct {
...
@@ -375,7 +388,7 @@ type manager struct {
func
startManager
(
fs
FileSystem
,
requests
chan
*
managerRequest
)
{
func
startManager
(
fs
FileSystem
,
requests
chan
*
managerRequest
)
{
m
:=
new
(
manager
)
m
:=
new
(
manager
)
m
.
fs
=
fs
m
.
fs
=
fs
m
.
client
=
&
managerClient
{
requests
}
m
.
client
=
&
managerClient
{
requests
}
m
.
dirHandles
=
make
(
map
[
uint64
]
*
dirHandle
)
m
.
dirHandles
=
make
(
map
[
uint64
]
*
dirHandle
)
m
.
nodes
=
make
(
map
[
uint64
]
string
)
m
.
nodes
=
make
(
map
[
uint64
]
string
)
m
.
nodes
[
1
]
=
""
// Root
m
.
nodes
[
1
]
=
""
// Root
...
@@ -410,6 +423,10 @@ func (c *managerClient) getDirReader(nodeId, fh uint64) (resp *managerResponse)
...
@@ -410,6 +423,10 @@ func (c *managerClient) getDirReader(nodeId, fh uint64) (resp *managerResponse)
return
c
.
makeManagerRequest
(
nodeId
,
fh
,
getHandleOp
,
""
)
return
c
.
makeManagerRequest
(
nodeId
,
fh
,
getHandleOp
,
""
)
}
}
func
(
c
*
managerClient
)
getPath
(
fh
uint64
)
(
resp
*
managerResponse
)
{
return
c
.
makeManagerRequest
(
0
,
fh
,
getPathOp
,
""
)
}
func
(
c
*
managerClient
)
closeDir
(
nodeId
,
fh
uint64
)
(
resp
*
managerResponse
)
{
func
(
c
*
managerClient
)
closeDir
(
nodeId
,
fh
uint64
)
(
resp
*
managerResponse
)
{
return
c
.
makeManagerRequest
(
nodeId
,
fh
,
closeDirOp
,
""
)
return
c
.
makeManagerRequest
(
nodeId
,
fh
,
closeDirOp
,
""
)
}
}
...
@@ -426,6 +443,8 @@ func (m *manager) run(requests chan *managerRequest) {
...
@@ -426,6 +443,8 @@ func (m *manager) run(requests chan *managerRequest) {
resp
=
m
.
closeDir
(
req
)
resp
=
m
.
closeDir
(
req
)
case
lookupOp
:
case
lookupOp
:
resp
=
m
.
lookup
(
req
)
resp
=
m
.
lookup
(
req
)
case
getPathOp
:
resp
=
m
.
getPath
(
req
)
default
:
default
:
resp
:=
new
(
managerResponse
)
resp
:=
new
(
managerResponse
)
resp
.
err
=
os
.
NewError
(
fmt
.
Sprintf
(
"Unknown FileOp: %v"
,
req
.
op
))
resp
.
err
=
os
.
NewError
(
fmt
.
Sprintf
(
"Unknown FileOp: %v"
,
req
.
op
))
...
@@ -506,6 +525,22 @@ func (m *manager) lookup(req *managerRequest) (resp *managerResponse) {
...
@@ -506,6 +525,22 @@ func (m *manager) lookup(req *managerRequest) (resp *managerResponse) {
return
return
}
}
func
(
m
*
manager
)
getPath
(
req
*
managerRequest
)
(
resp
*
managerResponse
)
{
resp
=
new
(
managerResponse
)
h
,
ok
:=
m
.
dirHandles
[
req
.
fh
]
if
!
ok
{
resp
.
err
=
os
.
NewError
(
fmt
.
Sprintf
(
"Can't find fh: %d"
,
req
.
fh
))
return
}
path
,
ok
:=
m
.
nodes
[
h
.
nodeId
]
if
!
ok
{
resp
.
err
=
os
.
NewError
(
fmt
.
Sprintf
(
"Fh = %d points to unknown nodeId: %d"
,
req
.
fh
,
h
.
nodeId
))
return
}
resp
.
path
=
path
return
}
func
readDirRoutine
(
dir
string
,
fs
FileSystem
,
c
*
managerClient
,
requests
chan
*
dirRequest
)
{
func
readDirRoutine
(
dir
string
,
fs
FileSystem
,
c
*
managerClient
,
requests
chan
*
dirRequest
)
{
defer
close
(
requests
)
defer
close
(
requests
)
dir
=
path
.
Clean
(
dir
)
dir
=
path
.
Clean
(
dir
)
...
@@ -513,11 +548,11 @@ func readDirRoutine(dir string, fs FileSystem, c *managerClient, requests chan *
...
@@ -513,11 +548,11 @@ func readDirRoutine(dir string, fs FileSystem, c *managerClient, requests chan *
i
:=
uint64
(
0
)
i
:=
uint64
(
0
)
for
req
:=
range
requests
{
for
req
:=
range
requests
{
if
err
!=
nil
{
if
err
!=
nil
{
req
.
resp
<-
&
dirResponse
{
nil
,
err
}
req
.
resp
<-
&
dirResponse
{
nil
,
err
}
return
return
}
}
if
code
!=
OK
{
if
code
!=
OK
{
req
.
resp
<-
&
dirResponse
{
nil
,
os
.
NewError
(
fmt
.
Sprintf
(
"fs.List returned code: %d"
,
code
))}
req
.
resp
<-
&
dirResponse
{
nil
,
os
.
NewError
(
fmt
.
Sprintf
(
"fs.List returned code: %d"
,
code
))}
return
return
}
}
if
req
.
offset
!=
i
{
if
req
.
offset
!=
i
{
...
@@ -532,7 +567,7 @@ func readDirRoutine(dir string, fs FileSystem, c *managerClient, requests chan *
...
@@ -532,7 +567,7 @@ func readDirRoutine(dir string, fs FileSystem, c *managerClient, requests chan *
entry
.
name
=
names
[
i
]
entry
.
name
=
names
[
i
]
lookupResp
:=
c
.
lookup
(
req
.
nodeId
,
entry
.
name
)
lookupResp
:=
c
.
lookup
(
req
.
nodeId
,
entry
.
name
)
if
lookupResp
.
err
!=
nil
{
if
lookupResp
.
err
!=
nil
{
req
.
resp
<-
&
dirResponse
{
nil
,
lookupResp
.
err
}
req
.
resp
<-
&
dirResponse
{
nil
,
lookupResp
.
err
}
return
return
}
}
entry
.
nodeId
=
lookupResp
.
nodeId
entry
.
nodeId
=
lookupResp
.
nodeId
...
...
fuse/fuse_test.go
View file @
5610b3e4
...
@@ -13,15 +13,15 @@ import (
...
@@ -13,15 +13,15 @@ import (
const
(
const
(
tempMountDir
=
"./.testMountDir"
tempMountDir
=
"./.testMountDir"
)
)
var
(
var
(
testFileNames
=
[]
string
{
"one"
,
"two"
,
"three3"
}
testFileNames
=
[]
string
{
"one"
,
"two"
,
"three3"
}
)
)
type
testFuse
struct
{}
type
testFuse
struct
{}
func
(
fs
*
testFuse
)
GetAttr
(
h
*
InHeader
,
in
*
GetAttrIn
)
(
out
*
AttrOut
,
code
Error
,
err
os
.
Error
)
{
func
(
fs
*
testFuse
)
GetAttr
(
path
string
,
id
*
Identity
,
flags
uint32
)
(
out
*
AttrOut
,
code
Error
,
err
os
.
Error
)
{
out
=
new
(
AttrOut
)
out
=
new
(
AttrOut
)
out
.
Ino
=
h
.
NodeId
out
.
Mode
=
S_IFDIR
out
.
Mode
=
S_IFDIR
return
return
}
}
...
...
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