473,324 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

DeviceIOControl FSCTL_ENUM_USN_DATA gives error 1 Incorrect Functi

We are successfully getting a handle to a drive using createfile then using that handle to query the change journal using DeviceIOControl with the paramter FSCTL_QUERY_USN_DATA. However when we try to enumerate the change journal data using the same handle and using DeviceIOControl with FSCTL_ENUM_DATA it gives error 1 Incorrect function. The help says this means that the drive does not support change journals but this is not the case as we can query the change journal successfully. The code is below. ahandle is a valid handle (we know this becuase we can use it successfully to query the change journal) and ujd is our output buffer from FSCTL_QUERY_USN_DATA, containing valid values. Does anyone know why we are getting error 1?

Public Const FILE_READ_DATA = &H1
Public Const FILE_DEVICE_FILE_SYSTEM = &H9
Public Const METHOD_NEITHER = &H3

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> Public Structure MFT_ENUM_DATA
Public StartFileReferenceNumber As Long
Public LowUsn As Int64
Public HighUsn As Int64
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> Public Structure ENUM_USN_DATA
Public USN As Int64
Public RECORD As USN_RECORD
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> Public Structure USN_RECORD
Dim RecordLength As Integer
Dim MajorVersion As Integer
Dim MinorVersion As Integer
Dim FileReferenceNumber As Integer
Dim ParentFileReferenceNumber As Integer
Dim Usn As Integer
Dim TimeStamp As Integer
Dim Reason As Integer
Dim SourceInfo As Integer
Dim SecurityId As Integer
Dim FileAttributes As Integer
Dim FileNameLength As Integer
Dim FileNameOffset As Integer
Dim FileName As String
End Structure

Public Declare Function DeviceIoControl Lib "kernel32.dll" (ByVal hDevice As IntPtr, ByVal dwIoControlCode As Int32, <MarshalAs(UnmanagedType.Struct)> ByRef lpInBuffer As MFT_ENUM_DATA, ByVal nInBufferSize As Integer, <MarshalAs(UnmanagedType.Struct)> ByRef lpOutBuffer As ENUM_USN_DATA, ByVal nOutBufferSize As Integer, ByRef lpBytesReturned As Integer, ByVal lpOverlapped As Integer) As IntPtr

Public Sub QueryJournal()
Dim FSCTL_ENUM_USN_DATA As Long = CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 44, METHOD_NEITHER, FILE_READ_DATA)
EnumDataBufferIn.StartFileReferenceNumber = 0
EnumDataBufferIn.LowUsn = ujd.LowestValidUsn
EnumDataBufferIn.HighUsn = ujd.NextUsn
anObject = DeviceIoControl(aHandle, FSCTL_ENUM_USN_DATA, EnumDataBufferIn, Marshal.SizeOf(EnumDataBufferIn), EUSN, Marshal.SizeOf(EUSN), byteBack, 0)
end sub

Public Function CTL_CODE(ByVal dwDeviceType As Long, _
ByVal dwFunction As Long, _
ByVal dwMethod As Long, _
ByVal dwAccess As Long) As Long

On Error GoTo Out

CTL_CODE = ShiftBits(dwDeviceType, 16) Or _
ShiftBits(dwAccess, 14) Or _
ShiftBits(dwFunction, 2) Or dwMethod

Out:
End Function
Nov 20 '05 #1
0 2290

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ewoo | last post by:
I'm trying to write a wrapper in csharp to wrap DeviceIoControl() win32 method for IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS control code--without much luck. I've seen lots of examples out there for...
2
by: Michael Allen | last post by:
I would like to perform something similar to the below function in C# .NET. The C++ below code is from a Microsoft DDK sample driver application. Specifically, I would like to perform Device I/O...
3
by: Mads Tjørnelund Toustrup | last post by:
I'm having difficulties converting the GET_CONFIGURATION_HEADER from the IOCTL_CDROM_GET_CONDIGURATION DeviceIoControl command to usable C# code. The C struct look like this: typedef struct...
3
by: Jacky | last post by:
Hi, I am trying to make network card interface with VB.NET 2002. I use DeviceIOControl-function. I have tried to define inbuffer and outbuffer using byte array and it's pointer. The second I...
1
by: Pixie | last post by:
I am trying to query the change journal using the deviceIOControl API. The API doesn't return an error, but all of the values in the output buffer are zero, and they shouldn't be. My code is below. I...
1
by: Juan Pedro Gonzalez | last post by:
Helo, I'm having problems here with the input buffer.... Ive defined the API call as: <System.Runtime.InteropServices.DllImport("kernel32", SetLastError:=True)> _ Private Shared Function...
5
by: Lou | last post by:
is there a VB .NET way to use the API "DeviceIoControl"? -Lou
0
by: Andrew | last post by:
Hello I am trying to port some code and I am running into some issues I may or may not be able to solve on my own and would appreciate your help Basically I am trying to open the Tun Driver...
4
by: =?Utf-8?B?TWFyaW5h?= | last post by:
Does any know any sample of how to do a basic DeviceIoControl with something like IOCTL_BATTERY_GETSYSTEMPOWERSTATUSEX2 in C# I have been stuck all week :( and google doesnt yield anything of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.