Keil™, An ARM® Company

Discussion Forum

Diff between File system and FAT file system

Next Thread | Thread List | Previous Thread Start a Thread | Settings

DetailsMessage
Read-Only
Author
keil Enthu
Posted
2-Jul-2009 08:06 GMT
Toolset
ARM
New! Diff between File system and FAT file system

Hi to all, i started to work on FAT file system on SD 1GB card. LPC2388 on MCB2300 board.

Just now i have completed my binary search on File system on SD card. Simply fopen, fread, fseek,etc.

Now i have to work on SD card using FAT file system. i went through so many web pages that didnt answer my question or i was not able to understand.

how to make a File allocating table on my SD Card? Some simple example can give me a good start...

my question is Whats the difference between Normal File system (which i have done on my SD card) and FAT File system?

And I had formatted the SD card on LAPTOP with the 2 options of FAT(Default) and FAT32.
When i tried to use the card after i did format using FAT(Default) option, i was able to work with my code which i developed for SD card using normal File system.

But if format using FAT32 option, then while trying to initialize the card it says SD card un formatted.

So what its trying to say?

So by default my controller accept FAT12?

Can i use FAT32 on the same SD card for my same code in which i didnt give an option to recognize FAT32?

As i studied from the web source for FAT16, the clusters address divide my SD card in to sectors and gives back the location address to me(2^16 address)?

So on for FAT32?

So please give me some clear explanation how to start? And i gone through Wikipedia and all the sources so dont give me the link for wikipedia pls.

Read-Only
Author
Tamir Michael
Posted
2-Jul-2009 08:20 GMT
Toolset
ARM
New! RE: Diff between File system and FAT file system

Just now i have completed my binary search on File system on SD card. Simply fopen, fread, fseek,etc.

Now i have to work on SD card using FAT file system

but how could you, without implementing your own FAT FS?
please explain and try to focus your questions to the core issues - what EXACTLY are you trying to do?

Read-Only
Author
Per Westermark
Posted
2-Jul-2009 08:36 GMT
Toolset
ARM
New! RE: Diff between File system and FAT file system

FAT12, FAT16 or FAT32 are basically the same thing. The big difference is how many bits that are used in each FAT entry, to point at a usable cluster. With 12 bits, you can not have more than 4096 clusters. With 16 bits, you can have at most 65536 clusters. With 32 bits, you can have 2^32 clusters.

For a large memory card, you will either need to have few but large clusters, or switch to a version of the FAT file system that has more bits to address many smaller clusters.

You can write code that autodetects if a memory card has FAT12, FAT16 or FAT32. I really do thing you should return to the wikipedia pages and read them again - and possibly a third time. If you are going to implement your own FAT code, then you must understand how the FAT file system works. How to detect the file-system parameters (such as FS type, cluster size, ...) How to locate a primary and secondary FAT. How to locate the root directory. How to translate a directory entry into a chain if clusters. How to compute the address of these clusters to retrieve the data. How to differentiate between used and unused clusters (in case you need write support).

Read-Only
Author
keil Enthu
Posted
2-Jul-2009 10:26 GMT
Toolset
ARM
New! RE: Diff between File system and FAT file system

but how could you, without implementing your own FAT FS?
please explain and try to focus your questions to the core issues - what EXACTLY are you trying to do?

y did i say that means I didnt create any clusters, volume , drive and directory. by default it may be FAT12 i think.

In the file_config.c i made my default drive as memory card drive.

i was using RT Agent and File_config.h which provided by RL ARM.

So i was directly influenced by create anything.

So as you said should i have a FAT to implement a file system?
My code working well. So what FAT's role over there?

When ever i need a data i just fopen, fread and fseek with the data what ever i need. if a match occurs simply i read the data from that location using offset..

        FILE *loc;
        FILE *dat;
        loc = fopen ("Index.txt", "r");
        dat = fopen ("UserLocation.txt", "r");

then i do the Binary searching

        mid = (begin + end) / 2;
                offset = mid;

            fseek (loc, offset * 2, SEEK_SET);
            fread (&count2[0], 2, 1, loc);

                location = count2[0];

            fseek (dat, location * 4, SEEK_SET);
                fread (&First_fourByte[0], 4, 1, dat);

