|
|
@ -24,6 +24,10 @@ type File struct { |
|
|
|
// Open opens a file and returns it as an fs.File to
|
|
|
|
// satisfy the fs.FS interface
|
|
|
|
func (blefs *FS) Open(path string) (*File, error) { |
|
|
|
if blefs.readOpen { |
|
|
|
return nil, ErrReadOpen |
|
|
|
} |
|
|
|
blefs.readOpen = true |
|
|
|
// Make a read file request. This opens the file for reading.
|
|
|
|
err := blefs.request( |
|
|
|
FSCmdReadFile, |
|
|
@ -49,6 +53,10 @@ func (blefs *FS) Open(path string) (*File, error) { |
|
|
|
|
|
|
|
// Create makes a new file on the BLE file system and returns it.
|
|
|
|
func (blefs *FS) Create(path string, size uint32) (*File, error) { |
|
|
|
if blefs.writeOpen { |
|
|
|
return nil, ErrWriteOpen |
|
|
|
} |
|
|
|
blefs.writeOpen = true |
|
|
|
// Make a write file request. This will create and open a file for writing.
|
|
|
|
err := blefs.request( |
|
|
|
FSCmdWriteFile, |
|
|
@ -316,9 +324,14 @@ func (fl *File) Seek(offset int64, whence int) (int64, error) { |
|
|
|
return int64(newOffset), nil |
|
|
|
} |
|
|
|
|
|
|
|
// Close implements the fs.File interface.
|
|
|
|
// It just returns nil.
|
|
|
|
// Close must be called before opening another file
|
|
|
|
func (fl *File) Close() error { |
|
|
|
if fl.isReadOnly { |
|
|
|
fl.fs.readOpen = false |
|
|
|
} else if fl.isWriteOnly { |
|
|
|
fl.fs.writeOpen = false |
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|