//private void fill_volume_info() //{ // IntPtr h_file = IntPtr.Zero; // try // { // h_file = WinAPiFSwrapper.CreateFileHandle // (FileName, // Win32FileAccess.READ_ATTRIBUTES | Win32FileAccess.READ_EA, // FileShare.ReadWrite | FileShare.Delete, // FileMode.Open, // is_directory ? CreateFileOptions.BACKUP_SEMANTICS : CreateFileOptions.None); // FILE_FS_VOLUME_INFORMATION vol_info = ntApiFSwrapper.GetFileVolumeInfo(h_file); // textBoxVolumeCreationTime.Text = string.Format // (Options.GetLiteral(Options.LANG_DATE_TIME_LONG_FORMAT), // vol_info.VolumeCreationDateTime.ToShortDateString(), // vol_info.VolumeCreationDateTime.ToLongTimeString(), // vol_info.VolumeCreationDateTime.Millisecond); // textBoxVolumeLabel.Text = vol_info.VolumeLabel; // textBoxVolumeSerialNumber.Text = vol_info.VolumeSerialNumber.ToString(); // } // catch (Exception ex) // { // textBoxVolumeLabel.Text = ex.Message; // } // finally // { // if ((h_file.ToInt32() != WinApiFS.INVALID_HANDLE_VALUE) && (h_file != IntPtr.Zero)) // { // WinApiFS.CloseHandle(h_file); // } // } //} ////private void fill_volume_attr() ////{ //// IntPtr h_file = IntPtr.Zero; //// try //// { //// h_file = WinAPiFSwrapper.CreateFileHandle //// (FileName, //// Win32FileAccess.READ_ATTRIBUTES | Win32FileAccess.READ_EA | Win32FileAccess.LIST_DIRECTORY, //// FileShare.ReadWrite | FileShare.Delete, //// FileMode.Open, //// is_directory ? CreateFileOptions.BACKUP_SEMANTICS : CreateFileOptions.None); //// FILE_FS_ATTRIBUTE_INFORMATION vol_attr = ntApiFSwrapper.GetFileVolumeAttributeInfo(h_file, IntPtr.Zero, 0); //// textBoxVolumeFScaps.Text = vol_attr.VolumeAttributes.ToString(); //// textBoxVolumeFStype.Text = vol_attr.FileSystemName; //// textBoxVolumeMaxNameLen.Text = vol_attr.MaximumComponentNameLength.ToString(); //// if ((vol_attr.VolumeAttributes & VolumeCaps.ReadOnly) != VolumeCaps.ReadOnly) //// { //// try //// { //// FILE_FS_FULLSIZE_INFORMATION vol_fs = ntApiFSwrapper.GetFileVolumeFullsizeInfo(h_file); //// textBoxVolumeAvailableUnits.Text = string.Format //// ("{0:N0}", //// vol_fs.CallerAvailableAllocationUnits); //// textBoxVolumeAvailableBytes.Text = string.Format //// ("{0:N0}", //// vol_fs.UserAvailableAllocationBytes); //// textBoxVolumeBytesPerSector.Text = string.Format //// ("{0:N0}", //// vol_fs.BytesPerSector); //// textBoxVolumeBytesPerSector.Text = string.Format //// ("{0:N0}", //// vol_fs.BytesPerSector); //// textBoxVolumeBytesPerUnit.Text = string.Format //// ("{0:N0}", //// vol_fs.BytesPerSector * vol_fs.SectorsPerAllocationUnit); //// } //// catch (Exception ex) //// { //// textBoxVolumeAvailableUnits.Text = ex.Message; //// } //// } //// if ((vol_attr.VolumeAttributes & VolumeCaps.Quotas) == VolumeCaps.Quotas) //// { //// try //// { //// FILE_FS_CONTROL_INFORMATION vol_ctrl = ntApiFSwrapper.GetFileVolumeControlInfo(h_file); //// textBoxVolumeControlFlags.Text = vol_ctrl.FileSystemControlFlags.ToString(); //// textBoxVolumeQuotaLimit.Text = string.Format //// ("{0:N0}", //// vol_ctrl.DefaultQuotaLimit); //// textBoxVolumeQuoteThreshold.Text = string.Format //// ("{0:N0}", //// vol_ctrl.DefaultQuotaThreshold); //// } //// catch (Exception ex) //// { //// textBoxVolumeControlFlags.Text = ex.Message; //// } //// } //// }//try //// catch (Exception ex) //// { //// textBoxVolumeFScaps.Text = ex.Message; //// } //// finally //// { //// if ((h_file.ToInt32() != WinApiFS.INVALID_HANDLE_VALUE) && (h_file != IntPtr.Zero)) //// { //// WinApiFS.CloseHandle(h_file); //// } //// } ////} //private void fill_device() //{ // IntPtr h_file = IntPtr.Zero; // try // { // h_file = WinAPiFSwrapper.CreateFileHandle // (FileName, // Win32FileAccess.READ_ATTRIBUTES | Win32FileAccess.READ_EA, // FileShare.ReadWrite | FileShare.Delete, // FileMode.Open, // is_directory ? CreateFileOptions.BACKUP_SEMANTICS : CreateFileOptions.None); // FILE_FS_DEVICE_INFORMATION vol_dev = ntApiFSwrapper.GetFileVolumeDeviceInfo(h_file); // textBoxVolumeDeviceCharateristics.Text = vol_dev.Characteristics.ToString(); // textBoxVolumeDeviceType.Text = vol_dev.DeviceType.ToString(); // } // catch (Exception ex) // { // textBoxVolumeDeviceCharateristics.Text = ex.Message; // } // finally // { // if ((h_file.ToInt32() != WinApiFS.INVALID_HANDLE_VALUE) && (h_file != IntPtr.Zero)) // { // WinApiFS.CloseHandle(h_file); // } // } //} private void fill_links(IO_REPARSE_TAG tag) { try { switch (tag) { case IO_REPARSE_TAG.MOUNT_POINT: REPARSE_DATA_BUFFER_MOUNTPOINT mp_buf = WinAPiFSwrapper.GetMountpointInfo(FileName); textBoxSoftlinks.Text = mp_buf.SubstituteName; break; case IO_REPARSE_TAG.SYMLINK: REPARSE_DATA_BUFFER_SYMLINK sl_buf = WinAPiFSwrapper.GetSymboliclinkInfo(FileName); textBoxSoftlinks.Text = sl_buf.SubstituteName; break; } } catch (Exception ex) { textBoxSoftlinks.Text = ex.Message; } }
private static bool WinCreateJunction(string path, string target) { if (!String.IsNullOrEmpty(path)) { if (!String.IsNullOrEmpty(target)) { using (SafeHandle handle = OpenReparsePoint(path, FileDesiredAccess.GenericWrite)) { byte[] mountPointBytes = Encoding.Unicode.GetBytes(NonInterpretedPathPrefix + Path.GetFullPath(target)); REPARSE_DATA_BUFFER_MOUNTPOINT mountPoint = new REPARSE_DATA_BUFFER_MOUNTPOINT(); mountPoint.ReparseTag = IO_REPARSE_TAG_MOUNT_POINT; mountPoint.ReparseDataLength = (ushort)(mountPointBytes.Length + 12); //Added space for the header and null endo mountPoint.SubstituteNameOffset = 0; mountPoint.SubstituteNameLength = (ushort)mountPointBytes.Length; mountPoint.PrintNameOffset = (ushort)(mountPointBytes.Length + 2); // 2 as unicode null take 2 bytes. mountPoint.PrintNameLength = 0; mountPoint.PathBuffer = new byte[0x3FF0]; //Buffer for max size. Array.Copy(mountPointBytes, mountPoint.PathBuffer, mountPointBytes.Length); int nativeBufferSize = Marshal.SizeOf(mountPoint); IntPtr nativeBuffer = Marshal.AllocHGlobal(nativeBufferSize); bool success = false; try { Marshal.StructureToPtr(mountPoint, nativeBuffer, false); int bytesReturned = 0; //OACR warning 62001 about using DeviceIOControl has been disabled. // According to MSDN guidance DangerousAddRef() and DangerousRelease() have been used. handle.DangerousAddRef(ref success); bool result = DeviceIoControl(handle.DangerousGetHandle(), FSCTL_SET_REPARSE_POINT, nativeBuffer, mountPointBytes.Length + 20, IntPtr.Zero, 0, out bytesReturned, IntPtr.Zero); if (!result) { throw new Win32Exception(Marshal.GetLastWin32Error()); } return result; } finally { Marshal.FreeHGlobal(nativeBuffer); if (success) { handle.DangerousRelease(); } } } } else { throw new ArgumentNullException("target"); } } else { throw new ArgumentNullException("path"); } }