File system help
File system help
I'm programming a new os, all coded with nasm.
It has a shell with 3 commands and a logo made with colored text at the start.
It doesn't support protected mode yet.
Now, i need help to continue evolving it: i'm projecting to implement FAT32 filesytem to let the user create, modify and delete files and folders.
The help i need is:
1)How can i read sectors and files from floppy?
2)How can i implement FAT32 to create, modify and delete files?
It has a shell with 3 commands and a logo made with colored text at the start.
It doesn't support protected mode yet.
Now, i need help to continue evolving it: i'm projecting to implement FAT32 filesytem to let the user create, modify and delete files and folders.
The help i need is:
1)How can i read sectors and files from floppy?
2)How can i implement FAT32 to create, modify and delete files?
Re:File system help
hello, if have not in prtected mode you can read sectors easly just use the bios:
P.S. http://www.xaff.org/GI/biosref.html#int13-02
is where i got this from
Code: Select all
mov ah, 02h ;read sector func
mov dl, 00h ;drive to read 00h = floppy 1
mov dh, 00h ;head to read from
mov ch, 00h ;track to read from
mov cl, 02h ;sector to read from
mov al, 01h ;number of sectors to read
xor bx, bx
mov es, bx ;Segment to put data read
mov bx, 0x1000 ;Offset to put data read
int 13h ;put it all in motion
is where i got this from
Re:File system help
I've read about 13h function and 25h,26h functions but i don't know how to use them with fat32 filesystem.
I have some ideas but i don't know how to apply it.
For example: if i want to create a txt file named text.txt and contain "hello world!", in wich way can i?
I have some ideas but i don't know how to apply it.
For example: if i want to create a txt file named text.txt and contain "hello world!", in wich way can i?
Re:File system help
If you'r working with floppies it's problably FAT12 you want info on, not FAT32.
Some FAT12 info: http://www.osdev.org/osfaq2/index.php/FAT12%20document
/ Christoffer
Some FAT12 info: http://www.osdev.org/osfaq2/index.php/FAT12%20document
/ Christoffer
Re:File system help
I read it some days ago, and i learned how fat12 works.
The thing i need is some example code.
(I have to learn it before 4th June and i need help)
The thing i need is some example code.
(I have to learn it before 4th June and i need help)
Re:File system help
For a starter go here : http://alexfru.chat.ru/epm.html#bootprog
get bootprog, in the zip file there is well commented nasm code to do most of what you want, if you want C code then get this "OS Loader" from here : http://alexfru.chat.ru/epm.html#los4d
get bootprog, in the zip file there is well commented nasm code to do most of what you want, if you want C code then get this "OS Loader" from here : http://alexfru.chat.ru/epm.html#los4d
Re:File system help
I looked bootloaders too, and learned somethink about reading files but i need to write, for example, a .txt file containing data.
Re:File system help
But first you need to learn how to load a file from a fat12 floppy, and then move on to writing a file to a floppy, if you do not understand the load from, you will not beable to go to the write too.
Re:File system help
The only thing i haven't understood is how to use the fat table to find the next cluster of a file.
I'm browsing bootloaders source for it.
Could anyone explain it to me?
After that, i'll need help on how to write files(i have a few days to start implementing the filesystem in my os).
I'm browsing bootloaders source for it.
Could anyone explain it to me?
After that, i'll need help on how to write files(i have a few days to start implementing the filesystem in my os).
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:File system help
basically, the FAT is a table indexed by "cluster number" and each entry contains the cluster number for the next one. E.g. if the file consist of clusters 5,3,4, the directory entry will contain cluster number "5" and the FAT will look like
note that FAT12 makes it a bit more complex to grab since it packs 2 entries on 3 bytes, e.g. entries "000", "111", "222", "333" will be encoded somehow like
[tt]00 01 11 22 23 33[/tt]
Code: Select all
FAT[0]= ?
FAT[1]= ?
FAT[2]= ?
FAT[3]= 4
FAT[4]= end_of_file
FAT[5]= 3
FAT[6]= ?
...
[tt]00 01 11 22 23 33[/tt]
Re:File system help
So, if i want to read a file i need follow this sequence of operation?
1)read root dir searching a file
2)read the 32 bytes of the root dir about the file found
3)read the position of the file's first cluster
4)go to the fat and search the byte indexed with the cluster lba
5)use the found value to read the second cluster and to found the next cluster
6)repeat operation until the program found in the fat the end of file
1)read root dir searching a file
2)read the 32 bytes of the root dir about the file found
3)read the position of the file's first cluster
4)go to the fat and search the byte indexed with the cluster lba
5)use the found value to read the second cluster and to found the next cluster
6)repeat operation until the program found in the fat the end of file
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:File system help
yep. Make sure to perform the appropriate translations (e.g. clusters are X blocks and are numbered past the FAT, iirc) And that explains while most implementations will try to read the whole FAT out of the floppy before doing anything else (avoiding head displacement latencies, etc).
<ot, slightly> Btw, if anyone here is willing to provide FAT32 C code to be used as basis for Clicker's driver (appropriate credits given, etc). </ot>
<ot, slightly> Btw, if anyone here is willing to provide FAT32 C code to be used as basis for Clicker's driver (appropriate credits given, etc). </ot>
Re:File system help
So, the value stored in the fat are the address of the corresponding cluster and the value of the next byte in the fat(the next byte of the file)?
Then, i think i understood, but now, could i have some nasm code wich write a .txt file on the floppy?
I'll try the code on my os and i'll read and study it.
Then, i think i understood, but now, could i have some nasm code wich write a .txt file on the floppy?
I'll try the code on my os and i'll read and study it.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:File system help
well, over-writing some data in some existing file is rather simple: you just have to resolve which cluster/block is to be used based on the content of the FAT.
Appending new data to a file is already a bit more complicated: you have to find free sectors in the FAT and link them to the end of the current file (e.g. write "end-of-file" instead of "free-cluster" in FAT[ X ] and "X" instead of "end-of-file")
For testing purpose (e.g. if all you want is "bootlog.txt"), i suggest you stick to a pre-allocated file atm.
Creating a new file is yet one more step: you need to locate a free directory entry and write name, attributes and first cluster accordingly.
Appending new data to a file is already a bit more complicated: you have to find free sectors in the FAT and link them to the end of the current file (e.g. write "end-of-file" instead of "free-cluster" in FAT[ X ] and "X" instead of "end-of-file")
For testing purpose (e.g. if all you want is "bootlog.txt"), i suggest you stick to a pre-allocated file atm.
Creating a new file is yet one more step: you need to locate a free directory entry and write name, attributes and first cluster accordingly.
Re:File system help
ok, but i need some example code to read because i'm new to assembly and some source code could help me.