reading a text file

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
vishal
Posts: 17
Joined: Sun Nov 11, 2007 3:30 pm

reading a text file

Post 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
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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?)
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post 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...
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
vishal
Posts: 17
Joined: Sun Nov 11, 2007 3:30 pm

Post 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 ???
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post 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.
Every good solution is obvious once you've found it.
User avatar
Red Shaya
Posts: 15
Joined: Wed Oct 03, 2007 4:21 pm
Contact:

Post 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.
The Bina OS - More of a challenge then an OS
The Eddie OS - OS for kids and for fun loving adults
Post Reply