473,770 Members | 1,954 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 8821
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
2991
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
4534
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
2879
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
19358
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
3862
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
3876
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
9617
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10254
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...
0
10099
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8929
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7451
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
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
3607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.