Then normal C code...

I think i did not understand the FAT FS well. I know there might be some good for me when i understand it fully. Where i am using FAT here?

Read-Only
Author
Andy Neil
Posted
2-Jul-2009 09:10 GMT
Toolset
ARM
New! RE: Diff between File system and FAT file system

"Whats the difference between Normal File system (which i have done on my SD card) and FAT File system?"

There is no such thing as a "Normal File system" - there are plenty of different file systems, but you can't say that one of them is uniquely "Normal" and all the others are not!

"FAT File System" is usually taken to mean the Microsoft FAT File System - as found on MS-DOS and later Microsoft systems.

The technical specification of the Microsoft FAT File System is available for free download here: http://www.microsoft.com/whdc/system/platform/firmware/fatgen.mspx

FatFs is an open-source implementation of the Microsoft FAT File System: http://elm-chan.org/fsw/ff/00index_e.html

It includes an example for SD Cards: http://elm-chan.org/docs/mmc/mmc_e.html

Read-Only
Author
keil Enthu
Posted
2-Jul-2009 10:29 GMT
Toolset
ARM
New! RE: Diff between File system and FAT file system

However i cant fseek a data when i opened a file for writing?

So can a FAT fs fix this issue?

Read-Only
Author
Andy Neil
Posted
2-Jul-2009 10:54 GMT
Toolset
ARM
New! i cant fseek a data when i opened a file for writing?

Is that a question, or a statement?

Does the specification of your fseek function say that this should be possible?

"can a FAT fs fix this issue?"

See previous reply: "a FAT fs" simply means any file system that uses a File Allocation Table - so it is impossible to answer your question without knowing which specific FAT File System you are talking about, and which specific implementation of that file system you are talking about!

Read-Only
Author
keil Enthu
Posted
2-Jul-2009 11:58 GMT
Toolset
ARM
New! Still in confusion

Something still i am in confusion..

FAT12 can have 2^12 clusters.
so Each cluster can hold how much data?
A typical cluster size is 2,048 bytes, 4,096 bytes, or 8,192 bytes

So for my 1 GB SD card how many clusters i need and what ill be the each clusters size/
and how its depend my project requirement?

Explain me with an example if you wish..

continue....How it relates to Size of the memory card?
And how to choose a FAT(12 or 16 or 32) with the size of SD card?
What are the criteria presents to choose a FAT fs?

And FAT32 or FAT16 formatting can only done by PC or our MCU can do this?

as per said How can we figure out which FAT system table available in the SD card by using a MCU?

Read-Only
Author
Andy Neil
Posted
2-Jul-2009 12:12 GMT
Toolset
None
New! SD Cards

I think the format to be used on the card is defined by the card manufacturers.

If you use the http://elm-chan.org/fsw/ff/00index_e.html implementation, this is all handled for you.

Read-Only
Author
Per Westermark
Posted
2-Jul-2009 13:16 GMT
Toolset
None
New! RE: SD Cards

You don't want to receive Wiki links, but the question is:
Have you _really_ read this page?
http://en.wikipedia.org/wiki/File_Allocation_Table

1GB and max 32kB cluster size means how many clusters?
4096 clusters * 32kB is 128MB.

Any PC or microcontroller can create a FAT12, FAT16 or FAT32 file system. It is just a question of if the used source code supports it, and if the connected hardware needs it.

A camera can manage reasonably well with FAT16, since it generates few, but large, photos. This means that the waste will be small if you format the memory card with very large clusters.

But 65536 clusters of 32kB is still a limiting factor, since that would represent a limit of 2GB.

You might have noticed that older cameras (or MP3 players, ...) do not support FAT32 and can't be used with larger memory cards.

Next step up is of course to consider patens and licenses. Microsoft will _probably_ only be able to sue if you implement support for long file names. The alternative is to pay licensing fees.

Read-Only
Author
John Linq
Posted
3-Jul-2009 03:40 GMT
Toolset
None
New! RE: SD Cards

->
However i cant fseek a data when i opened a file for writing?

