Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "WinAPI";
Текущий архив: 2004.09.19;
Скачать: [xml.tar.bz2];

Вниз

DeviceIoControl error   Найти похожие ветки 

 
Aldor_   (2004-08-05 15:26) [0]

Вызываю сабжевую функцию с параметрами:

DeviceIoControl(DeviceHandle, IOCTL_DISK_GET_LENGTH_INFO, nil, 0, @LengthInformation, SizeOf(TGetLengthInformation), BytesReturned, nil)

До этого определяю хэндл девайса:

DeviceHandle := CreateFile("\\.\PHYSICALDRIVE0", GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);


В WinXP все работает отлично, на соседней машине Win2K на выделенной строке GetLastError дает "Incorrect function".

Правда на второй машине стоит винт SerialATA (а я ведь именно к нему обращаюсь).

Да, и на всякий случай, до всего этого:

type
 _GET_LENGTH_INFORMATION = record
   Length: Int64;
 end;
 TGetLengthInformation = _GET_LENGTH_INFORMATION;

const
 FILE_READ_ACCESS = $00000001;
 METHOD_BUFFERED = $00000000;
 IOCTL_DISK_BASE = $00000007;
 IOCTL_DISK_GET_LENGTH_INFO = (IOCTL_DISK_BASE shl 16) or FILE_READ_ACCESS shl 14) or ($0017 shl 2) or METHOD_BUFFERED; { CTL_CODE }

var
 DeviceHandle: THandle;
 LengthInformation: TGetLengthInformation;
 BytesReturned: Cardinal;


В чем может быть дело?


 
Игорь Шевченко ©   (2004-08-05 15:29) [1]


> В чем может быть дело?


Функция не поддерживается ?


 
Aldor_   (2004-08-05 15:30) [2]

Ой, извиняюсь за незакрытый тэг.


 
Aldor_   (2004-08-05 15:31) [3]

Ой, извиняюсь за незакрытый тэг. (выделенная строка - вызов DeviceIOControl)


 
Aldor_   (2004-08-05 15:35) [4]

Игорь Шевченко ©   (05.08.04 15:29) [1]
> Функция не поддерживается ?

В описании DeviceIOControl написано: Windows CE 1.0 and later
В описании IOCTL_DISK_GET_LENGTH_INFO ничего проверсию ОС не сказано. Вот и не могу понять, то ли дело в типе винта, то ли в функции (других машин для проверки нету).

Может протестирует кто, этот кусок можно вставить прямо в любую процедуру:

type
 _GET_LENGTH_INFORMATION = record
   Length: Int64;
 end;
 TGetLengthInformation = _GET_LENGTH_INFORMATION;

const
 FILE_READ_ACCESS = $00000001;
 METHOD_BUFFERED = $00000000;
 IOCTL_DISK_BASE = $00000007;
 IOCTL_DISK_GET_LENGTH_INFO = (IOCTL_DISK_BASE shl 16) or
   (FILE_READ_ACCESS shl 14) or ($0017 shl 2) or METHOD_BUFFERED;

var
 DeviceHandle: THandle;
 LengthInformation: TGetLengthInformation;
 BytesReturned: Cardinal;
