WDK help???

I am new to the device driver scene.
I want to try and modify a USB mass storage device driver and I was wondering
whether WDK (from http://www.microsoft.com/whdc/DevTools/WDK/WDKpkg.mspx) has any sample code?
I was told that it has a framework for the driver, but I could someone please conform if WDK has or has not got any actual sample code for USB mass storage devices?

Thanks

xxxxx@googlemail.com wrote:

I am new to the device driver scene.
I want to try and modify a USB mass storage device driver and I was wondering
whether WDK (from http://www.microsoft.com/whdc/DevTools/WDK/WDKpkg.mspx) has any sample code?
I was told that it has a framework for the driver, but I could someone please conform if WDK has or has not got any actual sample code for USB mass storage devices?

There are no samples for USB mass storage devices, because there is no
need to write one ever again. Microsoft’s driver will handle any device
that meets the Mass Storage Class specification, and no designer who is
not in a nut house would ever design a USB mass storage device that did
not meet the spec.

Mass storage drivers are quite complicated. What, exactly, are you
hoping to do? You can tweak some thing using a filter driver, but there
are a lot of layers in a mass storage driver stack (device, volume,
partition, file system), and you have to know where you belong.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Thanks for your reply Tim.
I wanted to modify the code for a USB mass storage driver or filter driver, to see if I can get at a physical location on a USB (which may or may not be possible).

I have looked at the WDK and under src/ there is a folder called ‘USB’ - which I am assuming is for USB mass stoage devices.

Is there any sample filter driver code on the WDK? Which I can use to access a physical memory address on a USB device?

Thanks

USB device drivers do not access physical memory addresses, the usb host controller does that on your behalf. What is your goal? To learn how to write a driver or to specifically deliver something around usb mass storage?

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@googlemail.com
Sent: Monday, November 30, 2009 10:01 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] WDK help???

Thanks for your reply Tim.
I wanted to modify the code for a USB mass storage driver or filter driver, to see if I can get at a physical location on a USB (which may or may not be possible).

I have looked at the WDK and under src/ there is a folder called ‘USB’ - which I am assuming is for USB mass stoage devices.

Is there any sample filter driver code on the WDK? Which I can use to access a physical memory address on a USB device?

Thanks


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

xxxxx@googlemail.com wrote:

I wanted to modify the code for a USB mass storage driver or filter driver, to see if I can get at a physical location on a USB (which may or may not be possible).

Again, it depends on what you’re after. You can open ANY mass storage
device in raw mode (USB or not), and read and write absolute sectors,
using \.\physicaldrive1. All user-mode, no driver required. Of
course, writing in that way is quite likely to destroy the file system
on the drive.

I have looked at the WDK and under src/ there is a folder called ‘USB’ - which I am assuming is for USB mass stoage devices.

No, not at all. The src\usb folder contains tools and sample drivers
for accessing endpoints on generic USB devices. There is nothing in
there related to mass-storage at all, because no one in the world writes
USB mass storage drivers. That problem is solved.

Is there any sample filter driver code on the WDK? Which I can use to access a physical memory address on a USB device?

USB mass storage devices are not memory. You need to think of them as
disks, because that’s exactly how the operating system sees them. They
are a sequential collection of sectors, accessed using SCSI commands.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

> I wanted to modify the code for a USB mass storage driver or filter driver, to see if I can get at a

physical location on a USB (which may or may not be possible).

I think USBVIEW tool can do this without writing a driver for any USB device, storage included.

Anyway note that USB designed in a way to make the notion of “physical location” volatile and not useful. Nobody cares to what laptop’s port the flash drive is inserted.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

OK… can you please explain what you mean by “get a physical location on a USB”?

Peter
OSR

Thank you all for your comments.

My goal is to try and write/modify a USB mass storage device code so that I can get at the physical memory.
From my understanding , a device driver interacts with the OS, which gives the device driver the logical location on the disk (of a file when requested). What I want to try and do is get under this (I assume using a lower level filter driver) and change it so that it gives me the physical location instead.
Normally it is the HAL that does this, but my ultimate goal is to try and get the USB device driver to bring me back the physical location.

You are confused. The HAL has nothing to do with the physical location on
a USB mass storage drive. It appears you are assuming that since most USB
storage is flash memory it is treated as memory, this is incorrect. You
can use FSCTL_GET_RETRIEVAL_POINTERS to get the physical block offsets on
the drive, but that is the limit of physical.


Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

wrote in message news:xxxxx@ntdev…
> Thank you all for your comments.
>
> My goal is to try and write/modify a USB mass storage device code so that
> I can get at the physical memory.
> From my understanding , a device driver interacts with the OS, which gives
> the device driver the logical location on the disk (of a file when
> requested). What I want to try and do is get under this (I assume using a
> lower level filter driver) and change it so that it gives me the physical
> location instead.
> Normally it is the HAL that does this, but my ultimate goal is to try and
> get the USB device driver to bring me back the physical location.
>
>
> Information from ESET NOD32 Antivirus, version of virus
> signature database 4651 (20091201)

>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>

Information from ESET NOD32 Antivirus, version of virus signature database 4651 (20091201)

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

wrote in message news:xxxxx@ntdev…
>
> My goal is to try and write/modify a USB mass storage device code so that
> I can get at the physical memory.
> From my understanding , a device driver interacts with the OS, which gives
> the device driver the logical location on the disk (of a file when
> requested). What I want to try and do is get under this (I assume using a
> lower level filter driver) and change it so that it gives me the physical
> location instead.

Then, you would be much better off with an opensource OS.
Good luck.
–pa

xxxxx@googlemail.com wrote:

My goal is to try and write/modify a USB mass storage device code so that I can get at the physical memory.

It’s not memory. You cannot think of a USB mass storage device as
memory. The USB Mass Storage Class specification requires that such
devices behave like disk drives. The lowest-level protocol to the
device is the SCSI disk command set: read sector, write sector, etc.
You must stop thinking of them as memory.

From my understanding , a device driver interacts with the OS, which gives the device driver the logical location on the disk (of a file when requested).

It is far more complicated than that. Applications make open, read, and
write requests to the operating system. The system passes those to a
file system driver (like NTFS), which knows nothing about the underlying
device. The file system driver reads and writes the file system tables
on the disk, and uses those to find the sector numbers for a particular
file. It makes requests of the disk driver, which turns those sector
requests into hardware commands and passes them to the bus driver. The
bus driver sends those commands on to the USB device.

What I want to try and do is get under this (I assume using a lower level filter driver) and change it so that it gives me the physical location instead.

Physical location of what?

Normally it is the HAL that does this, but my ultimate goal is to try and get the USB device driver to bring me back the physical location.

As Don said, there’s no HAL here. The file system driver is the one
that comes up with the sector numbers to read and write. The USB Mass
Storage driver turns those into SCSI commands and sends them to the
device, which returns the sectors up the stack.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

> My goal is to try and write/modify a USB mass storage device code so that I can get at the physical

memory.

How the physical memory is related to USB mass storage?

From my understanding , a device driver interacts with the OS, which gives the device driver the
logical location on the disk (of a file when requested). What I want to try and do is get under this (I
assume using a lower level filter driver) and change it so that it gives me the physical location instead.

Sorry, what is “physical location” and “logical location” of the USB mass storage?

The only “physical location” I can imagine in this context is the USB hub number and hub port number.

Normally it is the HAL that does this

HAL knows nothing on USB.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

Thanks all.

First off I think it would be a good start for me to try and change the name of a driver, but I have no idea where to start.
I have found a filter driver under the ‘src’ folder of WDK and a ‘USB’ folder. By changing the DriverEntry of these files, would that change the name of the driver?

Is there any sample code for low level filter driver under WDK?

“Low level” doesn’t mean anything specific. We don’t understand what you want to accomplish.

Dude… You’ve ignored every bit of advice we’ve provided and every question we’ve asked.

This is not conducive to getting us to help you… which is what we all want to do.

Soooo, let us start from the beginning: Please explain to us the ROOT PROBLEM that you’d like to solve. If it’s just “learn how to write Windows drivers” just say that. If it’s “make a super-secret blah blah that interfaces with a foo bar” describe it in the most general terms, without giving away any secrets.

If you need guidance as to what I mean by ROOT PROBLEM, read the following:

http://www.osronline.com/downloads/pp_asking.pdf

(it’s not technical, it’s satirical… for some meaning of the word “satire”)

Peter
OSR

OK so my aim is to try and understand how a USB mass storage device driver reads and writes (and if possible change the code in some way - even changing the name of the device).
I have done some reading on the issue, but actually trying to do the practical is turning out to be harder than I thought.
Can anyone point me in the right direction i.e. what code I need to look at and how to go about understanding the read and write procedures, to begin with?

Thanks!

“Doing the practical” is, indeed, much harder than it might at first appear.

Well, “the name of the device” is a drive letter in Windows. And how that’s assigned really isn’t related to “how a USB mass storage device driver reads and writes.”

Let’s start with the latter: I assume you’ve read the following??

http://www.usb.org/developers/devclass_docs/usb_msc_overview_1.2.pdf

http://www.usb.org/developers/devclass_docs/usbmassbulk_10.pdf

These detail how the USB storage driver reads/writes to a USB storage device.

Putting this in the larger context of the storage stack is a bit more difficult, but this will show you the storage stack architecture:

http://msdn.microsoft.com/en-us/library/ms801427.aspx

(and associated pages)

… what this shows as the “storage port driver” in the above diagram, in the case of USB, is the USB Mass Storage Driver, which in turn sits on top of the USB Stack:

http://msdn.microsoft.com/en-us/library/ms794302.aspx

(and associated pages)

(which will at least be the root hub and host controller drivers. It’s the host controller driver that interfaces directly with the USB bus using the OHCI/UHCI/EHCI protocol).

Admittedly, a lot of “gobbeldy gook” that does little to clearly explain the general framework of what’s going on, but it’s a start.

Are you with me so far? If so, does this help you clarify what you want to do? If not, what is it specifically that you don’t follow?

Peter
OSR

xxxxx@googlemail.com wrote:

OK so my aim is to try and understand how a USB mass storage device driver reads and writes (and if possible change the code in some way - even changing the name of the device).
I have done some reading on the issue, but actually trying to do the practical is turning out to be harder than I thought.
Can anyone point me in the right direction i.e. what code I need to look at and how to go about understanding the read and write procedures, to begin with?

The USB Mass Storage Class specification can be downloaded for free from
the USB Implementor’s Forum (www.usb.org). That has the ultimate answer
on what the exchanges look like on the wire. That spec will also point
you to a SCSI command set specification.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Thanks for your replies.

I have not read the pdf documents, but am in the process of doing so. Most of my reading has been with “Windows Internals” by Mark Russinovich and David Solomon.
I will read these documents and try to understand them.

My aim is to understand how USB’s read and write data, but also to try and understand if they read and write differently to a hard drive. But first I want to understand how the read and write functions work on a USB.

xxxxx@googlemail.com wrote:

I have not read the pdf documents, but am in the process of doing so. Most of my reading has been with “Windows Internals” by Mark Russinovich and David Solomon.
I will read these documents and try to understand them.

My aim is to understand how USB’s read and write data, but also to try and understand if they read and write differently to a hard drive. But first I want to understand how the read and write functions work on a USB.

The USB specifications have all of this information, although a book
like Axelson’s “USB Complete” might make some of it more clear.

USB is a layered protocol bus, similar to Ethernet in some ways. At the
wire level, it just transfers packets of up to 1024 bytes, with no
meaning to the packets. Some packets are commands, some are data. On
top of that, there are device classes that assign meaning to the
packets. It’s quite possible to have a USB device that isn’t in one of
the classes, where your driver and your device have some private
understanding of what’s in the packets.

The USB Mass Storage Class spec defines what the packets mean for mass
storage devices. The packets that get exchanged are a subset of the
SCSI disk command set. After configuration, the commands are basically
just “read sector X” and “write sector Y”. It’s no more complicated
than that. All of the file system functions are provided by higher
layers, which have no clue that they are talking to a USB device.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

OK so I have read the USB specifications and I understand USB’s a bit more. It has been useful.

After reading through all the comments again and thinking about what I want to do, I would like to rephrase my initial question.
Is is possible to get to a physical sector on a USB? That would be my main goal.
I would like to try and create a USB mass storage device driver that reads a particular sector on my USB and outputs its contents - which could be nothing. Would this be possible, would this be a valid statement to make?

Thanks