Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jacobsa-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
Kirill Smelkov
jacobsa-fuse
Commits
eca0a376
Commit
eca0a376
authored
Mar 24, 2015
by
Aaron Jacobs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored hellofs.
parent
5a839727
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
11 deletions
+38
-11
samples/hellofs/hello_fs.go
samples/hellofs/hello_fs.go
+38
-11
No files found.
samples/hellofs/hello_fs.go
View file @
eca0a376
...
...
@@ -25,17 +25,44 @@ import (
"github.com/jacobsa/fuse/fuseutil"
)
//
A
file system with a fixed structure that looks like this:
//
Create a
file system with a fixed structure that looks like this:
//
// hello
// dir/
// world
//
// Each file contains the string "Hello, world!".
type
HelloFS
struct
{
func
NewHelloFS
(
clock
timeutil
.
Clock
)
(
server
fuse
.
Server
,
err
error
)
{
fs
:=
&
helloFS
{
Clock
:
clock
,
}
server
=
fuse
.
Server
(
fs
.
serve
)
return
}
type
helloFS
struct
{
Clock
timeutil
.
Clock
}
func
(
fs
*
helloFS
)
serve
(
c
*
fuse
.
Connection
)
{
for
{
op
,
err
:=
c
.
ReadOp
()
if
err
==
io
.
EOF
{
break
}
if
err
!=
nil
{
panic
(
err
)
}
switch
typed
:=
op
.
(
type
)
{
default
:
typed
.
Respond
(
fuse
.
ENOSYS
)
}
}
}
const
(
rootInode
fuseops
.
InodeID
=
fuseops
.
RootInodeID
+
iota
helloInode
...
...
@@ -128,7 +155,7 @@ func findChildInode(
return
}
func
(
fs
*
H
elloFS
)
patchAttributes
(
func
(
fs
*
h
elloFS
)
patchAttributes
(
attr
*
fuseops
.
InodeAttributes
)
{
now
:=
fs
.
Clock
.
Now
()
attr
.
Atime
=
now
...
...
@@ -136,11 +163,11 @@ func (fs *HelloFS) patchAttributes(
attr
.
Crtime
=
now
}
func
(
fs
*
H
elloFS
)
init
(
op
*
fuseops
.
InitOp
)
{
func
(
fs
*
h
elloFS
)
init
(
op
*
fuseops
.
InitOp
)
{
op
.
Respond
(
nil
)
}
func
(
fs
*
H
elloFS
)
lookUpInode
(
op
*
fuseops
.
LookUpInodeOp
)
{
func
(
fs
*
h
elloFS
)
lookUpInode
(
op
*
fuseops
.
LookUpInodeOp
)
{
var
err
error
defer
func
()
{
op
.
Respond
(
err
)
}()
...
...
@@ -167,7 +194,7 @@ func (fs *HelloFS) lookUpInode(op *fuseops.LookUpInodeOp) {
return
}
func
(
fs
*
H
elloFS
)
getInodeAttributes
(
op
*
fuseops
.
GetInodeAttributesOp
)
{
func
(
fs
*
h
elloFS
)
getInodeAttributes
(
op
*
fuseops
.
GetInodeAttributesOp
)
{
var
err
error
defer
func
()
{
op
.
Respond
(
err
)
}()
...
...
@@ -187,12 +214,12 @@ func (fs *HelloFS) getInodeAttributes(op *fuseops.GetInodeAttributesOp) {
return
}
func
(
fs
*
H
elloFS
)
openDir
(
op
*
fuseops
.
OpenDirOp
)
{
func
(
fs
*
h
elloFS
)
openDir
(
op
*
fuseops
.
OpenDirOp
)
{
// Allow opening any directory.
op
.
Respond
(
nil
)
}
func
(
fs
*
H
elloFS
)
readDir
(
op
fuseops
.
ReadDirOp
)
{
func
(
fs
*
h
elloFS
)
readDir
(
op
fuseops
.
ReadDirOp
)
{
var
err
error
defer
func
()
{
op
.
Respond
(
err
)
}()
...
...
@@ -211,7 +238,7 @@ func (fs *HelloFS) readDir(op fuseops.ReadDirOp) {
entries
:=
info
.
children
// Grab the range of interest.
if
op
.
Offset
>
fuse
.
DirOffset
(
len
(
entries
))
{
if
op
.
Offset
>
fuse
ops
.
DirOffset
(
len
(
entries
))
{
err
=
fuse
.
EIO
return
}
...
...
@@ -230,12 +257,12 @@ func (fs *HelloFS) readDir(op fuseops.ReadDirOp) {
return
}
func
(
fs
*
H
elloFS
)
openFile
(
op
*
fuseops
.
OpenFileOp
)
{
func
(
fs
*
h
elloFS
)
openFile
(
op
*
fuseops
.
OpenFileOp
)
{
// Allow opening any file.
op
.
Respond
(
nil
)
}
func
(
fs
*
H
elloFS
)
readFile
(
op
*
fuseops
.
ReadFileOp
)
{
func
(
fs
*
h
elloFS
)
readFile
(
op
*
fuseops
.
ReadFileOp
)
{
var
err
error
defer
func
()
{
op
.
Respond
(
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