github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/pkg/mount/mtd/ops_linux.go (about) 1 // Copyright 2019 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package mtd 6 7 import ( 8 "os" 9 ) 10 11 // Dev contains information about ongoing MTD status and operation. 12 type Dev struct { 13 *os.File 14 devName string 15 } 16 17 // DevName is the default name for the MTD device. 18 var DevName = "/dev/mtd0" 19 20 // NewDev creates a Dev, returning Flasher or error. 21 func NewDev(n string) (Flasher, error) { 22 f, err := os.OpenFile(n, os.O_RDWR, 0) 23 if err != nil { 24 return nil, err 25 } 26 return &Dev{File: f, devName: n}, nil 27 } 28 29 // QueueWrite adds a []byte to the pending write queue. 30 func (m *Dev) QueueWrite(b []byte, off int64) (int, error) { 31 return m.File.WriteAt(b, off) 32 } 33 34 // SyncWrite syncs a pending queue of writes to a device. 35 func (m *Dev) SyncWrite() error { 36 return nil 37 } 38 39 // ReadAt implements io.ReadAT 40 func (m *Dev) ReadAt(b []byte, off int64) (int, error) { 41 return m.File.ReadAt(b, off) 42 } 43 44 // Close implements io.Close 45 func (m *Dev) Close() error { 46 return m.File.Close() 47 } 48 49 // DevName returns the name of the flash device. 50 func (m *Dev) DevName() string { 51 return m.devName 52 }