From 6fdbd3c0c2b1231a9604f2265efde6c97bfb2589 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Tue, 19 May 2015 15:48:17 +1000 Subject: [PATCH] Fixed names. --- samples/memfs/inode.go | 118 ++++++++++++++++++++--------------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/samples/memfs/inode.go b/samples/memfs/inode.go index c2094d5..998a829 100644 --- a/samples/memfs/inode.go +++ b/samples/memfs/inode.go @@ -131,7 +131,7 @@ func (in *inode) checkInvariants() { // INVARIANT: Contains no duplicate names in used entries. childNames := make(map[string]struct{}) - for i, e := range inode.entries { + for i, e := range in.entries { if e.Type != fuseutil.DT_Unknown { if _, ok := childNames[e.Name]; ok { 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. // -// REQUIRES: inode.dir -// SHARED_LOCKS_REQUIRED(inode.mu) -func (inode *inode) Len() (n int) { - for _, e := range inode.entries { +// REQUIRES: in.isDir() +// SHARED_LOCKS_REQUIRED(in.mu) +func (in *inode) Len() (n int) { + for _, e := range in.entries { if e.Type != fuseutil.DT_Unknown { n++ } @@ -189,12 +189,12 @@ func (inode *inode) Len() (n int) { // Find an entry for the given child name and return its inode ID. // -// REQUIRES: inode.dir -// SHARED_LOCKS_REQUIRED(inode.mu) -func (inode *inode) LookUpChild(name string) (id fuseops.InodeID, ok bool) { - index, ok := inode.findChild(name) +// REQUIRES: in.isDir() +// SHARED_LOCKS_REQUIRED(in.mu) +func (in *inode) LookUpChild(name string) (id fuseops.InodeID, ok bool) { + index, ok := in.findChild(name) if ok { - id = inode.entries[index].Inode + id = in.entries[index].Inode } return @@ -202,22 +202,22 @@ func (inode *inode) LookUpChild(name string) (id fuseops.InodeID, ok bool) { // Add an entry for a child. // -// REQUIRES: inode.dir +// REQUIRES: in.isDir() // REQUIRES: dt != fuseutil.DT_Unknown -// EXCLUSIVE_LOCKS_REQUIRED(inode.mu) -func (inode *inode) AddChild( +// EXCLUSIVE_LOCKS_REQUIRED(in.mu) +func (in *inode) AddChild( id fuseops.InodeID, name string, dt fuseutil.DirentType) { var index int // 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 // field. defer func() { - inode.entries[index].Offset = fuseops.DirOffset(index + 1) + in.entries[index].Offset = fuseops.DirOffset(index + 1) }() // Set up the entry. @@ -228,35 +228,35 @@ func (inode *inode) AddChild( } // Look for a gap in which we can insert it. - for index = range inode.entries { - if inode.entries[index].Type == fuseutil.DT_Unknown { - inode.entries[index] = e + for index = range in.entries { + if in.entries[index].Type == fuseutil.DT_Unknown { + in.entries[index] = e return } } // Append it to the end. - index = len(inode.entries) - inode.entries = append(inode.entries, e) + index = len(in.entries) + in.entries = append(in.entries, e) } // Remove an entry for a child. // -// REQUIRES: inode.dir +// REQUIRES: in.isDir() // REQUIRES: An entry for the given name exists. -// EXCLUSIVE_LOCKS_REQUIRED(inode.mu) -func (inode *inode) RemoveChild(name string) { +// EXCLUSIVE_LOCKS_REQUIRED(in.mu) +func (in *inode) RemoveChild(name string) { // Update the modification time. - inode.attributes.Mtime = inode.clock.Now() + in.attributes.Mtime = in.clock.Now() // Find the entry. - i, ok := inode.findChild(name) + i, ok := in.findChild(name) if !ok { panic(fmt.Sprintf("Unknown child: %s", name)) } // Mark it as unused. - inode.entries[i] = fuseutil.Dirent{ + in.entries[i] = fuseutil.Dirent{ Type: fuseutil.DT_Unknown, Offset: fuseops.DirOffset(i + 1), } @@ -264,22 +264,22 @@ func (inode *inode) RemoveChild(name string) { // Serve a ReadDir request. // -// REQUIRES: inode.dir -// SHARED_LOCKS_REQUIRED(inode.mu) -func (inode *inode) ReadDir(offset int, size int) (data []byte, err error) { - if !inode.dir { +// REQUIRES: in.isDir() +// SHARED_LOCKS_REQUIRED(in.mu) +func (in *inode) ReadDir(offset int, size int) (data []byte, err error) { + if !in.dir { panic("ReadDir called on non-directory.") } - for i := offset; i < len(inode.entries); i++ { - e := inode.entries[i] + for i := offset; i < len(in.entries); i++ { + e := in.entries[i] // Skip unused entries. if e.Type == fuseutil.DT_Unknown { 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. 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. // -// REQUIRES: !inode.dir -// SHARED_LOCKS_REQUIRED(inode.mu) -func (inode *inode) ReadAt(p []byte, off int64) (n int, err error) { - if inode.dir { +// REQUIRES: in.isFile() +// SHARED_LOCKS_REQUIRED(in.mu) +func (in *inode) ReadAt(p []byte, off int64) (n int, err error) { + if in.dir { panic("ReadAt called on directory.") } // Ensure the offset is in range. - if off > int64(len(inode.contents)) { + if off > int64(len(in.contents)) { err = io.EOF return } // Read what we can. - n = copy(p, inode.contents[off:]) + n = copy(p, in.contents[off:]) if n < len(p) { 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. // -// REQUIRES: !inode.dir -// EXCLUSIVE_LOCKS_REQUIRED(inode.mu) -func (inode *inode) WriteAt(p []byte, off int64) (n int, err error) { - if inode.dir { +// REQUIRES: in.isFile() +// EXCLUSIVE_LOCKS_REQUIRED(in.mu) +func (in *inode) WriteAt(p []byte, off int64) (n int, err error) { + if in.dir { panic("WriteAt called on directory.") } // Update the modification time. - inode.attributes.Mtime = inode.clock.Now() + in.attributes.Mtime = in.clock.Now() // Ensure that the contents slice is long enough. newLen := int(off) + len(p) - if len(inode.contents) < newLen { - padding := make([]byte, newLen-len(inode.contents)) - inode.contents = append(inode.contents, padding...) - inode.attributes.Size = uint64(newLen) + if len(in.contents) < newLen { + padding := make([]byte, newLen-len(in.contents)) + in.contents = append(in.contents, padding...) + in.attributes.Size = uint64(newLen) } // Copy in the data. - n = copy(inode.contents[off:], p) + n = copy(in.contents[off:], p) // Sanity check. 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. // -// EXCLUSIVE_LOCKS_REQUIRED(inode.mu) -func (inode *inode) SetAttributes( +// EXCLUSIVE_LOCKS_REQUIRED(in.mu) +func (in *inode) SetAttributes( size *uint64, mode *os.FileMode, mtime *time.Time) { // Update the modification time. - inode.attributes.Mtime = inode.clock.Now() + in.attributes.Mtime = in.clock.Now() // Truncate? if size != nil { intSize := int(*size) // Update contents. - if intSize <= len(inode.contents) { - inode.contents = inode.contents[:intSize] + if intSize <= len(in.contents) { + in.contents = in.contents[:intSize] } else { - padding := make([]byte, intSize-len(inode.contents)) - inode.contents = append(inode.contents, padding...) + padding := make([]byte, intSize-len(in.contents)) + in.contents = append(in.contents, padding...) } // Update attributes. - inode.attributes.Size = *size + in.attributes.Size = *size } // Change mode? if mode != nil { - inode.attributes.Mode = *mode + in.attributes.Mode = *mode } // Change mtime? if mtime != nil { - inode.attributes.Mtime = *mtime + in.attributes.Mtime = *mtime } }