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
400d74db
Commit
400d74db
authored
Mar 03, 2015
by
Aaron Jacobs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented inode.RemoveChild.
parent
621df57d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
7 deletions
+31
-7
samples/memfs/inode.go
samples/memfs/inode.go
+31
-7
No files found.
samples/memfs/inode.go
View file @
400d74db
...
...
@@ -38,7 +38,8 @@ type inode struct {
// INVARIANT: If !dir, then os.ModeDir is not set
attributes
fuse
.
InodeAttributes
// GUARDED_BY(mu)
// For directories, entries describing the children of the directory.
// For directories, entries describing the children of the directory. Unused
// entries are of type DT_Unknown.
//
// This array can never be shortened, nor can its elements be moved, because
// we use its indices for Dirent.Offset, which is exposed to the user who
...
...
@@ -50,7 +51,7 @@ type inode struct {
//
// INVARIANT: If dir is false, this is nil.
// INVARIANT: For each i, entries[i].Offset == i+1
// INVARIANT: Contains no duplicate names.
// INVARIANT: Contains no duplicate names
in used entries
.
entries
[]
fuseutil
.
Dirent
// GUARDED_BY(mu)
// For files, the current contents of the file.
...
...
@@ -100,6 +101,7 @@ func (inode *inode) checkInvariants() {
panic
(
fmt
.
Sprintf
(
"Unexpected offset: %v"
,
e
.
Offset
))
}
if
e
.
Type
!=
fuseutil
.
DT_Unknown
{
if
_
,
ok
:=
childNames
[
e
.
Name
];
ok
{
panic
(
fmt
.
Sprintf
(
"Duplicate name: %s"
,
e
.
Name
))
}
...
...
@@ -107,6 +109,7 @@ func (inode *inode) checkInvariants() {
childNames
[
e
.
Name
]
=
struct
{}{}
}
}
}
// Check file-specific stuff.
if
!
inode
.
dir
{
...
...
@@ -156,6 +159,7 @@ func (inode *inode) LookUpChild(name string) (id fuse.InodeID, ok bool) {
// Add an entry for a child.
//
// REQUIRES: inode.dir
// REQUIRES: dt != fuseutil.DT_Unknown
// EXCLUSIVE_LOCKS_REQUIRED(inode.mu)
func
(
inode
*
inode
)
AddChild
(
id
fuse
.
InodeID
,
...
...
@@ -169,6 +173,8 @@ func (inode *inode) AddChild(
}
inode
.
entries
=
append
(
inode
.
entries
,
e
)
// TODO(jacobsa): Re-use gaps.
}
// Remove an entry for a child.
...
...
@@ -176,7 +182,18 @@ func (inode *inode) AddChild(
// REQUIRES: inode.dir
// REQUIRES: An entry for the given name exists.
// EXCLUSIVE_LOCKS_REQUIRED(inode.mu)
func
(
inode
*
inode
)
RemoveChild
(
name
string
)
func
(
inode
*
inode
)
RemoveChild
(
name
string
)
{
// Find the entry.
i
,
ok
:=
inode
.
findChild
(
name
)
if
!
ok
{
panic
(
fmt
.
Sprintf
(
"Unknown child: %s"
,
name
))
}
// Mark it as unused.
inode
.
entries
[
i
]
=
fuseutil
.
Dirent
{
Type
:
fuseutil
.
DT_Unknown
,
}
}
// Serve a ReadDir request.
//
...
...
@@ -188,6 +205,13 @@ func (inode *inode) ReadDir(offset int, size int) (data []byte, err error) {
}
for
i
:=
offset
;
i
<
len
(
inode
.
entries
);
i
++
{
e
:=
inode
.
entries
[
i
]
// Skip unused entries.
if
e
.
Type
==
fuseutil
.
DT_Unknown
{
continue
}
data
=
fuseutil
.
AppendDirent
(
data
,
inode
.
entries
[
i
])
// Trim and stop early if we've exceeded the requested 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