how to start writing in the end of an existing file? (SD Card)

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

hello to all

 

i am using ff.h library for working with sd card.

 

i want to go to end of file to continue writing

 

and used this code:

 

f_lseek(&file,f_size(&file));

 

but the compliler shows below error:

 

Error: C:\Users\...\sd_test.c(77): undefined symbol 'f_size'

 

please help me by your priceless comments

 

best regards

This topic has a solution.

Last Edited: Tue. Sep 20, 2016 - 01:39 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Interesting, as http://elm-chan.org/fsw/ff/en/si... says "f_size 'always available' ".

 

I use an older FATFS version.  In my code, I access it in the FIL structure, or FILINFO structure after filling it in .

 

/* File object structure */
typedef struct _FIL {
	WORD	id;				/* Owner file system mount ID */
	BYTE	flag;			/* File status flags */
	BYTE	csect;			/* Sector address in the cluster */
	FATFS*	fs;				/* Pointer to owner file system */
	DWORD	fptr;			/* File R/W pointer */
	DWORD	fsize;			/* File size */
	CLUST	org_clust;		/* File start cluster */
	CLUST	curr_clust;		/* Current cluster */
	DWORD	curr_sect;		/* Current sector */
#if !_FS_READONLY
	DWORD	dir_sect;		/* Sector containing the directory entry */
	BYTE*	dir_ptr;		/* Ponter to the directory entry in the window */
#endif
} FIL;


/* File status structure */
typedef struct _FILINFO {
	DWORD fsize;			/* Size */
	WORD fdate;				/* Date */
	WORD ftime;				/* Time */
	BYTE fattrib;			/* Attribute */
	char fname[8+1+3+1];	/* Name (8.3 format) */
} FILINFO;

In practice:

					// Put file pointer at end of file
					card_retval = f_lseek (&card_file_log, card_file_log.fsize);

 

There is no f_size macro in my build R0.06 .

 

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

Interesting, in my version of FATFS (R0.12b 2016, #define _FATFS    68020    /* Revision ID */) I do have the macro:

#define f_size(fp) ((fp)->obj.objsize)

Edit: in ff.h

David (aka frog_jr)

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

So I guess as a start we need to know what version OP is using?

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

hidian wrote:
i am using ff.h library (sic) 

ff.h is not a library - it is just a header file.

 

Have you also included the actual library (Whether as source or an actual pre-built library) in your project?

 

but the compliler shows below error:

 

Error: C:\Users\...\sd_test.c(77): undefined symbol 'f_size'

Is that the one & only error - or do you also get others?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hidian wrote:
i want to go to end of file to continue writing

So why don't you just open the file in Append mode??

 

See FA_OPEN_APPEND - http://elm-chan.org/fsw/ff/en/op...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks alot, i used your code

card_retval = f_lseek (&card_file_log, card_file_log.fsize);

and it work correctly.

 

 

 

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

So I guess as a start we need to know what version OP is using?

i use CodevisionAVR and couldn't find out which version of FATSF is added to it.

Have you also included the actual library (Whether as source or an actual pre-built library) in your project?

yes, the actual library is included and i can write.

Is that the one & only error - or do you also get others?

yes,its only error.

 

So why don't you just open the file in Append mode??

i couldn't use it. an error occure like this: undefined FA_APPEND

 

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

Is FA_APPEND the same as FA_OPEN_APPEND then? 

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

yes, this the error:

Error: C:\Users\...\M_Bayati.c(90): undefined symbol 'FA_OPEN_APPEND'

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

Have you included ff.h in the file M_Bayati.c (prior to line 90)?

 

Edit: If yes, then what revision is listed in the first two lines of ff.h?

David (aka frog_jr)

Last Edited: Sat. Sep 17, 2016 - 12:30 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hidian wrote:
i use CodevisionAVR and couldn't find out which version of FATSF is added to it.

Aahh, yes, when bound into CV FATFS is kind of a black box.  But your .h should be plain text.  Does that give a hint as to version?  When you do Find in Files, does CV come up with any hits on f_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. Sep 17, 2016 - 02:22 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

IIRC gcc has an option that will tell it to print all defined macros.

Can't find it right now.

"SCSI is NOT magic. There are *fundamental technical
reasons* why it is necessary to sacrifice a young
goat to your SCSI chain now and then." -- John Woods

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

skeeve wrote:
IIRC gcc has an option that will tell it to print all defined macros.
hidian wrote:
i use CodevisionAVR

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

Just for the record it is "-E -dM", but as Lee says, not relevant here.

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

theusch wrote:
 When you do 'Find in Files', does CV come up with any hits on f_size ?

Or even on FA_OPEN_APPEND ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dear friends thanks for your priceless comments.

i use the code

card_retval = f_lseek (&card_file_log, card_file_log.fsize);

and my problem has solved.