Fixed names.
parent
ccac11385f
commit
6fdbd3c0c2
|
@ -131,7 +131,7 @@ func (in *inode) checkInvariants() {
|
||||||
|
|
||||||
// INVARIANT: Contains no duplicate names in used entries.
|
// INVARIANT: Contains no duplicate names in used entries.
|
||||||
childNames := make(map[string]struct{})
|
childNames := make(map[string]struct{})
|
||||||
for i, e := range inode.entries {
|
for i, e := range in.entries {
|
||||||
if e.Type != fuseutil.DT_Unknown {
|
if e.Type != fuseutil.DT_Unknown {
|
||||||
if _, ok := childNames[e.Name]; ok {
|
if _, ok := childNames[e.Name]; ok {
|
||||||
panic(fmt.Sprintf("Duplicate name: %s", e.Name))
|
panic(fmt.Sprintf("Duplicate name: %s", e.Name))
|
||||||
|
@ -175,10 +175,10 @@ func (in *inode) isFile() bool {
|
||||||
|
|
||||||
// Return the number of children of the directory.
|
// Return the number of children of the directory.
|
||||||
//
|
//
|
||||||
// REQUIRES: inode.dir
|
// REQUIRES: in.isDir()
|
||||||
// SHARED_LOCKS_REQUIRED(inode.mu)
|
// SHARED_LOCKS_REQUIRED(in.mu)
|
||||||
func (inode *inode) Len() (n int) {
|
func (in *inode) Len() (n int) {
|
||||||
for _, e := range inode.entries {
|
for _, e := range in.entries {
|
||||||
if e.Type != fuseutil.DT_Unknown {
|
if e.Type != fuseutil.DT_Unknown {
|
||||||
n++
|
n++
|
||||||
}
|
}
|
||||||
|
@ -189,12 +189,12 @@ func (inode *inode) Len() (n int) {
|
||||||
|
|
||||||
// Find an entry for the given child name and return its inode ID.
|
// Find an entry for the given child name and return its inode ID.
|
||||||
//
|
//
|
||||||
// REQUIRES: inode.dir
|
// REQUIRES: in.isDir()
|
||||||
// SHARED_LOCKS_REQUIRED(inode.mu)
|
// SHARED_LOCKS_REQUIRED(in.mu)
|
||||||
func (inode *inode) LookUpChild(name string) (id fuseops.InodeID, ok bool) {
|
func (in *inode) LookUpChild(name string) (id fuseops.InodeID, ok bool) {
|
||||||
index, ok := inode.findChild(name)
|
index, ok := in.findChild(name)
|
||||||
if ok {
|
if ok {
|
||||||
id = inode.entries[index].Inode
|
id = in.entries[index].Inode
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -202,22 +202,22 @@ func (inode *inode) LookUpChild(name string) (id fuseops.InodeID, ok bool) {
|
||||||
|
|
||||||
// Add an entry for a child.
|
// Add an entry for a child.
|
||||||
//
|
//
|
||||||
// REQUIRES: inode.dir
|
// REQUIRES: in.isDir()
|
||||||
// REQUIRES: dt != fuseutil.DT_Unknown
|
// REQUIRES: dt != fuseutil.DT_Unknown
|
||||||
// EXCLUSIVE_LOCKS_REQUIRED(inode.mu)
|
// EXCLUSIVE_LOCKS_REQUIRED(in.mu)
|
||||||
func (inode *inode) AddChild(
|
func (in *inode) AddChild(
|
||||||
id fuseops.InodeID,
|
id fuseops.InodeID,
|
||||||
name string,
|
name string,
|
||||||
dt fuseutil.DirentType) {
|
dt fuseutil.DirentType) {
|
||||||
var index int
|
var index int
|
||||||
|
|
||||||
// Update the modification time.
|
// Update the modification time.
|
||||||
inode.attributes.Mtime = inode.clock.Now()
|
in.attributes.Mtime = in.clock.Now()
|
||||||
|
|
||||||
// No matter where we place the entry, make sure it has the correct Offset
|
// No matter where we place the entry, make sure it has the correct Offset
|
||||||
// field.
|
// field.
|
||||||
defer func() {
|
defer func() {
|
||||||
inode.entries[index].Offset = fuseops.DirOffset(index + 1)
|
in.entries[index].Offset = fuseops.DirOffset(index + 1)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Set up the entry.
|
// Set up the entry.
|
||||||
|
@ -228,35 +228,35 @@ func (inode *inode) AddChild(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look for a gap in which we can insert it.
|
// Look for a gap in which we can insert it.
|
||||||
for index = range inode.entries {
|
for index = range in.entries {
|
||||||
if inode.entries[index].Type == fuseutil.DT_Unknown {
|
if in.entries[index].Type == fuseutil.DT_Unknown {
|
||||||
inode.entries[index] = e
|
in.entries[index] = e
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append it to the end.
|
// Append it to the end.
|
||||||
index = len(inode.entries)
|
index = len(in.entries)
|
||||||
inode.entries = append(inode.entries, e)
|
in.entries = append(in.entries, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove an entry for a child.
|
// Remove an entry for a child.
|
||||||
//
|
//
|
||||||
// REQUIRES: inode.dir
|
// REQUIRES: in.isDir()
|
||||||
// REQUIRES: An entry for the given name exists.
|
// REQUIRES: An entry for the given name exists.
|
||||||
// EXCLUSIVE_LOCKS_REQUIRED(inode.mu)
|
// EXCLUSIVE_LOCKS_REQUIRED(in.mu)
|
||||||
func (inode *inode) RemoveChild(name string) {
|
func (in *inode) RemoveChild(name string) {
|
||||||
// Update the modification time.
|
// Update the modification time.
|
||||||
inode.attributes.Mtime = inode.clock.Now()
|
in.attributes.Mtime = in.clock.Now()
|
||||||
|
|
||||||
// Find the entry.
|
// Find the entry.
|
||||||
i, ok := inode.findChild(name)
|
i, ok := in.findChild(name)
|
||||||
if !ok {
|
if !ok {
|
||||||
panic(fmt.Sprintf("Unknown child: %s", name))
|
panic(fmt.Sprintf("Unknown child: %s", name))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark it as unused.
|
// Mark it as unused.
|
||||||
inode.entries[i] = fuseutil.Dirent{
|
in.entries[i] = fuseutil.Dirent{
|
||||||
Type: fuseutil.DT_Unknown,
|
Type: fuseutil.DT_Unknown,
|
||||||
Offset: fuseops.DirOffset(i + 1),
|
Offset: fuseops.DirOffset(i + 1),
|
||||||
}
|
}
|
||||||
|
@ -264,22 +264,22 @@ func (inode *inode) RemoveChild(name string) {
|
||||||
|
|
||||||
// Serve a ReadDir request.
|
// Serve a ReadDir request.
|
||||||
//
|
//
|
||||||
// REQUIRES: inode.dir
|
// REQUIRES: in.isDir()
|
||||||
// SHARED_LOCKS_REQUIRED(inode.mu)
|
// SHARED_LOCKS_REQUIRED(in.mu)
|
||||||
func (inode *inode) ReadDir(offset int, size int) (data []byte, err error) {
|
func (in *inode) ReadDir(offset int, size int) (data []byte, err error) {
|
||||||
if !inode.dir {
|
if !in.dir {
|
||||||
panic("ReadDir called on non-directory.")
|
panic("ReadDir called on non-directory.")
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := offset; i < len(inode.entries); i++ {
|
for i := offset; i < len(in.entries); i++ {
|
||||||
e := inode.entries[i]
|
e := in.entries[i]
|
||||||
|
|
||||||
// Skip unused entries.
|
// Skip unused entries.
|
||||||
if e.Type == fuseutil.DT_Unknown {
|
if e.Type == fuseutil.DT_Unknown {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
data = fuseutil.AppendDirent(data, inode.entries[i])
|
data = fuseutil.AppendDirent(data, in.entries[i])
|
||||||
|
|
||||||
// Trim and stop early if we've exceeded the requested size.
|
// Trim and stop early if we've exceeded the requested size.
|
||||||
if len(data) > size {
|
if len(data) > size {
|
||||||
|
@ -293,21 +293,21 @@ func (inode *inode) ReadDir(offset int, size int) (data []byte, err error) {
|
||||||
|
|
||||||
// Read from the file's contents. See documentation for ioutil.ReaderAt.
|
// Read from the file's contents. See documentation for ioutil.ReaderAt.
|
||||||
//
|
//
|
||||||
// REQUIRES: !inode.dir
|
// REQUIRES: in.isFile()
|
||||||
// SHARED_LOCKS_REQUIRED(inode.mu)
|
// SHARED_LOCKS_REQUIRED(in.mu)
|
||||||
func (inode *inode) ReadAt(p []byte, off int64) (n int, err error) {
|
func (in *inode) ReadAt(p []byte, off int64) (n int, err error) {
|
||||||
if inode.dir {
|
if in.dir {
|
||||||
panic("ReadAt called on directory.")
|
panic("ReadAt called on directory.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the offset is in range.
|
// Ensure the offset is in range.
|
||||||
if off > int64(len(inode.contents)) {
|
if off > int64(len(in.contents)) {
|
||||||
err = io.EOF
|
err = io.EOF
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read what we can.
|
// Read what we can.
|
||||||
n = copy(p, inode.contents[off:])
|
n = copy(p, in.contents[off:])
|
||||||
if n < len(p) {
|
if n < len(p) {
|
||||||
err = io.EOF
|
err = io.EOF
|
||||||
}
|
}
|
||||||
|
@ -317,26 +317,26 @@ func (inode *inode) ReadAt(p []byte, off int64) (n int, err error) {
|
||||||
|
|
||||||
// Write to the file's contents. See documentation for ioutil.WriterAt.
|
// Write to the file's contents. See documentation for ioutil.WriterAt.
|
||||||
//
|
//
|
||||||
// REQUIRES: !inode.dir
|
// REQUIRES: in.isFile()
|
||||||
// EXCLUSIVE_LOCKS_REQUIRED(inode.mu)
|
// EXCLUSIVE_LOCKS_REQUIRED(in.mu)
|
||||||
func (inode *inode) WriteAt(p []byte, off int64) (n int, err error) {
|
func (in *inode) WriteAt(p []byte, off int64) (n int, err error) {
|
||||||
if inode.dir {
|
if in.dir {
|
||||||
panic("WriteAt called on directory.")
|
panic("WriteAt called on directory.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the modification time.
|
// Update the modification time.
|
||||||
inode.attributes.Mtime = inode.clock.Now()
|
in.attributes.Mtime = in.clock.Now()
|
||||||
|
|
||||||
// Ensure that the contents slice is long enough.
|
// Ensure that the contents slice is long enough.
|
||||||
newLen := int(off) + len(p)
|
newLen := int(off) + len(p)
|
||||||
if len(inode.contents) < newLen {
|
if len(in.contents) < newLen {
|
||||||
padding := make([]byte, newLen-len(inode.contents))
|
padding := make([]byte, newLen-len(in.contents))
|
||||||
inode.contents = append(inode.contents, padding...)
|
in.contents = append(in.contents, padding...)
|
||||||
inode.attributes.Size = uint64(newLen)
|
in.attributes.Size = uint64(newLen)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy in the data.
|
// Copy in the data.
|
||||||
n = copy(inode.contents[off:], p)
|
n = copy(in.contents[off:], p)
|
||||||
|
|
||||||
// Sanity check.
|
// Sanity check.
|
||||||
if n != len(p) {
|
if n != len(p) {
|
||||||
|
@ -348,37 +348,37 @@ func (inode *inode) WriteAt(p []byte, off int64) (n int, err error) {
|
||||||
|
|
||||||
// Update attributes from non-nil parameters.
|
// Update attributes from non-nil parameters.
|
||||||
//
|
//
|
||||||
// EXCLUSIVE_LOCKS_REQUIRED(inode.mu)
|
// EXCLUSIVE_LOCKS_REQUIRED(in.mu)
|
||||||
func (inode *inode) SetAttributes(
|
func (in *inode) SetAttributes(
|
||||||
size *uint64,
|
size *uint64,
|
||||||
mode *os.FileMode,
|
mode *os.FileMode,
|
||||||
mtime *time.Time) {
|
mtime *time.Time) {
|
||||||
// Update the modification time.
|
// Update the modification time.
|
||||||
inode.attributes.Mtime = inode.clock.Now()
|
in.attributes.Mtime = in.clock.Now()
|
||||||
|
|
||||||
// Truncate?
|
// Truncate?
|
||||||
if size != nil {
|
if size != nil {
|
||||||
intSize := int(*size)
|
intSize := int(*size)
|
||||||
|
|
||||||
// Update contents.
|
// Update contents.
|
||||||
if intSize <= len(inode.contents) {
|
if intSize <= len(in.contents) {
|
||||||
inode.contents = inode.contents[:intSize]
|
in.contents = in.contents[:intSize]
|
||||||
} else {
|
} else {
|
||||||
padding := make([]byte, intSize-len(inode.contents))
|
padding := make([]byte, intSize-len(in.contents))
|
||||||
inode.contents = append(inode.contents, padding...)
|
in.contents = append(in.contents, padding...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update attributes.
|
// Update attributes.
|
||||||
inode.attributes.Size = *size
|
in.attributes.Size = *size
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change mode?
|
// Change mode?
|
||||||
if mode != nil {
|
if mode != nil {
|
||||||
inode.attributes.Mode = *mode
|
in.attributes.Mode = *mode
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change mtime?
|
// Change mtime?
|
||||||
if mtime != nil {
|
if mtime != nil {
|
||||||
inode.attributes.Mtime = *mtime
|
in.attributes.Mtime = *mtime
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue