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
Kirill Smelkov
go-fuse
Commits
5af9ce62
Commit
5af9ce62
authored
Sep 25, 2011
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Memnode: serve attributes completely from memory.
parent
fa9d6f17
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
13 deletions
+47
-13
fuse/memnode.go
fuse/memnode.go
+40
-13
fuse/memnode_test.go
fuse/memnode_test.go
+7
-0
No files found.
fuse/memnode.go
View file @
5af9ce62
...
...
@@ -125,7 +125,32 @@ func (me *memNode) Create(name string, flags uint32, mode uint32, context *Conte
return
nil
,
nil
,
nil
,
OsErrorToErrno
(
err
)
}
me
.
Inode
()
.
AddChild
(
name
,
n
.
Inode
())
return
&
LoopbackFile
{
File
:
f
},
&
n
.
info
,
n
,
OK
return
n
.
newFile
(
f
),
&
n
.
info
,
n
,
OK
}
type
memNodeFile
struct
{
LoopbackFile
node
*
memNode
}
func
(
me
*
memNodeFile
)
InnerFile
()
File
{
return
&
me
.
LoopbackFile
}
func
(
me
*
memNodeFile
)
Flush
()
Status
{
code
:=
me
.
LoopbackFile
.
Flush
()
fi
,
_
:=
me
.
LoopbackFile
.
GetAttr
()
me
.
node
.
info
.
Size
=
fi
.
Size
me
.
node
.
info
.
Blocks
=
fi
.
Blocks
log
.
Println
(
"reset size"
,
me
.
node
.
info
.
Size
,
me
.
node
.
Inode
()
.
nodeId
)
return
code
}
func
(
me
*
memNode
)
newFile
(
f
*
os
.
File
)
File
{
return
&
memNodeFile
{
LoopbackFile
:
LoopbackFile
{
File
:
f
},
node
:
me
,
}
}
func
(
me
*
memNode
)
Open
(
flags
uint32
,
context
*
Context
)
(
file
File
,
code
Status
)
{
...
...
@@ -134,14 +159,11 @@ func (me *memNode) Open(flags uint32, context *Context) (file File, code Status)
return
nil
,
OsErrorToErrno
(
err
)
}
return
&
LoopbackFile
{
File
:
f
}
,
OK
return
me
.
newFile
(
f
)
,
OK
}
func
(
me
*
memNode
)
GetAttr
(
file
File
,
context
*
Context
)
(
fi
*
os
.
FileInfo
,
code
Status
)
{
if
me
.
info
.
Mode
&
S_IFREG
!=
0
{
fi
,
err
:=
os
.
Lstat
(
me
.
filename
())
return
fi
,
OsErrorToErrno
(
err
)
}
return
&
me
.
info
,
OK
}
...
...
@@ -150,22 +172,27 @@ func (me *memNode) Truncate(file File, size uint64, context *Context) (code Stat
return
file
.
Truncate
(
size
)
}
me
.
info
.
Size
=
int64
(
size
)
err
:=
os
.
Truncate
(
me
.
filename
(),
int64
(
size
))
return
OsErrorToErrno
(
err
)
}
func
(
me
*
memNode
)
Utimens
(
file
File
,
atime
uint64
,
mtime
uint64
,
context
*
Context
)
(
code
Status
)
{
if
file
!=
nil
{
return
file
.
Utimens
(
atime
,
mtime
)
}
if
me
.
info
.
Mode
&
S_IFREG
!=
0
{
err
:=
os
.
Chtimes
(
me
.
filename
(),
int64
(
atime
),
int64
(
mtime
))
return
OsErrorToErrno
(
err
)
}
me
.
info
.
Atime_ns
=
int64
(
atime
)
me
.
info
.
Mtime_ns
=
int64
(
mtime
)
return
OK
}
func
(
me
*
memNode
)
Chmod
(
file
File
,
perms
uint32
,
context
*
Context
)
(
code
Status
)
{
me
.
info
.
Mode
=
(
me
.
info
.
Mode
^
07777
)
|
perms
return
OK
}
func
(
me
*
memNode
)
Chown
(
file
File
,
uid
uint32
,
gid
uint32
,
context
*
Context
)
(
code
Status
)
{
me
.
info
.
Uid
=
int
(
uid
)
me
.
info
.
Gid
=
int
(
gid
)
return
OK
}
fuse/memnode_test.go
View file @
5af9ce62
...
...
@@ -47,9 +47,16 @@ func TestMemNodeFs(t *testing.T) {
err
:=
ioutil
.
WriteFile
(
wd
+
"/test"
,
[]
byte
{
42
},
0644
)
CheckSuccess
(
err
)
fi
,
err
:=
os
.
Lstat
(
wd
+
"/test"
)
CheckSuccess
(
err
)
if
fi
.
Size
!=
1
{
t
.
Errorf
(
"Size after write incorrect: got %d want 1"
,
fi
.
Size
)
}
entries
,
err
:=
ioutil
.
ReadDir
(
wd
)
log
.
Println
(
entries
)
if
len
(
entries
)
!=
1
||
entries
[
0
]
.
Name
!=
"test"
{
t
.
Fatalf
(
"Readdir got %v, expected 1 file named 'test'"
,
entries
)
}
}
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