LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Embedded & Single-board computer (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/)
-   -   Write data stream to SD-Card (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/write-data-stream-to-sd-card-775518/)

jcornuz 12-14-2009 04:50 AM

Write data stream to SD-Card
 
My device receives a data stream. I want to write a C program to save this data stream to many files in a SD-Card. The SD-Card is formatted in FAT32 for a compatibility reason. I want to write full page of memory to aim to improve the write efficiency and get longer life of the SD-Card. Is it possible to lock the synchronization between the cache buffer and the storage device until the buffer is as long as the page size ? In other word, flush only full page of data ? Or I have to format the SD-Card to JFFS2 or YAFFS ?

Regards

business_kid 12-15-2009 03:33 AM

Welcome to LQ. If you're writing C, that ought do be doable in your program. If you have to ask, you've failed the exam :-P. The system has it's own mind on matters, and doing that through the system is not on.

jcornuz 12-15-2009 07:24 AM

Thanks for your quick answer.

Yes, I'm writing in C. That was actually my idea to store temporary the data stream in a buffer, and when I have enough data (one page size), write them in the SD-Card :
write (fd, buffer, PAGE_SIZE);

But I was wondering if the OS really flushes the data in one time from the virtual memory to the hardware.

Maybe a other method it to map the memory :
mem = mmap (0, PAGE_SIZE, PROT_WRITE, MAP_SHARED, PAGE_SIZE * pageCounter);
memcpy (mem, buffer, PAGE_SIZE);
munmap (mem, PAGE_SIZE);

But again, my question is the same, does the OS flush in one time from the virtual memory to the hardware ? I hope so with the MAP_SHARED flag.

business_kid 12-16-2009 03:16 AM

If you're writing C make sure to install the info pages from your distro, as they have entries for the various function calls. There is a HOWTO and several guides on programming for linux. People will expect you to have a knowledge of that stuff before you start asking. I will bow out here, as C is not hugely my thing.


All times are GMT -5. The time now is 06:46 AM.