List directory content - How?

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
DossKl

List directory content - How?

Post by DossKl »

Hello!
I am searching for a way to list the content of a directory and to change to an other. But I don't find anything that could help me. Are there any tutorials for this or understandable sources?
My OS runs in realmode.

Thanks for your help!

mfG
DossKl
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re: List directory content - How?

Post by df »

erm.. you have to understand the filesystem your OS is paresing...
-- Stu --
Kenneth Garin

Re: List directory content - How?

Post by Kenneth Garin »

If you're using the FAT filesystem that ms-dos uses then you must first find the LBA sector where the root directory begins. To do this you simply...
rootstart = reservedsectors + fatsizesect * fatcount
reservedsectors is how many sectors there is before the FAT table starts, for a 1.44MB floppy the number is 1 since there is one reserved sector for the bootstrap (LBA sector 0).
fatsizesect is how many sectors one single FAT occupies, for a 1.44MB floppy this would be 9 sectors.
There is two total FATs on a disk, they are both mirrors of each other so fatsizesect * fatcount = 18 (for 1.44MB flop).
To get the above values for how much reserved sectors or ect.. you have to read the bootblock LBA 0 and if you don't know how to do this then you're screwed until you learn more.
Now for a normal 1.44 floppy formatted for ms-dos the value of rootstart should be 19 (13h) so now you know where the root directory begins. Another name for the root directory is- VTOC (Volume Table Of Contents).
(quick tip, use debug and type L 100 0 13 10, it shows you a physical view of the root directory on disk in drive A: so you know how it works and looks to the OS)
Each entry in the VTOC is 32 bytes big, the first 11 characters is the filename and all others in a entry are for various other things like the first cluster hi/low and the filesize in bytes and time/date and ect...
A good document that shows how to read this information is at my web site at...
http://dakidd.freeservers.com
Click on the link on the main page that downloads the .PDF file about the FAT12/16/32. The FAT filesystem is one of the easiest fs's to program for/with.
After you learn how to read the VTOC then move on to reading the FAT and then you can move on to actually loading files. Directories are nothing more then files on there own with there own VTOC inside of them.
Hope this helps some, KG.  :D
DossKl

Re: List directory content - How?

Post by DossKl »

Thanks Kenneth, that is I wanted to know.
I already wanted to download your fat.pdf file on your webpage but I am not able to.
Are there any other documents on this? I have looked at several sites but all there about the fat-filesystem are too complicated for me.

Anyway, thank you for the information!
mfG
DossKl
Kenneth Garin

Re: List directory content - How?

Post by Kenneth Garin »

The best document on the FAT is the one at my web site. Why can't you download it? I could email it if you need. I have been studying the FAT filesystem for over a month now and it is far from easy to program for unless you're a very advanced programmer and understand exactly how ms-dos works. The main things you first need to understand is how to read the root directory and how to read the FAT table. Once you know how to read at least the root directory you can then write a quick DIR type command. Once you understand that much then you need to write a cluster reader so that you can call your cluster read routine with the cluster to read and it reads it into a buffer. Your API (in the kernel) needs to be able to read bytes of the buffer at a time and once at the end of the buffer it will read another cluster. If the cluster is a EOF marker then quit reading the file and ect.. I find that the best way to understand the FAT is by looking at good working examples, like bootstraps that load a image from the disk. Look through a well commented bootstrap and it will show you step by step how everything works. FAT16 is different from FAT12 because each FAT entry is 16 bits wide, not 12 :)
I really recommend getting that PDF file, it will teach you everything you need to know for now. Once you do get it, don't skip through parts, read it all! It shows you things you will need to know even if you don't think you need to.
Also once you learn the FAT filesystems it will be much easier to learn other fs's also since most use the same ideas that FAT uses.
Good luck, KG.
Chris Giese

Re: List directory content - How?

Post by Chris Giese »

Hi,

Here is a snapshot of my second stage bootloader:
http://www.execpc.com/~geezer/temp/boot.zip

It build with NASM and the free Turbo C 2.01
Everything is read-only. It has a VFS layer, and
works with ext2 (Linux) and FAT (DOS) disks.

The FAT filesystem code is in file FAT.C
This code doesn't work with FAT32 or handle VFAT
long file names.

The file browser code in file BING.C uses
POSIX directory functions (opendir(), readdir(),
etc.), so you can compile it separately as a DOS or
Linux program, instead of a bootloader.

Watch out for FAT12 because a 12-bit FAT entry can
straddle two 512-byte sectors. This is a pain.
Also, FAT doesn't store the exact size of directories.
Post Reply