Commit 94244f10 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Run Gofmt.

parent 736b11e3
...@@ -13,12 +13,12 @@ func main() { ...@@ -13,12 +13,12 @@ func main() {
debug := flag.Bool("debug", false, "print debugging messages.") debug := flag.Bool("debug", false, "print debugging messages.")
threaded := flag.Bool("threaded", true, "switch off threading; print debugging messages.") threaded := flag.Bool("threaded", true, "switch off threading; print debugging messages.")
flag.Parse() flag.Parse()
if flag.NArg() < 2 { if flag.NArg() < 2 {
// TODO - where to get program name? // TODO - where to get program name?
fmt.Println("usage: main ORIGINAL MOUNTPOINT") fmt.Println("usage: main ORIGINAL MOUNTPOINT")
os.Exit(2) os.Exit(2)
} }
orig := flag.Arg(0) orig := flag.Arg(0)
pt := examplelib.NewPassThroughFuse(orig) pt := examplelib.NewPassThroughFuse(orig)
fs := fuse.NewPathFileSystemConnector(pt) fs := fuse.NewPathFileSystemConnector(pt)
...@@ -31,4 +31,3 @@ func main() { ...@@ -31,4 +31,3 @@ func main() {
fmt.Printf("Mounted %s on %s (threaded=%v, debug=%v)\n", orig, mountPoint, *threaded, *debug) fmt.Printf("Mounted %s on %s (threaded=%v, debug=%v)\n", orig, mountPoint, *threaded, *debug)
state.Loop(*threaded) state.Loop(*threaded)
} }
package examplelib package examplelib
import ( import (
"github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse"
) )
// Declare dummy methods, for cut & paste convenience. // Declare dummy methods, for cut & paste convenience.
type DummyFuse struct{} type DummyFuse struct{}
...@@ -200,5 +201,5 @@ func (self *DummyPathFuse) Utimens(name string, AtimeNs uint64, CtimeNs uint64) ...@@ -200,5 +201,5 @@ func (self *DummyPathFuse) Utimens(name string, AtimeNs uint64, CtimeNs uint64)
} }
func (self *DummyPathFuse) SetOptions(*fuse.PathFileSystemConnectorOptions) { func (self *DummyPathFuse) SetOptions(*fuse.PathFileSystemConnectorOptions) {
} }
...@@ -173,10 +173,10 @@ func (self *PassThroughFile) Fsync(*fuse.FsyncIn) (code fuse.Status) { ...@@ -173,10 +173,10 @@ func (self *PassThroughFile) Fsync(*fuse.FsyncIn) (code fuse.Status) {
type PassThroughDir struct { type PassThroughDir struct {
directoryChannel chan *os.FileInfo directoryChannel chan *os.FileInfo
directoryError os.Error directoryError os.Error
shipped int shipped int
exported int exported int
leftOver *os.FileInfo leftOver *os.FileInfo
} }
func NewPassThroughDir(file *os.File) *PassThroughDir { func NewPassThroughDir(file *os.File) *PassThroughDir {
...@@ -214,7 +214,7 @@ func (self *PassThroughDir) ReadDir(input *fuse.ReadIn) (*fuse.DirEntryList, fus ...@@ -214,7 +214,7 @@ func (self *PassThroughDir) ReadDir(input *fuse.ReadIn) (*fuse.DirEntryList, fus
} }
self.leftOver = nil self.leftOver = nil
} }
for { for {
fi := <-self.directoryChannel fi := <-self.directoryChannel
if fi == nil { if fi == nil {
...@@ -223,7 +223,7 @@ func (self *PassThroughDir) ReadDir(input *fuse.ReadIn) (*fuse.DirEntryList, fus ...@@ -223,7 +223,7 @@ func (self *PassThroughDir) ReadDir(input *fuse.ReadIn) (*fuse.DirEntryList, fus
if !list.AddString(fi.Name, fuse.FUSE_UNKNOWN_INO, fi.Mode) { if !list.AddString(fi.Name, fuse.FUSE_UNKNOWN_INO, fi.Mode) {
self.leftOver = fi self.leftOver = fi
break break
} }
} }
return list, fuse.OsErrorToFuseError(self.directoryError) return list, fuse.OsErrorToFuseError(self.directoryError)
} }
...@@ -235,4 +235,3 @@ func (self *PassThroughDir) ReleaseDir() { ...@@ -235,4 +235,3 @@ func (self *PassThroughDir) ReleaseDir() {
func (self *PassThroughDir) FsyncDir(input *fuse.FsyncIn) (code fuse.Status) { func (self *PassThroughDir) FsyncDir(input *fuse.FsyncIn) (code fuse.Status) {
return fuse.ENOSYS return fuse.ENOSYS
} }
...@@ -396,9 +396,9 @@ func (self *testCase) testReaddir() { ...@@ -396,9 +396,9 @@ func (self *testCase) testReaddir() {
self.tester.Errorf("readdir err %v", err) self.tester.Errorf("readdir err %v", err)
} }
wanted := map[string] bool{ wanted := map[string]bool{
"hello.txt": true, "hello.txt": true,
"subdir": true, "subdir": true,
} }
if len(wanted) != len(infos) { if len(wanted) != len(infos) {
self.tester.Errorf("Length mismatch %v", infos) self.tester.Errorf("Length mismatch %v", infos)
...@@ -437,7 +437,7 @@ func (self *testCase) testFSync() { ...@@ -437,7 +437,7 @@ func (self *testCase) testFSync() {
func (self *testCase) testLargeRead() { func (self *testCase) testLargeRead() {
name := path.Join(self.origDir, "large") name := path.Join(self.origDir, "large")
f, err := os.Open(name, os.O_WRONLY | os.O_CREATE, 0777) f, err := os.Open(name, os.O_WRONLY|os.O_CREATE, 0777)
if err != nil { if err != nil {
self.tester.Errorf("open write err %v", err) self.tester.Errorf("open write err %v", err)
} }
...@@ -469,10 +469,10 @@ func (self *testCase) testLargeRead() { ...@@ -469,10 +469,10 @@ func (self *testCase) testLargeRead() {
readSlice := make([]byte, len(slice)) readSlice := make([]byte, len(slice))
m, err := g.Read(readSlice) m, err := g.Read(readSlice)
if m != n { if m != n {
self.tester.Errorf("read mismatch %v %v", m, n ) self.tester.Errorf("read mismatch %v %v", m, n)
} }
for i, v := range(readSlice) { for i, v := range readSlice {
if (slice[i] != v) { if slice[i] != v {
self.tester.Errorf("char mismatch %v %v %v", i, slice[i], v) self.tester.Errorf("char mismatch %v %v %v", i, slice[i], v)
break break
} }
...@@ -506,8 +506,7 @@ func (self *testCase) testLargeRead() { ...@@ -506,8 +506,7 @@ func (self *testCase) testLargeRead() {
} }
g.Close() g.Close()
os.Remove(name)
os.Remove(name)
} }
func randomLengthString(length int) string { func randomLengthString(length int) string {
...@@ -541,7 +540,7 @@ func (self *testCase) testLargeDirRead() { ...@@ -541,7 +540,7 @@ func (self *testCase) testLargeDirRead() {
nameSet[base] = true nameSet[base] = true
f, err := os.Open(name, os.O_WRONLY | os.O_CREATE, 0777) f, err := os.Open(name, os.O_WRONLY|os.O_CREATE, 0777)
if err != nil { if err != nil {
self.tester.Errorf("open write err %v", err) self.tester.Errorf("open write err %v", err)
break break
...@@ -552,13 +551,13 @@ func (self *testCase) testLargeDirRead() { ...@@ -552,13 +551,13 @@ func (self *testCase) testLargeDirRead() {
names[i] = name names[i] = name
} }
dir, err := os.Open(path.Join(self.mountPoint, "readdirSubdir"), os.O_RDONLY, 0) dir, err := os.Open(path.Join(self.mountPoint, "readdirSubdir"), os.O_RDONLY, 0)
if err != nil { if err != nil {
self.tester.Errorf("dirread %v", err) self.tester.Errorf("dirread %v", err)
} }
// Chunked read. // Chunked read.
total := 0 total := 0
readSet := make(map[string] bool) readSet := make(map[string]bool)
for { for {
namesRead, err := dir.Readdirnames(200) namesRead, err := dir.Readdirnames(200)
if err != nil { if err != nil {
...@@ -568,7 +567,7 @@ func (self *testCase) testLargeDirRead() { ...@@ -568,7 +567,7 @@ func (self *testCase) testLargeDirRead() {
if len(namesRead) == 0 { if len(namesRead) == 0 {
break break
} }
for _, v := range(namesRead) { for _, v := range namesRead {
readSet[v] = true readSet[v] = true
} }
total += len(namesRead) total += len(namesRead)
...@@ -577,7 +576,7 @@ func (self *testCase) testLargeDirRead() { ...@@ -577,7 +576,7 @@ func (self *testCase) testLargeDirRead() {
if total != created { if total != created {
self.tester.Errorf("readdir mismatch got %v wanted %v", total, created) self.tester.Errorf("readdir mismatch got %v wanted %v", total, created)
} }
for k, _ := range(nameSet) { for k, _ := range nameSet {
_, ok := readSet[k] _, ok := readSet[k]
if !ok { if !ok {
self.tester.Errorf("Name %v not found in output", k) self.tester.Errorf("Name %v not found in output", k)
...@@ -590,7 +589,6 @@ func (self *testCase) testLargeDirRead() { ...@@ -590,7 +589,6 @@ func (self *testCase) testLargeDirRead() {
} }
// Test driver. // Test driver.
func TestMount(t *testing.T) { func TestMount(t *testing.T) {
ts := new(testCase) ts := new(testCase)
......
...@@ -109,7 +109,7 @@ func (self *MountState) Mount(mountPoint string) os.Error { ...@@ -109,7 +109,7 @@ func (self *MountState) Mount(mountPoint string) os.Error {
self.mountFile = file self.mountFile = file
return nil return nil
} }
// Normally, callers should run loop() and wait for FUSE to exit, but // Normally, callers should run loop() and wait for FUSE to exit, but
// tests will want to run this in a goroutine. // tests will want to run this in a goroutine.
func (self *MountState) Loop(threaded bool) { func (self *MountState) Loop(threaded bool) {
...@@ -263,7 +263,6 @@ func dispatch(state *MountState, h *InHeader, arg *bytes.Buffer) (outBytes [][]b ...@@ -263,7 +263,6 @@ func dispatch(state *MountState, h *InHeader, arg *bytes.Buffer) (outBytes [][]b
status = OK status = OK
fs := state.fileSystem fs := state.fileSystem
filename := "" filename := ""
// Perhaps a map is faster? // Perhaps a map is faster?
if h.Opcode == FUSE_UNLINK || h.Opcode == FUSE_RMDIR || if h.Opcode == FUSE_UNLINK || h.Opcode == FUSE_RMDIR ||
...@@ -380,7 +379,7 @@ func dispatch(state *MountState, h *InHeader, arg *bytes.Buffer) (outBytes [][]b ...@@ -380,7 +379,7 @@ func dispatch(state *MountState, h *InHeader, arg *bytes.Buffer) (outBytes [][]b
return serialize(h, status, out, flatData, state.Debug) return serialize(h, status, out, flatData, state.Debug)
} }
func serialize(h *InHeader, res Status, out interface{}, flatData []byte, debug bool) ([][]byte) { func serialize(h *InHeader, res Status, out interface{}, flatData []byte, debug bool) [][]byte {
out_data := make([]byte, 0) out_data := make([]byte, 0)
b := new(bytes.Buffer) b := new(bytes.Buffer)
if out != nil && res == OK { if out != nil && res == OK {
...@@ -395,7 +394,7 @@ func serialize(h *InHeader, res Status, out interface{}, flatData []byte, debug ...@@ -395,7 +394,7 @@ func serialize(h *InHeader, res Status, out interface{}, flatData []byte, debug
var hout OutHeader var hout OutHeader
hout.Unique = h.Unique hout.Unique = h.Unique
hout.Status = -res hout.Status = -res
hout.Length = uint32(len(out_data) + SizeOfOutHeader + len(flatData)) hout.Length = uint32(len(out_data) + SizeOfOutHeader + len(flatData))
b = new(bytes.Buffer) b = new(bytes.Buffer)
err := binary.Write(b, binary.LittleEndian, &hout) err := binary.Write(b, binary.LittleEndian, &hout)
if err != nil { if err != nil {
......
...@@ -251,7 +251,7 @@ func Writev(fd int, packet [][]byte) (n int, err os.Error) { ...@@ -251,7 +251,7 @@ func Writev(fd int, packet [][]byte) (n int, err os.Error) {
} }
iovecs := make([]syscall.Iovec, len(packet)) iovecs := make([]syscall.Iovec, len(packet))
j := 0 j := 0
for i, v := range packet { for i, v := range packet {
if v == nil || len(v) == 0 { if v == nil || len(v) == 0 {
continue continue
......
...@@ -10,13 +10,13 @@ import ( ...@@ -10,13 +10,13 @@ import (
// TODO should rename to dentry? // TODO should rename to dentry?
type inodeData struct { type inodeData struct {
Parent *inodeData Parent *inodeData
NodeId uint64 NodeId uint64
Name string Name string
LookupCount int LookupCount int
// Number of inodeData that have this as parent. // Number of inodeData that have this as parent.
RefCount int RefCount int
} }
// Should implement some hash table method instead? // Should implement some hash table method instead?
...@@ -48,8 +48,8 @@ func (self *inodeData) GetPath() string { ...@@ -48,8 +48,8 @@ func (self *inodeData) GetPath() string {
} }
type PathFileSystemConnectorOptions struct { type PathFileSystemConnectorOptions struct {
EntryTimeout float64 EntryTimeout float64
AttrTimeout float64 AttrTimeout float64
NegativeTimeout float64 NegativeTimeout float64
} }
...@@ -57,8 +57,8 @@ type PathFileSystemConnector struct { ...@@ -57,8 +57,8 @@ type PathFileSystemConnector struct {
fileSystem PathFilesystem fileSystem PathFilesystem
// Protects the hashmap, its contents and the nextFreeInode counter. // Protects the hashmap, its contents and the nextFreeInode counter.
lock sync.RWMutex lock sync.RWMutex
// Invariants // Invariants
// - For all values, (RefCount > 0 || LookupCount > 0). // - For all values, (RefCount > 0 || LookupCount > 0).
// - For all values, value = inodePathMap[value.Key()] // - For all values, value = inodePathMap[value.Key()]
...@@ -71,7 +71,7 @@ type PathFileSystemConnector struct { ...@@ -71,7 +71,7 @@ type PathFileSystemConnector struct {
// > 0. // > 0.
inodePathMap map[string]*inodeData inodePathMap map[string]*inodeData
inodePathMapByInode map[uint64]*inodeData inodePathMapByInode map[uint64]*inodeData
nextFreeInode uint64 nextFreeInode uint64
options PathFileSystemConnectorOptions options PathFileSystemConnectorOptions
} }
...@@ -82,11 +82,11 @@ func (self *PathFileSystemConnector) setParent(data *inodeData, parentId uint64) ...@@ -82,11 +82,11 @@ func (self *PathFileSystemConnector) setParent(data *inodeData, parentId uint64)
if data.Parent == newParent { if data.Parent == newParent {
return return
} }
if newParent == nil { if newParent == nil {
panic("Unknown parent") panic("Unknown parent")
} }
oldParent := data.Parent oldParent := data.Parent
if oldParent != nil { if oldParent != nil {
self.unrefNode(oldParent) self.unrefNode(oldParent)
...@@ -100,7 +100,7 @@ func (self *PathFileSystemConnector) setParent(data *inodeData, parentId uint64) ...@@ -100,7 +100,7 @@ func (self *PathFileSystemConnector) setParent(data *inodeData, parentId uint64)
// Must be called with lock held. // Must be called with lock held.
func (self *PathFileSystemConnector) unrefNode(data *inodeData) { func (self *PathFileSystemConnector) unrefNode(data *inodeData) {
data.RefCount-- data.RefCount--
if data.RefCount <= 0 && data.LookupCount <= 0{ if data.RefCount <= 0 && data.LookupCount <= 0 {
self.inodePathMapByInode[data.NodeId] = nil, false self.inodePathMapByInode[data.NodeId] = nil, false
} }
} }
...@@ -146,8 +146,8 @@ func (self *PathFileSystemConnector) forgetUpdate(nodeId uint64, forgetCount int ...@@ -146,8 +146,8 @@ func (self *PathFileSystemConnector) forgetUpdate(nodeId uint64, forgetCount int
} }
} }
func (self *PathFileSystemConnector) renameUpdate(oldParent uint64, oldName string, newParent uint64, newName string) { func (self *PathFileSystemConnector) renameUpdate(oldParent uint64, oldName string, newParent uint64, newName string) {
self.lock.Lock() self.lock.Lock()
defer self.lock.Unlock() defer self.lock.Unlock()
oldKey := inodeDataKey(oldParent, oldName) oldKey := inodeDataKey(oldParent, oldName)
...@@ -163,7 +163,7 @@ func (self *PathFileSystemConnector) renameUpdate(oldParent uint64, oldName stri ...@@ -163,7 +163,7 @@ func (self *PathFileSystemConnector) renameUpdate(oldParent uint64, oldName stri
} }
self.inodePathMap[oldKey] = nil, false self.inodePathMap[oldKey] = nil, false
self.setParent(data, newParent) self.setParent(data, newParent)
data.Name = newName data.Name = newName
newKey := data.Key() newKey := data.Key()
...@@ -182,7 +182,7 @@ func (self *PathFileSystemConnector) renameUpdate(oldParent uint64, oldName stri ...@@ -182,7 +182,7 @@ func (self *PathFileSystemConnector) renameUpdate(oldParent uint64, oldName stri
self.setParent(target, FUSE_ROOT_ID) self.setParent(target, FUSE_ROOT_ID)
target.Name = fmt.Sprintf("overwrittenByRename%d", self.nextFreeInode) target.Name = fmt.Sprintf("overwrittenByRename%d", self.nextFreeInode)
self.nextFreeInode++; self.nextFreeInode++
self.inodePathMap[target.Key()] = target self.inodePathMap[target.Key()] = target
} }
...@@ -225,7 +225,7 @@ func NewPathFileSystemConnector(fs PathFilesystem) (out *PathFileSystemConnector ...@@ -225,7 +225,7 @@ func NewPathFileSystemConnector(fs PathFilesystem) (out *PathFileSystemConnector
out.options.EntryTimeout = 1.0 out.options.EntryTimeout = 1.0
fs.SetOptions(&out.options) fs.SetOptions(&out.options)
return out return out
} }
...@@ -249,7 +249,7 @@ func (self *PathFileSystemConnector) Lookup(header *InHeader, name string) (out ...@@ -249,7 +249,7 @@ func (self *PathFileSystemConnector) Lookup(header *InHeader, name string) (out
// Hmm. - fuse.c has special case code for name == "." and "..". // Hmm. - fuse.c has special case code for name == "." and "..".
// Should we have it too? // Should we have it too?
fullPath := path.Join(parent.GetPath(), name) fullPath := path.Join(parent.GetPath(), name)
attr, err := self.fileSystem.GetAttr(fullPath) attr, err := self.fileSystem.GetAttr(fullPath)
if err == ENOENT && self.options.NegativeTimeout > 0.0 { if err == ENOENT && self.options.NegativeTimeout > 0.0 {
...@@ -315,7 +315,7 @@ func (self *PathFileSystemConnector) Open(header *InHeader, input *OpenIn) (flag ...@@ -315,7 +315,7 @@ func (self *PathFileSystemConnector) Open(header *InHeader, input *OpenIn) (flag
func (self *PathFileSystemConnector) SetAttr(header *InHeader, input *SetAttrIn) (out *AttrOut, code Status) { func (self *PathFileSystemConnector) SetAttr(header *InHeader, input *SetAttrIn) (out *AttrOut, code Status) {
var err Status = OK var err Status = OK
// TODO - support Fh. (FSetAttr/FGetAttr/FTruncate.) // TODO - support Fh. (FSetAttr/FGetAttr/FTruncate.)
fullPath := self.GetPath(header.NodeId) fullPath := self.GetPath(header.NodeId)
if input.Valid&FATTR_MODE != 0 { if input.Valid&FATTR_MODE != 0 {
...@@ -374,12 +374,12 @@ func (self *PathFileSystemConnector) Unlink(header *InHeader, name string) (code ...@@ -374,12 +374,12 @@ func (self *PathFileSystemConnector) Unlink(header *InHeader, name string) (code
// Like fuse.c, we update our internal tables. // Like fuse.c, we update our internal tables.
self.unlinkUpdate(header.NodeId, name) self.unlinkUpdate(header.NodeId, name)
return code return code
} }
func (self *PathFileSystemConnector) Rmdir(header *InHeader, name string) (code Status) { func (self *PathFileSystemConnector) Rmdir(header *InHeader, name string) (code Status) {
code = self.fileSystem.Rmdir(path.Join(self.GetPath(header.NodeId), name)) code = self.fileSystem.Rmdir(path.Join(self.GetPath(header.NodeId), name))
self.unlinkUpdate(header.NodeId, name) self.unlinkUpdate(header.NodeId, name)
return code return code
} }
...@@ -397,12 +397,12 @@ func (self *PathFileSystemConnector) Symlink(header *InHeader, pointedTo string, ...@@ -397,12 +397,12 @@ func (self *PathFileSystemConnector) Symlink(header *InHeader, pointedTo string,
func (self *PathFileSystemConnector) Rename(header *InHeader, input *RenameIn, oldName string, newName string) (code Status) { func (self *PathFileSystemConnector) Rename(header *InHeader, input *RenameIn, oldName string, newName string) (code Status) {
oldPath := path.Join(self.GetPath(header.NodeId), oldName) oldPath := path.Join(self.GetPath(header.NodeId), oldName)
newPath := path.Join(self.GetPath(input.Newdir), newName) newPath := path.Join(self.GetPath(input.Newdir), newName)
code = self.fileSystem.Rename(oldPath, newPath) code = self.fileSystem.Rename(oldPath, newPath)
if code != OK { if code != OK {
return return
} }
// It is conceivable that the kernel module will issue a // It is conceivable that the kernel module will issue a
// forget for the old entry, and a lookup request for the new // forget for the old entry, and a lookup request for the new
// one, but the fuse.c updates its client-side tables on its // one, but the fuse.c updates its client-side tables on its
......
...@@ -38,8 +38,8 @@ const ( ...@@ -38,8 +38,8 @@ const (
FUSE_BIG_WRITES = (1 << 5) FUSE_BIG_WRITES = (1 << 5)
FUSE_DONT_MASK = (1 << 6) FUSE_DONT_MASK = (1 << 6)
FUSE_UNKNOWN_INO = 0xffffffff FUSE_UNKNOWN_INO = 0xffffffff
CUSE_UNRESTRICTED_IOCTL = (1 << 0) CUSE_UNRESTRICTED_IOCTL = (1 << 0)
FUSE_RELEASE_FLUSH = (1 << 0) FUSE_RELEASE_FLUSH = (1 << 0)
...@@ -89,7 +89,7 @@ const ( ...@@ -89,7 +89,7 @@ const (
ENOENT = Status(syscall.ENOENT) ENOENT = Status(syscall.ENOENT)
ENOTDIR = Status(syscall.ENOTDIR) ENOTDIR = Status(syscall.ENOTDIR)
EACCES = Status(syscall.EACCES) EACCES = Status(syscall.EACCES)
EPERM = Status(syscall.EPERM) EPERM = Status(syscall.EPERM)
) )
type Opcode int type Opcode int
...@@ -545,8 +545,8 @@ type RawFuseDir interface { ...@@ -545,8 +545,8 @@ type RawFuseDir interface {
// Should make interface ? // Should make interface ?
type DirEntryList struct { type DirEntryList struct {
buf bytes.Buffer buf bytes.Buffer
offset uint64 offset uint64
maxSize int maxSize int
} }
......
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