µTasker Forum

µTasker Forum => utFAT => Topic started by: neil on January 08, 2015, 05:31:22 AM

Title: utReadFile/utWriteFile return code
Post by: neil on January 08, 2015, 05:31:22 AM
Hi Mark,
  if a utReadFile(..) command doesnt return UTFAT_SUCCESS, can I assume that no data was read, and the file position hasnt moved, so another read would continue from the same position within the file? The same with utWriteFile, if it doesnt return UTFAT_SUCCESS , can I assume no data was written and the file position hasnt changed, so another attempt will continue from the same place?

I ask the above, as mentioned in a previous post, there is a possibility that the SD cards internal processor may be busy when a request is made, thus preventing the command to return success.

Best Regards
Neil
Title: Re: utReadFile/utWriteFile return code
Post by: mark on January 08, 2015, 02:28:47 PM
Hi Neil

You will need to check the error code that is returned.

- when the card is temporarily busy the function will not return until it has completed the work. Therefore it will never return without doing what was requested from it unless there was an "error" that means that the operation fail
- If the opertion failed it will presumably be due to HW problems an so the error code should help what the exact problem was
- In the case of errors it is not possible to generally say how much data was successfully written or read so an error is more a "catastrophic" error unless not due to somethig like tryig to access a file that doesn't exist where of course no file pointers etc. are involved.

Regards

Mark
Title: Re: utReadFile/utWriteFile return code
Post by: neil on January 08, 2015, 03:59:13 PM
Hi Mark,
  Thanks for the reply. 

If UTFAT_SUCCESS is not returned , is there any problems then reading the ptr_utFile->usLastReadWriteLength value then do a Seek(..) , only if its not zero, with the UTFAT_SEEK_CUR option , just to make sure the position is in the same place as before the read/write? 
Is ptr_utFile->usLastReadWriteLength always set to a value , regardless if UTFAT_SUCCESS is returned or not?


Regard
Neil
Title: Re: utReadFile/utWriteFile return code
Post by: mark on January 08, 2015, 06:35:05 PM
Neil

usLastReadWriteLength is set to zero when the read or write is started.
It is then incremented by the amount of "successfully" read/written data. Since data is read in chunks (sector size) it will be incremented for each successfully chunk read (or by the valid content when partical chunks are involved)
This means that if a read/write fails you can indeed use this value to know how much data was "successfully" read/written before a problem was detected.

Regards

Mark