This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

how to decide the data size in a FLASH memory?



Hello, i would like to know how can one determine how much data is written on a NAND-FLASH drive without reading the entire FLASH drive? how does a USB-flash drive/windows OS determine how much data is written into it?

i would like to implement the same using a NAND flash. Wehn a user plugs in a MSP430 with NAND-flash in its peripheral, MSP430 should be able to determine how much data is written onto the NAND flash...

any algorithm would be appreaciated...

  • Funny1234 Guy said:
    how does a USB-flash drive/windows OS determine how much data is written into it?

    By maintaining an allocation table. However, this table does nto tell how much was written to it, only which sectors have to be considered containing valid data.
    The flash controller may maintain an additional internal table where it keeps information which sectors have been erased (so they can be written to wihtout prior erase) or have failed write and need to be replaced by spare sectors.

    However, the 'capacity uused' information depends solely on teh information itself. In case of a file system, the file system itself contains information about what valid data is and what is obsolete. The flash drive itself doesn't know about the meaning, about what is still needed and what not. It just writes where it is told to write and reads form wwhere it is told to read. However, some 'smart' drivers 'know' the windows file system (usually FAT32) and can run the same algorithm on stored data as windows itself does. As long as the data stored on it really is this known file system.

    At the end, it is up to you to define how data is stored and how to keep track of what has been stored and where.

  • so, if we would like to implement this feature in a NAND flash, how can we do it? suppose the NAND flash contains analog input  data about sensors being acquired and saved onto it.

  • You could reserve a block of the flash and write an information structure there, containing some data which might be useful for you. Like: Data Start, Data End, Total Data, Total Space available, last access and well a lot of other things.

    If your MSP starts it will first read the information structure and then can calculate how much space is free. Of course this requires that the writing program keeps the information structure up to date everytime it changes data, or at least at the end of the process. 

    If you have no control over the writing part and there is no information structure written anywhere, I guess you are out of luck and have to search for the end of data. As Jens wrote in Windows the file system will contain such informations or it can be derived from the information stored.

    Probably noone notices this, but as soon as you plug in a FAT32 formatted pen drive into the PC Windows will read the entire file allocation table and buffer it somewhere in RAM and by doing that it will have the information about space usage readily available - but still it needs to read the 8 MB or whatever size the FAT has to get that informations - so it's not doing some magic. You can check that for yourself using the SysInternals tools - there is one available which tracks low level access. I used this to compare my own program for getting all files on a FAT32 against a dir /s. 

**Attention** This is a public forum