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
5ee141ce
Commit
5ee141ce
authored
Jun 23, 2013
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use XAttr functions provided by syscall package.
parent
e41b8b68
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
92 deletions
+40
-92
fuse/pathfs/loopback_linux.go
fuse/pathfs/loopback_linux.go
+6
-5
fuse/pathfs/syscall_linux.go
fuse/pathfs/syscall_linux.go
+14
-67
fuse/pathfs/xattr_test.go
fuse/pathfs/xattr_test.go
+20
-20
No files found.
fuse/pathfs/loopback_linux.go
View file @
5ee141ce
...
...
@@ -26,13 +26,14 @@ func (fs *loopbackFileSystem) StatFs(name string) *fuse.StatfsOut {
}
func
(
fs
*
loopbackFileSystem
)
ListXAttr
(
name
string
,
context
*
fuse
.
Context
)
([]
string
,
fuse
.
Status
)
{
data
,
err
No
:=
L
istXAttr
(
fs
.
GetPath
(
name
))
data
,
err
:=
l
istXAttr
(
fs
.
GetPath
(
name
))
return
data
,
fuse
.
Status
(
errNo
)
return
data
,
fuse
.
ToStatus
(
err
)
}
func
(
fs
*
loopbackFileSystem
)
RemoveXAttr
(
name
string
,
attr
string
,
context
*
fuse
.
Context
)
fuse
.
Status
{
return
fuse
.
Status
(
Removexattr
(
fs
.
GetPath
(
name
),
attr
))
err
:=
syscall
.
Removexattr
(
fs
.
GetPath
(
name
),
attr
)
return
fuse
.
ToStatus
(
err
)
}
func
(
fs
*
loopbackFileSystem
)
String
()
string
{
...
...
@@ -41,7 +42,7 @@ func (fs *loopbackFileSystem) String() string {
func
(
fs
*
loopbackFileSystem
)
GetXAttr
(
name
string
,
attr
string
,
context
*
fuse
.
Context
)
([]
byte
,
fuse
.
Status
)
{
data
:=
make
([]
byte
,
1024
)
data
,
err
No
:=
G
etXAttr
(
fs
.
GetPath
(
name
),
attr
,
data
)
data
,
err
:=
g
etXAttr
(
fs
.
GetPath
(
name
),
attr
,
data
)
return
data
,
fuse
.
Status
(
errNo
)
return
data
,
fuse
.
ToStatus
(
err
)
}
fuse/pathfs/syscall_linux.go
View file @
5ee141ce
...
...
@@ -3,62 +3,32 @@ package pathfs
import
(
"bytes"
"syscall"
"unsafe"
)
func
getxattr
(
path
string
,
attr
string
,
dest
[]
byte
)
(
sz
int
,
errno
int
)
{
pathBs
:=
syscall
.
StringBytePtr
(
path
)
attrBs
:=
syscall
.
StringBytePtr
(
attr
)
size
,
_
,
errNo
:=
syscall
.
Syscall6
(
syscall
.
SYS_GETXATTR
,
uintptr
(
unsafe
.
Pointer
(
pathBs
)),
uintptr
(
unsafe
.
Pointer
(
attrBs
)),
uintptr
(
unsafe
.
Pointer
(
&
dest
[
0
])),
uintptr
(
len
(
dest
)),
0
,
0
)
return
int
(
size
),
int
(
errNo
)
}
func
GetXAttr
(
path
string
,
attr
string
,
dest
[]
byte
)
(
value
[]
byte
,
errno
int
)
{
sz
,
errno
:=
getxattr
(
path
,
attr
,
dest
)
for
sz
>
cap
(
dest
)
&&
errno
==
0
{
func
getXAttr
(
path
string
,
attr
string
,
dest
[]
byte
)
(
value
[]
byte
,
err
error
)
{
sz
,
err
:=
syscall
.
Getxattr
(
path
,
attr
,
dest
)
for
sz
>
cap
(
dest
)
&&
err
==
nil
{
dest
=
make
([]
byte
,
sz
)
sz
,
err
no
=
g
etxattr
(
path
,
attr
,
dest
)
sz
,
err
=
syscall
.
G
etxattr
(
path
,
attr
,
dest
)
}
if
err
no
!=
0
{
return
nil
,
err
no
if
err
!=
nil
{
return
nil
,
err
}
return
dest
[
:
sz
],
err
no
return
dest
[
:
sz
],
err
}
func
listxattr
(
path
string
,
dest
[]
byte
)
(
sz
int
,
errno
int
)
{
pathbs
:=
syscall
.
StringBytePtr
(
path
)
var
destPointer
unsafe
.
Pointer
if
len
(
dest
)
>
0
{
destPointer
=
unsafe
.
Pointer
(
&
dest
[
0
])
}
size
,
_
,
errNo
:=
syscall
.
Syscall
(
syscall
.
SYS_LISTXATTR
,
uintptr
(
unsafe
.
Pointer
(
pathbs
)),
uintptr
(
destPointer
),
uintptr
(
len
(
dest
)))
return
int
(
size
),
int
(
errNo
)
}
func
ListXAttr
(
path
string
)
(
attributes
[]
string
,
errno
int
)
{
func
listXAttr
(
path
string
)
(
attributes
[]
string
,
err
error
)
{
dest
:=
make
([]
byte
,
0
)
sz
,
err
no
:=
l
istxattr
(
path
,
dest
)
if
err
no
!=
0
{
return
nil
,
err
no
sz
,
err
:=
syscall
.
L
istxattr
(
path
,
dest
)
if
err
!=
nil
{
return
nil
,
err
}
for
sz
>
cap
(
dest
)
&&
err
no
==
0
{
for
sz
>
cap
(
dest
)
&&
err
==
nil
{
dest
=
make
([]
byte
,
sz
)
sz
,
err
no
=
l
istxattr
(
path
,
dest
)
sz
,
err
=
syscall
.
L
istxattr
(
path
,
dest
)
}
// -1 to drop the final empty slice.
...
...
@@ -68,29 +38,6 @@ func ListXAttr(path string) (attributes []string, errno int) {
for
i
,
v
:=
range
attributesBytes
{
attributes
[
i
]
=
string
(
v
)
}
return
attributes
,
err
no
return
attributes
,
err
}
func
Setxattr
(
path
string
,
attr
string
,
data
[]
byte
,
flags
int
)
(
errno
int
)
{
pathbs
:=
syscall
.
StringBytePtr
(
path
)
attrbs
:=
syscall
.
StringBytePtr
(
attr
)
_
,
_
,
errNo
:=
syscall
.
Syscall6
(
syscall
.
SYS_SETXATTR
,
uintptr
(
unsafe
.
Pointer
(
pathbs
)),
uintptr
(
unsafe
.
Pointer
(
attrbs
)),
uintptr
(
unsafe
.
Pointer
(
&
data
[
0
])),
uintptr
(
len
(
data
)),
uintptr
(
flags
),
0
)
return
int
(
errNo
)
}
func
Removexattr
(
path
string
,
attr
string
)
(
errno
int
)
{
pathbs
:=
syscall
.
StringBytePtr
(
path
)
attrbs
:=
syscall
.
StringBytePtr
(
attr
)
_
,
_
,
errNo
:=
syscall
.
Syscall
(
syscall
.
SYS_REMOVEXATTR
,
uintptr
(
unsafe
.
Pointer
(
pathbs
)),
uintptr
(
unsafe
.
Pointer
(
attrbs
)),
0
)
return
int
(
errNo
)
}
fuse/pathfs/xattr_test.go
View file @
5ee141ce
...
...
@@ -100,9 +100,9 @@ func (fs *XAttrTestFs) RemoveXAttr(name string, attr string, context *fuse.Conte
return
fuse
.
OK
}
func
readXAttr
(
p
,
a
string
)
(
val
[]
byte
,
err
no
int
)
{
func
readXAttr
(
p
,
a
string
)
(
val
[]
byte
,
err
error
)
{
val
=
make
([]
byte
,
1024
)
return
G
etXAttr
(
p
,
a
,
val
)
return
g
etXAttr
(
p
,
a
,
val
)
}
func
xattrTestCase
(
t
*
testing
.
T
,
nm
string
)
(
mountPoint
string
,
cleanup
func
())
{
...
...
@@ -138,8 +138,8 @@ func TestXAttrNoExist(t *testing.T) {
t
.
Error
(
"Unexpected stat error"
,
err
)
}
val
,
err
no
:=
readXAttr
(
mounted
,
"noexist"
)
if
err
no
==
0
{
val
,
err
:=
readXAttr
(
mounted
,
"noexist"
)
if
err
==
nil
{
t
.
Error
(
"Expected GetXAttr error"
,
val
)
}
}
...
...
@@ -150,15 +150,15 @@ func TestXAttrRead(t *testing.T) {
defer
clean
()
mounted
:=
filepath
.
Join
(
mountPoint
,
nm
)
attrs
,
err
no
:=
L
istXAttr
(
mounted
)
attrs
,
err
:=
l
istXAttr
(
mounted
)
readback
:=
make
(
map
[
string
][]
byte
)
if
err
no
!=
0
{
t
.
Error
(
"Unexpected ListXAttr error"
,
err
no
)
if
err
!=
nil
{
t
.
Error
(
"Unexpected ListXAttr error"
,
err
)
}
else
{
for
_
,
a
:=
range
attrs
{
val
,
err
no
:=
readXAttr
(
mounted
,
a
)
if
err
no
!=
0
{
t
.
Errorf
(
"GetXAttr(%q) failed: %v"
,
a
,
syscall
.
Errno
(
errno
)
)
val
,
err
:=
readXAttr
(
mounted
,
a
)
if
err
!=
nil
{
t
.
Errorf
(
"GetXAttr(%q) failed: %v"
,
a
,
err
)
}
readback
[
a
]
=
val
}
...
...
@@ -174,18 +174,18 @@ func TestXAttrRead(t *testing.T) {
}
}
err
no
=
Setxattr
(
mounted
,
"third"
,
[]
byte
(
"value"
),
0
)
if
err
no
!=
0
{
t
.
Error
(
"Setxattr error"
,
err
no
)
err
=
syscall
.
Setxattr
(
mounted
,
"third"
,
[]
byte
(
"value"
),
0
)
if
err
!=
nil
{
t
.
Error
(
"Setxattr error"
,
err
)
}
val
,
err
no
:=
readXAttr
(
mounted
,
"third"
)
if
err
no
!=
0
||
string
(
val
)
!=
"value"
{
t
.
Error
(
"Read back set xattr:"
,
err
no
,
string
(
val
))
val
,
err
:=
readXAttr
(
mounted
,
"third"
)
if
err
!=
nil
||
string
(
val
)
!=
"value"
{
t
.
Error
(
"Read back set xattr:"
,
err
,
string
(
val
))
}
Removexattr
(
mounted
,
"third"
)
val
,
err
no
=
readXAttr
(
mounted
,
"third"
)
if
err
no
!=
int
(
fuse
.
ENODATA
)
{
t
.
Error
(
"Data not removed?"
,
err
no
,
val
)
syscall
.
Removexattr
(
mounted
,
"third"
)
val
,
err
=
readXAttr
(
mounted
,
"third"
)
if
err
!=
syscall
.
ENODATA
{
t
.
Error
(
"Data not removed?"
,
err
,
val
)
}
}
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