begin
 DeviceHandle := CreateFile("\\.\PHYSICALDRIVE0", GENERIC_READ or GENERIC_WRITE,
   FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
 if DeviceHandle = INVALID_HANDLE_VALUE then
   RaiseLastOSError;
 try
   if not DeviceIoControl(DeviceHandle, IOCTL_DISK_GET_LENGTH_INFO, nil, 0,
       @LengthInformation, SizeOf(TGetLengthInformation), BytesReturned, nil) then
     RaiseLastOSError;
   ShowMessage("BytesReturned = " + IntToStr(BytesReturned) + " Length = " +
     IntToStr(LengthInformation.Length));
 finally
   if not CloseHandle(DeviceHandle) then
     RaiseLastOSError;
   Close;
 end;


P.S. Игорь, еще раз спасибо за ntdddisk.h


 
Игорь Шевченко ©   (2004-08-05 16:08) [5]

Aldor_   (05.08.04 15:35) [4]

"IOCTL_DISK_GET_LENGTH_INFO

The IOCTL_DISK_GET_LENGTH_INFO control code retrieves the length of the specified disk, volume, or partition.

To perform this operation, call the DeviceIoControl function with the following parameters.

BOOL DeviceIoControl(
 (HANDLE) hDevice,              // handle to device
 IOCTL_DISK_GET_LENGTH_INFO,    // dwIoControlCode
 NULL,                          // lpInBuffer
 0,                             // nInBufferSize
 (LPVOID) lpOutBuffer,          // output buffer
 (DWORD) nOutBufferSize,        // size of output buffer
 (LPDWORD) lpBytesReturned,     // number of bytes returned
 (LPOVERLAPPED) lpOverlapped    // OVERLAPPED structure
);
Parameters
hDevice
[in] Handle to the disk, volume, or partition. To retrieve a device handle, call the CreateFile function.
dwIoControlCode
[in] Control code for the operation. Use IOCTL_DISK_GET_LENGTH_INFO for this operation.
lpInBuffer
Not used with this operation; set to NULL.
nInBufferSize
Not used with this operation; set to zero.
lpOutBuffer
[out] Pointer to the output buffer that receives a GET_LENGTH_INFORMATION structure.
nOutBufferSize
[in] Size of the output buffer, in bytes.
lpBytesReturned
[out] Pointer to a variable that receives the size of the data stored in the output buffer, in bytes.
If the output buffer is too small, the call fails, GetLastError returns ERROR_INSUFFICIENT_BUFFER, and lpBytesReturned is zero.

If lpOverlapped is NULL, lpBytesReturned cannot be NULL. Even when an operation returns no output data and lpOutBuffer is NULL, DeviceIoControl makes use of lpBytesReturned. After such an operation, the value of lpBytesReturned is meaningless.

If lpOverlapped is not NULL, lpBytesReturned can be NULL. If this parameter is not NULL and the operation returns data, lpBytesReturned is meaningless until the overlapped operation has completed. To retrieve the number of bytes returned, call GetOverlappedResult. If hDevice is associated with an I/O completion port, you can retrieve the number of bytes returned by calling GetQueuedCompletionStatus.

lpOverlapped
[in] Pointer to an OVERLAPPED structure.
If hDevice was opened without specifying FILE_FLAG_OVERLAPPED, lpOverlapped is ignored.

If hDevice was opened with the FILE_FLAG_OVERLAPPED flag, the operation is performed as an overlapped (asynchronous) operation. In this case, lpOverlapped must point to a valid OVERLAPPED structure that contains a handle to an event object. Otherwise, the function fails in unpredictable ways.

For overlapped operations, DeviceIoControl returns immediately, and the event object is signaled when the operation has been completed. Otherwise, the function does not return until the operation has been completed or an error occurs.

Return Values
If the operation succeeds, DeviceIoControl returns a nonzero value.

If the operation fails, DeviceIoControl returns zero. To get extended error information, call GetLastError.

Remarks
This operation should be used instead of IOCTL_DISK_GET_PARTITION_INFO_EX for volumes that do not have partition info—such as partition type or number of hidden sectors.

Requirements
Client: Requires Windows XP.
Server: Requires Windows Server 2003.
Header: Declared in Winioctl.h."

Ку ?


> Игорь, еще раз спасибо за ntdddisk.h


Не за что :)


 
Aldor_   (2004-08-05 16:20) [6]

Вот кю, у нас что, msdn"ы разные?

Скажите, плиз, ссылку, откуда документ.
У меня вот, другое:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/storage/hh/storage/k307_50fea771-4937-481d-9a1b-f4d69bb 939bb.xml.asp (IOCTL_DISK_GET_LENGTH_INFO)

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcesdk40/html/cerefDeviceIoControl.asp (DeviceIoControl)


 
Игорь Шевченко ©   (2004-08-05 16:22) [7]


> Вот кю, у нас что, msdn"ы разные?


Наверное.


> Скажите, плиз, ссылку, откуда документ


MSDN Library April 2004


 
Aldor_   (2004-08-05 16:40) [8]

> MSDN Library April 2004

Тогда разрешите вопрос оффтоп: инфа на сайте msdn.com отличается от той библиотеки MSDN, которая у Вас? Она у Вас, наверное, на каком-нибудь носителе?

 К тому же настораживает: в конце документов, которых я указал в [6] стоит: Last updated on Saturday, April 10, 2004


 
Игорь Шевченко ©   (2004-08-05 16:45) [9]


> инфа на сайте msdn.com отличается от той библиотеки MSDN,
> которая у Вас? Она у Вас, наверное, на каком-нибудь носителе?


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/ioctl_disk_get_length_info.asp

не отличается


 
Aldor_   (2004-08-05 16:59) [10]

А, понял, моя ссылка на IOCTL_DISK_GET_LENGTH_INFO из Windows DDK, а Ваша - из Platform SDK.

 Дублированная инфа? Или для DDK и SDK сабж имеет действительно разный смысл?


 
Игорь Шевченко ©   (2004-08-05 17:22) [11]


> понял, моя ссылка на IOCTL_DISK_GET_LENGTH_INFO из Windows
> DDK


По приведенной ссылке Page Cannot be found, вообще-то, так что мне трудно сказать.
Но в DDK для W2k такой константы (IOCTL_DISK_GET_LENGTH_INFO) нету. Отсюда делаем вывод, что в Win2k она не реализована, о чем и говорит ошибка.


 
Aldor_   (2004-08-06 04:33) [12]

Спасибо большое за консультацию



Страницы: 1 вся ветка

Форум: "WinAPI";
Текущий архив: 2004.09.19;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.48 MB
Время: 0.032 c
1-1094124337
demonyator
2004-09-02 15:25
2004.09.19
Acdsee


1-1094202416
Ира
2004-09-03 13:06
2004.09.19
20-ти знаковое целое положительное число ???


14-1092995027
Kerk
2004-08-20 13:43
2004.09.19
"Ночной дозор" купили американцы


14-1093604350
ydv
2004-08-27 14:59
2004.09.19
Форум


1-1094198084
NewDelpher
2004-09-03 11:54
2004.09.19
Логические выражения





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский