Page 1 of 1

Int21h - renaming a file

Posted: Wed Dec 17, 2008 9:02 am
by Baxos
Hi guys :)
Im trying to write a little assembly code which will rename a file and here is the code :
mov ah, 56h
mov dx, [fileName]
mov di [newName]
int 21h
salc
cmp ah, 0h
je .succes

fileName db "text.txt", 0
newName db "test.txt", 0

im assembling with NASM and after that i type this in terminal :
cat main.o text.txt > floppy.img
qemu floppy.img

But even if the name is wrong it allways go to .succes ..
What am i doing wrong? :s

Re: Int21h - renaming a file

Posted: Wed Dec 17, 2008 9:26 am
by eddyb
omg... you cat it to make a floppy?
also, int 21h is in dos...

Re: Int21h - renaming a file

Posted: Wed Dec 17, 2008 9:49 am
by Baxos
yeah cant i do that ? it boots up fine?
Aint it just a real mode interrupt?

Re: Int21h - renaming a file

Posted: Wed Dec 17, 2008 9:53 am
by Khaoticmind
For what i know int21 is a DOS interrupt, as shiner said, and because of that it works only on DOS.
That said you can't use it in OS Deving.

Also, you can't create a floppy using cat.
Probably this function to rename a file was developed to work on a FAT formated disk. Doing a cat you are just "forcing the file to be there", so to say, you are not actually storing it in the file system.

Hope this made things clearer to you.
If not ask out and i try to elaborate more on that.

Re: Int21h - renaming a file

Posted: Wed Dec 17, 2008 9:57 am
by Baxos
It did make it alot more clear, but how do a make a "floppy image" then `? i need to make it virtual because i dont have a working floppy disc..
Okay but if i format it in FAT can i then use the int21h call or do i need to find another solution?

Re: Int21h - renaming a file

Posted: Wed Dec 17, 2008 10:19 am
by Khaoticmind
Baxos wrote:It did make it alot more clear, but how do a make a "floppy image" then `? i need to make it virtual because i dont have a working floppy disc..
That really depends on the OS you are using.
If its Linux you can use these commands to create a FAT formated floppy

Code: Select all

dd if=/dev/zero of=/floppy.img bs=512 count=2880
mkdosfs floppy.img
and to copy a file inside it you can use

Code: Select all

mcopy -i floppy.img youfile.txt ::/
If you are using windows than i won't really know how to do it :(
Okay but if i format it in FAT can i then use the int21h call or do i need to find another solution?
IF you are doing OS development (thats why you are here, right? :)), than no, you can't use it.
To accomplish a renaming file function you would need to first write an OS, with memory management, floppy driver, and a file system. THEN you could work on the rename function.

Cheers

Re: Int21h - renaming a file

Posted: Wed Dec 17, 2008 10:22 am
by AJ
In addition to the multitude of problems outlined above, you also probably want the pointer to fileName and newName, not the first word.

Cheers,
Adam

Re: Int21h - renaming a file

Posted: Wed Dec 17, 2008 11:04 am
by Baxos
Okay thankes alot that helped alot i will start working on some of thoose things ;)

Re: Int21h - renaming a file

Posted: Thu Dec 18, 2008 1:24 pm
by DeletedAccount
May be you should do something like this

Code: Select all

        mov bx , 0  
        push bx
        pop es  
        mov bx, offset handler
        mov es:[21 *4 ], bx
        mov bx, seg handler
        mov es:[21 *4 + 2], bx

and set everthing properly before calling int 21 h :wink: .
Regards
Shrek