problem with low-level file creation

The company that I work for produces embedded controls. The project that I'm working on now runs on an ARM7 microprocessor. We're not using any commercial RTOS or API for file operations - all of the software is written by the software team. Currently, we are developing the ability to write a file to an SD card that's attached to our target. We've learned how to deal with FAT, including FAT12, FAT16 and FAT32, and can read any size file. We can also change the contents of an existing file. (After removing the SD card and putting it into a card reader attached to a computer running Windows XP, we see the new contents).

When we create a file, we can read it using our software. We can also see the directory entry we've made. But when we try to open it by clicking on it (it's a .txt file), XP tells us that it can't find the file.

Our file creation algorithm basically goes like this, with some refinements:

search for a free directory entry

if free entry found

search for free cluster in FAT

if free FAT cluster found

create new entry in directory *

write new directory to SD card

while there's more data

search for a free cluster in FAT

if there's a free cluster

write data to correct cluster location on SD card

update FAT table with cluster number

update FAT table with EOF value in cluster location

write updated FAT to SD card

* All of the following actions for creating a new entry in a directory are performed on a buffer, before we write it to the SD card

enter name (bytes 0-7, padded with spaces if necessary)

enter extension (bytes 8-10, padded with spaces if necessary)

enter attribute (byte 11 0x20 for archive)

enter NT byte (byte 12 I'm using 0x18 because that seems to be what other, XP-created files use)

enter fine resolution byte (byte 13 - I think this is optional, but I'm entering a value)

enter time of creation (bytes 14-17; I'm taking an arbitrary date and time, but it displays correctly)

enter last access time (bytes 18-19; I think this is optional but I enter a value)

enter high 2 bytes of first cluster for FAT32 for bytes 20-21; no entry if I'm using FAT16

enter last modified time (bytes 22-25; I'm taking an arbitrary date and time, but it displays correctly)

enter first cluster for FAT12 or FAT16, low 2 bytes of cluster for FAT32 (bytes26-27)

enter file size (bytes 28-31)

The essence of the problem is that the file that we create can be seen and read by our software, but XP can't open it.

Thanks in advance to anyone who can offer any guidance or assistance!

Sallyz



Answer this question

problem with low-level file creation

  • Waleedead

    This question is related to the previous one about low-level file creation on FAT - I'm writing a file to an SD card. I know I must enter upper case letters in the directory entry in order for windows to be able to open the file. I'm trying to create a file with the path \\ABC\\DEF.TXT

    My software enters the directory "ABC" on the root, and changes the name of the file to "DEF TXT" so it will be in upper case and in 8.3 format. With the debugger, I can see the entry for "DEF TXT" on the ABC subdirectory as I'm creating it. But afterwards, when I put the card in a card reader, Window shows the entry for the file in lower case. Also, when I try to open it, I get "failed to open document" and, from Notepad, "the file or directory is corrupted and unreadable". I believe that I've done everything I need to do with the FAT (it looks as I expect it to in the debugger). I make a directory with dot and dotDot entries for ABC. And it looks like the file data is being written to the correct address. The thing that puzzles me is why the file name turns up in lower case when I've explicitly created an entry for it in upper case.

    I really need some enlightenment on this issue!

    Thanks!

    SallyZ


  • aspnovice

    I solved my problem. The solution was to enter the file and extension in the directory in upper case letters (they were lower case.)

    sallyz


  • problem with low-level file creation