Recommended way to query byte offset from file or IRP descriptors when handling an IRP in framework driver

Charles Gardiner 96 Reputation points

We are developing a custom hardware and device driver. The custom hardware has a large RAM which is to be accessed similarly to a character-based file (not file system).

The application SW will call e.g.

ReadFile() or ReadFileEx()

In the IRP handler what is the recommended way to obtain the byte offset into the file. In the hardware this must be written to a register to set up the initial RAM address for a read or write operation.

In the KMDF docu I have found the following options:

WDFFILEOBJECT                    mFile;
WDF_REQUEST_PARAMETERS           mReqParams;  

WdfRequestGetParameters((WdfDmaTransactionGetRequest(Transaction)), &mReqParams);
mFile       = WdfRequestGetFileObject(WdfDmaTransactionGetRequest(Transaction));
pFileCtx    = CbGetFileContext(mFile);

   // Options
pFileCtx->mDmaOffset = WdfFileObjectWdmGetFileObject(mFile)->CurrentByteOffset.LowPart;

pFileCtx->mDmaOffset = mReqParams.Parameters.Read.DeviceOffset & 0xffffffff;

pFileCtx->mDmaOffset = WdfRequestWdmGetIrp(WdfDmaTransactionGetRequest(Transaction))->Tail.Overlay.CurrentStackLocation->FileObject->CurrentByteOffset.LowPart;

pFileCtx->mDmaOffset = WdfRequestWdmGetIrp(WdfDmaTransactionGetRequest(Transaction))->Tail.Overlay.CurrentStackLocation->Parameters.Read.ByteOffset

pFileCtx->mDmaOffset = WdfRequestWdmGetIrp(WdfDmaTransactionGetRequest(Transaction))->Tail.Overlay.OriginalFileObject->CurrentByteOffset.LowPart;

Do all of these options do the same thing or which solution is the correct one to use?

Should I be using a different solution?

Windows Hardware Performance
Windows Hardware Performance
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.Hardware Performance: Delivering / providing hardware or hardware systems or adjusting / adapting hardware or hardware systems.
1,460 questions
0 comments No comments
{count} votes