@@ -38,6 +38,7 @@ const (
3838 FileResultTooManyOpenFiles FileResult = C .FR_TOO_MANY_OPEN_FILES
3939 FileResultInvalidParameter FileResult = C .FR_INVALID_PARAMETER
4040 FileResultReadOnly FileResult = 99
41+ FileResultNotImplemented FileResult = 0xe0 // tinyfs custom error
4142
4243 TypeFAT12 Type = C .FS_FAT12
4344 TypeFAT16 Type = C .FS_FAT16
@@ -125,6 +126,8 @@ func (r FileResult) Error() string {
125126 msg = "(19) Given parameter is invalid"
126127 case FileResultReadOnly :
127128 msg = "(99) Read-only filesystem"
129+ case FileResultNotImplemented :
130+ msg = "(e0) Feature Not Implemented"
128131 default :
129132 msg = "unknown file result error"
130133 }
@@ -375,19 +378,32 @@ func (f *File) Read(buf []byte) (n int, err error) {
375378 return int (br ), nil
376379}
377380
378- /*
379381// Seek changes the position of the file
380382func (f * File ) Seek (offset int64 , whence int ) (ret int64 , err error ) {
381- errno := C.int(C.lfs_file_seek(f.lfs.lfs, &f.fptr, C.lfs_soff_t(offset), C.int(whence)))
382- if errno < 0 {
383- return -1, errval(errno)
383+ // FRESULT f_lseek (
384+ // FIL* fp, /* Pointer to the file object */
385+ // FSIZE_t ofs /* File pointer from top of file */
386+ // )
387+ switch whence {
388+ case io .SeekStart :
389+ case io .SeekCurrent :
390+ return - 1 , FileResultNotImplemented // FIXME: support these options
391+ case io .SeekEnd :
392+ return - 1 , FileResultNotImplemented // FIXME: support these options
393+ default :
394+ return - 1 , FileResultInvalidParameter
384395 }
385- return int64(errno), nil
396+ errno := C .f_lseek (f .fileptr (), C .FSIZE_t (offset ))
397+ if err := errval (errno ); err != nil {
398+ return - 1 , err
399+ }
400+ return offset , nil
386401}
387402
403+ /*
388404// Tell returns the position of the file
389405func (f *File) Tell() (ret int64, err error) {
390- errno := C.int(C.lfs_file_tell (f.lfs.lfs , &f.fptr))
406+ errno := C.int(C.f_tell (f.fileptr() , &f.fptr))
391407 if errno < 0 {
392408 return -1, errval(errno)
393409 }
0 commit comments