So can a FAT fs fix this issue?
<-

http://www.keil.com/support/man/docs/rlarm/rlarm_fseek.htm

Note

* Seeking within a file opened for "w" mode is currently unsupported.

Read-Only
Author
John Linq
Posted
3-Jul-2009 03:57 GMT
Toolset
None
New! RE: SD Cards

Hi keil Enthu,

To better understand and control the SD-card on you embedded system, you need to learn a lot of things. There is no shortcut.

But in your situation, you might be able to treat something as a Black Box, and just use them until you encounter a related problem.

However, you must need to read the manual of RLARM, it is the basic requirement.

Read-Only
Author
Andy Neil
Posted
3-Jul-2009 06:53 GMT
Toolset
None
New! RE: must need to read the manual of RLARM

Only if he is actually using RLARM - which has not been mentioned before.

RLARM is certainly not necessary to implement a File System - including the MS FAT File Systems - on an SD Card.

Read-Only
Author
keil Enthu
Posted
3-Jul-2009 07:24 GMT
Toolset
None
New! RE: must need to read the manual of RLARM

Only if he is actually using RLARM - which has not been mentioned before.

I was using RLARM only for my existing project(Binary search on SD card file system).

Read-Only
Author
keil Enthu
Posted
3-Jul-2009 07:19 GMT
Toolset
None
New! RE: SD Cards

Ok i take all your advice.

but if i get any simple or big doubt, to whom i can ask??

i can ask here and to you peoples only...:)

I dont want to make more no of threads by simply asking small small doubts(Even i try to figure out by my self) and wasting your time ...

Then my post may not be worthy to all. may give bore to the thread readers...

Thats why i wanted to make it as single and bulk...

Anyway i want to make this post as worth for me.

So in the chan's documents in which i went through, What they mean by Disk(Isn't not SD card)?

Whats that No of physical drive on SD card?

And on SD card also do we have physical drives?

Do we have to partition the SD card into no of physical drives?and how?

Read-Only
Author
Per Westermark
Posted
3-Jul-2009 07:27 GMT
Toolset
None
New! RE: SD Cards

Are you going to implement a FATx file system yourself, or use an existing implementation?

If you are going to implement one - format the card in a PC and then read back the structures and analyze them. That should give you a lot of ideas about how a FAT file system works.

Read-Only
Author
Andy Neil
Posted
3-Jul-2009 08:29 GMT
Toolset
None
New! RE: format the card in a PC

I think that may not be a good idea?

I seem to remember reading somewhere that you need to take care when formatting an SD-Card in a PC - or you can end up with an inappropriate format.

The disks come correctly formatted from the manufacturer - so don't mess with the formatting if at all poissible!

Read-Only
Author
Per Westermark
Posted
3-Jul-2009 08:45 GMT
Toolset
None
New! RE: format the card in a PC

This is the classical concept already discussed above. Format with FAT16 and huge clusters, or FAT32 and small clusters. And a lot of MP3 players or cameras will not support FAT32, in which case they will reject a card that is default-formatted by a PC.

That is a good reason for formatting a card in the device it is intended to be used with.

If the goal is to decode data structures, then it is helpful to also test with the values generated by a PC. A number of cameras manages to generate incorrect file systems, where some fields either have incorrect values, or no values at all.

Read-Only
Author
Andy Neil
Posted
3-Jul-2009 08:26 GMT
Toolset
None
New! RE: in the chan's documents...

You are referring to http://elm-chan.org/fsw/ff/00index_e.html aren't you?

You need to make this clear, as not everyone reading this thread will automatically know what you mean by "the chan's documents"

"So in the chan's documents in which i went through, What they mean by Disk (Isn't not SD card)?"

It uses the term "disk" generically to mean "the physical storage medium" - so that includes real disks, SD-Cards, or anything else.

This is much the same as the way that PCs view storage media like SD-Cards and USB sticks: they all appear as "drives", and it is (largely) irrelevant whether the "drive" is a real disk or not...

Read-Only
Author
keil Enthu
Posted
6-Jul-2009 12:43 GMT
Toolset
ARM
New! RE: Came back with Black box doubts

