public static FILE_FS_ATTRIBUTE_INFORMATION FromBuffer(IntPtr buffer) { FILE_FS_ATTRIBUTE_INFORMATION ret = new FILE_FS_ATTRIBUTE_INFORMATION(); ret.VolumeAttributes = (VolumeCaps)IOhelper.PtrToUint(buffer, 0); ret.MaximumComponentNameLength = Marshal.ReadInt32(buffer, 4); ret.FileSystemNameLength = IOhelper.PtrToUint(buffer, 8); ret.FileSystemName = IOhelper.PtrToStringUni(buffer, 12, ((int)ret.FileSystemNameLength) / 2); return(ret); }
public static FILE_FS_ATTRIBUTE_INFORMATION GetFileVolumeAttributeInfo(IntPtr file_handle, IntPtr buffer, int buffer_len) { IO_STATUS_BLOCK status = new IO_STATUS_BLOCK(); bool need_free_buffer = false; IntPtr ret_buffer = buffer; int ret_buffer_len = buffer_len; try { if (buffer_len == 0) { need_free_buffer = true; ret_buffer_len = VOLUME_INFO_BUFFER_LEN; ret_buffer = Marshal.AllocHGlobal(VOLUME_INFO_BUFFER_LEN); } uint res = ntApiFS.NtQueryVolumeInformationFile (file_handle, ref status, ret_buffer, ret_buffer_len, FS_INFORMATION_CLASS.FileFsAttributeInformation); //check res NTSTATUS_helper.ThrowOnError(res, status, NTSTATUS_severity.Warning); FILE_FS_ATTRIBUTE_INFORMATION ret = FILE_FS_ATTRIBUTE_INFORMATION.FromBuffer(ret_buffer); return(ret); } finally { if (need_free_buffer) { Marshal.FreeHGlobal(ret_buffer); } } }
public static FILE_FS_ATTRIBUTE_INFORMATION GetFileVolumeAttributeInfo(string file_name) { IntPtr file_handle = IntPtr.Zero; try { file_handle = WinApiFS.CreateFile_intptr (file_name, Win32FileAccess.GENERIC_READ, FileShare.ReadWrite, IntPtr.Zero, FileMode.Open, CreateFileOptions.None, IntPtr.Zero); if (file_handle.ToInt32() == WinApiFS.INVALID_HANDLE_VALUE) { int win_err = Marshal.GetLastWin32Error(); Win32Exception ex = new Win32Exception(win_err); throw ex; } FILE_FS_ATTRIBUTE_INFORMATION ret = GetFileVolumeAttributeInfo (file_handle, IntPtr.Zero, 0); return(ret); } finally { if ((file_handle != IntPtr.Zero) && (file_handle.ToInt32() != WinApiFS.INVALID_HANDLE_VALUE)) { WinApiFS.CloseHandle(file_handle); } } }