Page 1 of 1

How 2 create files in FAT12 ?

Posted: Fri Jun 24, 2005 3:42 pm
by viral
hi...
I have implemented a floppy driver and a fat12(partial) driver. I can read files and explorer directories. But how can i create new files or directories in FAT12 disk ?

Re:How 2 create files in FAT12 ?

Posted: Fri Jun 24, 2005 4:36 pm
by smiddy
1 ) Find first free directory entry
2 ) Place file information there
3 ) Find first free cluster in FAT
4 ) Save (starting) cluster number to directory entry
5 ) Save file to sector of correpsonding cluster
6 ) If file is greater than one cluster, find next free cluster, else goto 9
7 ) Place next cluster number into last cluster
8 ) Repeat 5, 6, and 7 until end of file
9 ) Mark last cluster as last cluster

That's it off the top of my head...hope that helps.

Re:How 2 create files in FAT12 ?

Posted: Sat Jun 25, 2005 3:15 am
by Dex4u
There is only one more thing, i would add to smiddy list, that is check file/dir with same name is not already on the disk.

Re:How 2 create files in FAT12 ?

Posted: Sat Jun 25, 2005 11:52 am
by viral
Thanks for the reply...
But can u plz tell me how to find the free sectors ?

Re:How 2 create files in FAT12 ?

Posted: Sat Jun 25, 2005 1:40 pm
by smiddy
Dex4u wrote: There is only one more thing, i would add to smiddy list, that is check file/dir with same name is not already on the disk.
Whoops, that is correct. You don't wanna write the same file name twice... ;)

Re:How 2 create files in FAT12 ?

Posted: Sat Jun 25, 2005 1:44 pm
by smiddy
viral wrote: Thanks for the reply...
But can u plz tell me how to find the free sectors ?
Well, you'd look in the fat for the first cluster that is zero. For further information and a very infomative look into FAT file system, look here: http://www.rose-hulman.edu/Users/class0 ... gen102.pdf

This document is full of answer to what I expect your next question(s) will be. Happy coding.

Re:How 2 create files in FAT12 ?

Posted: Sat Jun 25, 2005 2:38 pm
by Dex4u
You can tell its a M$ doc, when the licence agreement take 6 pages ;D.

Re:How 2 create files in FAT12 ?

Posted: Sun Jun 26, 2005 8:03 am
by smiddy
Yeah, its all about protection. They pay their legal department to ensure their proprietary rights are covered. :P

Re:How 2 create files in FAT12 ?

Posted: Tue Jun 28, 2005 1:37 pm
by viral
Thnx for that doc... its really helpfull.
Now i have made a "class Fat12" which has all functions to excess files and folders. Can i built a common "class FAT" which can work for any given type of fat(12, 16 or 32). Actually i have heard about vfs but i dont know anything about it. And i want to implement the same. I only have a floppy driver with me. Is it sufficient or I should do something else?

Re:How 2 create files in FAT12 ?

Posted: Tue Jun 28, 2005 2:31 pm
by smiddy
I assume by class you mean C++? I am not versed in it and would probably steer you in the wrong direction in that regard, however with my limited knowledge of C++, I would say it should be possible.

Re:How 2 create files in FAT12 ?

Posted: Tue Jun 28, 2005 3:11 pm
by Kim
You write a base fat class and make other fat classes extend that one. So when you mount a fat12 disk, you will spawn a fat12 class but you interface to it as if was the base class. So for the system it doesn't make any differents.

Re:How 2 create files in FAT12 ?

Posted: Tue Jun 28, 2005 9:37 pm
by AR
A VFS (Virtual Filesystem) is demonstrated by Linux, it is essentially exactly what it's called, it's an imaginary filesystem. So for example:
/home
/etc
/usr
/var

The elements can be accessed by fopen("/usr/something.txt", "r"); as you would expect but appearances are decieving as they could be for example:
/ -> /dev/hda2
/home -> /dev/hda5
/usr -> /dev/hda6
/var -> /dev/hda7
Key: hda1 = Hard Drive 1, Partition 1

So essentially the VFS allows physical partitions to be mounted as folders within the virtual filesystem, all of which is transparent to user software unless it is explicitly checking the mount points.

Re:How 2 create files in FAT12 ?

Posted: Wed Jun 29, 2005 4:29 am
by viral
so thats "virtual file system"....
that means to implement vfs , first i must have "floppy driver & Hard disk driver". i guess floppy driver is optional but harddisk is must...
do "vfs" stores its information in a unique filesystem (like ext2fs) or it does not required it..

sorry i am posting here to avoid unnecessary new thread.

Re:How 2 create files in FAT12 ?

Posted: Wed Jun 29, 2005 4:45 am
by AR
Linux has a "root filesystem" which is mounted as the base point ("/"), that can be avoided to a certain extent by mounting root as a ram disk. The filesystem itself is really just a map pointing to the physical drive(s).

I don't know what Linux does exactly internally but my guess is that it translates the path so from my above example /usr/something.txt would be translated to /dev/hda6/something.txt (and then we can get more complicated in that /dev/hda6 is a link to another file making it something like /devices/ide0/drv0/part6/something.txt).

The hard drive drivers are not a requirement, the VFS is just a map of points where other partitions are mounted within the root partition, the root partition itself as well as the mounted partitions can all be RAM drives or whatever you like. For example, Linux has pretend filesystems like proc, usbfs and devfs which provide interfaces for the kernel, usb devices and general hardware respectively within the VFS.

Re:How 2 create files in FAT12 ?

Posted: Wed Jun 29, 2005 5:02 am
by distantvoices
This mapping can be performed as easy as by storing information about the fs driver and the according partition - so we know which device driver to ask for data with which minor number - in some driver structure which is passed to a field in the vnodes. (at least I do it this way in my own vfs layer - simplifys things a lot)

upon mounting you get some data from disk, query it for what kind of filesystem we have here and initialize the adequate structures: the root inode of this file system (it gets the device and fs driver which is passed to all underlying nodes) The fs driver is just a set of functions which map to vfs calls - to perform fs specific tasks.

To make proper vfs, know ya, you have to split between fs independent and fs dependent tasks. So you can easily go the oop approach with function pointers and have an easy life. :-)

If you have more questions, bug me. :-)