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
155e343e
Commit
155e343e
authored
May 20, 2012
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify dirent serialization.
parent
25d1f10b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
30 deletions
+21
-30
fuse/direntry.go
fuse/direntry.go
+21
-30
No files found.
fuse/direntry.go
View file @
155e343e
...
@@ -3,7 +3,6 @@ package fuse
...
@@ -3,7 +3,6 @@ package fuse
// all of the code for DirEntryList.
// all of the code for DirEntryList.
import
(
import
(
"bytes"
"log"
"log"
"unsafe"
"unsafe"
...
@@ -12,6 +11,7 @@ import (
...
@@ -12,6 +11,7 @@ import (
var
_
=
log
.
Print
var
_
=
log
.
Print
var
eightPadding
[
8
]
byte
var
eightPadding
[
8
]
byte
const
direntSize
=
int
(
unsafe
.
Sizeof
(
raw
.
Dirent
{}))
// DirEntry is a type for PathFileSystem and NodeFileSystem to return
// DirEntry is a type for PathFileSystem and NodeFileSystem to return
// directory contents in.
// directory contents in.
...
@@ -21,15 +21,13 @@ type DirEntry struct {
...
@@ -21,15 +21,13 @@ type DirEntry struct {
}
}
type
DirEntryList
struct
{
type
DirEntryList
struct
{
buf
*
bytes
.
Buffer
buf
[]
byte
offset
uint64
offset
uint64
maxSize
int
}
}
func
NewDirEntryList
(
data
[]
byte
,
off
uint64
)
*
DirEntryList
{
func
NewDirEntryList
(
data
[]
byte
,
off
uint64
)
*
DirEntryList
{
return
&
DirEntryList
{
return
&
DirEntryList
{
buf
:
bytes
.
NewBuffer
(
data
[
:
0
]),
buf
:
data
[
:
0
],
maxSize
:
len
(
data
),
offset
:
off
,
offset
:
off
,
}
}
}
}
...
@@ -39,41 +37,34 @@ func (l *DirEntryList) AddDirEntry(e DirEntry) bool {
...
@@ -39,41 +37,34 @@ func (l *DirEntryList) AddDirEntry(e DirEntry) bool {
}
}
func
(
l
*
DirEntryList
)
Add
(
name
string
,
inode
uint64
,
mode
uint32
)
bool
{
func
(
l
*
DirEntryList
)
Add
(
name
string
,
inode
uint64
,
mode
uint32
)
bool
{
dirent
:=
raw
.
Dirent
{
padding
:=
(
8
-
len
(
name
)
&
7
)
&
7
Off
:
l
.
offset
+
1
,
delta
:=
padding
+
direntSize
+
len
(
name
)
Ino
:
inode
,
oldLen
:=
len
(
l
.
buf
)
NameLen
:
uint32
(
len
(
name
)),
newLen
:=
delta
+
oldLen
Typ
:
ModeToType
(
mode
),
}
padding
:=
8
-
len
(
name
)
&
7
if
newLen
>
cap
(
l
.
buf
)
{
if
padding
==
8
{
padding
=
0
}
delta
:=
padding
+
int
(
unsafe
.
Sizeof
(
raw
.
Dirent
{}))
+
len
(
name
)
newLen
:=
delta
+
l
.
buf
.
Len
()
if
newLen
>
l
.
maxSize
{
return
false
return
false
}
}
_
,
err
:=
l
.
buf
.
Write
(
asSlice
(
unsafe
.
Pointer
(
&
dirent
),
unsafe
.
Sizeof
(
raw
.
Dirent
{})))
l
.
buf
=
l
.
buf
[
:
newLen
]
if
err
!=
nil
{
dirent
:=
(
*
raw
.
Dirent
)(
unsafe
.
Pointer
(
&
l
.
buf
[
oldLen
]))
panic
(
"Serialization of Dirent failed"
)
dirent
.
Off
=
l
.
offset
+
1
}
dirent
.
Ino
=
inode
l
.
buf
.
WriteString
(
name
)
dirent
.
NameLen
=
uint32
(
len
(
name
))
dirent
.
Typ
=
ModeToType
(
mode
)
oldLen
+=
direntSize
copy
(
l
.
buf
[
oldLen
:
],
name
)
oldLen
+=
len
(
name
)
if
padding
>
0
{
if
padding
>
0
{
l
.
buf
.
Write
(
eightPadding
[
:
padding
])
copy
(
l
.
buf
[
oldLen
:
],
eightPadding
[
:
padding
])
}
}
l
.
offset
=
dirent
.
Off
l
.
offset
=
dirent
.
Off
if
l
.
buf
.
Len
()
!=
newLen
{
log
.
Panicf
(
"newLen mismatch %d %d"
,
l
.
buf
.
Len
(),
newLen
)
}
return
true
return
true
}
}
func
(
l
*
DirEntryList
)
Bytes
()
[]
byte
{
func
(
l
*
DirEntryList
)
Bytes
()
[]
byte
{
return
l
.
buf
.
Bytes
()
return
l
.
buf
}
}
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
...
...
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