Page 1 of 1
Get Media Status in ATAPI?
Posted: Mon Jan 18, 2010 3:28 pm
by iocoder
Hello All,
All i want to know: How to know whether there is a medium in the CD-ROM or not?
While trying to get the status of mediums in an ATAPI Drive supporting Removable Media Feature Set, i failed getting it work, as i tried to send a NOP command, and read the error register, and it doesn't return other than 'Command Aborted' as usual. i tried to send 'GET MEDIA STATUS' Command, but it is obsolete and doesn't work with neither VMware 7 nor my real computer.
What can i do? would any one help me plzzzzzzzzzzzzzz?
All i want to know: How to know whether there is a medium in the CD-ROM or not?
thanks all.
Regards,
Mostafa.
Re: Get Media Status in ATAPI?
Posted: Mon Jan 18, 2010 8:56 pm
by pcmattman
Look at the sense data. IIRC the ATAPI (or possibly SCSI, can't remember) spec has a table listing all the different variations of sense data. One of these, off the top of my head, relates to media presence. I could be wrong though.
I'm unable to access any of the specs at the moment otherwise I'd post something a little more useful to you
.
Re: Get Media Status in ATAPI?
Posted: Tue Jan 19, 2010 2:09 pm
by jal
A quick Google found a reference in the AROS source
here. Though I have little knowledge on ATAPI, it may help you.
JAL
Re: Get Media Status in ATAPI?
Posted: Tue Jan 19, 2010 5:19 pm
by iocoder
Thank you both pcmattman and JAL for helping me. i have found the way according to your helpings.
Here is the method of media insert/remove Sense in Quafios:
Every 1000 millisecond, a specific function is called in the IDE Driver, when it is called, it searches for connected drives which are ATAPI [almost all ATAPI Drives use Removable Media Feature Set] and whose channels aren't not active. Then the function sends a 'SCSI Read Capacity' Command after an ATA_PACKET Command, the 'SCSI Read Capacity' Command shall return the number of last LBA in the inserted medium. if there isn't a medium, an error is occured.
This helped me in mainly three thigns:
- Detecting whether there is a medium or not.
- Detecting medium changes (if errors stop, so a new medium is inserted, if errors return, the medium is removed)
- Detecting the size of the medium.
http://en.wikipedia.org/wiki/SCSI_Read_Capacity_Command
Thank you all for helping me,
Regards,
Mostafa.
Re: Get Media Status in ATAPI?
Posted: Wed Jan 20, 2010 1:42 am
by jal
Glad we were of help. All this should be added to the wiki, but I haven't got time now...
JAL
Re: Get Media Status in ATAPI?
Posted: Wed Jan 20, 2010 12:34 pm
by iocoder
jal wrote:
All this should be added to the wiki, but I haven't got time now...
I'll try to add them myself in the right location in the wiki
.
Regards,
Mostafa.
Re: Get Media Status in ATAPI?
Posted: Wed Jan 20, 2010 1:59 pm
by jal
mostafazizo wrote:I'll try to add them myself in the right location in the wiki
That would be great! There's an ATAPI article, but I don't think it mentions this.
JAL
Re: Get Media Status in ATAPI?
Posted: Wed Jan 20, 2010 4:30 pm
by iocoder
jal wrote:
That would be great! There's an ATAPI article, but I don't think it mentions this.
Now it mentions this.
http://wiki.osdev.org/ATAPI#Detecting_a ... s_Capacity
But Could I ask another question?
I would want to know what about Floppy Disk Controller? i wanted to sense media status in FDC but i couldn't, i'm searching for a command that doesn't need to activate the drive's motor, as i will send it each 1, 2 or 4 seconds. but i couldn't find such an one. anyone has an idea about this????
Thanks and Regards,
Mostafa.
Re: Get Media Status in ATAPI?
Posted: Thu Jan 21, 2010 4:08 am
by Owen
There is none.
Well, there "is", kinda. It's not really a command; more a sequence which will eventually tell you whether the disk is inserted or not.
It has a problem: Some drives return a 1 for disk inserted, others return a 0.
In English: It's useless.
Re: Get Media Status in ATAPI?
Posted: Fri Jan 22, 2010 1:56 pm
by jal
mostafazizo wrote:I would want to know what about Floppy Disk Controller? i wanted to sense media status in FDC but i couldn't, i'm searching for a command that doesn't need to activate the drive's motor
You remember that in the old days, on computer startup the floppy drive came alive? That's because it is not possible in any reliable way (or, as far as old floppy controllers are concerned, in any way) to get an insert status or a change status. The only way is to read and see if you succeed.
JAL
Re: Get Media Status in ATAPI?
Posted: Fri Jan 22, 2010 1:58 pm
by jal
Owen wrote:It has a problem: Some drives return a 1 for disk inserted, others return a 0. (...) It's useless.
Not necessarily. Though disk may be swapped, the chances of a disk
drive being swapped are little to none. So you start reading, then do your magic sequence, and see if it returns a 1 or a 0. Not that I'd recommend it, floppies are a thing of the past anyway, and you'll get bad results doing it on an emulated CD or memory stick.
JAL
Re: Get Media Status in ATAPI?
Posted: Sat Jan 23, 2010 7:19 am
by Owen
jal wrote:Owen wrote:It has a problem: Some drives return a 1 for disk inserted, others return a 0. (...) It's useless.
Not necessarily. Though disk may be swapped, the chances of a disk
drive being swapped are little to none. So you start reading, then do your magic sequence, and see if it returns a 1 or a 0. Not that I'd recommend it, floppies are a thing of the past anyway, and you'll get bad results doing it on an emulated CD or memory stick.
JAL
"I swapped my floppy drive and now the disk status is inverted. HELP!"
Oh, and some drives don't support it at all.
Emulation isn't a problem since it involves talking directly to the FDC
Re: Get Media Status in ATAPI?
Posted: Sun Jan 24, 2010 12:31 am
by bewing
I wrote as much as I could on the media sensing issue in the
Floppy Disk Controller wiki article. Yes, you have to turn on the motor flag in the DOR. But it is for less than a millisecond. Modern drives do not even start the actual drive motor until you send a read or write command. A human will never even see the light flash. Especially since you only have to keep trying to sense new media when you already have a good idea that there is none. So you are only doing the motor on/test/motor off sequence on an empty drive.
Re: Get Media Status in ATAPI?
Posted: Sun Jan 24, 2010 1:57 pm
by iocoder
Thank you Owen, JAL, bewing for your helpful posts.
bewing wrote:
I wrote as much as I could on the media sensing issue in the Floppy Disk Controller wiki article.
Thank you very much for the article, notice that i had read it before, and i focused on the part of 'DIR register, Disk Change bit', then i said to myself 'why don't i try the written method?' and myself replied 'and why not?' then i wrote the code. it works perfectly on VMware 7, Bochs, but on my real machine happens great problems:
the floppy lump is truned on, strange voice is listened 'like music' and Quafiso [My OS] is stopped working, because this happens when it does seek in order to clear the bit, but seek takes more than a minute, and the function is called every minute, so that Quafios is stopped working.
i tried to make the function called every 5 minutes, but the problem that seek doesn't work correctly on my real machine when there is no disk. i don't know why. i think all of these problems because of my floppy disk drive and your method has no mistake.
JAL wrote:
floppies are a thing of the past anyway
and because of that, i decided to stop supporting Floppy disk in my operating system and to start enhancing USB as a replacement.
Thank you all and regards,
Mostafa