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
Hide 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 @@
...
@@ -7,59 +7,49 @@
package
main
package
main
import
(
import
(
"context"
"flag"
"flag"
"log"
"log"
"syscall"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/nodefs"
"github.com/hanwen/go-fuse/fuse/pathfs"
)
)
type
Hello
Fs
struct
{
type
Hello
Root
struct
{
pathfs
.
FileSystem
nodefs
.
Inode
}
}
func
(
me
*
HelloFs
)
GetAttr
(
name
string
,
context
*
fuse
.
Context
)
(
*
fuse
.
Attr
,
fuse
.
Status
)
{
func
(
r
*
HelloRoot
)
OnAdd
(
ctx
context
.
Context
)
{
switch
name
{
ch
:=
r
.
NewPersistentInode
(
case
"file.txt"
:
ctx
,
&
nodefs
.
MemRegularFile
{
return
&
fuse
.
Attr
{
Data
:
[]
byte
(
"file.txt"
),
Mode
:
fuse
.
S_IFREG
|
0644
,
Size
:
uint64
(
len
(
name
)),
Attr
:
fuse
.
Attr
{
},
fuse
.
OK
Mode
:
0644
,
case
""
:
},
return
&
fuse
.
Attr
{
},
nodefs
.
NodeAttr
{
Ino
:
2
})
Mode
:
fuse
.
S_IFDIR
|
0755
,
r
.
AddChild
(
"file.txt"
,
ch
,
false
)
},
fuse
.
OK
}
return
nil
,
fuse
.
ENOENT
}
}
func
(
me
*
HelloFs
)
OpenDir
(
name
string
,
context
*
fuse
.
Context
)
(
c
[]
fuse
.
DirEntry
,
code
fuse
.
Status
)
{
func
(
r
*
HelloRoot
)
Getattr
(
ctx
context
.
Context
,
fh
nodefs
.
FileHandle
,
out
*
fuse
.
AttrOut
)
syscall
.
Errno
{
if
name
==
""
{
out
.
Mode
=
0755
c
=
[]
fuse
.
DirEntry
{{
Name
:
"file.txt"
,
Mode
:
fuse
.
S_IFREG
}}
return
0
return
c
,
fuse
.
OK
}
return
nil
,
fuse
.
ENOENT
}
}
func
(
me
*
HelloFs
)
Open
(
name
string
,
flags
uint32
,
context
*
fuse
.
Context
)
(
file
nodefs
.
File
,
code
fuse
.
Status
)
{
var
_
=
(
nodefs
.
Getattrer
)((
*
HelloRoot
)(
nil
))
if
name
!=
"file.txt"
{
var
_
=
(
nodefs
.
OnAdder
)((
*
HelloRoot
)(
nil
))
return
nil
,
fuse
.
ENOENT
}
if
flags
&
fuse
.
O_ANYWRITE
!=
0
{
return
nil
,
fuse
.
EPERM
}
return
nodefs
.
NewDataFile
([]
byte
(
name
)),
fuse
.
OK
}
func
main
()
{
func
main
()
{
debug
:=
flag
.
Bool
(
"debug"
,
false
,
"print debug data"
)
flag
.
Parse
()
flag
.
Parse
()
if
len
(
flag
.
Args
())
<
1
{
if
len
(
flag
.
Args
())
<
1
{
log
.
Fatal
(
"Usage:
\n
hello MOUNTPOINT"
)
log
.
Fatal
(
"Usage:
\n
hello MOUNTPOINT"
)
}
}
nfs
:=
pathfs
.
NewPathNodeFs
(
&
HelloFs
{
FileSystem
:
pathfs
.
NewDefaultFileSystem
()},
nil
)
opts
:=
&
nodefs
.
Options
{}
server
,
_
,
err
:=
nodefs
.
MountRoot
(
flag
.
Arg
(
0
),
nfs
.
Root
(),
nil
)
opts
.
Debug
=
*
debug
server
,
err
:=
nodefs
.
Mount
(
flag
.
Arg
(
0
),
&
HelloRoot
{},
opts
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatalf
(
"Mount fail: %v
\n
"
,
err
)
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