Opening Files
Re:Opening Files
You mean in kernel space C? By using whatever file handling routines you have implemented in your file system.
In user space, you traditionally use what <stdio.h> gives you (fopen(), fscanf(), fread())
In user space, you traditionally use what <stdio.h> gives you (fopen(), fscanf(), fread())
Every good solution is obvious once you've found it.
Re:Opening Files
Let us be precise in this: do you mean "how do I read from and write to the disk?", "how do I write a filesystem?", or "how do I open a file in standard C?"
The first will require you to study the floppy and hard disk interfaces, and write the appropriate drivers. RTQL and the FAQ for the appropriate references, and perhaps read "How to Ask Questions" as well.
For the second, that will depend on the filesystem you use, and how you intend to implement system calls and drivers in general. Do What Thou Wilt.
The answer to the last one is to use the standard I/O functions; if you need more details, inquire in the general forum, or consult your pineal gland.
The first will require you to study the floppy and hard disk interfaces, and write the appropriate drivers. RTQL and the FAQ for the appropriate references, and perhaps read "How to Ask Questions" as well.
For the second, that will depend on the filesystem you use, and how you intend to implement system calls and drivers in general. Do What Thou Wilt.
The answer to the last one is to use the standard I/O functions; if you need more details, inquire in the general forum, or consult your pineal gland.
Re:Opening Files
It might be worth a mention that there's no special way of opening a text file or a com file in an OS. Ideally the OS is full of mechanism and lacking in policy. It's up to usermode standard libraries to impose a policy, for instance seeing a file with structure.
The OS sees nothing but a bunch of bytes in some areas on a disk (actually, it doesn't see them, strictly speaking, because the filesystem code does that. And it too does not see anything but an array of bytes of some length.)
Reading from a file (any file) is reading the bytes on the file's disk blocks into a buffer in memory. For this, you need a disk driver, a filesystem, and some library functions to open/close files, read/write files and seek to offsets within files.
The OS sees nothing but a bunch of bytes in some areas on a disk (actually, it doesn't see them, strictly speaking, because the filesystem code does that. And it too does not see anything but an array of bytes of some length.)
Reading from a file (any file) is reading the bytes on the file's disk blocks into a buffer in memory. For this, you need a disk driver, a filesystem, and some library functions to open/close files, read/write files and seek to offsets within files.