Page 1 of 1

reading a text file

Posted: Tue Dec 04, 2007 11:31 am
by vishal
i have implemented putch() , getchar() and other elemnetary functions in c [without the header files] now i want to perform read operations on a text file before loading the kernel ...... i am utterly confused in implemneting file i/o functions??? please help
i can read a fat filesystem

Posted: Tue Dec 04, 2007 12:57 pm
by JamesM
*before* loading the kernel?

Is this a bootloader we're talking about? you'll have to provide more specifics than that!

(and if you can access a fat filesystem then you should have open/read/write/close written already?)

Posted: Tue Dec 04, 2007 1:42 pm
by Combuster
I think he wants an fread() implemented on top of get_512_bytes()...

If you keep 512 bytes reserved for temporary storage that is just as simple as copying the amount of bytes and keeping track of how much is left. If you have eaten up all the 512 bytes, you load the next set and copy whatever you still need to do.

Nothing interesting really...

Posted: Tue Dec 04, 2007 2:34 pm
by vishal
after i have loaded the second stage bootloader in the memory i want to display the contents of a text file which contains the names and the paths of the various kernels present on the disk in the form of a list so that the user can select his kernel from the list..but i am helpless as to how to read the file ???

Posted: Wed Dec 05, 2007 12:51 am
by Solar
getch() / putch() won't help you there. You need, in your second stage, logic for accessing an arbitrary sector on disk, logic for interpreting the file system (i.e., where to find the directory, how to search the directory for a given file name, and how to determine first / subsequent sectors of the file once you've found it), and then reading the sectors of the file at the appropriate memory locations.

Basically, you need a rudimentary disk / file system driver in your second stage.

Posted: Mon Dec 17, 2007 3:41 am
by Red Shaya
I wouldn't implement this list as a file as it will require support for a FS to be already implemented on your second stage. What I would do is store the "data" of the list at a predefined place on your boot image and read it using basic disk IO operations into memory. Then handling it in whatever way you'd like.