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
0a5037fa
Commit
0a5037fa
authored
Apr 01, 2019
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
example/hello: convert hello to new nodefs API
parent
f5e4c658
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
34 deletions
+24
-34
example/hello/main.go
example/hello/main.go
+24
-34
No files found.
example/hello/main.go
View file @
0a5037fa
...
...
@@ -7,59 +7,49 @@
package
main
import
(
"context"
"flag"
"log"
"syscall"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/fuse/pathfs"
"github.com/hanwen/go-fuse/nodefs"
)
type
Hello
Fs
struct
{
pathfs
.
FileSystem
type
Hello
Root
struct
{
nodefs
.
Inode
}
func
(
me
*
HelloFs
)
GetAttr
(
name
string
,
context
*
fuse
.
Context
)
(
*
fuse
.
Attr
,
fuse
.
Status
)
{
switch
name
{
case
"file.txt"
:
return
&
fuse
.
Attr
{
Mode
:
fuse
.
S_IFREG
|
0644
,
Size
:
uint64
(
len
(
name
)),
},
fuse
.
OK
case
""
:
return
&
fuse
.
Attr
{
Mode
:
fuse
.
S_IFDIR
|
0755
,
},
fuse
.
OK
}
return
nil
,
fuse
.
ENOENT
func
(
r
*
HelloRoot
)
OnAdd
(
ctx
context
.
Context
)
{
ch
:=
r
.
NewPersistentInode
(
ctx
,
&
nodefs
.
MemRegularFile
{
Data
:
[]
byte
(
"file.txt"
),
Attr
:
fuse
.
Attr
{
Mode
:
0644
,
},
},
nodefs
.
NodeAttr
{
Ino
:
2
})
r
.
AddChild
(
"file.txt"
,
ch
,
false
)
}
func
(
me
*
HelloFs
)
OpenDir
(
name
string
,
context
*
fuse
.
Context
)
(
c
[]
fuse
.
DirEntry
,
code
fuse
.
Status
)
{
if
name
==
""
{
c
=
[]
fuse
.
DirEntry
{{
Name
:
"file.txt"
,
Mode
:
fuse
.
S_IFREG
}}
return
c
,
fuse
.
OK
}
return
nil
,
fuse
.
ENOENT
func
(
r
*
HelloRoot
)
Getattr
(
ctx
context
.
Context
,
fh
nodefs
.
FileHandle
,
out
*
fuse
.
AttrOut
)
syscall
.
Errno
{
out
.
Mode
=
0755
return
0
}
func
(
me
*
HelloFs
)
Open
(
name
string
,
flags
uint32
,
context
*
fuse
.
Context
)
(
file
nodefs
.
File
,
code
fuse
.
Status
)
{
if
name
!=
"file.txt"
{
return
nil
,
fuse
.
ENOENT
}
if
flags
&
fuse
.
O_ANYWRITE
!=
0
{
return
nil
,
fuse
.
EPERM
}
return
nodefs
.
NewDataFile
([]
byte
(
name
)),
fuse
.
OK
}
var
_
=
(
nodefs
.
Getattrer
)((
*
HelloRoot
)(
nil
))
var
_
=
(
nodefs
.
OnAdder
)((
*
HelloRoot
)(
nil
))
func
main
()
{
debug
:=
flag
.
Bool
(
"debug"
,
false
,
"print debug data"
)
flag
.
Parse
()
if
len
(
flag
.
Args
())
<
1
{
log
.
Fatal
(
"Usage:
\n
hello MOUNTPOINT"
)
}
nfs
:=
pathfs
.
NewPathNodeFs
(
&
HelloFs
{
FileSystem
:
pathfs
.
NewDefaultFileSystem
()},
nil
)
server
,
_
,
err
:=
nodefs
.
MountRoot
(
flag
.
Arg
(
0
),
nfs
.
Root
(),
nil
)
opts
:=
&
nodefs
.
Options
{}
opts
.
Debug
=
*
debug
server
,
err
:=
nodefs
.
Mount
(
flag
.
Arg
(
0
),
&
HelloRoot
{},
opts
)
if
err
!=
nil
{
log
.
Fatalf
(
"Mount fail: %v
\n
"
,
err
)
}
server
.
Serve
()
server
.
Wait
()
}
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