Knowning your way in a file system

Hello,
My apologies for asking a question that is not strictly Keil related, but I know that there are people here with different backgrounds of experiences - maybe one of you can help me? I am using the Keil tool set so cut me some slack...

I need to build a system that has one simple property: depending on the requested folder by the host, the device must provide the contents of differnet peripherals. to be more exact: The device itself is a USB mass storage device, and I can already display the contents of an on-board SD card, and a piece of RAM dedicated to hold FAT12. that is not the problem. the real issue is that I must be able to tell accesses to specific folder apart, in order to provide the host with the appropriate data. I have a feeling that the host, asking the device data in blocks of 64 bytes each, knows more than the device. the host knows which folder you want to browse and interrogates the device's FAT (reading even more than it needs), in which it can search for the right entry and address the disk at the proper location (again, the host asking a certain sector could also mean that the required data starts at a certain offset from the beginning of the sector - but does the device know that?). since I am operating in the realm of the device only - can I achieve the same? or: how can I make sure that browsing into folder "SD" will yield the contents of the file system of the SD card, while "xram" the content of a file system in external RAM?

Parents
  • Hello Michael,

    You want to provide different sets of data residing in different folders - right ?

    So first thing is that you must get away from thinking "data-wise"

    If you want to be an USB Mass storage, all you have in hand are always SECTORS.
    The organisation of them is beyond your control and always OS-dependant.

    If you want to pretend to be a FAT12 disk, you need to set up the initial data sectors to hold valid data, eg the boot sector, die FAT and the directory entries. You can see that in the Keil sample.

    So this is what you would need (just roughly to clarify)

    Rootsector
    FAT
    Rootdirectory containing directory entries to point to your intended subdirectories

    these subdirs need directory entries for your files
    and finally you need the "files"

    so when you want the OS to access a file, it will read root, then subdirs and then access the file via read_sector. This is the point where your data need to be prepared and be sent to host

    Maybe you should just think of say four files in root containing different data
    (if the naming incl paths is not fixed from somewhere for whatever reason)

    this yould be a stage easier

    Rootsector -> rootdir -> containing
    directory entries for
    FILE_A (FAT points to say sector 14
    FILE_B -> Sec 15
    FILE_C -> Sec 16

    every read access to sec 16 then means, that s.o. wants to read the file C, then you have to prepare and send the data needed for that case

    and be sure to mark drive as read only or reject any write issues

Reply
  • Hello Michael,

    You want to provide different sets of data residing in different folders - right ?

    So first thing is that you must get away from thinking "data-wise"

    If you want to be an USB Mass storage, all you have in hand are always SECTORS.
    The organisation of them is beyond your control and always OS-dependant.

    If you want to pretend to be a FAT12 disk, you need to set up the initial data sectors to hold valid data, eg the boot sector, die FAT and the directory entries. You can see that in the Keil sample.

    So this is what you would need (just roughly to clarify)

    Rootsector
    FAT
    Rootdirectory containing directory entries to point to your intended subdirectories

    these subdirs need directory entries for your files
    and finally you need the "files"

    so when you want the OS to access a file, it will read root, then subdirs and then access the file via read_sector. This is the point where your data need to be prepared and be sent to host

    Maybe you should just think of say four files in root containing different data
    (if the naming incl paths is not fixed from somewhere for whatever reason)

    this yould be a stage easier

    Rootsector -> rootdir -> containing
    directory entries for
    FILE_A (FAT points to say sector 14
    FILE_B -> Sec 15
    FILE_C -> Sec 16

    every read access to sec 16 then means, that s.o. wants to read the file C, then you have to prepare and send the data needed for that case

    and be sure to mark drive as read only or reject any write issues

Children
More questions in this forum