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
67e4fbbc
Commit
67e4fbbc
authored
Dec 14, 2015
by
Aaron Jacobs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added memFS.MkNode.
parent
47638fa8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
12 deletions
+29
-12
samples/memfs/memfs.go
samples/memfs/memfs.go
+29
-12
No files found.
samples/memfs/memfs.go
View file @
67e4fbbc
...
@@ -305,28 +305,37 @@ func (fs *memFS) MkDir(
...
@@ -305,28 +305,37 @@ func (fs *memFS) MkDir(
return
return
}
}
func
(
fs
*
memFS
)
CreateFil
e
(
func
(
fs
*
memFS
)
MkNod
e
(
ctx
context
.
Context
,
ctx
context
.
Context
,
op
*
fuseops
.
CreateFil
eOp
)
(
err
error
)
{
op
*
fuseops
.
MkNod
eOp
)
(
err
error
)
{
fs
.
mu
.
Lock
()
fs
.
mu
.
Lock
()
defer
fs
.
mu
.
Unlock
()
defer
fs
.
mu
.
Unlock
()
op
.
Entry
,
err
=
fs
.
createFile
(
op
.
Parent
,
op
.
Name
,
op
.
Mode
)
return
}
// LOCKS_REQUIRED(fs.mu)
func
(
fs
*
memFS
)
createFile
(
parentID
fuseops
.
InodeID
,
name
string
,
mode
os
.
FileMode
)
(
entry
fuseops
.
ChildInodeEntry
,
err
error
)
{
// Grab the parent, which we will update shortly.
// Grab the parent, which we will update shortly.
parent
:=
fs
.
getInodeOrDie
(
op
.
Parent
)
parent
:=
fs
.
getInodeOrDie
(
parentID
)
// Ensure that the name doesn't already exist, so we don't wind up with a
// Ensure that the name doesn't already exist, so we don't wind up with a
// duplicate.
// duplicate.
_
,
_
,
exists
:=
parent
.
LookUpChild
(
op
.
N
ame
)
_
,
_
,
exists
:=
parent
.
LookUpChild
(
n
ame
)
if
exists
{
if
exists
{
err
=
fuse
.
EEXIST
err
=
fuse
.
EEXIST
return
return
}
}
// Set up attributes f
rom
the child.
// Set up attributes f
or
the child.
now
:=
time
.
Now
()
now
:=
time
.
Now
()
childAttrs
:=
fuseops
.
InodeAttributes
{
childAttrs
:=
fuseops
.
InodeAttributes
{
Nlink
:
1
,
Nlink
:
1
,
Mode
:
op
.
M
ode
,
Mode
:
m
ode
,
Atime
:
now
,
Atime
:
now
,
Mtime
:
now
,
Mtime
:
now
,
Ctime
:
now
,
Ctime
:
now
,
...
@@ -339,19 +348,27 @@ func (fs *memFS) CreateFile(
...
@@ -339,19 +348,27 @@ func (fs *memFS) CreateFile(
childID
,
child
:=
fs
.
allocateInode
(
childAttrs
)
childID
,
child
:=
fs
.
allocateInode
(
childAttrs
)
// Add an entry in the parent.
// Add an entry in the parent.
parent
.
AddChild
(
childID
,
op
.
N
ame
,
fuseutil
.
DT_File
)
parent
.
AddChild
(
childID
,
n
ame
,
fuseutil
.
DT_File
)
// Fill in the response entry.
// Fill in the response entry.
op
.
E
ntry
.
Child
=
childID
e
ntry
.
Child
=
childID
op
.
E
ntry
.
Attributes
=
child
.
attrs
e
ntry
.
Attributes
=
child
.
attrs
// We don't spontaneously mutate, so the kernel can cache as long as it wants
// We don't spontaneously mutate, so the kernel can cache as long as it wants
// (since it also handles invalidation).
// (since it also handles invalidation).
op
.
Entry
.
AttributesExpiration
=
time
.
Now
()
.
Add
(
365
*
24
*
time
.
Hour
)
entry
.
AttributesExpiration
=
time
.
Now
()
.
Add
(
365
*
24
*
time
.
Hour
)
op
.
Entry
.
EntryExpiration
=
op
.
Entry
.
EntryExpiration
entry
.
EntryExpiration
=
entry
.
AttributesExpiration
return
}
// We have nothing interesting to put in the Handle field.
func
(
fs
*
memFS
)
CreateFile
(
ctx
context
.
Context
,
op
*
fuseops
.
CreateFileOp
)
(
err
error
)
{
fs
.
mu
.
Lock
()
defer
fs
.
mu
.
Unlock
()
op
.
Entry
,
err
=
fs
.
createFile
(
op
.
Parent
,
op
.
Name
,
op
.
Mode
)
return
return
}
}
...
...
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