Hi to all,
I trying to understand the FAT fs. So i made some efforts for that. now i am referring http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/arm_memcards/#chanfat_lpc2k_mci

i made some changes on the code and i got some results :).

my code from main.c is:

    FATFS *fs;/* Pointer to file system object */
    DWORD fre_clust, fre_sect, tot_sect;
    DRESULT Disk;
    FRESULT res1;




    IoInit(); //Timer, UART and LED initialize

    xputs("\nFatFs module test monitor for LPC2388");

    w1 = f_mount(0,fs); // mounting logical drive 0
    xprintf("\r\nmount status %d",w1);

//    res = disk_initialize(0); // physical drive 0. But i dont know why
//      xprintf("\r\n Return value of diak_initilize() is %d",res);

     Disk = disk_status(0); // status if physical drive 0
     xprintf("\r\n Return value of diak_status() is %x",Disk);


    // Get drive information and free clusters
    res1 = f_getfree("/Test.txt", &fre_clust, &fs);
    if (res1)
        put_rc(res1);
    xprintf("\r\n Retuen value of getfree() is %d",res1);

//      xprintf("\r\n Free Clusters %ld",fre_clust);




    // Get total sectors and free sectors
    tot_sect = (fs->max_clust - 2) * fs->csize;
    fre_sect = fre_clust * fs->csize;

    // Print free space in unit of KB (assuming 512B/sector)
    xprintf("%\r\nlu KB total drive space.\n"
           "%lu KB available.\n",
           fre_sect / 2, tot_sect / 2);


    // Open source file
    res1 = f_open(&file1, "Test.txt", FA_OPEN_EXISTING | FA_READ);
    if (res1)
        {
                put_rc(res1);
        }
        xprintf("\r\n status Opening Test1 file %d",res1);

    // Create destination file
    res1 = f_open(&file2, "b.txt", FA_CREATE_ALWAYS | FA_WRITE);
    if (res1)
        {
                put_rc(res1);
        }
        xprintf("\r\n status of opening b file %d",res1);


    // Copy source to destination
    for (;;)
        {
        res1 = f_read(&file1, Buff, sizeof(Buff), &br);
        if (res1 || br == 0)
                {
                        put_rc(res1);
                        xprintf("\r\n Reading status %d",res1);
                        break;   // error or eof
                }
                xprintf("\r\n Read sta %d",w1);
        res1 = f_write(&file2, Buff, br, &bw);
        if (res1 || bw < br)
                {
                        put_rc(res1);
                        xprintf("\r\n write status %d",res1);
                        break;   // error or disk full
                }
        xprintf("\r\n Write Sta %d",w1);
    }

   // Close all files
    f_close(&file1);
    f_close(&file2);

    // Unregister a work area before discard it
    f_mount(0, NULL);

i give the result here.

FatFs module test monitor for LPC2388

mount status 0

Return value of diak_status() is MCI_INIT ok
no timeout on CMD8 -> SD-Card>=Version 2.0
ACMD41 success -> SD-Card SC or HC
SDSC detected
MCI_Send_CSD result: 002f0032 5f5983bd edb7ff9f 964000a8
setting 4bit width success

rc=11 FR_NO_FILESYSTEM
Retuen value of getfree() is 11MCI_INIT ok
no timeout on CMD8 -> SD-Card>=Version 2.0
ACMD41 success -> SD-Card SC or HC
SDSC detected
MCI_Send_CSD result: 002f0032 5f5983bd edb7ff9f 964000a8
setting 4bit width success

rc=11 FR_NO_FILESYSTEM

status Opening Test1 file 11MCI_INIT ok
no timeout on CMD8 -> SD-Card>=Version 2.0
ACMD41 success -> SD-Card SC or HC
SDSC detected
MCI_Send_CSD result: 002f0032 5f5983bd edb7ff9f 964000a8

I dont remember that i formatted SD card by either FAT32 or FAT Default.

But after the result i tried to format it again, but it using FAT32 but it says write protected.
But i didnt make it as write protected.

So how can i remove this Write protected?

I dont know whats the MCI_Send_CSD result?
What those values tell me?

