EvtIoRead/Write and offsets?

Hello,

I have issues concerning the EvtIoRead and EvtIoWrite functions. I am currently programming a driver for a simple PCI device. It is necessary that a user application is able to read and write certain memory addresses of the PCI card (its a very low level project, so no fancy stuff here).

Currently I am using the “normal” EvtIoDeviceControl function and BufferedIO with a kind of “protocol” to pass the offset and the command (READ or WRITE) to the driver.

But i would like to use EvtIoRead and EvtIoWrite instead. Therefor it would be necessary to pass an offset down to the driver. But as ReadFile and WriteFile don’t provide file positions or offsets I guess I have to use SetFilePointer instead.
But how do I access the position set by SetFilePointer during handling EvtIoRead for example?

It should be in the byteoffset field of the parameters…

–Mark Cariddi
OSR Open Systems Resources, Inc.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@conplement.de
Sent: Wednesday, August 24, 2011 9:02 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] EvtIoRead/Write and offsets?

Hello,

I have issues concerning the EvtIoRead and EvtIoWrite functions. I am currently programming a driver for a simple PCI device. It is necessary that a user application is able to read and write certain memory addresses of the PCI card (its a very low level project, so no fancy stuff here).

Currently I am using the “normal” EvtIoDeviceControl function and BufferedIO with a kind of “protocol” to pass the offset and the command (READ or WRITE) to the driver.

But i would like to use EvtIoRead and EvtIoWrite instead. Therefor it would be necessary to pass an offset down to the driver. But as ReadFile and WriteFile don’t provide file positions or offsets I guess I have to use SetFilePointer instead.
But how do I access the position set by SetFilePointer during handling EvtIoRead for example?


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

Personally I would stick with ioctls. Read and write usually only show up in file systems and storage drivers.

d

debt from my phone

-----Original Message-----
From: Mark Cariddi
Sent: Wednesday, August 24, 2011 6:12 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] EvtIoRead/Write and offsets?

It should be in the byteoffset field of the parameters…

–Mark Cariddi
OSR Open Systems Resources, Inc.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@conplement.de
Sent: Wednesday, August 24, 2011 9:02 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] EvtIoRead/Write and offsets?

Hello,

I have issues concerning the EvtIoRead and EvtIoWrite functions. I am currently programming a driver for a simple PCI device. It is necessary that a user application is able to read and write certain memory addresses of the PCI card (its a very low level project, so no fancy stuff here).

Currently I am using the “normal” EvtIoDeviceControl function and BufferedIO with a kind of “protocol” to pass the offset and the command (READ or WRITE) to the driver.

But i would like to use EvtIoRead and EvtIoWrite instead. Therefor it would be necessary to pass an offset down to the driver. But as ReadFile and WriteFile don’t provide file positions or offsets I guess I have to use SetFilePointer instead.
But how do I access the position set by SetFilePointer during handling EvtIoRead for example?


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


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

FYI ReadFile & WriteFile do support specific offsets thru the use of the
OVERLAPPED struct. This does not change the advice that in general
DeviceIoControl provides a more flexible option when the device semantic is
not block or stream IO. If by ‘read and write certain memory address’ you
mean that the semantic is block IO (ex your device has onboard flash or
other storage), then ReadFile / WriteFile may be better for you.

wrote in message news:xxxxx@ntdev…

Hello,

I have issues concerning the EvtIoRead and EvtIoWrite functions. I am
currently programming a driver for a simple PCI device. It is necessary that
a user application is able to read and write certain memory addresses of the
PCI card (its a very low level project, so no fancy stuff here).

Currently I am using the “normal” EvtIoDeviceControl function and BufferedIO
with a kind of “protocol” to pass the offset and the command (READ or WRITE)
to the driver.

But i would like to use EvtIoRead and EvtIoWrite instead. Therefor it would
be necessary to pass an offset down to the driver. But as ReadFile and
WriteFile don’t provide file positions or offsets I guess I have to use
SetFilePointer instead.
But how do I access the position set by SetFilePointer during handling
EvtIoRead for example?

You should use Read/WriteFileEx and using the overlapped parameter to pass
the offset values. In driver, you can retrieve offset from the
IO_STACK_LOCATION’s Read/Write parameters:

//
// Parametersms-help:for
IRP_MJ_WRITEms-help:
//
struct {
ULONG Length;
ULONG POINTER_ALIGNMENT Key;
LARGE_INTEGER ByteOffset;
} Write;

-----Original Message-----

From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@conplement.de

Sent: Wednesday, August 24, 2011 9:02 AM

To: Windows System Software Devs Interest List

Subject: [ntdev] EvtIoRead/Write and offsets?

Hello,

I have issues concerning the EvtIoRead and EvtIoWrite functions. I am
currently programming a driver for a simple PCI device. It is necessary that
a user application is able to read and write certain memory addresses of the
PCI card (its a very low level project, so no fancy stuff here).

Currently I am using the “normal” EvtIoDeviceControl function and BufferedIO
with a kind of “protocol” to pass the offset and the command (READ or WRITE)
to the driver.

But i would like to use EvtIoRead and EvtIoWrite instead. Therefor it would
be necessary to pass an offset down to the driver. But as ReadFile and
WriteFile don’t provide file positions or offsets I guess I have to use
SetFilePointer instead.

But how do I access the position set by SetFilePointer during handling
EvtIoRead for example?



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



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



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

=================================
Best Regards!
Moore.Zhang (Zhang Pei)</ms-help:></ms-help:>

Thanks for the quick replies.

I guess I could use overlapped. I wanted to use synchronous IO though, at least for the read/write access.

Maybe I will stick with the IOControl and use two different IOCTLs instead. The point about stream/blocks is a valid one. In most cases the bytes to read/write will be located somewhere completely else then the bytes accessed before…

>> I guess I could use overlapped. I wanted to use synchronous IO though, at
least for the read/write access.
No guy. Using overlapped didn’t mean you should send a asynchronous request.
Using Read/WriteFile with hFile handle opened without FILE_FLAG_OVERLAPPED
flag, and set the offset through overlapped parameter. Such request is sent
synchronously.


Thanks for the quick replies.

I guess I could use overlapped. I wanted to use synchronous IO though, at
least for the read/write access.

Maybe I will stick with the IOControl and use two different IOCTLs instead.
The point about stream/blocks is a valid one. In most cases the bytes to
read/write will be located somewhere completely else then the bytes accessed
before…


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

Moore.Zhang wrote:

>> I guess I could use overlapped. I wanted to use synchronous IO though, at
No guy. Using overlapped didn’t mean you should send a asynchronous request.
Using Read/WriteFile with hFile handle opened without FILE_FLAG_OVERLAPPED
flag, and set the offset through overlapped parameter. Such request is sent
synchronously.

Even so, I’m not sure this is good advice. The issue here is one of
philosophy, not technology… ReadFile and WriteFile have certain
connotations that don’t neatly map to devices other than disks. The
Unix world has long tried to make every device into a stream, but in
Windows, for devices other than disks, it is generally more sensible to
do everything with DeviceIoControl.

After all, there is absolutely no difference in the driver. They all
come in as IRPs, and the ioctl has the (rather small) benefit of
allowing you to choose buffered vs direct on a request by request basis,
rather than requiring one approach for all I/Os.


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