Commit 83798dc7 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Run gofmt.

parent 50a64bf6
......@@ -27,42 +27,42 @@ type FsNode interface {
// The following are called by the FileSystemConnector
Inode() *Inode
SetInode(node *Inode)
RmChild(name string, child FsNode)
AddChild(name string, child FsNode)
Lookup(name string) (fi *os.FileInfo, node FsNode, code Status)
Lookup(name string) (fi *os.FileInfo, node FsNode, code Status)
// Misc.
Access(mode uint32, context *Context) (code Status)
Readlink(c *Context) ([]byte, Status)
Access(mode uint32, context *Context) (code Status)
Readlink(c *Context) ([]byte, Status)
// Namespace operations
Mknod(name string, mode uint32, dev uint32, context *Context) (fi *os.FileInfo, newNode FsNode, code Status)
Mkdir(name string, mode uint32, context *Context) (fi *os.FileInfo, newNode FsNode, code Status)
Unlink(name string, context *Context) (code Status)
Rmdir(name string, context *Context) (code Status)
Mknod(name string, mode uint32, dev uint32, context *Context) (fi *os.FileInfo, newNode FsNode, code Status)
Mkdir(name string, mode uint32, context *Context) (fi *os.FileInfo, newNode FsNode, code Status)
Unlink(name string, context *Context) (code Status)
Rmdir(name string, context *Context) (code Status)
Symlink(name string, content string, context *Context) (fi *os.FileInfo, newNode FsNode, code Status)
Rename(oldName string, newParent FsNode, newName string, context *Context) (code Status)
Link(name string, existing FsNode, context *Context) (fi *os.FileInfo, newNode FsNode, code Status)
Rename(oldName string, newParent FsNode, newName string, context *Context) (code Status)
Link(name string, existing FsNode, context *Context) (fi *os.FileInfo, newNode FsNode, code Status)
// Files
Create(name string, flags uint32, mode uint32, context *Context) (file File, fi *os.FileInfo, newNode FsNode, code Status)
Create(name string, flags uint32, mode uint32, context *Context) (file File, fi *os.FileInfo, newNode FsNode, code Status)
Open(flags uint32, context *Context) (file File, code Status)
Flush(file File, openFlags uint32, context *Context) (code Status)
OpenDir(context *Context) (chan DirEntry, Status)
Flush(file File, openFlags uint32, context *Context) (code Status)
OpenDir(context *Context) (chan DirEntry, Status)
// XAttrs
GetXAttr(attribute string, context *Context) (data []byte, code Status)
RemoveXAttr(attr string, context *Context) Status
SetXAttr(attr string, data []byte, flags int, context *Context) Status
ListXAttr(context *Context) (attrs []string, code Status)
GetXAttr(attribute string, context *Context) (data []byte, code Status)
RemoveXAttr(attr string, context *Context) Status
SetXAttr(attr string, data []byte, flags int, context *Context) Status
ListXAttr(context *Context) (attrs []string, code Status)
// Attributes
GetAttr(file File, context *Context) (fi *os.FileInfo, code Status)
Chmod(file File, perms uint32, context *Context) (code Status)
Chown(file File, uid uint32, gid uint32, context *Context) (code Status)
Truncate(file File, size uint64, context *Context) (code Status)
Truncate(file File, size uint64, context *Context) (code Status)
Utimens(file File, atime uint64, mtime uint64, context *Context) (code Status)
}
......
......@@ -7,6 +7,7 @@ import (
"os"
"testing"
)
var _ = log.Println
type cacheFs struct {
......
package fuse
import (
"os"
)
......
package fuse
import (
"os"
)
......
package fuse
import (
"os"
)
......@@ -44,8 +45,7 @@ func (me *DefaultFsNode) RmChild(name string, child FsNode) {
func (me *DefaultFsNode) AddChild(name string, child FsNode) {
}
func (me *DefaultFsNode) Lookup(name string) (fi *os.FileInfo, node FsNode, code Status) {
func (me *DefaultFsNode) Lookup(name string) (fi *os.FileInfo, node FsNode, code Status) {
return nil, nil, ENOSYS
}
......@@ -85,35 +85,34 @@ func (me *DefaultFsNode) Create(name string, flags uint32, mode uint32, context
return nil, nil, nil, ENOSYS
}
func (me *DefaultFsNode) Open(flags uint32, context *Context) (file File, code Status) {
func (me *DefaultFsNode) Open(flags uint32, context *Context) (file File, code Status) {
return nil, ENOSYS
}
func (me *DefaultFsNode) Flush(file File, openFlags uint32, context *Context) (code Status) {
func (me *DefaultFsNode) Flush(file File, openFlags uint32, context *Context) (code Status) {
return ENOSYS
}
func (me *DefaultFsNode) OpenDir(context *Context) (chan DirEntry, Status) {
func (me *DefaultFsNode) OpenDir(context *Context) (chan DirEntry, Status) {
return nil, ENOSYS
}
func (me *DefaultFsNode) GetXAttr(attribute string, context *Context) (data []byte, code Status) {
func (me *DefaultFsNode) GetXAttr(attribute string, context *Context) (data []byte, code Status) {
return nil, ENOSYS
}
func (me *DefaultFsNode) RemoveXAttr(attr string, context *Context) Status {
func (me *DefaultFsNode) RemoveXAttr(attr string, context *Context) Status {
return ENOSYS
}
func (me *DefaultFsNode) SetXAttr(attr string, data []byte, flags int, context *Context) Status {
func (me *DefaultFsNode) SetXAttr(attr string, data []byte, flags int, context *Context) Status {
return ENOSYS
}
func (me *DefaultFsNode) ListXAttr(context *Context) (attrs []string, code Status) {
func (me *DefaultFsNode) ListXAttr(context *Context) (attrs []string, code Status) {
return nil, ENOSYS
}
func (me *DefaultFsNode) GetAttr(file File, context *Context) (fi *os.FileInfo, code Status) {
return nil, ENOSYS
}
......@@ -126,11 +125,10 @@ func (me *DefaultFsNode) Chown(file File, uid uint32, gid uint32, context *Conte
return ENOSYS
}
func (me *DefaultFsNode) Truncate(file File, size uint64, context *Context) (code Status) {
func (me *DefaultFsNode) Truncate(file File, size uint64, context *Context) (code Status) {
return ENOSYS
}
func (me *DefaultFsNode) Utimens(file File, atime uint64, mtime uint64, context *Context) (code Status) {
return ENOSYS
}
......@@ -76,9 +76,9 @@ type rawDir interface {
}
type connectorDir struct {
extra []DirEntry
stream chan DirEntry
leftOver DirEntry
extra []DirEntry
stream chan DirEntry
leftOver DirEntry
lastOffset uint64
}
......
......@@ -150,10 +150,10 @@ func (me *FileSystemConnector) considerDropInode(n *Inode) (drop bool) {
if n == me.rootNode || n.mountPoint != nil {
return false
}
n.openFilesMutex.Lock()
defer n.openFilesMutex.Unlock()
return len(n.openFiles) == 0
return len(n.openFiles) == 0
}
func (me *FileSystemConnector) renameUpdate(oldParent *Inode, oldName string, newParent *Inode, newName string) {
......@@ -164,7 +164,7 @@ func (me *FileSystemConnector) renameUpdate(oldParent *Inode, oldName string, ne
if oldParent.mount != newParent.mount {
panic("Cross mount rename")
}
node := oldParent.rmChild(oldName)
if node == nil {
panic("Source of rename does not exist")
......@@ -175,7 +175,7 @@ func (me *FileSystemConnector) renameUpdate(oldParent *Inode, oldName string, ne
func (me *FileSystemConnector) unlinkUpdate(parent *Inode, name string) {
defer me.verify()
parent.treeLock.Lock()
defer parent.treeLock.Unlock()
......
......@@ -125,7 +125,7 @@ func setupFAttrTest(fs FileSystem) (dir string, clean func()) {
state, _, err := MountPathFileSystem(dir, fs, nil)
CheckSuccess(err)
state.Debug = true
go state.Loop(false)
// Trigger INIT.
......@@ -133,7 +133,7 @@ func setupFAttrTest(fs FileSystem) (dir string, clean func()) {
if state.KernelSettings().Flags&CAP_FILE_OPS == 0 {
log.Println("Mount does not support file operations")
}
return dir, func() {
if state.Unmount() == nil {
os.RemoveAll(dir)
......@@ -145,7 +145,7 @@ func TestFSetAttr(t *testing.T) {
fs := &FSetAttrFs{}
dir, clean := setupFAttrTest(fs)
defer clean()
fn := dir + "/file"
f, err := os.OpenFile(fn, os.O_CREATE|os.O_WRONLY, 0755)
CheckSuccess(err)
......
......@@ -6,6 +6,7 @@ import (
"sync"
"unsafe"
)
var _ = log.Println
// openedFile stores either an open dir or an open file.
......@@ -57,7 +58,7 @@ func (me *fileSystemMount) fileInfoToEntry(fi *os.FileInfo) (out *EntryOut) {
}
return out
}
func (me *fileSystemMount) fileInfoToAttr(fi *os.FileInfo, out *AttrOut) {
CopyFileInfo(fi, &out.Attr)
SplitNs(me.options.AttrTimeout, &out.AttrValid, &out.AttrValidNsec)
......@@ -94,9 +95,9 @@ func (me *fileSystemMount) registerFileHandle(node *Inode, dir rawDir, f File, f
node.openFilesMutex.Lock()
defer node.openFilesMutex.Unlock()
b := &openedFile{
dir: dir,
file: f,
OpenFlags: flags,
dir: dir,
file: f,
OpenFlags: flags,
}
withFlags, ok := f.(*WithFlags)
......
......@@ -11,7 +11,6 @@ import (
var _ = log.Println
func (me *FileSystemConnector) Init(fsInit *RawFsInit) {
me.fsInit = *fsInit
}
......@@ -60,12 +59,12 @@ func (me *FileSystemConnector) internalLookup(parent *Inode, name string, lookup
}
if child != nil && code.Ok() {
out = parent.mount.fileInfoToEntry(fi)
out = parent.mount.fileInfoToEntry(fi)
out.NodeId = child.nodeId
out.Generation = 1
return out, OK, child
}
fi, fsNode, code := parent.fsInode.Lookup(name)
if code == ENOENT && mount.options.NegativeTimeout > 0.0 {
return NegativeEntry(mount.options.NegativeTimeout), OK, nil
......@@ -74,7 +73,7 @@ func (me *FileSystemConnector) internalLookup(parent *Inode, name string, lookup
return nil, code, nil
}
out, _ = me.createChild(parent, name, fi, fsNode)
out, _ = me.createChild(parent, name, fi, fsNode)
return out, OK, node
}
......@@ -91,7 +90,7 @@ func (me *FileSystemConnector) GetAttr(header *InHeader, input *GetAttrIn) (out
f = opened.file
}
}
fi, code := node.fsInode.GetAttr(f, &header.Context)
if !code.Ok() {
return nil, code
......@@ -101,7 +100,7 @@ func (me *FileSystemConnector) GetAttr(header *InHeader, input *GetAttrIn) (out
node.mount.fileInfoToAttr(fi, out)
return out, OK
}
func (me *FileSystemConnector) OpenDir(header *InHeader, input *OpenIn) (flags uint32, handle uint64, code Status) {
node := me.getInodeData(header.NodeId)
stream, err := node.fsInode.OpenDir(&header.Context)
......@@ -115,7 +114,7 @@ func (me *FileSystemConnector) OpenDir(header *InHeader, input *OpenIn) (flags u
}
de.extra = append(de.extra, DirEntry{S_IFDIR, "."}, DirEntry{S_IFDIR, ".."})
h, opened := node.mount.registerFileHandle(node, de, nil, input.Flags)
// TODO - implement seekable directories
opened.FuseFlags |= FOPEN_NONSEEKABLE
return opened.FuseFlags, h, OK
......@@ -238,7 +237,6 @@ func (me *FileSystemConnector) Symlink(header *InHeader, pointedTo string, linkN
return out, code
}
func (me *FileSystemConnector) Rename(header *InHeader, input *RenameIn, oldName string, newName string) (code Status) {
oldParent := me.getInodeData(header.NodeId)
isMountPoint := me.lookupMount(oldParent, oldName, 0) != nil
......@@ -265,7 +263,7 @@ func (me *FileSystemConnector) Link(header *InHeader, input *LinkIn, name string
if existing.mount != parent.mount {
return nil, EXDEV
}
fi, fsInode, code := parent.fsInode.Link(name, existing.fsInode, &header.Context)
if !code.Ok() {
return nil, code
......@@ -323,7 +321,7 @@ func (me *FileSystemConnector) GetXAttr(header *InHeader, attribute string) (dat
func (me *FileSystemConnector) RemoveXAttr(header *InHeader, attr string) Status {
node := me.getInodeData(header.NodeId)
return node.fsInode.RemoveXAttr(attr, &header.Context)
}
}
func (me *FileSystemConnector) SetXAttr(header *InHeader, input *SetXAttrIn, attr string, data []byte) Status {
node := me.getInodeData(header.NodeId)
......
......@@ -25,9 +25,9 @@ type Inode struct {
treeLock *sync.RWMutex
// All data below is protected by treeLock.
fsInode FsNode
children map[string]*Inode
fsInode FsNode
children map[string]*Inode
// Contains directories that function as mounts. The entries
// are duplicated in children.
......@@ -49,7 +49,7 @@ type Inode struct {
// LockTree() Locks the mutex used for tree operations, and returns the
// unlock function.
func (me *Inode) LockTree() (func()) {
func (me *Inode) LockTree() func() {
// TODO - this API is tricky.
me.treeLock.Lock()
return func() { me.treeLock.Unlock() }
......@@ -59,9 +59,9 @@ func (me *Inode) LockTree() (func()) {
func (me *Inode) AnyFile() (file File) {
me.openFilesMutex.Lock()
defer me.openFilesMutex.Unlock()
for _, f := range me.openFiles {
if file == nil || f.OpenFlags & O_ANYWRITE != 0 {
if file == nil || f.OpenFlags&O_ANYWRITE != 0 {
file = f.file
}
}
......@@ -82,14 +82,14 @@ func (me *Inode) Children() (out map[string]*Inode) {
func (me *Inode) FsNode() FsNode {
return me.fsInode
}
// Returns an open writable file for the given Inode.
func (me *Inode) WritableFiles() (files []File) {
me.openFilesMutex.Lock()
defer me.openFilesMutex.Unlock()
for _, f := range me.openFiles {
if f.OpenFlags & O_ANYWRITE != 0 {
if f.OpenFlags&O_ANYWRITE != 0 {
files = append(files, f.file)
}
}
......@@ -111,12 +111,12 @@ func (me *Inode) CreateChild(name string, isDir bool, fsi FsNode) *Inode {
}
ch = me.connector.newInode(isDir)
ch.fsInode = fsi
fsi.SetInode(ch)
fsi.SetInode(ch)
ch.mount = me.mount
ch.treeLock = me.treeLock
ch.lookupCount = 1
ch.connector = me.connector
me.addChild(name, ch)
return ch
}
......@@ -124,7 +124,7 @@ func (me *Inode) CreateChild(name string, isDir bool, fsi FsNode) *Inode {
func (me *Inode) GetChild(name string) (child *Inode) {
me.treeLock.Lock()
defer me.treeLock.Unlock()
return me.children[name]
}
......@@ -217,7 +217,7 @@ func (me *Inode) verify(cur *fileSystemMount) {
me.mountPoint, name, me.children))
}
}
for _, ch := range me.children {
if ch == nil {
panic("Found nil child.")
......
......@@ -27,13 +27,13 @@ type testCase struct {
orig string
mnt string
mountFile string
mountSubdir string
origFile string
origSubdir string
tester *testing.T
state *MountState
connector *FileSystemConnector
mountFile string
mountSubdir string
origFile string
origSubdir string
tester *testing.T
state *MountState
connector *FileSystemConnector
}
const testTtl = 0.1
......@@ -682,17 +682,17 @@ func TestOriginalIsSymlink(t *testing.T) {
}
func TestDoubleOpen(t *testing.T) {
ts := NewTestCase(t)
defer ts.Cleanup()
err := ioutil.WriteFile(ts.orig +"/file", []byte("blabla"), 0644)
CheckSuccess(err)
roFile, err := os.Open(ts.mnt + "/file")
CheckSuccess(err)
defer roFile.Close()
rwFile, err := os.OpenFile(ts.mnt + "/file", os.O_WRONLY | os.O_TRUNC, 0666)
CheckSuccess(err)
defer rwFile.Close()
ts := NewTestCase(t)
defer ts.Cleanup()
err := ioutil.WriteFile(ts.orig+"/file", []byte("blabla"), 0644)
CheckSuccess(err)
roFile, err := os.Open(ts.mnt + "/file")
CheckSuccess(err)
defer roFile.Close()
rwFile, err := os.OpenFile(ts.mnt+"/file", os.O_WRONLY|os.O_TRUNC, 0666)
CheckSuccess(err)
defer rwFile.Close()
}
......@@ -27,10 +27,10 @@ func (me *PathNodeFs) StatFs() *StatfsOut {
func NewPathNodeFs(fs FileSystem) *PathNodeFs {
root := new(pathInode)
root.fs = fs
me := &PathNodeFs{
fs: fs,
root: root,
fs: fs,
root: root,
}
root.ifs = me
return me
......@@ -40,15 +40,14 @@ func (me *PathNodeFs) Root() FsNode {
return me.root
}
// This is a combination of dentry (entry in the file/directory and
// the inode). This structure is used to implement glue for FSes where
// there is a one-to-one mapping of paths and inodes, ie. FSes that
// disallow hardlinks.
type pathInode struct {
ifs *PathNodeFs
fs FileSystem
Name string
ifs *PathNodeFs
fs FileSystem
Name string
// This is nil at the root of the mount.
Parent *pathInode
......@@ -95,7 +94,7 @@ func (me *pathInode) RmChild(name string, child FsNode) {
func (me *pathInode) Readlink(c *Context) ([]byte, Status) {
path := me.GetPath()
val, err := me.fs.Readlink(path, c)
return []byte(val), err
}
......@@ -148,7 +147,7 @@ func (me *pathInode) Mknod(name string, mode uint32, dev uint32, context *Contex
}
return
}
func (me *pathInode) Mkdir(name string, mode uint32, context *Context) (fi *os.FileInfo, newNode FsNode, code Status) {
code = me.fs.Mkdir(filepath.Join(me.GetPath(), name), mode, context)
if code.Ok() {
......@@ -179,12 +178,11 @@ func (me *pathInode) Symlink(name string, content string, context *Context) (fi
return
}
func (me *pathInode) Rename(oldName string, newParent FsNode, newName string, context *Context) (code Status) {
p := newParent.(*pathInode)
oldPath := filepath.Join(me.GetPath(), oldName)
newPath := filepath.Join(p.GetPath(), newName)
return me.fs.Rename(oldPath, newPath, context)
}
......@@ -202,7 +200,7 @@ func (me *pathInode) Link(name string, existing FsNode, context *Context) (fi *o
}
newNode = me.createChild(name)
}
return
return
}
func (me *pathInode) Create(name string, flags uint32, mode uint32, context *Context) (file File, fi *os.FileInfo, newNode FsNode, code Status) {
......@@ -211,11 +209,11 @@ func (me *pathInode) Create(name string, flags uint32, mode uint32, context *Con
if code.Ok() {
newNode = me.createChild(name)
fi = &os.FileInfo{
Mode: S_IFREG | mode,
// TODO - ctime, mtime, atime?
Mode: S_IFREG | mode,
// TODO - ctime, mtime, atime?
}
}
return
return
}
func (me *pathInode) createChild(name string) *pathInode {
......@@ -247,7 +245,7 @@ func (me *pathInode) GetAttr(file File, context *Context) (fi *os.FileInfo, code
// called on a deleted files.
file = me.inode.AnyFile()
}
if file != nil {
fi, code = file.GetAttr()
}
......@@ -255,12 +253,12 @@ func (me *pathInode) GetAttr(file File, context *Context) (fi *os.FileInfo, code
if file == nil || code == ENOSYS {
fi, code = me.fs.GetAttr(me.GetPath(), context)
}
if fi != nil && !fi.IsDirectory() && fi.Nlink == 0 {
fi.Nlink = 1
}
return fi, code
}
}
func (me *pathInode) Chmod(file File, perms uint32, context *Context) (code Status) {
files := me.inode.WritableFiles()
......@@ -271,14 +269,13 @@ func (me *pathInode) Chmod(file File, perms uint32, context *Context) (code Stat
break
}
}
if len(files) == 0 || code == ENOSYS {
code = me.fs.Chmod(me.GetPath(), perms, context)
}
return code
}
func (me *pathInode) Chown(file File, uid uint32, gid uint32, context *Context) (code Status) {
files := me.inode.WritableFiles()
for _, f := range files {
......
......@@ -893,7 +893,7 @@ func TestDoubleOpen(t *testing.T) {
roFile, err := os.Open(wd + "/mount/file")
CheckSuccess(err)
defer roFile.Close()
rwFile, err := os.OpenFile(wd + "/mount/file", os.O_WRONLY | os.O_TRUNC, 0666)
rwFile, err := os.OpenFile(wd+"/mount/file", os.O_WRONLY|os.O_TRUNC, 0666)
CheckSuccess(err)
defer rwFile.Close()
......@@ -910,7 +910,7 @@ func TestDoubleOpen(t *testing.T) {
CheckSuccess(err)
b := make([]byte, 100)
roFile.Seek(0, 0)
n, err := roFile.Read(b)
CheckSuccess(err)
......@@ -921,4 +921,3 @@ func TestDoubleOpen(t *testing.T) {
}
}
}
......@@ -17,14 +17,13 @@ type memNode struct {
file MemFile
}
// MemTreeFs creates a tree of internal Inodes. Since the tree is
// loaded in memory completely at startup, it does not need to inode
// discovery through Lookup() at serve time.
type MemTreeFs struct {
fuse.DefaultNodeFileSystem
root memNode
files map[string]MemFile
root memNode
files map[string]MemFile
}
func NewMemTreeFs() *MemTreeFs {
......@@ -55,7 +54,7 @@ func (me *memNode) Print(indent int) {
fmt.Println(s + k + ":")
mn, ok := v.FsNode().(*memNode)
if ok {
mn.Print(indent+2)
mn.Print(indent + 2)
}
} else {
fmt.Println(s + k)
......@@ -96,7 +95,7 @@ func (me *memNode) Open(flags uint32, context *fuse.Context) (fuseFile fuse.File
func (me *memNode) GetAttr(file fuse.File, context *fuse.Context) (*os.FileInfo, fuse.Status) {
if me.Inode().IsDir() {
return &os.FileInfo{
Mode: fuse.S_IFDIR | 0777,
Mode: fuse.S_IFDIR | 0777,
}, fuse.OK
}
......@@ -114,7 +113,7 @@ func (me *MemTreeFs) addFile(name string, f MemFile) {
if i == len(comps)-1 {
fsnode.file = f
}
ch = node.CreateChild(c, fsnode.file == nil, fsnode)
}
node = ch
......
......@@ -44,7 +44,7 @@ func (me *TarFile) Data() []byte {
return me.data
}
func NewTarTree(r io.Reader) (map[string]MemFile) {
func NewTarTree(r io.Reader) map[string]MemFile {
files := map[string]MemFile{}
tr := tar.NewReader(r)
......@@ -80,8 +80,8 @@ func NewTarTree(r io.Reader) (map[string]MemFile) {
io.Copy(buf, tr)
files[hdr.Name] = &TarFile{
Header: *hdr,
data: buf.Bytes(),
Header: *hdr,
data: buf.Bytes(),
}
}
return files
......
......@@ -33,7 +33,7 @@ func (me *ZipFile) Data() []byte {
panic(err)
}
dest := bytes.NewBuffer(make([]byte, 0, me.UncompressedSize))
_, err = io.Copyn(dest, rc, int64(me.UncompressedSize))
if err != nil {
panic(err)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment