Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
c52a4ac4
Commit
c52a4ac4
authored
Jun 24, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
1df9b3eb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
4 deletions
+41
-4
go/wcsrv/t/t.go
go/wcsrv/t/t.go
+41
-4
No files found.
go/wcsrv/t/t.go
View file @
c52a4ac4
...
@@ -2,8 +2,10 @@ package main
...
@@ -2,8 +2,10 @@ package main
import
(
import
(
"flag"
"flag"
"fmt"
"log"
"log"
"os"
"os"
"time"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/fuse/nodefs"
...
@@ -21,11 +23,14 @@ type file struct {
...
@@ -21,11 +23,14 @@ type file struct {
// fileHandle represents opened file.
// fileHandle represents opened file.
type
fileHandle
struct
{
type
fileHandle
struct
{
nodefs
.
File
content
[]
byte
}
}
func
(
d
*
dir
)
Lookup
(
out
*
fuse
.
Attr
,
name
string
,
ctx
*
fuse
.
Context
)
(
*
nodefs
.
Inode
,
fuse
.
Status
)
{
func
(
d
*
dir
)
Lookup
(
out
*
fuse
.
Attr
,
name
string
,
_
*
fuse
.
Context
)
(
*
nodefs
.
Inode
,
fuse
.
Status
)
{
ientry
:=
d
.
Inode
()
.
GetChild
(
name
)
ientry
:=
d
.
Inode
()
.
GetChild
(
name
)
if
ientry
==
nil
{
if
ientry
==
nil
{
return
nil
,
fuse
.
ENOENT
return
nil
,
fuse
.
ENOENT
...
@@ -34,6 +39,39 @@ func (d *dir) Lookup(out *fuse.Attr, name string, ctx *fuse.Context) (*nodefs.In
...
@@ -34,6 +39,39 @@ func (d *dir) Lookup(out *fuse.Attr, name string, ctx *fuse.Context) (*nodefs.In
return
ientry
,
fuse
.
OK
return
ientry
,
fuse
.
OK
}
}
var
nopen
=
0
func
(
f
*
file
)
Open
(
flags
uint32
,
_
*
fuse
.
Context
)
(
nodefs
.
File
,
fuse
.
Status
)
{
_
,
name
:=
f
.
Inode
()
.
Parent
()
nopen
++
// XXX -> atomic
data
:=
fmt
.
Sprintf
(
"%04d %s
\n
"
,
nopen
,
name
)
h
:=
&
fileHandle
{
File
:
nodefs
.
NewDefaultFile
(),
content
:
[]
byte
(
data
)}
// force direct-io to disable pagecache: we alway return different data
// and st_size=0 (like in /proc).
return
&
nodefs
.
WithFlags
{
File
:
h
,
FuseFlags
:
fuse
.
FOPEN_DIRECT_IO
,
},
fuse
.
OK
}
func
(
fh
*
fileHandle
)
Read
(
dest
[]
byte
,
off
int64
)
(
fuse
.
ReadResult
,
fuse
.
Status
)
{
l
:=
int64
(
len
(
dest
))
// XXX demonstrate we can indeed serve different content to different openings.
if
l
>=
1
{
l
=
1
time
.
Sleep
(
1
*
time
.
Second
)
}
end
:=
off
+
l
if
ldata
:=
int64
(
len
(
fh
.
content
));
end
>
ldata
{
end
=
ldata
}
res
:=
fh
.
content
[
off
:
end
]
fmt
.
Printf
(
"read [%d:%d] -> %q
\n
"
,
off
,
end
,
res
)
return
fuse
.
ReadResultData
(
res
),
fuse
.
OK
}
func
(
d
*
dir
)
mkdir
(
name
string
)
*
dir
{
func
(
d
*
dir
)
mkdir
(
name
string
)
*
dir
{
...
@@ -57,9 +95,6 @@ func main() {
...
@@ -57,9 +95,6 @@ func main() {
}
}
mntpt
:=
flag
.
Args
()[
0
]
mntpt
:=
flag
.
Args
()[
0
]
root
:=
&
dir
{
Node
:
nodefs
.
NewDefaultNode
()}
root
:=
&
dir
{
Node
:
nodefs
.
NewDefaultNode
()}
//nodefs.NewInode(true, root)
//println(root.Inode())
opts
:=
nodefs
.
NewOptions
()
opts
:=
nodefs
.
NewOptions
()
if
*
debug
{
if
*
debug
{
opts
.
Debug
=
true
opts
.
Debug
=
true
...
@@ -69,6 +104,8 @@ func main() {
...
@@ -69,6 +104,8 @@ func main() {
log
.
Fatal
(
err
)
// XXX err ctx?
log
.
Fatal
(
err
)
// XXX err ctx?
}
}
// NOTE cannot make entries before mount because Inode.AddChild does
// not work before that (panics on nil deref to mountRootXXX)
root
.
mkdir
(
"aaa"
)
root
.
mkdir
(
"aaa"
)
root
.
mkfile
(
"hello.txt"
)
root
.
mkfile
(
"hello.txt"
)
...
...
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