Commit e8e94fea authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Run gofmt.

parent 49cf5940
...@@ -163,7 +163,7 @@ func (me *DefaultFile) Fsync(*FsyncIn) (code Status) { ...@@ -163,7 +163,7 @@ func (me *DefaultFile) Fsync(*FsyncIn) (code Status) {
func (me *DefaultFile) Utimens(atimeNs uint64, mtimeNs uint64) Status { func (me *DefaultFile) Utimens(atimeNs uint64, mtimeNs uint64) Status {
return ENOSYS return ENOSYS
} }
func (me *DefaultFile) Truncate(size uint64) Status { func (me *DefaultFile) Truncate(size uint64) Status {
return ENOSYS return ENOSYS
} }
...@@ -171,7 +171,7 @@ func (me *DefaultFile) Truncate(size uint64) Status { ...@@ -171,7 +171,7 @@ func (me *DefaultFile) Truncate(size uint64) Status {
func (me *DefaultFile) Chown(uid uint32, gid uint32) Status { func (me *DefaultFile) Chown(uid uint32, gid uint32) Status {
return ENOSYS return ENOSYS
} }
func (me *DefaultFile) Chmod(perms uint32) Status { func (me *DefaultFile) Chmod(perms uint32) Status {
return ENOSYS return ENOSYS
} }
......
...@@ -16,7 +16,7 @@ type MutableDataFile struct { ...@@ -16,7 +16,7 @@ type MutableDataFile struct {
} }
func (me *MutableDataFile) Read(r *ReadIn, bp *BufferPool) ([]byte, Status) { func (me *MutableDataFile) Read(r *ReadIn, bp *BufferPool) ([]byte, Status) {
return me.data[r.Offset:r.Offset+uint64(r.Size)], OK return me.data[r.Offset : r.Offset+uint64(r.Size)], OK
} }
func (me *MutableDataFile) Write(w *WriteIn, d []byte) (uint32, Status) { func (me *MutableDataFile) Write(w *WriteIn, d []byte) (uint32, Status) {
...@@ -24,7 +24,7 @@ func (me *MutableDataFile) Write(w *WriteIn, d []byte) (uint32, Status) { ...@@ -24,7 +24,7 @@ func (me *MutableDataFile) Write(w *WriteIn, d []byte) (uint32, Status) {
if int(end) > len(me.data) { if int(end) > len(me.data) {
data := make([]byte, len(me.data), end) data := make([]byte, len(me.data), end)
copy(data, me.data) copy(data, me.data)
me.data = data me.data = data
} }
copy(me.data[w.Offset:end], d) copy(me.data[w.Offset:end], d)
return w.Size, OK return w.Size, OK
...@@ -42,12 +42,12 @@ func (me *MutableDataFile) getAttr() *Attr { ...@@ -42,12 +42,12 @@ func (me *MutableDataFile) getAttr() *Attr {
a := &Attr{} a := &Attr{}
CopyFileInfo(&me.FileInfo, a) CopyFileInfo(&me.FileInfo, a)
a.Size = uint64(len(me.data)) a.Size = uint64(len(me.data))
return a return a
} }
func (me *MutableDataFile) GetAttr() *Attr { func (me *MutableDataFile) GetAttr() *Attr {
me.GetAttrCalled = true me.GetAttrCalled = true
return me.getAttr() return me.getAttr()
} }
...@@ -60,7 +60,7 @@ func (me *MutableDataFile) Utimens(atimeNs uint64, mtimeNs uint64) Status { ...@@ -60,7 +60,7 @@ func (me *MutableDataFile) Utimens(atimeNs uint64, mtimeNs uint64) Status {
me.FileInfo.Mtime_ns = int64(mtimeNs) me.FileInfo.Mtime_ns = int64(mtimeNs)
return OK return OK
} }
func (me *MutableDataFile) Truncate(size uint64) Status { func (me *MutableDataFile) Truncate(size uint64) Status {
me.data = me.data[:size] me.data = me.data[:size]
return OK return OK
...@@ -71,7 +71,7 @@ func (me *MutableDataFile) Chown(uid uint32, gid uint32) Status { ...@@ -71,7 +71,7 @@ func (me *MutableDataFile) Chown(uid uint32, gid uint32) Status {
me.FileInfo.Gid = int(uid) me.FileInfo.Gid = int(uid)
return OK return OK
} }
func (me *MutableDataFile) Chmod(perms uint32) Status { func (me *MutableDataFile) Chmod(perms uint32) Status {
me.FileInfo.Mode = (me.FileInfo.Mode &^ 07777) | perms me.FileInfo.Mode = (me.FileInfo.Mode &^ 07777) | perms
return OK return OK
...@@ -93,7 +93,7 @@ func (me *FSetAttrFs) GetAttr(name string) (*Attr, Status) { ...@@ -93,7 +93,7 @@ func (me *FSetAttrFs) GetAttr(name string) (*Attr, Status) {
return &Attr{Mode: S_IFDIR | 0700}, OK return &Attr{Mode: S_IFDIR | 0700}, OK
} }
if name == "file" && me.file != nil { if name == "file" && me.file != nil {
a := me.file.getAttr() a := me.file.getAttr()
a.Mode |= S_IFREG a.Mode |= S_IFREG
return a, OK return a, OK
} }
...@@ -131,17 +131,17 @@ func TestFSetAttr(t *testing.T) { ...@@ -131,17 +131,17 @@ func TestFSetAttr(t *testing.T) {
state.Mount(dir) state.Mount(dir)
state.Debug = true state.Debug = true
defer state.Unmount() defer state.Unmount()
go state.Loop(false) go state.Loop(false)
fn := dir + "/file" fn := dir + "/file"
f, err := os.OpenFile(fn, os.O_CREATE | os.O_WRONLY, 0755) f, err := os.OpenFile(fn, os.O_CREATE|os.O_WRONLY, 0755)
CheckSuccess(err) CheckSuccess(err)
defer f.Close() defer f.Close()
_, err = f.WriteString("hello") _, err = f.WriteString("hello")
CheckSuccess(err) CheckSuccess(err)
fmt.Println("Ftruncate") fmt.Println("Ftruncate")
code := syscall.Ftruncate(f.Fd(), 3) code := syscall.Ftruncate(f.Fd(), 3)
if code != 0 { if code != 0 {
...@@ -151,13 +151,13 @@ func TestFSetAttr(t *testing.T) { ...@@ -151,13 +151,13 @@ func TestFSetAttr(t *testing.T) {
t.Error("truncate") t.Error("truncate")
} }
if state.KernelSettings().Flags & CAP_FILE_OPS == 0 { if state.KernelSettings().Flags&CAP_FILE_OPS == 0 {
log.Println("Mount does not support file operations") log.Println("Mount does not support file operations")
m, _ := json.Marshal(state.KernelSettings()) m, _ := json.Marshal(state.KernelSettings())
log.Println("Kernel settings: ", string(m)) log.Println("Kernel settings: ", string(m))
return return
} }
_, err = os.Lstat(fn) _, err = os.Lstat(fn)
CheckSuccess(err) CheckSuccess(err)
...@@ -167,13 +167,13 @@ func TestFSetAttr(t *testing.T) { ...@@ -167,13 +167,13 @@ func TestFSetAttr(t *testing.T) {
err = os.Chmod(fn, 024) err = os.Chmod(fn, 024)
CheckSuccess(err) CheckSuccess(err)
if fs.file.FileInfo.Mode & 07777 != 024 { if fs.file.FileInfo.Mode&07777 != 024 {
t.Error("chmod") t.Error("chmod")
} }
err = os.Chtimes(fn, 100, 101) err = os.Chtimes(fn, 100, 101)
CheckSuccess(err) CheckSuccess(err)
if fs.file.FileInfo.Atime_ns != 100 || fs.file.FileInfo.Atime_ns != 101 { if fs.file.FileInfo.Atime_ns != 100 || fs.file.FileInfo.Atime_ns != 101 {
t.Error("Utimens") t.Error("Utimens")
} }
......
...@@ -32,7 +32,7 @@ type MountState struct { ...@@ -32,7 +32,7 @@ type MountState struct {
buffers *BufferPool buffers *BufferPool
*LatencyMap *LatencyMap
kernelSettings InitIn kernelSettings InitIn
} }
......
...@@ -60,10 +60,10 @@ const ( ...@@ -60,10 +60,10 @@ const (
func doInit(state *MountState, req *request) { func doInit(state *MountState, req *request) {
const ( const (
FUSE_KERNEL_VERSION = 7 FUSE_KERNEL_VERSION = 7
FUSE_KERNEL_MINOR_VERSION = 13 FUSE_KERNEL_MINOR_VERSION = 13
) )
input := (*InitIn)(req.inData) input := (*InitIn)(req.inData)
if input.Major != FUSE_KERNEL_VERSION { if input.Major != FUSE_KERNEL_VERSION {
log.Printf("Major versions does not match. Given %d, want %d\n", input.Major, FUSE_KERNEL_VERSION) log.Printf("Major versions does not match. Given %d, want %d\n", input.Major, FUSE_KERNEL_VERSION)
...@@ -82,7 +82,7 @@ func doInit(state *MountState, req *request) { ...@@ -82,7 +82,7 @@ func doInit(state *MountState, req *request) {
Major: FUSE_KERNEL_VERSION, Major: FUSE_KERNEL_VERSION,
Minor: FUSE_KERNEL_MINOR_VERSION, Minor: FUSE_KERNEL_MINOR_VERSION,
MaxReadAhead: input.MaxReadAhead, MaxReadAhead: input.MaxReadAhead,
Flags: state.kernelSettings.Flags, Flags: state.kernelSettings.Flags,
MaxWrite: maxRead, MaxWrite: maxRead,
CongestionThreshold: _BACKGROUND_TASKS * 3 / 4, CongestionThreshold: _BACKGROUND_TASKS * 3 / 4,
MaxBackground: _BACKGROUND_TASKS, MaxBackground: _BACKGROUND_TASKS,
...@@ -467,14 +467,14 @@ func init() { ...@@ -467,14 +467,14 @@ func init() {
_OP_LOOKUP: func(ptr unsafe.Pointer) interface{} { return (*EntryOut)(ptr) }, _OP_LOOKUP: func(ptr unsafe.Pointer) interface{} { return (*EntryOut)(ptr) },
_OP_OPEN: func(ptr unsafe.Pointer) interface{} { return (*EntryOut)(ptr) }, _OP_OPEN: func(ptr unsafe.Pointer) interface{} { return (*EntryOut)(ptr) },
_OP_GETATTR: func(ptr unsafe.Pointer) interface{} { return (*AttrOut)(ptr) }, _OP_GETATTR: func(ptr unsafe.Pointer) interface{} { return (*AttrOut)(ptr) },
_OP_CREATE: func(ptr unsafe.Pointer) interface{} { return (*CreateOut)(ptr) }, _OP_CREATE: func(ptr unsafe.Pointer) interface{} { return (*CreateOut)(ptr) },
} { } {
operationHandlers[op].DecodeOut = f operationHandlers[op].DecodeOut = f
} }
for op, f := range map[opcode]castPointerFunc{ for op, f := range map[opcode]castPointerFunc{
_OP_GETATTR: func(ptr unsafe.Pointer) interface{} { return (*GetAttrIn)(ptr) }, _OP_GETATTR: func(ptr unsafe.Pointer) interface{} { return (*GetAttrIn)(ptr) },
_OP_SETATTR: func(ptr unsafe.Pointer) interface{} { return (*SetAttrIn)(ptr) }, _OP_SETATTR: func(ptr unsafe.Pointer) interface{} { return (*SetAttrIn)(ptr) },
_OP_INIT: func(ptr unsafe.Pointer) interface{} { return (*InitIn)(ptr) }, _OP_INIT: func(ptr unsafe.Pointer) interface{} { return (*InitIn)(ptr) },
} { } {
operationHandlers[op].DecodeIn = f operationHandlers[op].DecodeIn = f
} }
......
...@@ -15,8 +15,8 @@ package fuse ...@@ -15,8 +15,8 @@ package fuse
- We are doing lookups (incurring GetAttr() costs) for internal - We are doing lookups (incurring GetAttr() costs) for internal
lookups (eg. after doing a symlink). We could probably do without lookups (eg. after doing a symlink). We could probably do without
the GetAttr calls. the GetAttr calls.
*/ */
import ( import (
"fmt" "fmt"
...@@ -230,7 +230,7 @@ func (me *FileSystemConnector) registerFile(node *inode, mount *mountData, f int ...@@ -230,7 +230,7 @@ func (me *FileSystemConnector) registerFile(node *inode, mount *mountData, f int
defer me.fileLock.Unlock() defer me.fileLock.Unlock()
b := &interfaceBridge{ b := &interfaceBridge{
Iface: f, Iface: f,
mountData: mount, mountData: mount,
} }
h := uint64(uintptr(unsafe.Pointer(b))) h := uint64(uintptr(unsafe.Pointer(b)))
...@@ -525,6 +525,6 @@ func (me *FileSystemConnector) getOpenFileData(nodeid uint64, fh uint64) (f File ...@@ -525,6 +525,6 @@ func (me *FileSystemConnector) getOpenFileData(nodeid uint64, fh uint64) (f File
p, m = node.GetPath() p, m = node.GetPath()
} }
return return
} }
...@@ -74,13 +74,13 @@ func (me *FileSystemConnector) Forget(h *InHeader, input *ForgetIn) { ...@@ -74,13 +74,13 @@ func (me *FileSystemConnector) Forget(h *InHeader, input *ForgetIn) {
} }
func (me *FileSystemConnector) GetAttr(header *InHeader, input *GetAttrIn) (out *AttrOut, code Status) { func (me *FileSystemConnector) GetAttr(header *InHeader, input *GetAttrIn) (out *AttrOut, code Status) {
if input.Flags & FUSE_GETATTR_FH != 0 { if input.Flags&FUSE_GETATTR_FH != 0 {
f, mount := me.getFile(input.Fh) f, mount := me.getFile(input.Fh)
attr := f.GetAttr() attr := f.GetAttr()
if attr != nil { if attr != nil {
out = &AttrOut{ out = &AttrOut{
Attr: *attr, Attr: *attr,
} }
out.Attr.Ino = header.NodeId out.Attr.Ino = header.NodeId
SplitNs(mount.options.AttrTimeout, &out.AttrValid, &out.AttrValidNsec) SplitNs(mount.options.AttrTimeout, &out.AttrValid, &out.AttrValidNsec)
...@@ -88,7 +88,7 @@ func (me *FileSystemConnector) GetAttr(header *InHeader, input *GetAttrIn) (out ...@@ -88,7 +88,7 @@ func (me *FileSystemConnector) GetAttr(header *InHeader, input *GetAttrIn) (out
return out, OK return out, OK
} }
} }
fullPath, mount, _ := me.GetPath(header.NodeId) fullPath, mount, _ := me.GetPath(header.NodeId)
if mount == nil { if mount == nil {
return nil, ENOENT return nil, ENOENT
...@@ -205,17 +205,17 @@ func (me *FileSystemConnector) SetAttr(header *InHeader, input *SetAttrIn) (out ...@@ -205,17 +205,17 @@ func (me *FileSystemConnector) SetAttr(header *InHeader, input *SetAttrIn) (out
fileResult = ENOSYS fileResult = ENOSYS
} }
} }
if err == OK && (input.Valid& (FATTR_ATIME|FATTR_MTIME|FATTR_ATIME_NOW|FATTR_MTIME_NOW) != 0) { if err == OK && (input.Valid&(FATTR_ATIME|FATTR_MTIME|FATTR_ATIME_NOW|FATTR_MTIME_NOW) != 0) {
atime := uint64(input.Atime*1e9)+uint64(input.Atimensec) atime := uint64(input.Atime*1e9) + uint64(input.Atimensec)
if input.Valid & FATTR_ATIME_NOW != 0 { if input.Valid&FATTR_ATIME_NOW != 0 {
atime = uint64(time.Nanoseconds()) atime = uint64(time.Nanoseconds())
} }
mtime := uint64(input.Mtime*1e9)+uint64(input.Mtimensec) mtime := uint64(input.Mtime*1e9) + uint64(input.Mtimensec)
if input.Valid & FATTR_MTIME_NOW != 0 { if input.Valid&FATTR_MTIME_NOW != 0 {
mtime = uint64(time.Nanoseconds()) mtime = uint64(time.Nanoseconds())
} }
if f != nil { if f != nil {
fileResult = f.Utimens(atime, mtime) fileResult = f.Utimens(atime, mtime)
} }
......
...@@ -54,7 +54,7 @@ func (me *request) InputDebug() string { ...@@ -54,7 +54,7 @@ func (me *request) InputDebug() string {
names := "" names := ""
if me.handler.FileNames > 0 { if me.handler.FileNames > 0 {
names = fmt.Sprintf("names: %v", me.filenames(me.handler.FileNames)) names = fmt.Sprintf("names: %v", me.filenames(me.handler.FileNames))
} }
return fmt.Sprintf("Dispatch: %v, NodeId: %v.%v%v", return fmt.Sprintf("Dispatch: %v, NodeId: %v.%v%v",
me.inHeader.opcode, me.inHeader.NodeId, val, names) me.inHeader.opcode, me.inHeader.NodeId, val, names)
...@@ -89,7 +89,7 @@ func (req *request) parse() { ...@@ -89,7 +89,7 @@ func (req *request) parse() {
inHSize := unsafe.Sizeof(InHeader{}) inHSize := unsafe.Sizeof(InHeader{})
if len(req.inputBuf) < inHSize { if len(req.inputBuf) < inHSize {
log.Printf("Short read for input header: %v", req.inputBuf) log.Printf("Short read for input header: %v", req.inputBuf)
return return
} }
req.inHeader = (*InHeader)(unsafe.Pointer(&req.inputBuf[0])) req.inHeader = (*InHeader)(unsafe.Pointer(&req.inputBuf[0]))
......
...@@ -20,7 +20,7 @@ const ( ...@@ -20,7 +20,7 @@ const (
FUSE_POLL_SCHEDULE_NOTIFY = (1 << 0) FUSE_POLL_SCHEDULE_NOTIFY = (1 << 0)
CUSE_INIT_INFO_MAX = 4096 CUSE_INIT_INFO_MAX = 4096
S_IFDIR = syscall.S_IFDIR S_IFDIR = syscall.S_IFDIR
S_IFREG = syscall.S_IFREG S_IFREG = syscall.S_IFREG
...@@ -132,9 +132,9 @@ const ( ...@@ -132,9 +132,9 @@ const (
) )
type GetAttrIn struct { type GetAttrIn struct {
Flags uint32 Flags uint32
Dummy uint32 Dummy uint32
Fh uint64 Fh uint64
} }
type AttrOut struct { type AttrOut struct {
...@@ -165,7 +165,7 @@ type LinkIn struct { ...@@ -165,7 +165,7 @@ type LinkIn struct {
} }
const ( // SetAttrIn.Valid const ( // SetAttrIn.Valid
FATTR_MODE = (1 << 0) FATTR_MODE = (1 << 0)
FATTR_UID = (1 << 1) FATTR_UID = (1 << 1)
FATTR_GID = (1 << 2) FATTR_GID = (1 << 2)
...@@ -243,6 +243,7 @@ type FlushIn struct { ...@@ -243,6 +243,7 @@ type FlushIn struct {
const ( const (
FUSE_READ_LOCKOWNER = (1 << 1) FUSE_READ_LOCKOWNER = (1 << 1)
) )
type ReadIn struct { type ReadIn struct {
Fh uint64 Fh uint64
Offset uint64 Offset uint64
...@@ -258,6 +259,7 @@ const ( ...@@ -258,6 +259,7 @@ const (
FUSE_WRITE_CACHE = (1 << 0) FUSE_WRITE_CACHE = (1 << 0)
FUSE_WRITE_LOCKOWNER = (1 << 1) FUSE_WRITE_LOCKOWNER = (1 << 1)
) )
type WriteIn struct { type WriteIn struct {
Fh uint64 Fh uint64
Offset uint64 Offset uint64
...@@ -384,6 +386,7 @@ const ( ...@@ -384,6 +386,7 @@ const (
FUSE_IOCTL_UNRESTRICTED = (1 << 1) FUSE_IOCTL_UNRESTRICTED = (1 << 1)
FUSE_IOCTL_RETRY = (1 << 2) FUSE_IOCTL_RETRY = (1 << 2)
) )
type IoctlIn struct { type IoctlIn struct {
Fh uint64 Fh uint64
Flags uint32 Flags uint32
......
...@@ -329,7 +329,7 @@ func (me *UnionFs) Truncate(path string, offset uint64) (code fuse.Status) { ...@@ -329,7 +329,7 @@ func (me *UnionFs) Truncate(path string, offset uint64) (code fuse.Status) {
return code return code
} }
} }
return me.fileSystems[0].Truncate(path, offset) return me.fileSystems[0].Truncate(path, offset)
} }
......
...@@ -330,11 +330,11 @@ func TestTruncate(t *testing.T) { ...@@ -330,11 +330,11 @@ func TestTruncate(t *testing.T) {
writeToFile(wd+"/ro/file", "hello") writeToFile(wd+"/ro/file", "hello")
os.Truncate(wd+"/mount/file", 2) os.Truncate(wd+"/mount/file", 2)
content := readFromFile(wd+"/mount/file") content := readFromFile(wd + "/mount/file")
if content != "he" { if content != "he" {
t.Errorf("unexpected content %v", content) t.Errorf("unexpected content %v", content)
} }
content2 := readFromFile(wd+"/rw/file") content2 := readFromFile(wd + "/rw/file")
if content2 != content { if content2 != content {
t.Errorf("unexpected rw content %v", content2) t.Errorf("unexpected rw content %v", content2)
} }
......
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