PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : CD-Rom Laufwerk


snoopdog
24.01.2002, 21:14
Nabend
wollt mal fragen: wie macht z.B. das CD-Rom Laufwerk auf/zu????
Oder wie flippt man den Desktop??

Wo bekommt man da ne Liste von den Befehlen oder Routinen wie das funtioniert könnt ihr mir da helfen??
danke

mfg
snoopdog


sami
24.01.2002, 22:41
die dokumentation des WinAPI findest du unter http://msdn.microsoft.com/
kann es dir leider auch ned genauer sagen.

Felix Kaiser
24.01.2002, 23:03
Aus der Microsoft Zauberkiste ...


The DeviceIoControl function sends a control code directly to a specified device driver, causing the corresponding device to perform the specified operation.

BOOL DeviceIoControl(

HANDLE hDevice, // handle to device of interest
DWORD dwIoControlCode, // control code of operation to perform
LPVOID lpInBuffer, // pointer to buffer to supply input data
DWORD nInBufferSize, // size of input buffer
LPVOID lpOutBuffer, // pointer to buffer to receive output data
DWORD nOutBufferSize, // size of output buffer
LPDWORD lpBytesReturned, // pointer to variable to receive output byte count
LPOVERLAPPED lpOverlapped // pointer to overlapped structure for asynchronous operation
);
Parameters

hDevice

Handle to the device that is to perform the operation. Call the CreateFile function to obtain a device handle.

dwIoControlCode

Specifies the control code for the operation. This value identifies the specific operation to be performed and the type of device on which the operation is to be performed. The following values are defined:

Value Meaning
FSCTL_DISMOUNT_VOLUME Dismounts a volume.
FSCTL_GET_COMPRESSION Obtains the compression state of a file or directory
FSCTL_LOCK_VOLUME Locks a volume.
FSCTL_READ_COMPRESSION Reserved for future use.
FSCTL_SET_COMPRESSION Sets the compression state of a file or directory.
FSCTL_UNLOCK_VOLUME Unlocks a volume.
FSCTL_WRITE_COMPRESSION Reserved for future use.
IOCTL_DISK_CHECK_VERIFY Checks for change in a removable-media device.
IOCTL_DISK_EJECT_MEDIA Ejects media from a SCSI device.
IOCTL_DISK_FORMAT_TRACKS Formats a contiguous set of disk tracks.
IOCTL_DISK_GET_DRIVE_GEOMETRY Obtains information on the physical disk´s geometry.
IOCTL_DISK_GET_DRIVE_LAYOUT Provides information about each partition on a disk.
IOCTL_DISK_GET_MEDIA_TYPES Obtains information about media support.
IOCTL_DISK_GET_PARTITION_INFO Obtains disk partition information.
IOCTL_DISK_LOAD_MEDIA Loads media into a device.
IOCTL_DISK_MEDIA_REMOVAL Enables or disables the media eject mechanism.
IOCTL_DISK_PERFORMANCE Provides disk performance information.
IOCTL_DISK_REASSIGN_BLOCKS Maps disk blocks to spare-block pool.
IOCTL_DISK_SET_DRIVE_LAYOUT Partitions a disk.
IOCTL_DISK_SET_PARTITION_INFO Sets the disk partition type.
IOCTL_DISK_VERIFY Performs logical format of a disk extent.
IOCTL_SERIAL_LSRMST_INSERT Enables or disables placement of a line and modem status data into the data stream.
For more detailed information on each control code, see its topic. In particular, each topic provides details on the usage of the lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, and lpBytesReturned parameters.

lpInBuffer

Pointer to a buffer that contains the data required to perform the operation.
This parameter can be NULL if the dwIoControlCode parameter specifies an operation that does not require input data.

nInBufferSize

Specifies the size, in bytes, of the buffer pointed to by lpInBuffer.

lpOutBuffer

Pointer to a buffer that receives the operation´s output data.
This parameter can be NULL if the dwIoControlCode parameter specifies an operation that does not produce output data.

nOutBufferSize

Specifies the size, in bytes, of the buffer pointed to by lpOutBuffer.

lpBytesReturned

Pointer to a variable that receives the size, in bytes, of the data stored into the buffer pointed to by lpOutBuffer.
This parameter cannot be NULL. Even when an operation produces no output data, and lpOutBuffer can be NULL, the DeviceIoControl function makes use of the variable pointed to by lpBytesReturned. After such an operation, the value of the variable is without meaning.

lpOverlapped

Pointer to an OVERLAPPED structure to be used for asynchronous operations.
This parameter is ignored if the handle identified by hDevice was opened without specifying the FILE_FLAG_OVERLAPPED flag.
This parameter can be NULL if an overlapped (asynchronous) operation is not desired.


Return Value

