f_lseek FatFs question

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

if i append data to text.txt its work fine as long as text.txt has a minimal 1 char on it before append procedure. if i just create a blank file named text.txt it wont append.

 

UINT br;
		res = f_open(&fin, "text.txt", FA_READ | FA_WRITE);
		if(res == FR_OK)
		{
			if(f_lseek(&fin,f_size(&fin)) == FR_OK)
			{
				char *textt = "\r\n this is new line, appended to file";
				f_write(&fin, textt, strlen(textt), &br);

				_delay_ms(900);
				lcd_clear();
				lcd_str("appended");
				_delay_ms(900);
			}
			f_close(&fin);

i also used 

UINT br;
		res = f_open(&fin, "text.txt", FA_OPEN_ALWAYS | FA_WRITE);
		if(res == FR_OK)
		{
			if(f_lseek(&fin,f_size(&fin)) == FR_OK)
			{
				char *textt = "\r\n this is new line, appended to file";
				f_write(&fin, textt, strlen(textt), &br);

				_delay_ms(900);
				lcd_clear();
				lcd_str("appended");
				_delay_ms(900);
			}
			f_close(&fin);

but same problem. is there any i miss? maybe the cursor on f_sleek f_lseek?

 

edit: corrected spelling of f_lseek in title and text. Moderator

Last Edited: Sun. Jan 31, 2016 - 12:28 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What >>is<< the function returning?

 

I'd peek at the source.  F_EOF isn't listed as a return value, but is mentioned in the function description.

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

theusch wrote:

What >>is<< the function returning?

 

I'd peek at the source.  F_EOF isn't listed as a return value, but is mentioned in the function description.

 

 

i don't get it ?

Last Edited: Sat. Jan 30, 2016 - 05:07 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your code is only looking for FR_OK, and that is not happening.

 

What return value >>are<< you getting? Once you know that, then you can look in the source to see what condition is triggering that return value.

 

Myself, I'd just make a special case for 0 file size.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Sat. Jan 30, 2016 - 04:57 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

Your code is only looking for FR_OK, and that is not happening.

 

What return value >>are<< you getting? Once you know that, then you can look in the source to see what condition is triggering that return value.

 

Myself, I'd just make a special case for 0 file size.

--

 

so why if that is not happening i still get "appended" on my lcd? but nothing was appended if the file is 0 size?

do i need to use malloc to the pointer?
 

so i need another code for 0 file size?

Last Edited: Sat. Jan 30, 2016 - 05:22 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You could also look at br ...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

1. Look at the return value from f_write. Both your code snippets above simply ignore that. How is that? Have you ruled out that f_write might return something that might hint at why the write does not happen? If you code for cluelessness you get the results you deserve. Functions that have return values obviously have them for a reason.

 

2. I concur with theusch, look at br

 

3. I would also vdo the experiment of putting the \r\n at the end of the string rather than in the beginning. If it starts working with this change this hints at a bug or a peculiarity of either FatFs or FAT as such. (An alternative would be to simply write the line twice..)

 

3. None of the above might actually help you solve the problem but you need to start with the obvious. If Neither 1 nor 2 gives a clue then you need to look into the code of f_write, and possibly beyond that..

 

Now, I've seen some FatFs-calling code here merely a few weeks ago that named the bytes written parameter 'br' (rather than the more obvious 'bw'). Was sthat you or is this epidemic?

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Sat. Jan 30, 2016 - 07:26 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks for the reply, i'll take no 1.2.3 and yes no 4 ( none of above might help me,  but i can get the clue why it won't append on 0 size file) because i think you guys just give me an example or etc, but this is more than enough. be right back when found new problem :p

i usually use bw, br is because i copied and paste someone code that english is not their language. btw is just a name (maybe on other language) br is stand for bytes-write. not an epidemic

so nothing to be worried :)

Last Edited: Sun. Jan 31, 2016 - 08:59 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

zu_adha wrote:
btw is just a name

Agreed, but the unclear written will not help you to think clearly.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

so this is my debugging code
 

UINT bw;
		res = f_open(&fin, "text.txt", FA_OPEN_ALWAYS | FA_WRITE);
		if(res == FR_OK)
		{
			if(f_lseek(&fin,f_size(&fin)) == FR_OK)
			{
				char *textt = "new line";
				res = f_write(&fin, textt, strlen(textt), &bw);

				_delay_ms(900);
				lcd_clear();
				lcd_str("appended = ");

				    if(res == FR_OK)
                                    lcd_str("FR_OK");

                                    if(res == FR_DISK_ERR)
                                    lcd_str("FR_DISK_ERR");
                
                                    if(res == FR_INT_ERR)
                                    lcd_str("FR_INT_ERR");

                                    if(res == FR_INVALID_OBJECT)
                                    lcd_str("FR_INVLD_OBJT");

                                    if(res == FR_TIMEOUT)
                                    lcd_str("FR_TIMEOUT");

				_delay_ms(900);
			}
			f_close(&fin);

first i put 0 size file on mmc. and it give me FR_INT_ERR

 

and then i put 1 char on the file on mmc. and it give me FR_OK

 

on elmchan site
 

FR_INT_ERR

Assertion failed. An insanity is detected in the internal process. One of the following possibilities is suspected.

  • Work area (file system object, file object or etc...) has been broken by stack overflow or any other tasks. This is the reason in most case.
  • There is any error of the FAT structure on the volume.

Note that if once this error occured at any operation to an open file, the file object is aborted and all operations to the file except for close will be rejected.

i'll take a look on bw btw

 

note : i use FAT format MMC, is that any failure because of that? i mean if i use another mmc with FAT16/32 will give me the same result? btw i used 16MB old SDCard that cant be format to FAT16/32

and i don't have access to FAT16/32 due this problem https://www.avrfreaks.net/forum/a...

-change the code, first code was mistake debugging code-LOL

Last Edited: Sun. Jan 31, 2016 - 09:59 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JohanEkdahl wrote:

zu_adha wrote:
btw is just a name

Agreed, but the unclear written will not help you to think clearly.

 

sure....  "Words represent concepts. Use the wrong words, communicate the wrong concept." LOL

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

zu_adha wrote:

JohanEkdahl wrote:
"Words represent concepts. Use the wrong words, communicate the wrong concept."

 

sure....  "Words represent concepts. Use the wrong words, communicate the wrong concept." LOL

 

To be fair, that is a quote I have in my footer. The credits for the wisdom should go to J Morin, known here under the username 'joeymorin'.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JohanEkdahl wrote:

zu_adha wrote:

JohanEkdahl wrote:
"Words represent concepts. Use the wrong words, communicate the wrong concept."

 

sure....  "Words represent concepts. Use the wrong words, communicate the wrong concept." LOL

 

To be fair, that is a quote I have in my footer. The credits for the wisdom should go to J Morin, known here under the username 'joeymorin'.

 

yeah i copied and paste your footer, that's why i put "LOL" in the end of my sentence because you meet your footer is claiming "Agreed, but the unclear written will not help you to think clearly."

so any clue with my problem btw?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

so the problem is solved, i change my 16MB  SanDisk FAT with 2GB SanDisk FAT32 and it works !! with 0 size file. its look like FatFs fail on FAT system

Last Edited: Sun. Jan 31, 2016 - 11:09 AM