FAT LFN order

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Agola
Member
Member
Posts: 155
Joined: Sun Nov 20, 2016 7:26 am
Location: Somewhere

FAT LFN order

Post by Agola »

Hello forum.

I was implementing FAT32, FAT16 and FAT12 in my os. It's almost done, except one thing.

According to fatgen103 documentation (https://staff.washington.edu/dittrich/m ... gen103.pdf), LFN entries doesn't have to be fully ordered. But does it apply for first and last entries? So can I safely assume the first (entry->order is 0x1, or 0x41 if it's the first and last entry) LFN entry is just before the directory entry and the last (entry->order ORed with 0x40) LFN entry is the first entry of directory like that:

Image

And what's the best and correct method of parsing LFN entries? This is the method that I use:

Code: Select all

      ...
      {
            while (1)
            {
                 lfn_entry_t* lfn_entry = (lfn_entry_t*) (cluster_buffer + buffer_index);
                 uint32_t lfn_order = lfn_entry->order & 0x3F;

                 memcpy((uint8_t*)long_name_buffer, &lfn_entry->name_1, 10);
                 memcpy((uint8_t*)long_name_buffer + 10, &lfn_entry->name_2, 12);
                 memcpy((uint8_t*)long_name_buffer + 22, &lfn_entry->name_3, 4);
           
                 for (uint8_t index = 0; long_name_buffer[index] && long_name_buffer[index] != 0xFFFF && index < 13; index++) name_buffer[(lfn_order - 1) * 13 + index] = long_name_buffer[index] & 0xFF;

                 buffer_index += sizeof(lfn_entry_t);

                 if (lfn_order == 1) break;
            }

            directory_entry_t* directory_entry = (directory_entry_t*) (cluster_buffer + buffer_index);
            buffer_index += sizeof(directory_entry_t);

            ...
     }
     ...


This is really simple for now, and it doesn't make the important things like comparing checksums and checking lfn order. I'm going to make it better after I learn how can I correctly parse the LFN entries.

Thanks in advance.
Keyboard not found!

Press F1 to run setup.
Press F2 to continue.
Post Reply