fat12 simple question
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
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
Re: fat12 simple question
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).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
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.
Re: fat12 simple question
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.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.
JAL
Re: fat12 simple question
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.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 ..
JAL
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.
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.
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).kestaz wrote:no i can't figure out .. how directory entry can point to many list of files ? how it's possible ?
Perhaps you should read and try to understand the official FAT specification that you can find here. It's all in there.
JAL
Re: fat12 simple question
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).jal wrote: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.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.
JAL
Re: fat12 simple question
Perhaps the Linuxes use shell interpretation for . and .., but original Unix always used hardlinks.jal wrote: "." and ".." ... Unix file systems, which rely on the shell to interpret these ...
JAL
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
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
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!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 ...
No, they are not in the root directory, as mentioned.OK .. As you said there's ".." , "." but i can't see them ..
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!I see mane junk in my dump .. How to avoid it ?
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.any help will be appropriate
JAL