Page 1 of 1

opening files/reading files

Posted: Tue Oct 01, 2002 9:24 pm
by gtsphere
on a fat12 disk, how do i search for a file and then open it? i have looked at many different exmamples and i know there is an interupt somewhere, but i would really like to understand it, rather than just copy someone elses code. So is it possible to do this:

opening a file
reading a line into a variable

if anyone can offer advice it would be so great

thanks so much!!

Re:opening files/reading files

Posted: Wed Oct 02, 2002 12:20 am
by Pype.Clicker
the goal of "opening a file" is to create a structure in your OS that will hold all the informations gathered from the lookup, like
- what is the current sector of the file
- how can be found the previous/next sector if needed
- where in the current sector is the file pointer.

In a FAT12 system, all you need to do is searching the directory entries for your file name (and dive into subdirs if needed), then extracting the "first cluster" value from that entry.
Once you get the first cluster, you will have to compute
sector = <reserved+fat sectors>+<sizeof cluster>*<cluster nr>.

then just read that sector: it's the first one for your file...

If you want to read one line to a "variable", what you need to do is allocating some buffer-space for your file (the HDD will only return you sectors!) and read one sector into that buffer, then sweep it until you find a "end-of-line" tag.