Beispiel #1
0
        private static bool HasTrimEnabled(string drive)
        {
            Logger.Info("Checking trim enabled for drive: " + drive);
            SafeFileHandle fileW = SSDCheck.CreateFileW(drive, 0U, 3U, IntPtr.Zero, 3U, 128U, IntPtr.Zero);

            if (fileW == null || fileW.IsInvalid)
            {
                Logger.Error("CreateFile failed with message: " + SSDCheck.GetErrorMessage(Marshal.GetLastWin32Error()));
                throw new Exception("check the error message above");
            }
            uint dwIoControlCode = SSDCheck.CTL_CODE(45U, 1280U, 0U, 0U);

            SSDCheck.STORAGE_PROPERTY_QUERY lpInBuffer = new SSDCheck.STORAGE_PROPERTY_QUERY()
            {
                PropertyId = 8,
                QueryType  = 0
            };
            SSDCheck.DEVICE_TRIM_DESCRIPTOR lpOutBuffer = new SSDCheck.DEVICE_TRIM_DESCRIPTOR();
            int num = SSDCheck.DeviceIoControl(fileW, dwIoControlCode, ref lpInBuffer, (uint)Marshal.SizeOf((object)lpInBuffer), ref lpOutBuffer, (uint)Marshal.SizeOf((object)lpOutBuffer), out uint _, IntPtr.Zero) ? 1 : 0;

            fileW?.Close();
            if (num == 0)
            {
                Logger.Error("DeviceIoControl failed to query trim enabled. " + SSDCheck.GetErrorMessage(Marshal.GetLastWin32Error()));
                throw new Exception("check the error message above");
            }
            bool trimEnabled = lpOutBuffer.TrimEnabled;

            Logger.Info(string.Format("Is Trim Enabled: {0}", (object)trimEnabled));
            return(trimEnabled);
        }
Beispiel #2
0
 private static extern bool DeviceIoControl(
     SafeFileHandle hDevice,
     uint dwIoControlCode,
     ref SSDCheck.STORAGE_PROPERTY_QUERY lpInBuffer,
     uint nInBufferSize,
     ref SSDCheck.DEVICE_TRIM_DESCRIPTOR lpOutBuffer,
     uint nOutBufferSize,
     out uint lpBytesReturned,
     IntPtr lpOverlapped);