Int21h - renaming a file

Programming, for all ages and all languages.
Post Reply
Baxos
Posts: 10
Joined: Fri Mar 07, 2008 11:52 am
Location: Denmark

Int21h - renaming a file

Post 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
eddyb
Member
Member
Posts: 248
Joined: Fri Aug 01, 2008 7:52 am

Re: Int21h - renaming a file

Post by eddyb »

omg... you cat it to make a floppy?
also, int 21h is in dos...
Baxos
Posts: 10
Joined: Fri Mar 07, 2008 11:52 am
Location: Denmark

Re: Int21h - renaming a file

Post by Baxos »

yeah cant i do that ? it boots up fine?
Aint it just a real mode interrupt?
User avatar
Khaoticmind
Member
Member
Posts: 29
Joined: Tue Nov 18, 2008 1:06 pm
Location: Brazil

Re: Int21h - renaming a file

Post 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.
Baxos
Posts: 10
Joined: Fri Mar 07, 2008 11:52 am
Location: Denmark

Re: Int21h - renaming a file

Post 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?
User avatar
Khaoticmind
Member
Member
Posts: 29
Joined: Tue Nov 18, 2008 1:06 pm
Location: Brazil

Re: Int21h - renaming a file

Post 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
Last edited by Khaoticmind on Wed Dec 17, 2008 10:38 am, edited 1 time in total.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Int21h - renaming a file

Post 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
Baxos
Posts: 10
Joined: Fri Mar 07, 2008 11:52 am
Location: Denmark

Re: Int21h - renaming a file

Post by Baxos »

Okay thankes alot that helped alot i will start working on some of thoose things ;)
DeletedAccount
Member
Member
Posts: 566
Joined: Tue Jun 20, 2006 9:17 am

Re: Int21h - renaming a file

Post 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
Post Reply