If the function succeeds, the return value is TRUE.
If the function fails, the return value is FALSE. To get extended error information, call GetLastError.

Remarks

If the lpOverlapped parameter is NULL or the handle identified by hDevice was opened without specifying the FILE_FLAG_OVERLAPPED flag, the DeviceIoControl function does not return until the operation has been completed, or an error occurs.
If the lpOverlapped parameter points to an OVERLAPPED structure and the FILE_FLAG_OVERLAPPED flag was specified when the hDevice handle was opened, DeviceIoControl is performed as an overlapped (asynchronous) operation. In this case, the OVERLAPPED structure must contain a handle to a manual-reset event object (created by using the CreateEvent function). For more information on manual-reset event objects, see Synchronization.

If the overlapped operation cannot be completed immediately, the function returns FALSE, and GetLastError returns the ERROR_IO_PENDING value, indicating that the operation is executing in the background. When this happens, the operating system sets the event object in the OVERLAPPED structure to the nonsignaled state before DeviceIoControl returns. The system then sets the event object to the signaled state when the operation has been completed. The calling thread can use any of the wait functions to determine the state of the event object, then use the GetOverlappedResult function to determine the results of the operation. The GetOverlappedResult function reports the success or failure of the operation and the number of bytes returned in the lpOutBuffer buffer.

See Also

CreateEvent, CreateFile, GetOverlappedResult, OVERLAPPED, WaitForMultipleObjects, WaitForSingleObject

Prinzip klar? Laut API mit CreateFile den Zugriff auf das Laufwerk herstellen, mit DeviceIoControl dann Eject/Close Funktion des CD-ROM Laufwerks aufrufen und Handle vom Zugriff wieder freigeben.

inheritsched
31.01.2002, 18:42
Als Verweis auf das eigentliche Gerät , das CD-ROM Laufwerk, wird /dev/cdrom verwendet, mittels ioctl() kann man diverse Aktionen durchführen, z.B:

(dies hättest du durch suchen auch selber finden können)
CDROM IOCTL commands

CDROMPAUSE Pause Audio Operation
CDROMRESUME Resume paused Audio Operation
CDROMPLAYMSF Play Audio MSF (struct cdrom_msf)
CDROMPLAYTRKIND Play Audio Track/index (struct cdrom_ti)
CDROMREADTOCHDR Read TOC header (struct cdrom_tochdr)
CDROMREADTOCENTRY Read TOC entry (struct cdrom_tocentry)
CDROMSTOP Stop the cdrom drive
CDROMSTART Start the cdrom drive
CDROMEJECT Ejects the cdrom media
CDROMVOLCTRL Control output volume (struct cdrom_volctrl)
CDROMSUBCHNL Read subchannel data (struct cdrom_subchnl)
CDROMREADMODE2 Read CDROM mode 2 data (2336 Bytes) (struct cdrom_read)
CDROMREADMODE1 Read CDROM mode 1 data (2048 Bytes) (struct cdrom_read)
CDROMREADAUDIO (struct cdrom_read_audio)
CDROMEJECT_SW enable(1)/disable(0) auto-ejecting
CDROMMULTISESSION Obtain the start-of-last-session address of multi session disks (struct cdrom_multisession)
CDROM_GET_MCN Obtain the "Universal Product Code" if available (struct cdrom_mcn)
CDROMRESET hard-reset the drive
CDROMVOLREAD Get the drive´s volume setting (struct cdrom_volctrl)
CDROMREADRAW read data in raw mode (2352 Bytes) (struct cdrom_read)

Du musst anfangs nur den Device öffnen, also z.B.

int l_cdrom; /*dies ist der entsprechende FD für das CD-ROM Laufwerk */
...
l_cdrom = open("/dev/cdrom",O_RDONLY);
if(l_cdrom < 0)
{
fprintf(stderr,&quot;fehler...&quot;);
...
}

if(ioctl(l_cdrom,CDROMEJECT,NULL)<0)
{
/* Fehler */
....
}

----
das prinzip sollte klar sein, ist eigentlich sehr einfach
such einfach mal bei google

Felix Kaiser
31.01.2002, 23:29
Soso, &quot;das cd-rom laufwerk&quot;, ich hab 3 ;)
Also bei open jetzt noch richtig das Laufwerk angeben dann klappts, ... und die IoCtl Lösung hab ich bereits gepostet und da es keinerlei weitere Fragen gab gehe ich in der Annahme, dass die Lösung funktioniert hat so wie sie soll und man könnte Doppelpostings vermeiden.

Die CDROM Konstanten tragen übrigens die Werte der Standard IOCTL Konstanten, jedoch empfehle ich die direkten IOCTL Konstanten, da diese in den Headerfiles wenigstens genormt deklariert sind.