Exemplo n.º 1
0
        unsafe private void SetupMFT_Enum_DataBuffer(ref IntPtr medBuffer)
        {
            uint bytesReturned = 0;

            MFTReader.USN_JOURNAL_DATA ujd = new MFTReader.USN_JOURNAL_DATA();

            bool bOk = MFTReader.DeviceIoControl(_changeJournalRootHandle,           // Handle to drive
                                                 MFTReader.FSCTL_QUERY_USN_JOURNAL,  // IO Control Code
                                                 IntPtr.Zero,                        // In Buffer
                                                 0,                                  // In Buffer Size
                                                 out ujd,                            // Out Buffer
                                                 sizeof(MFTReader.USN_JOURNAL_DATA), // Size Of Out Buffer
                                                 out bytesReturned,                  // Bytes Returned
                                                 IntPtr.Zero);                       // lpOverlapped

            if (bOk)
            {
                MFTReader.MFT_ENUM_DATA med;
                med.StartFileReferenceNumber = 0;
                med.LowUsn  = 0;
                med.HighUsn = ujd.NextUsn;
                int sizeMftEnumData = Marshal.SizeOf(med);
                medBuffer = Marshal.AllocHGlobal(sizeMftEnumData);
                MFTReader.ZeroMemory(medBuffer, sizeMftEnumData);
                Marshal.StructureToPtr(med, medBuffer, true);
            }
            else
            {
                throw new IOException("DeviceIoControl() returned false", new Win32Exception(Marshal.GetLastWin32Error()));
            }
        }
Exemplo n.º 2
0
        unsafe private void SetupMFT_Enum_DataBuffer(ref IntPtr medBuffer)
        {
            uint bytesReturned = 0;
            MFTReader.USN_JOURNAL_DATA ujd = new MFTReader.USN_JOURNAL_DATA();

            bool bOk = MFTReader.DeviceIoControl(_changeJournalRootHandle,                           // Handle to drive  
                MFTReader.FSCTL_QUERY_USN_JOURNAL,   // IO Control Code  
                IntPtr.Zero,                // In Buffer  
                0,                          // In Buffer Size  
                out ujd,                    // Out Buffer  
                sizeof(MFTReader.USN_JOURNAL_DATA),  // Size Of Out Buffer  
                out bytesReturned,          // Bytes Returned  
                IntPtr.Zero);               // lpOverlapped  
            if (bOk)
            {
                MFTReader.MFT_ENUM_DATA med;
                med.StartFileReferenceNumber = 0;
                med.LowUsn = 0;
                med.HighUsn = ujd.NextUsn;
                int sizeMftEnumData = Marshal.SizeOf(med);
                medBuffer = Marshal.AllocHGlobal(sizeMftEnumData);
                MFTReader.ZeroMemory(medBuffer, sizeMftEnumData);
                Marshal.StructureToPtr(med, medBuffer, true);
            }
            else
            {
                throw new IOException("DeviceIoControl() returned false", new Win32Exception(Marshal.GetLastWin32Error()));
            }
        }