OSDev.org https://forum.osdev.org/ |
|
fat12 simple question https://forum.osdev.org/viewtopic.php?f=1&t=15888 |
Page 1 of 1 |
Author: | kestaz [ Thu Jan 10, 2008 8:11 pm ] |
Post subject: | fat12 simple question |
Hi all. I am trying to write fat12 img reader, but i have problem. I read http://www.osdev.org/osfaq2/index.php/FAT12%20document FAT12 documentation, but i can't figure out how directories and subdirectories are organized in fat12 file system .. maybe i misted something ? For example simpe directories tree: root / \ foo bar | test.txt and the Directory structure : Bytes Meaning 0 - 10 File name with extension 11 Attributes of the file 12 - 21 Reserved Bytes 22 - 23 Indicate the time 24 - 25 Indicate the date 26 - 27 Indicate the entry cluster value 28 - 31 Indicate the size of the file And can't see any pointers that will show how the directories tree is created ? How foo subdirectory will know that she belongs to root directory ? How the file test.txt will now that he belongs to foo subdirectory .. and etc .. kestaz |
Author: | skyking [ Fri Jan 11, 2008 1:39 am ] |
Post subject: | Re: fat12 simple question |
kestaz wrote: Hi all.
and the Directory structure : Bytes Meaning 0 - 10 File name with extension 11 Attributes of the file 12 - 21 Reserved Bytes 22 - 23 Indicate the time 24 - 25 Indicate the date 26 - 27 Indicate the entry cluster value 28 - 31 Indicate the size of the file And can't see any pointers that will show how the directories tree is created ? How foo subdirectory will know that she belongs to root directory ? How the file test.txt will now that he belongs to foo subdirectory .. and etc .. kestaz Simple it doesn't. The knowledge is that the directory entry knows what type of file each entry corresponds to (the directory knows it contents, but the contents does not know which directory it belongs to). If the subdirectory bit is set (0x10) the directory entry corresponds to a directory (and the it's size is determined via the FAT). In your case the root directory contains two entries (foo and bar), foo having subdir bit set. Folowing the entry cluster you find it's contents - clusters containing directory entries, one of them being test.txt. Having the files (and directories) not knowing which directory they belong to is important when implementing hard links since then the files can belong to multiple directories. |
Author: | jal [ Fri Jan 11, 2008 5:55 am ] |
Post subject: | Re: fat12 simple question |
skyking wrote: Having the files (and directories) not knowing which directory they belong to is important when implementing hard links since then the files can belong to multiple directories.
However, totally unimportant for FAT, since it doesn't have hard links. In fact, subdirectories actually have the "." and ".." as part of the directory contents (unlike Unix file systems, which rely on the shell to interpret these), and ".." actually links to the parent directory. JAL |
Author: | jal [ Fri Jan 11, 2008 6:00 am ] |
Post subject: | Re: fat12 simple question |
kestaz wrote: How foo subdirectory will know that she belongs to root directory ? How the file test.txt will now that he belongs to foo subdirectory .. and etc ..
Directories and files do not know anything about their location. I thinks there are very little file systems that store this knowledge together with the file. For FAT, all file information is stored in the directory 'file' (as opposed to e.g. the Unix-like file systems where the file information is stored in a global structure called 'i-node'). To build a complete directory tree, you start with the root directory. In the root directory, there are entries that indicate they are subdirectories. Read these subdirectories to discover their contents, etc. JAL |
Author: | kestaz [ Fri Jan 11, 2008 7:37 am ] |
Post subject: | |
no i can't figure out .. how directory entry can point to many list of files ? how it's possible ? |
Author: | hailstorm [ Fri Jan 11, 2008 8:24 am ] |
Post subject: | |
Skyking allready gave you the answer: Bits 26 and 27 gives you the starting cluster of the directory. B.t.w. The directory is just a file, but operating systems tend to use the directory for another purpose... You have to parse the fat-chain for the directory and read the cluster that belongs to that fat entry. All files and directories don't have any clue of their parent whatsoever. A file doesn't know to which directory it belongs and this is also true for a subdirectory. Subdirectories however, have 2 entries: dot (.) and dotdot (..). These entries point to itself and its parent respectively. That is, byte 26 and 27 contain the starting cluster. Hope this helps. |
Author: | jal [ Fri Jan 11, 2008 8:33 am ] |
Post subject: | |
kestaz wrote: no i can't figure out .. how directory entry can point to many list of files ? how it's possible ?
A directory is the same as a regular file, as far as the FAT file system is concerned. That means that it occupies disk sectors that you can read. A directory contains entries describing files that are 'inside' that directory. A directory is an array of 32-byte structures, each structure describing one file. The attributes inside the structure tell you whether it is a regular file or a directory (or a volume label, but you can ignore that one). Perhaps you should read and try to understand the official FAT specification that you can find here. It's all in there. JAL |
Author: | skyking [ Fri Jan 11, 2008 11:17 am ] |
Post subject: | Re: fat12 simple question |
jal wrote: skyking wrote: Having the files (and directories) not knowing which directory they belong to is important when implementing hard links since then the files can belong to multiple directories. However, totally unimportant for FAT, since it doesn't have hard links. In fact, subdirectories actually have the "." and ".." as part of the directory contents (unlike Unix file systems, which rely on the shell to interpret these), and ".." actually links to the parent directory. JAL I meant to design a VFS to rely on files to know where they are located is a bad idea for that reason (not that it matters much for FAT12). |
Author: | bewing [ Fri Jan 11, 2008 2:48 pm ] |
Post subject: | Re: fat12 simple question |
jal wrote: "." and ".." ... Unix file systems, which rely on the shell to interpret these ...
JAL Perhaps the Linuxes use shell interpretation for . and .., but original Unix always used hardlinks. |
Author: | kestaz [ Fri Jan 11, 2008 6:04 pm ] |
Post subject: | |
thanks everybody for replies. Still don't understand So I am wrote some code to make ROOT STRUCTURE dump .. You can see it at http://www.pastebin.ca/851490 ok i will try to explain what i don't understand Name: UNTITLED 2 ( Ext: 2 ( starting_sector: 0 Ok everything clear at this point.. I made image of usb flash .. so it was named UNTITLED .. Name: LABAS TXT !¨π)8)8 Ext: TXT !¨π)8)8 starting_sector: 23 And there's file.. And i see it's points to 23 .. OK .. it's points to FAT Name: LABAS -wπ)8)8 Attribute: directory Ext: -wπ)8)8 starting_sector: 22 Ok there's directory .. hmm but what 22 shows ? Where this pointer points ? To the FAT ? TO the ROOT DIRECTORY STRUCTURE ? I still i don't understand ... OK .. As you said there's ".." , "." but i can't see them .. I see mane junk in my dump .. How to avoid it ? You can see my code: http://www.pastebin.ca/851504 hope it helps.. any help will be appropriate |
Author: | jal [ Mon Jan 14, 2008 3:42 am ] |
Post subject: | |
kestaz wrote: Ok there's directory .. hmm but what 22 shows ? Where this pointer points ? To the FAT ? TO the ROOT DIRECTORY STRUCTURE ? I still i don't understand ... Please, PLEASE, PLEASE read the offical FAT specification I linked to somewhere earlier in the thread. It is really all in there. If you don't understand details of it, fine, let's discuss those, but it seems you just want us to provide all the answers that you can easily find yourself! Quote: OK .. As you said there's ".." , "." but i can't see them .. No, they are not in the root directory, as mentioned. Quote: I see mane junk in my dump .. How to avoid it ? The strings aren't zero-terminated, so you cannot use %s without specifying a width when printing. And that's something else easily available from the specification. Use %.8s and %.3s instead! Quote: any help will be appropriate
I (and no doubt many others) are more than willing to help, but like I said, please check the documentation first before asking questions, as we are not here to spell it out for you. JAL |
Page 1 of 1 | All times are UTC - 6 hours |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |