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

Run gofmt.

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