Page 1 of 1
FILE SUBSYSTEM
Posted: Sun Oct 21, 2007 5:46 pm
by frank913
Hello Hello fellas. I want to start writing the file subsystem of my OS first. The reason is that I want to fully test that part of the OS before I move on into something else. My question is, how do I test it. In other words, I want to start by creating the buffer cache, inode structure, start creating functions to allocate buffers, create files, modify files, etc... But I can't do that running on protected mode...or can I?. I wont be able to clear the interrupts, nor talk to the IDE disk controller...etc, is there a way for me to have full access to the machine and run my file subsystem just as any other program, but with full access, or I have to start with process management and booting my own kernel. Also, what if I started developing in DOS? since some versions of it don't run in protected mode. Thanks in advance.
Posted: Sun Oct 21, 2007 7:49 pm
by Dex
Maybe you could run it on top of a OS that let you have full access to all hardware etc, as a program than you can use the parts you are missing from the donor OS.
You could use Dos, but then you would have limited memory access and it will be tested in realmode.
As a starting point if you want 32bit pmode, you could use my OS,
http://www.dex4u.com/
Or BOS
http://bos.asmhackers.net/
Or V2_os
http://v2os.v2.nl/old/
Or if you want realmode you could try MiniDos
http://board.flatassembler.net/topic.php?t=5275&start=0
Posted: Sun Oct 21, 2007 8:43 pm
by bewing
I always find it much easier to write code if I have an actual immediate use for it. The process of booting a kernel is very much dependent on your filesystem structure. I found that actually writing my bootloader and the initialization portion of my kernel was a wonderful way for me to develop many of my filesystem algorithms and routines.
Writing a quickie hexeditor (inside my kernel initialization segment) forced me to develop several more.
Writing my first app (INIT) forced me to polish up a generic file reading algorithm and routine.
Now, attempting to read and write files while in a multitasking environment is forcing me to finalize everything, and make all the functions carefully independent.
So, I think this method worked very well for me, and I would recommend it. It helps you to see precisely what you need to do next, and gives you a concrete example to work with while you write code.
Posted: Mon Oct 22, 2007 11:13 am
by mystran
The device driver stuff you can develop using an emulator like Bochs (or QEMU, but Bochs is superior for debugging). Everything else you can pretty much build in a normal process. Once you've settled on some basic model of driver interface, you can write wrappers, that look like driver functions, yet in the reality simply use normal Host OS file access into a virtual drive image file. Added benefit is that it's now trivial to make backup copies of drive images..
Example interface could look something like:
Code: Select all
int disk_open();
int disk_close();
int disk_get_blocksize();
int disk_read_block(int blocknum, void * buf);
int disk_write_block(int blocknum, void * buf);
That should be enough for building fairly nice buffer cache, which in itself should be enough for building filesystems. Example implementation of said interface for a virtual disk image would look something like:
Code: Select all
static disk_fd; // disk image file descriptor
int disk_open() { disk_fd = open("disk_image", O_RDWR); }
int disk_close() { close(disk_fd); }
int disk_get_blocksize() { return 512; }
int disk_read_block(int blocknum, void * buf) {
lseek(disk_fd, blocknum * disk_get_blocksize(), SEEK_SET);
read(disk_fd, buf, disk_get_blocksize());
}
int disk_write_block(int blocknum, void * buf) {
lseek(disk_fd, blocknum * disk_get_blocksize(), SEEK_SET);
write(disk_fd, buf, disk_get_blocksize());
}
Ofcourse that's awful code, but the point is, it need not be anything special. An ugly hack (like the above) is enough to get you running in a safe environment.
If you want asynchronous access to disk driver, then you need a bit more wrapper code, but you get the idea?