github.com/system-transparency/u-root@v6.0.1-0.20190919065413-ed07a650de4c+incompatible/pkg/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 data []byte 16 } 17 18 // DevName is the default name for the MTD device. 19 var DevName = "/dev/mtd0" 20 21 // NewDev creates a Dev, returning Flasher or error. 22 func NewDev(n string) (Flasher, error) { 23 f, err := os.OpenFile(n, os.O_RDWR, 0) 24 if err != nil { 25 return nil, err 26 } 27 return &Dev{File: f, devName: n}, nil 28 } 29 30 // QueueWrite adds a []byte to the pending write queue. 31 func (m *Dev) QueueWrite(b []byte, off int64) (int, error) { 32 return m.File.WriteAt(b, off) 33 } 34 35 // SyncWrite syncs a pending queue of writes to a device. 36 func (m *Dev) SyncWrite() error { 37 return nil 38 } 39 40 // ReadAt implements io.ReadAT 41 func (m *Dev) ReadAt(b []byte, off int64) (int, error) { 42 return m.File.ReadAt(b, off) 43 } 44 45 // Close implements io.Close 46 func (m *Dev) Close() error { 47 return m.File.Close() 48 } 49 50 // DevName returns the name of the flash device. 51 func (m *Dev) DevName() string { 52 return m.devName 53 }