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
a5b08ac7
Commit
a5b08ac7
authored
Apr 04, 2019
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nodefs: implement Setattr in loopback
parent
928afa1c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
0 deletions
+94
-0
nodefs/loopback.go
nodefs/loopback.go
+73
-0
nodefs/simple_test.go
nodefs/simple_test.go
+21
-0
No files found.
nodefs/loopback.go
View file @
a5b08ac7
...
...
@@ -295,6 +295,79 @@ func (n *loopbackNode) Getattr(ctx context.Context, f FileHandle, out *fuse.Attr
return
OK
}
var
_
=
(
Setattrer
)((
*
loopbackNode
)(
nil
))
func
(
n
*
loopbackNode
)
Setattr
(
ctx
context
.
Context
,
f
FileHandle
,
in
*
fuse
.
SetAttrIn
,
out
*
fuse
.
AttrOut
)
syscall
.
Errno
{
p
:=
n
.
path
()
fsa
,
ok
:=
f
.
(
FileSetattrer
)
if
ok
&&
fsa
!=
nil
{
fsa
.
Setattr
(
ctx
,
in
,
out
)
}
else
{
if
m
,
ok
:=
in
.
GetMode
();
ok
{
if
err
:=
syscall
.
Chmod
(
p
,
m
);
err
!=
nil
{
return
ToErrno
(
err
)
}
}
uid
,
uok
:=
in
.
GetUID
()
gid
,
gok
:=
in
.
GetGID
()
if
uok
||
gok
{
suid
:=
-
1
sgid
:=
-
1
if
uok
{
suid
=
int
(
uid
)
}
if
gok
{
sgid
=
int
(
gid
)
}
if
err
:=
syscall
.
Chown
(
p
,
suid
,
sgid
);
err
!=
nil
{
return
ToErrno
(
err
)
}
}
mtime
,
mok
:=
in
.
GetMTime
()
atime
,
aok
:=
in
.
GetATime
()
if
mok
||
aok
{
ap
:=
&
atime
mp
:=
&
mtime
if
!
aok
{
ap
=
nil
}
if
!
mok
{
mp
=
nil
}
var
ts
[
2
]
syscall
.
Timespec
ts
[
0
]
=
fuse
.
UtimeToTimespec
(
ap
)
ts
[
1
]
=
fuse
.
UtimeToTimespec
(
mp
)
if
err
:=
syscall
.
UtimesNano
(
p
,
ts
[
:
]);
err
!=
nil
{
return
ToErrno
(
err
)
}
}
if
sz
,
ok
:=
in
.
GetSize
();
ok
{
if
err
:=
syscall
.
Truncate
(
p
,
int64
(
sz
));
err
!=
nil
{
return
ToErrno
(
err
)
}
}
}
fga
,
ok
:=
f
.
(
FileGetattrer
)
if
ok
&&
fga
!=
nil
{
fga
.
Getattr
(
ctx
,
out
)
}
else
{
st
:=
syscall
.
Stat_t
{}
err
:=
syscall
.
Lstat
(
p
,
&
st
)
if
err
!=
nil
{
return
ToErrno
(
err
)
}
out
.
FromStat
(
&
st
)
}
return
OK
}
// NewLoopback returns a root node for a loopback file system whose
// root is at the given root.
func
NewLoopbackRoot
(
root
string
)
(
InodeEmbedder
,
error
)
{
...
...
nodefs/simple_test.go
View file @
a5b08ac7
...
...
@@ -589,3 +589,24 @@ func TestMknod(t *testing.T) {
})
}
}
func
TestTruncate
(
t
*
testing
.
T
)
{
tc
:=
newTestCase
(
t
,
false
,
false
)
defer
tc
.
Clean
()
if
err
:=
ioutil
.
WriteFile
(
tc
.
origDir
+
"/file"
,
[]
byte
(
"hello"
),
0644
);
err
!=
nil
{
t
.
Errorf
(
"WriteFile: %v"
,
err
)
}
if
err
:=
syscall
.
Truncate
(
tc
.
mntDir
+
"/file"
,
1
);
err
!=
nil
{
t
.
Fatalf
(
"Truncate: %v"
,
err
)
}
var
st
syscall
.
Stat_t
if
err
:=
syscall
.
Lstat
(
tc
.
mntDir
+
"/file"
,
&
st
);
err
!=
nil
{
t
.
Fatalf
(
"Lstat: %v"
,
err
)
}
if
st
.
Size
!=
1
{
t
.
Errorf
(
"got size %d, want 1"
,
st
.
Size
)
}
}
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