473,785 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IOCTL_STORAGE_Q UERY_PROPERTY and the STORAGE_BUS_TYP E data type


Would appreciate any help with some test code I'm trying to write. I'm trying
to figure out how to use the IOCTL_STORAGE_Q UERY_PROPERTY stuff correctly when
querying a device/adapter. I've gone through the DDK and SDK and am still
stumped. Basically, the following code just gets a handle to the first physical
drive and calls the IOCTL_STORAGE_Q UERY_PROPERTY IO Control, and then dumps out
the result. It seems to work fine except that I had to alter one of the default
struct definitions which I originally got from the DDK. I had to change the
line "STORAGE_BUS_TY PE BusType;" to "USHORT BusType;" for the
STORAGE_ADAPTER _DESCRIPTOR structure. If I don't change this line, the BusType
value doesn't seem to come back correctly. I think I've narrowed it down to the
fact that enums are ints(4 bytes) when it seems to be returning the bustype back
as a 2 byte value(hence why I had to use USHORT). The following is an extract
of what the result is when I've got the BusType as USHORT:

Version: 32
Size: 32
MaxTransferLeng th: 131072
MaximumPhysical Pages: -1
AlignmentMask: 1
AdapterUsesPio: 1
AdapterScansDow n: 0
CommandQueueing : 0
AcceleratedTran sfer: 0
BusType: 3
BusMajorVersion : 1
BusMinorVersion : 0
ATA Drive Found
ATA Drive: 3
1394 Drive: 4
Unknown Drive: 127
SIZE Of STORAGE_BUS_TYP E: 4
SIZE Of USHORT: 2
SIZE Of INT: 4
SIZE Of ULONG: 4
SIZE Of BOOLEAN: 1

When I have the BusType as STORAGE_BUS_TYP E, I get the following, which doesn't
seem right
Version: 32
Size: 32
MaxTransferLeng th: 131072
MaximumPhysical Pages: -1
AlignmentMask: 1
AdapterUsesPio: 1
AdapterScansDow n: 0
CommandQueueing : 0
AcceleratedTran sfer: 0
BusType: 65539
BusMajorVersion : 0
BusMinorVersion : 0
ATA Drive: 3
1394 Drive: 4
Unknown Drive: 127
SIZE Of STORAGE_BUS_TYP E: 4
SIZE Of USHORT: 2
SIZE Of INT: 4
SIZE Of ULONG: 4
SIZE Of BOOLEAN: 1

Would appreciate if anyone who's experienced with this could shed some light on
this. Thanks

Relevant extract of code follows:
#define IOCTL_STORAGE_Q UERY_PROPERTY CTL_CODE(IOCTL_ STORAGE_BASE, 0x0500,
METHOD_BUFFERED , FILE_ANY_ACCESS )

typedef enum _STORAGE_BUS_TY PE {
BusTypeUnknown = 0x00,
BusTypeScsi,
BusTypeAtapi,
BusTypeAta,
BusType1394,
BusTypeSsa,
BusTypeFibre,
BusTypeUsb,
BusTypeRAID,
BusTypeMaxReser ved = 0x7F
} STORAGE_BUS_TYP E, *PSTORAGE_BUS_T YPE;

typedef struct _STORAGE_ADAPTE R_DESCRIPTOR {
ULONG Version;
ULONG Size;
ULONG MaximumTransfer Length;
ULONG MaximumPhysical Pages;
ULONG AlignmentMask;
BOOLEAN AdapterUsesPio;
BOOLEAN AdapterScansDow n;
BOOLEAN CommandQueueing ;
BOOLEAN AcceleratedTran sfer;
//??Should this be a storage bus type or a Ushort?
//STORAGE_BUS_TYP E BusType;
USHORT BusType;
USHORT BusMajorVersion ;
USHORT BusMinorVersion ;
} STORAGE_ADAPTER _DESCRIPTOR, *PSTORAGE_ADAPT ER_DESCRIPTOR;