Then i tried to fwrite a file and copy that file to another file. but i always failed. Y?

The way i am going on is correct or not?
From Andy and per's lot of reply helped me to come to this level. But still i need more....

f_mkdir("0:sub1");


It says invalied drive.
But

f_mkdir("1:sub1");

This one succeed. but is this a folder? like we create a new folder in Harddisk?

But i tried to read themon laptop. but no sign of them.
However it says write protected, but creating root directory has been succeed?

pls. need help?

Read-Only
Author
John Linq
Posted
7-Jul-2009 02:07 GMT
Toolset
ARM
New! RE: Came back with Black box doubts

->I dont know whats the MCI_Send_CSD result?
What those values tell me?
<-

In the below thread

http://www.keil.com/forum/docs/thread15098.asp

Andy (Andy Neil) provided a link to

the free "simplified" version of the SD Card interface specification

http://www.sdcard.org/developers/tech/sdcard

Search this documentation with "SEND_CSD", you will found:

The host issues SEND_CSD
(CMD9) to obtain the Card Specific Data (CSD register), e.g. block length, card storage capacity, etc.

Read-Only
Author
John Linq
Posted
7-Jul-2009 02:28 GMT
Toolset
ARM
New! RE: Came back with Black box doubts

->So how can i remove this Write protected?<-

You need to find the related function/source code, study it, find out that, how it works, why it detects a "Write protected".

To better understand and control the SD-card on you embedded system, you need to learn a lot of things. There is no shortcut.

But in your situation, you might be able to treat something as a Black Box, and just use them until you encounter a related problem.

However, before you modify any lines of the source code, you must need to read the documentation.

You need to know that Andy and Per are very intelligent and experienced experts, everything they told you will need you to spend several days or weeks to study.

My level is much closer to you, and I suggest that, RLARM/RLFlash is good for NXP LPC23xx, you should use it, and treat everything you don't understand as a Black Box.

Read-Only
Author
keil Enthu
Posted
10-Jul-2009 08:30 GMT
Toolset
ARM
New! RE: Not able to find out still

