opening files/reading files

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
gtsphere

opening files/reading files

Post 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!!
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:opening files/reading files

Post 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.
Post Reply