reading/writing sectors for filesystem

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.
Locked
ChrisSkura
Member
Member
Posts: 33
Joined: Sat Nov 07, 2009 2:47 am

reading/writing sectors for filesystem

Post by ChrisSkura »

I have been working on my os and I want to implement a file system. I try to save to a sector and then later read from that sector and ouput the information to the screen. I think I am writing correctly but I can't tell if i am because I can't figure out how to read from it.

this is how i write:

Code: Select all

buffer TIMES 512 db 0
mov byte [buffer+0], 65

mov ah, 03h
mov al, 1
mov cl, 18
mov ch, 79
mov dh, 1
mov dl, 0
mov bx, [buffer]
int 13h
and i read like this

Code: Select all

read TIMES 512 db 0

mov ah, 02h
mov al, 1
mov cl, 18
mov ch, 79
mov dh, 1
mov dl, 0
mov bx, [read]
int 13h
I then output the value of [read+0] to the screen and it is not an 'A'. it isn't anything.

i don't know what I am doing wrong. none of the tutorials a have found show how to do what I want to do.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: reading/writing sectors for filesystem

Post by neon »

Hello,

An easy way to test if writing is working (and reading, actually) is by comparing what you are reading/writing with whats on disk (use a disk editor or hex editor).
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: reading/writing sectors for filesystem

Post by bewing »

ChrisSkura wrote: this is how i write:

Code: Select all

buffer TIMES 512 db 0
...
mov bx, [buffer]
int 13h
ES:BX is supposed to be a pointer to the buffer. You are actually moving the first word of data from the buffer into BX. What you want it to say is MOV BX, buffer
(with no brackets). Please understand that the [] bracket operators in asm are the same as the * operator in C.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: reading/writing sectors for filesystem

Post by qw »

After calling INT 13H you should test the Carry Flag. If it is set, an error occurred, and you should reset the disk system and try again. Try at least four times.

Also, make sure that your buffer doesn't cross a DMA page boundary. It should be in a physical address range of X0000 - XFFFFH.
User avatar
paulqddinh
Posts: 9
Joined: Thu Jan 14, 2010 9:12 am
Location: Hanoi, VN

Re: reading/writing sectors for filesystem

Post by paulqddinh »

me too
i can't read/write using int 13h,
so my mbr is not able to load kernel :(
my mbr is on flashdisk
my kernel in on flashdisk also
any suggestion? [-o<
Asus EeePC 1000H/XP Pro
x86 Intel Atom N270 1.6GHz -- 1GB RAM
Locked