int GetDiskDetails( )
{
HANDLE hDevice; // handle to the drive to be examined
STORAGE_PROPERT Y_QUERY Query; // input param for query
DWORD dwOutBytes; // IOCTL output length
BOOL bResult; // IOCTL return val

STORAGE_ADAPTER _DESCRIPTOR AdapDesc;
PSTORAGE_ADAPTE R_DESCRIPTOR pAdapDesc;

hDevice = CreateFile("\\\ \.\\PhysicalDri ve0", // drive to open
0, // no access to the drive
FILE_SHARE_READ | // share mode
FILE_SHARE_WRIT E,
NULL, // default security attributes
OPEN_EXISTING, // disposition
0, // file attributes
NULL); // do not copy file attributes

if (hDevice == INVALID_HANDLE_ VALUE) // cannot open the drive
{
puts("Bad Name to open");
return (FALSE);
}

// specify the query type
Query.PropertyI d = StorageAdapterP roperty ;
Query.QueryType = PropertyStandar dQuery;

pAdapDesc = &AdapDesc;
pAdapDesc->Size = sizeof(STORAGE_ ADAPTER_DESCRIP TOR);

// Query using IOCTL_STORAGE_Q UERY_PROPERTY
bResult = DeviceIoControl (hDevice, // device handle
IOCTL_STORAGE_Q UERY_PROPERTY, // info of device property
&Query, sizeof(STORAGE_ PROPERTY_QUERY) , // input data buffer
pAdapDesc, pAdapDesc->Size, // output data buffer
&dwOutBytes, // out's length
(LPOVERLAPPED)N ULL);

if(bResult)
{
puts("Good");

printf("Version : %ld\n",pAdapDes c->Version);
printf("Size: %ld\n",pAdapDes c->Size);
printf("MaxTran sferLength: %ld\n",pAdapDes c->MaximumTransfe rLength);
printf("Maximum PhysicalPages: %ld\n",pAdapDes c->MaximumPhysica lPages);
printf("Alignme ntMask: %ld\n",pAdapDes c->AlignmentMask) ;
printf("Adapter UsesPio: %ld\n",pAdapDes c->AdapterUsesPio );
printf("Adapter ScansDown: %ld\n",pAdapDes c->AdapterScansDo wn);
printf("Command Queueing: %ld\n",pAdapDes c->CommandQueuein g);
printf("Acceler atedTransfer: %ld\n",pAdapDes c->AcceleratedTra nsfer);
printf("BusType : %ld\n",pAdapDes c->BusType);
printf("BusMajo rVersion: %ld\n",pAdapDes c->BusMajorVersio n);
printf("BusMino rVersion: %ld\n",pAdapDes c->BusMinorVersio n);

if(pAdapDesc->BusType == BusTypeAta)
puts("ATA Drive Found");

printf("ATA Drive: %d\n",BusTypeAt a);
printf("1394 Drive: %d\n",BusType13 94);
printf("Unknown Drive: %d\n",BusTypeMa xReserved);

printf("SIZE Of STORAGE_BUS_TYP E: %d\n",sizeof(ST ORAGE_BUS_TYPE) );
printf("SIZE Of USHORT: %d\n",sizeof(US HORT));
printf("SIZE Of INT: %d\n",sizeof(in t));
printf("SIZE Of CHAR: %d\n",sizeof(ch ar));
}
else
{
puts("Damn");
}

CloseHandle(hDe vice);
return bResult;
}

Nov 14 '05 #1
2 8822
GhostHouse <Gh********@exc ite.com> scribbled the following
on comp.lang.c:
Would appreciate any help with some test code I'm trying to write. I'm trying
to figure out how to use the IOCTL_STORAGE_Q UERY_PROPERTY stuff correctly when
querying a device/adapter.


