Page 1 of 1

c,filesystem..

Posted: Fri Aug 23, 2002 12:17 pm
by frank
Hi,
I've got a few "problems".

Code: Select all


asm("jmp start");
 char c=5;

void start()
{
 while (1)
  {
   }
}

this code creates a big binary, 'cause I set c to 5.
gcc adds a lot of "add [eax],al" commands to my code instead of using the code segment, how do I change that?
(a c code without char c=5; function works fine...)

I'm using this compile line:

Code: Select all

gcc -o4 -c kern.c
ld -o kern -Ttext 0x1000 -Tdata 0x1200 -e 0x0 -N kern.o
objcopy  -R .note -R .comment -S -O binary kern kern.bin

Also,
how do I create a file system?
for example:

I wrote an header which can write and read sectors of the disk,
so how do I open file?...
the files start at the end of the disk,
if you read a file, how does it know which disk it should use,
and how does it get the sector data from the disk? (the filesytem)

Re:c,filesystem..

Posted: Fri Aug 23, 2002 2:25 pm
by Tim
frank wrote:gcc adds a lot of "add [eax],al" commands to my code instead of using the code segment, how do I change that?
(a c code without char c=5; function works fine...)
Note that "add [eax], al" equates to a string of zero bytes. Which is normal: you're going to have 05 followed by (padding-1) bytes of zeroes, where padding is the section alignment. You can't avoid that. Padding the data section with zeroes is completely normal.
I wrote an header which can write and read sectors of the disk,
so how do I open file?...
the files start at the end of the disk,
if you read a file, how does it know which disk it should use,
and how does it get the sector data from the disk? (the filesytem)
A disk contains some raw data in some format: think of it as an array of, say, 4 gigabytes. You've got to translate that data somehow, which is where the file system comes in. First read a boot on OS development to get the general idea (e.g. OS: D&I by Tanenbaum), then read some real file system specs (e.g. FAT or ext2 specs on http://www.nondot.org/sabre/os/).

Re:c,filesystem..

Posted: Mon Aug 26, 2002 3:07 am
by Pype.Clicker
A very simple filesystem you can imagine : you have at a well-known place a sector containing the directory of your disk : n entries having a symbolic name, a first sector, a sector count and a byte count.

You need to lookup the directory for the file's name (open operation) and usually store the lookup result (size & first sector) in a structure that you will use as file handle.
Then if you want to access datas at ith byte of your file, you just read first_sector + (i mod sector_size) and get the wanted byte out of it (well, a small cache of 1 or 2 sectors per file handle will quickly become your friend ;)

In this scheme, it's quite hard to extend files or to remove them because you have nothing to keep track of freed sectors (allocation must be done top-down or bottom-up so that you're sure to have contiguous sectors for your file) but this is no problem for a boot partition that is rather static...