Commit 2c39d5b4 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Run gofmt.

parent 391ae350
package fuse package fuse
import ( import (
"fmt" "fmt"
"unsafe" "unsafe"
...@@ -17,16 +18,16 @@ import ( ...@@ -17,16 +18,16 @@ import (
// //
// This structure is thread-safe. // This structure is thread-safe.
type HandleMap struct { type HandleMap struct {
mutex sync.Mutex mutex sync.Mutex
handles map[uint64]*Handled handles map[uint64]*Handled
nextFree uint32 nextFree uint32
} }
func (me *HandleMap) verify() { func (me *HandleMap) verify() {
if !paranoia { if !paranoia {
return return
} }
me.mutex.Lock() me.mutex.Lock()
defer me.mutex.Unlock() defer me.mutex.Unlock()
for k, v := range me.handles { for k, v := range me.handles {
...@@ -39,7 +40,7 @@ func (me *HandleMap) verify() { ...@@ -39,7 +40,7 @@ func (me *HandleMap) verify() {
func NewHandleMap() *HandleMap { func NewHandleMap() *HandleMap {
return &HandleMap{ return &HandleMap{
handles: make(map[uint64]*Handled), handles: make(map[uint64]*Handled),
nextFree: 1, // to make tests easier. nextFree: 1, // to make tests easier.
} }
} }
...@@ -59,27 +60,27 @@ func (me *HandleMap) Register(obj *Handled) (handle uint64) { ...@@ -59,27 +60,27 @@ func (me *HandleMap) Register(obj *Handled) (handle uint64) {
} }
me.mutex.Lock() me.mutex.Lock()
defer me.mutex.Unlock() defer me.mutex.Unlock()
handle = uint64(uintptr(unsafe.Pointer(obj))) handle = uint64(uintptr(unsafe.Pointer(obj)))
check := me.nextFree check := me.nextFree
me.nextFree++ me.nextFree++
if unsafe.Sizeof(obj) == 8 { if unsafe.Sizeof(obj) == 8 {
me.nextFree = me.nextFree & (1 << (64 - 48 + 3) -1) me.nextFree = me.nextFree & (1<<(64-48+3) - 1)
rest := (handle &^ (1<<48 - 1)) | (handle & (1<<3 -1)) rest := (handle &^ (1<<48 - 1)) | (handle & (1<<3 - 1))
if rest != 0 { if rest != 0 {
panic("unaligned ptr or more than 48 bits in address") panic("unaligned ptr or more than 48 bits in address")
} }
handle >>= 3 handle >>= 3
handle |= uint64(obj.check) << (64 - 48 + 3) handle |= uint64(obj.check) << (64 - 48 + 3)
} }
if unsafe.Sizeof(obj) == 4 { if unsafe.Sizeof(obj) == 4 {
rest := (handle & 0x3) rest := (handle & 0x3)
if rest != 0 { if rest != 0 {
panic("unaligned ptr") panic("unaligned ptr")
} }
handle |= uint64(check) << 32 handle |= uint64(check) << 32
} }
obj.check = check obj.check = check
...@@ -100,19 +101,18 @@ func (me *HandleMap) Forget(handle uint64) (val *Handled) { ...@@ -100,19 +101,18 @@ func (me *HandleMap) Forget(handle uint64) (val *Handled) {
func DecodeHandle(handle uint64) (val *Handled) { func DecodeHandle(handle uint64) (val *Handled) {
var check uint32 var check uint32
if unsafe.Sizeof(val) == 8 { if unsafe.Sizeof(val) == 8 {
ptrBits := uintptr(handle & (1<<45-1)) ptrBits := uintptr(handle & (1<<45 - 1))
check = uint32(handle >> 45) check = uint32(handle >> 45)
val = (*Handled)(unsafe.Pointer(ptrBits<<3)) val = (*Handled)(unsafe.Pointer(ptrBits << 3))
} }
if unsafe.Sizeof(val) == 4 { if unsafe.Sizeof(val) == 4 {
check = uint32(handle >> 32) check = uint32(handle >> 32)
val = (*Handled)(unsafe.Pointer(uintptr(handle & ((1<<32)-1)))) val = (*Handled)(unsafe.Pointer(uintptr(handle & ((1 << 32) - 1))))
} }
if val.check != check { if val.check != check {
msg := fmt.Sprintf("handle check mismatch; handle has 0x%x, object has 0x%x", msg := fmt.Sprintf("handle check mismatch; handle has 0x%x, object has 0x%x",
check, val.check) check, val.check)
panic(msg) panic(msg)
} }
return val return val
} }
...@@ -34,7 +34,7 @@ func TestHandleMapUnaligned(t *testing.T) { ...@@ -34,7 +34,7 @@ func TestHandleMapUnaligned(t *testing.T) {
b := make([]byte, 100) b := make([]byte, 100)
v := (*Handled)(unsafe.Pointer(&b[1])) v := (*Handled)(unsafe.Pointer(&b[1]))
defer markSeen("unaligned") defer markSeen("unaligned")
hm.Register(v) hm.Register(v)
t.Error("Unaligned register did not panic") t.Error("Unaligned register did not panic")
...@@ -42,11 +42,11 @@ func TestHandleMapUnaligned(t *testing.T) { ...@@ -42,11 +42,11 @@ func TestHandleMapUnaligned(t *testing.T) {
func TestHandleMapPointerLayout(t *testing.T) { func TestHandleMapPointerLayout(t *testing.T) {
if unsafe.Sizeof(t) == 4 { if unsafe.Sizeof(t) == 4 {
return return
} }
hm := NewHandleMap() hm := NewHandleMap()
bogus := uint64(1) << uint32((8*(unsafe.Sizeof(t) - 1))) bogus := uint64(1) << uint32((8 * (unsafe.Sizeof(t) - 1)))
p := uintptr(bogus) p := uintptr(bogus)
v := (*Handled)(unsafe.Pointer(p)) v := (*Handled)(unsafe.Pointer(p))
defer markSeen("48") defer markSeen("48")
...@@ -79,7 +79,7 @@ func TestHandleMapMultiple(t *testing.T) { ...@@ -79,7 +79,7 @@ func TestHandleMapMultiple(t *testing.T) {
if DecodeHandle(h) != v { if DecodeHandle(h) != v {
t.Fatal("address mismatch") t.Fatal("address mismatch")
} }
if hm.Count() != i + 1 { if hm.Count() != i+1 {
t.Fatal("count error") t.Fatal("count error")
} }
} }
...@@ -87,10 +87,10 @@ func TestHandleMapMultiple(t *testing.T) { ...@@ -87,10 +87,10 @@ func TestHandleMapMultiple(t *testing.T) {
func TestHandleMapCheckFail(t *testing.T) { func TestHandleMapCheckFail(t *testing.T) {
defer markSeen("check mismatch") defer markSeen("check mismatch")
v := new(Handled) v := new(Handled)
hm := NewHandleMap() hm := NewHandleMap()
h := hm.Register(v) h := hm.Register(v)
DecodeHandle(h | (uint64(1)<<63)) DecodeHandle(h | (uint64(1) << 63))
t.Error("Borked decode did not panic") t.Error("Borked decode did not panic")
} }
...@@ -16,13 +16,13 @@ func (me *ownerFs) GetAttr(name string) (*os.FileInfo, Status) { ...@@ -16,13 +16,13 @@ func (me *ownerFs) GetAttr(name string) (*os.FileInfo, Status) {
if name == "" { if name == "" {
return &os.FileInfo{ return &os.FileInfo{
Mode: S_IFDIR | 0755, Mode: S_IFDIR | 0755,
}, OK },OK
} }
return &os.FileInfo{ return &os.FileInfo{
Mode: S_IFREG | 0644, Mode: S_IFREG | 0644,
Uid: _RANDOM_OWNER, Uid: _RANDOM_OWNER,
Gid: _RANDOM_OWNER, Gid: _RANDOM_OWNER,
}, OK },OK
} }
func setupOwnerTest(opts *FileSystemOptions) (workdir string, cleanup func()) { func setupOwnerTest(opts *FileSystemOptions) (workdir string, cleanup func()) {
......
...@@ -80,14 +80,14 @@ func (me *FileSystemDebug) GetAttr(path string) (*os.FileInfo, Status) { ...@@ -80,14 +80,14 @@ func (me *FileSystemDebug) GetAttr(path string) (*os.FileInfo, Status) {
if path == DebugDir { if path == DebugDir {
return &os.FileInfo{ return &os.FileInfo{
Mode: S_IFDIR | 0755, Mode: S_IFDIR | 0755,
}, OK },OK
} }
c := me.getContent(path) c := me.getContent(path)
if c != nil { if c != nil {
return &os.FileInfo{ return &os.FileInfo{
Mode: S_IFREG | 0644, Mode: S_IFREG | 0644,
Size: int64(len(c)), Size: int64(len(c)),
}, OK },OK
} }
return nil, ENOENT return nil, ENOENT
} }
......
...@@ -34,8 +34,8 @@ type openedFile struct { ...@@ -34,8 +34,8 @@ type openedFile struct {
*inode *inode
Flags uint32 Flags uint32
dir rawDir dir rawDir
file File file File
} }
type mountData struct { type mountData struct {
...@@ -79,10 +79,10 @@ func (me *mountData) setOwner(attr *Attr) { ...@@ -79,10 +79,10 @@ func (me *mountData) setOwner(attr *Attr) {
} }
} }
func (me *mountData) unregisterFileHandle(node *inode, handle uint64) (*openedFile) { func (me *mountData) unregisterFileHandle(node *inode, handle uint64) *openedFile {
obj := me.openFiles.Forget(handle) obj := me.openFiles.Forget(handle)
opened := (*openedFile)(unsafe.Pointer(obj)) opened := (*openedFile)(unsafe.Pointer(obj))
node.OpenCountMutex.Lock() node.OpenCountMutex.Lock()
defer node.OpenCountMutex.Unlock() defer node.OpenCountMutex.Unlock()
node.OpenCount-- node.OpenCount--
...@@ -95,7 +95,7 @@ func (me *mountData) registerFileHandle(node *inode, dir rawDir, f File, flags u ...@@ -95,7 +95,7 @@ func (me *mountData) registerFileHandle(node *inode, dir rawDir, f File, flags u
defer node.OpenCountMutex.Unlock() defer node.OpenCountMutex.Unlock()
b := &openedFile{ b := &openedFile{
dir: dir, dir: dir,
file: f, file: f,
inode: node, inode: node,
mountData: me, mountData: me,
Flags: flags, Flags: flags,
...@@ -119,7 +119,7 @@ type inode struct { ...@@ -119,7 +119,7 @@ type inode struct {
LookupCount int LookupCount int
OpenCountMutex sync.Mutex OpenCountMutex sync.Mutex
OpenCount int OpenCount int
// Non-nil if this is a mountpoint. // Non-nil if this is a mountpoint.
mountPoint *mountData mountPoint *mountData
...@@ -218,7 +218,7 @@ func (me *inode) GetFullPath() (path string) { ...@@ -218,7 +218,7 @@ func (me *inode) GetFullPath() (path string) {
func (me *inode) GetPath() (path string, mount *mountData) { func (me *inode) GetPath() (path string, mount *mountData) {
me.mount.treeLock.RLock() me.mount.treeLock.RLock()
defer me.mount.treeLock.RUnlock() defer me.mount.treeLock.RUnlock()
if me.NodeId != FUSE_ROOT_ID && me.Parent == nil { if me.NodeId != FUSE_ROOT_ID && me.Parent == nil {
// Deleted node. Treat as if the filesystem was unmounted. // Deleted node. Treat as if the filesystem was unmounted.
return ".deleted", nil return ".deleted", nil
......
...@@ -283,7 +283,7 @@ func (me *AutoUnionFs) GetAttr(path string) (*os.FileInfo, fuse.Status) { ...@@ -283,7 +283,7 @@ func (me *AutoUnionFs) GetAttr(path string) (*os.FileInfo, fuse.Status) {
if me.getUnionFs(path) != nil { if me.getUnionFs(path) != nil {
return &os.FileInfo{ return &os.FileInfo{
Mode: fuse.S_IFDIR | 0755, Mode: fuse.S_IFDIR | 0755,
}, fuse.OK },fuse.OK
} }
return nil, fuse.ENOENT return nil, fuse.ENOENT
......
...@@ -136,10 +136,10 @@ func NewCachingFileSystem(fs fuse.FileSystem, ttlNs int64) *CachingFileSystem { ...@@ -136,10 +136,10 @@ func NewCachingFileSystem(fs fuse.FileSystem, ttlNs int64) *CachingFileSystem {
c.links = NewTimedCache(func(n string) interface{} { return readLink(fs, n) }, ttlNs) c.links = NewTimedCache(func(n string) interface{} { return readLink(fs, n) }, ttlNs)
c.xattr = NewTimedCache(func(n string) interface{} { c.xattr = NewTimedCache(func(n string) interface{} {
return getXAttr(fs, n) return getXAttr(fs, n)
}, ttlNs) },ttlNs)
c.files = NewTimedCache(func(n string) interface{} { c.files = NewTimedCache(func(n string) interface{} {
return openFile(fs, n) return openFile(fs, n)
}, ttlNs) },ttlNs)
return c return c
} }
......
...@@ -571,7 +571,7 @@ func (me *UnionFs) GetAttr(name string) (a *os.FileInfo, s fuse.Status) { ...@@ -571,7 +571,7 @@ func (me *UnionFs) GetAttr(name string) (a *os.FileInfo, s fuse.Status) {
if name == _DROP_CACHE { if name == _DROP_CACHE {
return &os.FileInfo{ return &os.FileInfo{
Mode: fuse.S_IFREG | 0777, Mode: fuse.S_IFREG | 0777,
}, fuse.OK },fuse.OK
} }
if name == me.options.DeletionDirName { if name == me.options.DeletionDirName {
return nil, fuse.ENOENT return nil, fuse.ENOENT
......
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