Skip to content
Browse files

Run gofmt.

  • Loading branch information...
1 parent e984150 commit b2432529297e6e2d5476449b17f2b4c17fc4e361 @hanwen committed Feb 21, 2013
Showing with 47 additions and 51 deletions.
  1. +20 −21 fs/classic.go
  2. +17 −18 fs/fs.go
  3. +4 −3 mtp/nullreader.go
  4. +2 −2 mtp/select.go
  5. +4 −7 usb/usb_test.go
View
41 fs/classic.go
@@ -2,19 +2,19 @@ package fs
import (
"fmt"
- "log"
"io/ioutil"
+ "log"
"os"
"syscall"
"time"
-
+
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-mtpfs/mtp"
)
type classicNode struct {
mtpNodeImpl
-
+
// local file containing the contents.
backing string
@@ -89,19 +89,19 @@ func (n *classicNode) send() error {
_, _, handle, err := n.fs.dev.SendObjectInfo(n.StorageID(), f.ParentObject, f)
if err != nil {
log.Printf("SendObjectInfo failed %v", err)
- return syscall.EINVAL
+ return syscall.EINVAL
}
err = n.fs.dev.SendObject(backing, fi.Size())
if err != nil {
log.Printf("SendObject failed %v", err)
- return syscall.EINVAL
+ return syscall.EINVAL
}
dt := time.Now().Sub(start)
log.Printf("sent %d bytes in %d ms. %.1f MB/s", fi.Size(),
dt.Nanoseconds()/1e6, 1e3*float64(fi.Size())/float64(dt.Nanoseconds()))
n.dirty = false
n.handle = handle
-
+
// We could leave the file for future reading, but the
// management of free space is a hassle when doing large
// copies.
@@ -168,7 +168,7 @@ func (n *classicNode) fetch() error {
func (n *classicNode) Open(flags uint32, context *fuse.Context) (file fuse.File, code fuse.Status) {
return &pendingFile{
- node: n,
+ node: n,
}, fuse.OK
}
@@ -186,9 +186,9 @@ func (n *classicNode) Truncate(file fuse.File, size uint64, context *fuse.Contex
type pendingFile struct {
fuse.DefaultFile
- flags uint32
+ flags uint32
loopback *fuse.LoopbackFile
- node *classicNode
+ node *classicNode
}
func (p *pendingFile) rwLoopback() (*fuse.LoopbackFile, fuse.Status) {
@@ -209,7 +209,7 @@ func (p *pendingFile) rwLoopback() (*fuse.LoopbackFile, fuse.Status) {
func (p *pendingFile) Read(data []byte, off int64) (fuse.ReadResult, fuse.Status) {
if p.loopback == nil {
- if err := p.node.fetch(); err!= nil {
+ if err := p.node.fetch(); err != nil {
log.Printf("fetch failed: %v", err)
return nil, fuse.EIO
}
@@ -220,15 +220,15 @@ func (p *pendingFile) Read(data []byte, off int64) (fuse.ReadResult, fuse.Status
p.loopback = &fuse.LoopbackFile{File: f}
}
return p.loopback.Read(data, off)
-}
+}
func (p *pendingFile) Write(data []byte, off int64) (uint32, fuse.Status) {
p.node.dirty = true
f, code := p.rwLoopback()
if !code.Ok() {
return 0, code
}
-
+
n, code := f.Write(data, off)
if !code.Ok() {
p.node.error = code
@@ -241,7 +241,7 @@ func (p *pendingFile) Truncate(size uint64) fuse.Status {
if !code.Ok() {
return code
}
-
+
code = f.Truncate(size)
if !code.Ok() {
return code
@@ -277,7 +277,6 @@ func (p *pendingFile) Release() {
////////////////////////////////////////////////////////////////
-
func (fs *DeviceFs) trimUnused(todo int64, node *fuse.Inode) (done int64) {
for _, ch := range node.Children() {
if done > todo {
@@ -335,7 +334,7 @@ func (fs *DeviceFs) setupClassic() error {
}
fs.delBackingDir = true
}
- if fi, err := os.Lstat(fs.options.Dir); err != nil || !fi.IsDir() {
+ if fi, err := os.Lstat(fs.options.Dir); err != nil || !fi.IsDir() {
return fmt.Errorf("%s is not a directory")
}
return nil
@@ -349,19 +348,19 @@ func (fs *DeviceFs) OnUnmount() {
func (fs *DeviceFs) createClassicFile(obj mtp.ObjectInfo) (file fuse.File, node fuse.FsNode, err error) {
backingFile, err := ioutil.TempFile(fs.options.Dir, "")
- cl:= &classicNode{
+ cl := &classicNode{
mtpNodeImpl: mtpNodeImpl{
- obj: &obj,
- fs: fs,
+ obj: &obj,
+ fs: fs,
},
- dirty: true,
+ dirty: true,
backing: backingFile.Name(),
}
file = &pendingFile{
loopback: &fuse.LoopbackFile{File: backingFile},
- node: cl,
+ node: cl,
}
node = cl
- return
+ return
}
View
35 fs/fs.go
@@ -27,18 +27,17 @@ type DeviceFsOptions struct {
Android bool
}
-
// DeviceFS implements a fuse.NodeFileSystem that mounts multiple
// storages.
type DeviceFs struct {
fuse.DefaultNodeFileSystem
- backingDir string
+ backingDir string
delBackingDir bool
- root *rootNode
- dev *mtp.Device
- devInfo mtp.DeviceInfo
- storages []uint32
- mungeVfat map[uint32]bool
+ root *rootNode
+ dev *mtp.Device
+ devInfo mtp.DeviceInfo
+ storages []uint32
+ mungeVfat map[uint32]bool
options *DeviceFsOptions
}
@@ -122,14 +121,14 @@ func (fs *DeviceFs) newFile(obj mtp.ObjectInfo, size int64, id uint32) (node fus
}
mNode := mtpNodeImpl{
- obj: &obj,
+ obj: &obj,
handle: id,
- fs: fs,
- Size: size,
+ fs: fs,
+ Size: size,
}
if fs.options.Android {
node = &androidNode{
- mtpNodeImpl:mNode,
+ mtpNodeImpl: mNode,
}
} else {
node = &classicNode{
@@ -275,10 +274,10 @@ type folderNode struct {
func (fs *DeviceFs) newFolder(obj mtp.ObjectInfo, h uint32) *folderNode {
obj.AssociationType = mtp.OFC_Association
return &folderNode{
- mtpNodeImpl: mtpNodeImpl{
+ mtpNodeImpl: mtpNodeImpl{
handle: h,
- obj: &obj,
- fs: fs,
+ obj: &obj,
+ fs: fs,
},
}
}
@@ -514,11 +513,11 @@ func (n *folderNode) Create(name string, flags uint32, mode uint32, context *fus
node = &androidNode{
mtpNodeImpl: mtpNodeImpl{
- obj: &obj,
- fs: n.fs,
- handle: handle,
+ obj: &obj,
+ fs: n.fs,
+ handle: handle,
},
- write: true,
+ write: true,
}
file = &androidFile{
node: node.(*androidNode),
View
7 mtp/nullreader.go
@@ -1,15 +1,16 @@
package mtp
+
import (
"io"
)
-
-type NullReader struct {}
+
+type NullReader struct{}
func (nr *NullReader) Read(dest []byte) (n int, err error) {
return len(dest), nil
}
-type NullWriter struct {}
+type NullWriter struct{}
func (nw *NullWriter) Write(dest []byte) (n int, err error) {
return len(dest), nil
View
4 mtp/select.go
@@ -6,7 +6,7 @@ import (
"github.com/hanwen/go-mtpfs/usb"
)
-
+
func candidateFromDeviceDescriptor(d *usb.Device) *Device {
dd, err := d.GetDeviceDescriptor()
if err != nil {
@@ -21,7 +21,7 @@ func candidateFromDeviceDescriptor(d *usb.Device) *Device {
for _, a := range iface.AltSetting {
if len(a.EndPoints) != 3 {
continue
- }
+ }
m := Device{}
for _, s := range a.EndPoints {
switch {
View
11 usb/usb_test.go
@@ -22,20 +22,20 @@ func TestDevice(t *testing.T) {
}
t.Logf("Vendor/Product %x:%x Class/subclass/protocol %x:%x:%x: %s\n",
- dd.IdVendor, dd.IdProduct, dd.DeviceClass, dd.DeviceSubClass, dd.DeviceProtocol, CLASS_names[dd.DeviceClass])
+ dd.IdVendor, dd.IdProduct, dd.DeviceClass, dd.DeviceSubClass, dd.DeviceProtocol, CLASS_names[dd.DeviceClass])
- stringDescs :=[]byte{
+ stringDescs := []byte{
dd.Manufacturer, dd.Product, dd.SerialNumber,
}
-
+
for i := 0; i < int(dd.NumConfigurations); i++ {
cd, err := dev.GetConfigDescriptor(byte(i))
if err != nil {
t.Logf("GetConfigDescriptor failed: %v", err)
continue
}
stringDescs = append(stringDescs, cd.ConfigurationIndex)
- t.Logf(" config value %x, attributes %x power %d\n", cd.ConfigurationValue,
+ t.Logf(" config value %x, attributes %x power %d\n", cd.ConfigurationValue,
cd.Attributes, cd.MaxPower)
for idx, iface := range cd.Interfaces {
t.Logf(" iface %d\n", idx)
@@ -67,6 +67,3 @@ func TestDevice(t *testing.T) {
dh.Close()
}
}
-
-
-

0 comments on commit b243252

Please sign in to comment.
Something went wrong with that request. Please try again.