Recommended way to query byte offset from file or IRP descriptors when handling an IRP in framework driver
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.
SetFilePointer()
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;
WDF_REQUEST_PARAMETERS_INIT(&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?