Hi to all:(

Still i am not able to get any success on anything even i tried so many options(changing in the code).

But the same results or not good results.

Still i am working on this because i believe i can get some help from you peoples.

All commends i tried but no results. I followed the flow of cmds. But same results.

from the http://elm-chan.org/fsw/ff/en/dwrite.html

DRESULT disk_write ( BYTE Drive, /* Physical drive number */ const BYTE* Buffer, /* Pointer to the write data (may be non aligned) */ DWORD SectorNumber, /* Sector number to write */ BYTE SectorCount /* Number of sectors to write */
);

Here what is SectorNumber. What value i should give here?

From the page http://www.sdcard.org/developers/tech/sdcard/pls/Simplified_Physical_Layer_Spec.pdf
page no 89 gives me the details of received CSD values.
But with my result of CSD doesn't match with that table.

MCI_Send_CSD result: 002f0032 5f5983bd edb7ff9f 964000a8

From this value how can i get my Sector address where i can f_write and f_read?

The 0th bit of CSD is reserved int the doc that should be 1. but in my result Which one is that reserved bit? Please reply for my all questions. If you leave any then i ill be blank always.

simply here i am trying to write a sector with some value.

    FATFS fs;   // Work area (file system object) for logical drive
    BYTE buffer[4096];   // file copy buffer

        disk_initialize(0);

        i = disk_status(0);
        xprintf("\r\nDisk status is :%d", i);

        for(i = 0; i < 10; i++)
        buffer[i] = i;

        i = disk_write(0, (const BYTE *)&buffer, 0xD2, 56);
        xprintf("\r\nWrite status is :%d", i);

This one gives the result
MCI_INIT ok
no timeout on CMD8 -> SD-Card>=Version 2.0
ACMD41 success -> SD-Card SC or HC
SDSC detected
MCI_Send_CSD result: 002f0032 5f5983bd edb7ff9f 964000a8
setting 4bit width success

Disk status is :0

Write status is :0

Should i give BLOCK_LEN before i read or write the Block?

The Basic thing still i dont know is after formatting the card how to read the clusters and sectors with without file system?

Please really i tried a lot. I need some point out from you to make it....

From when i started i am trying so many things but no progress. hard luck...

Read-Only
Author
John Linq
Posted
10-Jul-2009 10:36 GMT
Toolset
ARM
New! RE: Not able to find out still

Do you have a disk_write() function for LPC2388?

Read-Only
Author
John Linq
Posted
10-Jul-2009 10:41 GMT
Toolset
ARM
New! RE: Not able to find out still
i = disk_write(0, (const BYTE *)&buffer, 0xD2, 56);

For example: 0xD2, what is that?

Read-Only
Author
keil Enthu
Posted
10-Jul-2009 11:02 GMT
Toolset
ARM
New! RE: Not able to find out still

Oh Thanks for your reply.

DWORD SectorNumber, /* Sector number to write */

But 0xD2 i collected from the CSD return value. But the thing is i dont know what correct value i have to put over there to get a correct reply.

DRESULT disk_write ( BYTE Drive, /* Physical drive number */ const BYTE* Buffer, /* Pointer to the write data (may be non aligned) */ DWORD SectorNumber, /* Sector number to write */ BYTE SectorCount /* Number of sectors to write */
);

So physical drive no is 0.
Buffer is (const BYTE *)&buffer,
SectorNumber is 0xD2(i assumed wrongly),
SectorCount is 56(but i tried 0 and 1).
but 0 is not a valid value.

I know i am doing wrongly. But i am not able to figure it out..pls

Read-Only
Author
keil Enthu
Posted
10-Jul-2009 11:08 GMT
Toolset
ARM
New! RE: Not able to find out still

Do you have a disk_write() function for LPC2388?

I guess i am not using this from RL ARM lib. This is available in diskio.c/.h for low level disk I/O module for lpc23xx/24xx.

But really i dont know the answer for your question..

Read-Only
Author
John Linq
Posted
11-Jul-2009 03:16 GMT
Toolset
ARM
New! Some news from Taiwan, not really related to KEIL forum.

No matter who provides/produces that products,
before we trust and rely on them, we better inspect them first.

=======================================

( long-unchanged fast food frying oil )

McDonald's apologizes over frying oil violation

http://taiwanjournal.nat.gov.tw/ct.asp?xItem=53791&ctNode=413

Four out of seven local fast food restaurants, including big names like McDonald's, KFC, and Domino's Pizza, failed frying oil spot checks in Taipei County June 21.

Taipei County's consumer protection officers announced the spot-check results June 29. The acid value of frying oil at McDonald's Zhongyang Road branch in Tucheng City reached 23.88 mg KOH/g, almost 12 times higher than the standard 2.0 mg KOH/g.

Carcinogens Found On McDonald's And KFC Food In Taipei County

http://www.chinacsr.com/en/2009/07/10/5646-carcinogens-found-on-mcdonalds-and-kfc-food-in-taipei-county/

Read-Only
Author
John Linq
Posted
11-Jul-2009 03:48 GMT
Toolset
ARM
New! RE: Some news from Taiwan, not really related to KEIL forum.

MRT malfunction strands hundreds

http://www.taipeitimes.com/News/front/archives/2009/07/11/2003448368

The Taipei City MRT's Neihu and Muzha lines were suspended yesterday afternoon after a sudden power outage, forcing about 700 passengers to walk down the elevated rail lines to return to station platforms after trains stopped between stations.

The lines are scheduled to resume operating at 6am today. The suspension of services yesterday was the first serious system failure on the Neihu Line since it began operations last Saturday.

Mayor apologizes for Neihu/Muzha MRT line's suspension

http://www.etaiwannews.com/etn/news_content.php?id=1000157&lang=eng_news

===========================================

Muzha line was built by MATRA, a French Company.

Neihu line is built by Bombardier, a Canadian Company.

News written in Chinese says that, the root cause might be related to System Integration Problem.

When we want to integrate a working-fine solution A and a working-fine solution B into a Big Project, there are alway a lot of problems, which need our effort to resolve.

Next Thread | Thread List | Previous Thread Start a Thread | Settings