This has nothing whatsoever to do with C. Follow-ups set.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"To doo bee doo bee doo."
- Frank Sinatra
Nov 14 '05 #2
Do not post things about the DDK in the C language group. Always post
to the most relevant group to keep stuff not of general interest from
cluttering other groups. That's the whole purpose of having a DDK
group.
It seems to work fine except that I had to alter one of the default
struct definitions which I originally got from the DDK.
Never modify the DDK header files! This is why you are having
problems. It will also make upgrading the DDK a lot of unnecessary
work.
I had to change the line "STORAGE_BUS_TY PE BusType;" to
"USHORT BusType;" for the STORAGE_ADAPTER _DESCRIPTOR structure.


The DDK defines it as UCHAR which you should be using. Yes, this is
dumb the DDK does not use its own enum for the purpose. Also you
should ensure structure packing is 8. The DDK headers have problems if
you try to use structure packing other than 8 and indeed this
particular structure is vulnerable (sizeof & field alignment). That's
dumb too, but less effort to just go with Microsoft's guidelines when
you are dealing with the DDK...
Nov 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2993
by: lawrence | last post by:
I'm trying to read up on the rfc's that govern form inputs. Much of what I'm reading is stuff I didn't know before and some of it is alarming. This one left with me questions: http://www.ietf.org/rfc/rfc1867.txt Is this (below) addressed to me as a web designer, or is this addressed to the makers of web browsers? Identifying the type of file being uploaded seems way outside of my scope as a PHP coder. Am I
21
4536
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
0
2880
by: elcc1958 | last post by:
I need to support a VB6 application that will be receiving disconnected ADODB.Recordset from out DotNet solution. Our dotnet solution deals with System.Data.DataTable. I need to populate a disconnected ADODB.Recordset from System.Data.DataTable data. Below is the source code I am implementing to test the process. I do not get any error, that I can see. The problem I have is that at the end, the recordset seems to be empty. Any...
10
19361
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is able to fill that one out just fine. The second form is multipart/form-data. Unfortunately, I haven't been able to fill that out in a way that makes the server happy. I set up a copy of this form at my web site so that I could see exactly what a...
2
1695
by: Pavils Jurjans | last post by:
Hello, I have a fairly complex project with server-side written in C# (.NET), and client-side heavily relying on the presence on JavaScript-compatible scripting engine. One of the features thie project utilizes is "virtual POST", ie, client side submits the data to the server side, using Microsoft.XMLHTTP ActiveX Object (in MSIE), or XMLHttpRequest class in Mozilla, and when the server returns reply, processes it in client side to run...
4
3863
by: Thomas Paul Diffenbach | last post by:
Can anyone point me to an open source library of /statically allocated/ data structures? I'm writing some code that would benefit from trees, preferably self balancing, but on an embedded system that doesn't offer dynamic memory allocation (to be clear: no malloc, no realloc), and with rather tight memory constraints. Writing my own malloc to do dynamic allocation from some static pool isn't really an option, for various reasons, not...
4
2476
by: Dan | last post by:
I'm trying to creat a data structure, that can be either a integer, double, string, or linked list. So I created the following, but don't know if it is the data structure itself causing problems, or something I am doing in the rest of the program. This is the data structure. struct node { char type;
4
2271
by: No One | last post by:
Here is my problem: I have a certain set of well-defined manipulations that I have to apply to different types of data. In all cases the manipulations are exactly the same, and are to be performed on the different types of data. Currently I have a collection of functions that do exactly the same - the only difference between them is the type of data they act on. Let me present a toy example: I have the following two data types:
9
3877
by: weirdwoolly | last post by:
Hopefully someone will be able to help. I have written a stored procedure in C++ called from a Java test harness to validate the graphic data types in C++ and their use. I have declared the vargraphic input parameters along the following lines in i_vargraphic100 vargraphic(100) and they are populated from String's in java.
0
9484
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10350
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10097
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9957
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.