Ejemplo n.º 1
0
        protected override ExitCode ExecuteFileTask()
        {
            VolumeInformation info = ExtendedFileService.GetVolumeInformation(Arguments.Target);

            Table table = Table.Create(new ColumnFormat(1, ContentVisibility.ShowAll, Justification.Right), new ColumnFormat(1));

            table.HasHeader = false;
            table.AddRow("Volume Name", info.VolumeName);
            table.AddRow("Serial Number", info.VolumeSerialNumber.ToString());
            table.AddRow("Max Component Length", info.MaximumComponentLength.ToString());
            table.AddRow("File System Name", info.FileSystemName.ToString());
            foreach (var value in Enum.GetValues(typeof(FileSystemFeature)))
            {
                FileSystemFeature feature = (FileSystemFeature)value;
                if ((feature & info.FileSystemFlags) == feature)
                {
                    table.AddRow(feature.ToString(), "true");
                }
                else
                {
                    table.AddRow(feature.ToString(), "false");
                }
            }

            this.Loggers[LoggerType.Result].Write(table);
            return(ExitCode.Success);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Obtains a users harddrive information.
        /// </summary>
        /// <param name="strRootDrive"></param>
        /// <returns></returns>
        private static object[] GetVolumeInfo(string strRootDrive)
        {
            try
            {
                StringBuilder     sbVolume = new StringBuilder(261);
                StringBuilder     sbName   = new StringBuilder(261);
                FileSystemFeature fsFlags  = 0;
                uint uiSerial = 0;
                uint uiMaxLen = 0;

                // Obtain Users Drive Information
                if (!GetVolumeInformation(strRootDrive, sbVolume, sbVolume.Capacity, out uiSerial, out uiMaxLen, out fsFlags, sbName, sbName.Capacity))
                {
                    throw new Exception("Failed to obtain drive information.");
                }

                // Build Return Value Array
                object[] objArray = new object[4];
                objArray[0] = sbVolume.ToString();
                objArray[1] = sbName.ToString();
                objArray[2] = uiSerial.ToString();
                objArray[3] = uiMaxLen;

                return(objArray);
            }
            catch
            {
                return(default(object[]));
            }
        }
Ejemplo n.º 3
0
 public extern static bool GetVolumeInformation(
     string rootPathName,
     StringBuilder volumeNameBuffer,
     int volumeNameSize,
     out uint volumeSerialNumber,
     out uint maximumComponentLength,
     out FileSystemFeature fileSystemFlags,
     StringBuilder fileSystemNameBuffer,
     int nFileSystemNameSize);
Ejemplo n.º 4
0
 private static extern bool GetVolumeInformation(
     string RootPathName,
     StringBuilder VolumeNameBuffer,
     int VolumeNameSize,
     out uint VolumeSerialNumber,
     out uint MaximumComponentLength,
     out FileSystemFeature FileSystemFlags,
     StringBuilder FileSystemNameBuffer,
     int nFileSystemNameSize);
Ejemplo n.º 5
0
 public static extern bool GetVolumeInformation(
   string RootPathName,
   StringBuilder VolumeNameBuffer,
   int VolumeNameSize,
   out uint VolumeSerialNumber,
   out uint MaximumComponentLength,
   out FileSystemFeature FileSystemFlags,
   StringBuilder FileSystemNameBuffer,
   int nFileSystemNameSize);
Ejemplo n.º 6
0
 extern static bool GetVolumeInformationByHandleW(
     SafeFileHandle RootPathName,
     StringBuilder VolumeNameBuffer,
     int VolumeNameSize,
     out uint VolumeSerialNumber,
     out uint MaximumComponentLength,
     out FileSystemFeature FileSystemFlags,
     StringBuilder FileSystemNameBuffer,
     int nFileSystemNameSize);
 internal static extern bool GetVolumeInformationW(
    string lpRootPathName,
    SafeHandle lpVolumeNameBuffer,
    uint nVolumeNameSize,
    out uint lpVolumeSerialNumber,
    out uint lpMaximumComponentLength,
    out FileSystemFeature lpFileSystemFlags,
    SafeHandle lpFileSystemNameBuffer,
    uint nFileSystemNameSize);
Ejemplo n.º 8
0
 internal extern static bool GetVolumeInformation(
     string RootPathName,
     StringBuilder VolumeNameBuffer,
     int VolumeNameSize,
     IntPtr VolumeSerialNumber,
     IntPtr MaximumComponentLength,
     out FileSystemFeature FileSystemFlags,
     IntPtr FileSystemNameBuffer,
     int nFileSystemNameSize);
Ejemplo n.º 9
0
 public static extern bool GetVolumeInformationW(
     string lpRootPathName,
     SafeHandle lpVolumeNameBuffer,
     uint nVolumeNameSize,
     out uint lpVolumeSerialNumber,
     out uint lpMaximumComponentLength,
     out FileSystemFeature lpFileSystemFlags,
     SafeHandle lpFileSystemNameBuffer,
     uint nFileSystemNameSize);
Ejemplo n.º 10
0
        public static void GetVolumeInformationOfPath(string itemPath, out string rootPathName, out string volumeName, out uint volumeSerialNumber, out FileSystemFeature features, out string fileSystemName, out uint maxComponentLength)
        {
            // Determine root path name:
            var rootPathNameBuilder = new StringBuilder(2000);
            Kernel32.GetVolumePathName(itemPath, rootPathNameBuilder, rootPathNameBuilder.Capacity);
            rootPathName = rootPathNameBuilder.ToString();

            // Get volumen information:
            StringBuilder volumeNameBuilder = new StringBuilder(261);
            StringBuilder fileSystemNameBuilder = new StringBuilder(261);
            if (!Kernel32.GetVolumeInformation(rootPathNameBuilder.ToString(), volumeNameBuilder, volumeNameBuilder.Capacity, out volumeSerialNumber, out maxComponentLength, out features, fileSystemNameBuilder, fileSystemNameBuilder.Capacity))
                Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
            volumeName = volumeNameBuilder.ToString();
            fileSystemName = fileSystemNameBuilder.ToString();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// ボリュームの情報を取得する
        /// </summary>
        /// <param name="RootPathName"></param>
        /// <param name="VolumeName"></param>
        /// <param name="VolumeSerialNumber"></param>
        /// <param name="MaximumComponentLength"></param>
        /// <param name="FileSystemFlags"></param>
        /// <param name="FileSystemName"></param>
        /// <returns></returns>
        public static bool GetVolumeInformation(
            string RootPathName,
            out string VolumeName,
            out uint VolumeSerialNumber,
            out uint MaximumComponentLength,
            out FileSystemFeature FileSystemFlags,
            out string FileSystemName)
        {
            var volumeNameBuffer     = new StringBuilder(1024, 1024);
            var fileSystemNameBuffer = new StringBuilder(1024, 1024);
            var result = NativeMethods.GetVolumeInformation(RootPathName, volumeNameBuffer, volumeNameBuffer.MaxCapacity, out VolumeSerialNumber, out MaximumComponentLength, out FileSystemFlags, fileSystemNameBuffer, fileSystemNameBuffer.Length);

            VolumeName     = result ? volumeNameBuffer.ToString() : string.Empty;
            FileSystemName = result ? fileSystemNameBuffer.ToString() : string.Empty;
            return(result);
        }
Ejemplo n.º 12
0
        public VolumeInformationTest(ITestOutputHelper outputHelper)
        {
            StringBuilder fileSystemNameBuffer = new StringBuilder(VolumeInformation.InteropStringCapacity);
            StringBuilder volumeNameBuffer     = new StringBuilder(VolumeInformation.InteropStringCapacity);

            _rootDirectory = (new DirectoryInfo(Environment.SystemDirectory)).Root;
            if (!VolumeInformation.GetVolumeInformation(_rootDirectory.FullName, volumeNameBuffer, VolumeInformation.InteropStringCapacity, out uint volumeSerialNumber, out uint maximumComponentLength, out FileSystemFeature fileSystemFlags, fileSystemNameBuffer, VolumeInformation.InteropStringCapacity))
            {
                Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
            }
            _fileSystemFlags        = fileSystemFlags;
            _isCaseSensitive        = fileSystemFlags.HasFlag(FileSystemFeature.CaseSensitiveSearch);
            _volumeSerialNumber     = volumeSerialNumber;
            _maximumComponentLength = maximumComponentLength;
            _fileSystemName         = fileSystemNameBuffer.ToString();
            _volumeName             = volumeNameBuffer.ToString();
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Initializes a new instance of <see cref="VolumeInformation"/>.
        /// </summary>
        /// <param name="directory">A child <seealso cref="DirectoryInfo"/> of the volume information to retrieve or null for the volume that contains the system directory.</param>
        public VolumeInformation(DirectoryInfo directory)
        {
            if (directory == null)
            {
                _root = new DirectoryInfo(Environment.SystemDirectory).Root;
            }

            StringBuilder volumeNameBuffer = new StringBuilder(InteropStringCapacity);
            StringBuilder fsn = new StringBuilder(InteropStringCapacity);

            if (!GetVolumeInformation(_root.FullName, volumeNameBuffer, InteropStringCapacity, out uint sn, out uint maxNameLength, out FileSystemFeature flags, fsn, InteropStringCapacity))
            {
                Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
            }
            VolumeName     = volumeNameBuffer.ToString();
            FileSystemName = fsn.ToString();
            Flags          = flags;
            SerialNumber   = sn;
            MaxNameLength  = maxNameLength;
            _nameComparer  = (IsCaseSensitive) ? StringComparer.InvariantCulture : StringComparer.InvariantCultureIgnoreCase;
        }
Ejemplo n.º 14
0
        private void lbl_help_Click(object sender, EventArgs e)
        {
            uint vol = 0, max = 0;
            FileSystemFeature f = new FileSystemFeature();

            NativeMethod.GetVolumeInformation("C:", new StringBuilder(), 0, out vol, out max, out f, new StringBuilder(), 0);
            textBox1.Text = vol.ToString();


            uint serialNum, serialNumLength;
            FileSystemFeature flags;
            StringBuilder     volumename = new StringBuilder(256);
            StringBuilder     fstype     = new StringBuilder(256);

            bool ok = NativeMethod.GetVolumeInformation("C:\\", volumename, (uint)volumename.Capacity - 1, out serialNum, out serialNumLength, out flags, fstype, (uint)fstype.Capacity - 1);

            if (ok)
            {
                textBox1.Text = serialNum.ToString("X");
            }
            var x = new System.IO.DriveInfo("C:\\ ");

            textBox2.Text = x.VolumeLabel;
        }
Ejemplo n.º 15
0
        public static void GetVolumeInformationOfPath(string itemPath, out string rootPathName, out string volumeName, out uint volumeSerialNumber, out FileSystemFeature features, out string fileSystemName, out uint maxComponentLength)
        {
            // Determine root path name:
            var rootPathNameBuilder = new StringBuilder(2000);

            Kernel32.GetVolumePathName(itemPath, rootPathNameBuilder, rootPathNameBuilder.Capacity);
            rootPathName = rootPathNameBuilder.ToString();

            // Get volumen information:
            StringBuilder volumeNameBuilder     = new StringBuilder(261);
            StringBuilder fileSystemNameBuilder = new StringBuilder(261);

            if (!Kernel32.GetVolumeInformation(rootPathNameBuilder.ToString(), volumeNameBuilder, volumeNameBuilder.Capacity, out volumeSerialNumber, out maxComponentLength, out features, fileSystemNameBuilder, fileSystemNameBuilder.Capacity))
            {
                Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
            }
            volumeName     = volumeNameBuilder.ToString();
            fileSystemName = fileSystemNameBuilder.ToString();
        }
Ejemplo n.º 16
0
 public static extern Boolean GetVolumeInformation(String RootPathName, StringBuilder VolumeNameBuffer, Int32 VolumeNameSize, out UInt32 VolumeSerialNumber,
                                                   out UInt32 MaximumComponentLength, out FileSystemFeature FileSystemFlags, StringBuilder FileSystemNameBuffer, Int32 nFileSystemNameSize);
Ejemplo n.º 17
0
 private static extern bool GetVolumeInformationPrivate(
    string lpRootPathName,
    StringBuilder lpVolumeNameBuffer,
    int nVolumeNameSize,
    out uint lpVolumeSerialNumber,
    out uint lpMaximumComponentLength,
    out FileSystemFeature lpFileSystemFlags,
    StringBuilder lpFileSystemNameBuffer,
    int nFileSystemNameSize);
Ejemplo n.º 18
0
 private static extern bool GetVolumeInformation(
   string rootPathName,
   StringBuilder volumeNameBuffer,
   int volumeNameSize,
   out uint volumeSerialNumber,
   out uint maximumComponentLength,
   out FileSystemFeature fileSystemFlags,
   StringBuilder fileSystemNameBuffer,
   int nFileSystemNameSize);