예제 #1
0
        public static bool CreateMountPoint(char driveLetter)
        {
            #region args check

            if (!Char.IsLetter(driveLetter))
            {
                throw new ArgumentException("Must be a letter from A to Z.", "driveLetter");
            }

            #endregion
            string mountPoint = GetMountPoint(driveLetter);
            string nativePath = @"\Device\ImDisk0";
            if (!Load())
            {
                return(false);
            }
            try
            {
                ImDiskAPI.CreateMountPoint(mountPoint,  // Path to empty directory on an NTFS volume, or a drive letter followed by a colon.
                                           nativePath); // Target path in native format, for example \Device\ImDisk0
                return(true);
            }
            catch (Exception) { }
            return(false);
        }
예제 #2
0
        /// <summary>
        /// create a virtual drive (unformatted)
        /// </summary>
        /// <param name="driveLetter">drive letter. Example : 'A', 'B', 'C', 'D', ..., 'Z'.</param>
        /// <param name="sizeInMegaBytes">drive size in mega bytes</param>
        /// <param name="deviceNumber">device number to create, UInt32.MaxValue for auto</param>
        /// <param name="backWithVirtualMemory">back the virtual drive with virtual memory (might slow the drive but enhance reliability)</param>
        /// <param name="skipImDiskNet">access directly the C++ ImDisk library without the ImDiskNet wrapper</param>
        /// <returns>true if success, false if failure</returns>
        public static bool CreateDevice(char driveLetter, int sizeInMegaBytes, ref uint deviceNumber, bool backWithVirtualMemory = false, bool skipImDiskNet = false)
        {
            #region args check

            if (!Char.IsLetter(driveLetter))
            {
                throw new ArgumentException("Must be a letter from A to Z.", "driveLetter");
            }
            if (sizeInMegaBytes < 1)
            {
                throw new ArgumentException("Must be positive.", "sizeInMegaBytes");
            }

            #endregion
            long        sizeInBytes = sizeInMegaBytes * 1024 * 1024;
            string      mountPoint  = GetMountPoint(driveLetter);
            ImDiskFlags mode        = ImDiskFlags.DeviceTypeHD;
            if (backWithVirtualMemory)
            {
                mode = ImDiskFlags.DeviceTypeHD | ImDiskFlags.TypeVM;
            }
            if (!Load())
            {
                return(false);
            }
            try
            {
                if (skipImDiskNet)
                {
                    CreateDevice_Cpl(sizeInBytes,      // Size of virtual disk. If this parameter is zero, current size of disk image file will automatically be used as virtual disk size.
                                     0,                // Number of tracks per cylinder for virtual disk geometry. This parameter can be zero in which case most reasonable value will be automatically used by the driver.
                                     0,                // Number of sectors per track for virtual disk geometry. This parameter can be zero in which case most reasonable value will be automatically used by the driver.
                                     0,                // Number of bytes per sector for virtual disk geometry. This parameter can be zero in which case most reasonable value will be automatically used by the driver.
                                     0,                // A skip offset if virtual disk data does not begin immediately at start of disk image file. Frequently used with image formats like Nero NRG which start with a file header not used by ImDisk or Windows filesystem drivers.
                                     mode,             // Flags specifying properties for virtual disk. See comments for each flag value.
                                     null,             // Name of disk image file to use or create. If disk image file already exists the DiskSize parameter can be zero in which case current disk image file size will be used as virtual disk size. If Filename paramter is Nothing/null disk will be created in virtual memory and not backed by a physical disk image file.
                                     false,            // Specifies whether Filename parameter specifies a path in Windows native path format, the path format used by drivers in Windows NT kernels, for example \Device\Harddisk0\Partition1\imagefile.img. If this parameter is False path in FIlename parameter will be interpreted as an ordinary user application path.
                                     mountPoint,       // Mount point in the form of a drive letter and colon to create for newly created virtual disk. If this parameter is Nothing/null the virtual disk will be created without a drive letter.
                                     ref deviceNumber, // In: Device number for device to create. Device number must not be in use by an existing virtual disk. For automatic allocation of device number, pass UInt32.MaxValue. Out: Device number for created device.
                                     IntPtr.Zero);     // Optional handle to control that can display status messages during operation.
                }
                else
                {
                    ImDiskAPI.CreateDevice(sizeInBytes,      // Size of virtual disk. If this parameter is zero, current size of disk image file will automatically be used as virtual disk size.
                                           0,                // Number of tracks per cylinder for virtual disk geometry. This parameter can be zero in which case most reasonable value will be automatically used by the driver.
                                           0,                // Number of sectors per track for virtual disk geometry. This parameter can be zero in which case most reasonable value will be automatically used by the driver.
                                           0,                // Number of bytes per sector for virtual disk geometry. This parameter can be zero in which case most reasonable value will be automatically used by the driver.
                                           0,                // A skip offset if virtual disk data does not begin immediately at start of disk image file. Frequently used with image formats like Nero NRG which start with a file header not used by ImDisk or Windows filesystem drivers.
                                           mode,             // Flags specifying properties for virtual disk. See comments for each flag value.
                                           null,             // Name of disk image file to use or create. If disk image file already exists the DiskSize parameter can be zero in which case current disk image file size will be used as virtual disk size. If Filename paramter is Nothing/null disk will be created in virtual memory and not backed by a physical disk image file.
                                           false,            // Specifies whether Filename parameter specifies a path in Windows native path format, the path format used by drivers in Windows NT kernels, for example \Device\Harddisk0\Partition1\imagefile.img. If this parameter is False path in FIlename parameter will be interpreted as an ordinary user application path.
                                           mountPoint,       // Mount point in the form of a drive letter and colon to create for newly created virtual disk. If this parameter is Nothing/null the virtual disk will be created without a drive letter.
                                           ref deviceNumber, // In: Device number for device to create. Device number must not be in use by an existing virtual disk. For automatic allocation of device number, pass UInt32.MaxValue. Out: Device number for created device.
                                           IntPtr.Zero);     // Optional handle to control that can display status messages during operation.
                }
                return(true);
            }
            catch (Exception) { }
            return(false);
        }
예제 #3
0
 /// <summary>
 /// load the ImDisk driver in Windows Kernel
 /// </summary>
 /// <returns>true if loaded, false otherwise</returns>
 public static bool Load()
 {
     if (Loaded == false)
     {
         try
         {
             ImDiskAPI.LoadDriver();
             Loaded = true;
         }
         catch (Exception)
         {
             Console.WriteLine("ImDiskInst.exe was not installed correctly, please reinstall it first.");
         }
     }
     return(Loaded);
 }
예제 #4
0
        // http://stackoverflow.com/questions/7060649/creating-a-virtual-disk-mount-point
#if IMDISK
        public bool CreateRAMDisk()
        {
            // Create Empty RAM Disk
            char driveLetter = ImDiskAPI.FindFreeDriveLetter();

            ImDiskAPI.CreateDevice(52428800, 0, 0, 0, 0, ImDiskFlags.DeviceTypeHD | ImDiskFlags.TypeVM, null, false, driveLetter.ToString(), ref deviceID, IntPtr.Zero);

            string mountPoint = driveLetter + @":\Device\ImDisk0";

            ImDiskAPI.CreateMountPoint(mountPoint, deviceID);

            // Format the Drive for NTFS
            if (FormatDrive(driveLetter.ToString(), "NTFS", true, 4096, "", false))
            {
            }
        }
예제 #5
0
        public static void Create()
        {
            uint a     = uint.MaxValue;
            int  index = 0;

            DriveInfo[] drives = DriveInfo.GetDrives();
            foreach (DriveInfo drive in drives)
            {
                if (drive.Name == driveL + ":\\")
                {
                    index++;
                    driveL = Letters[index].ToString();
                }
            }

            ImDiskAPI.CreateDevice(250 * 1024 * 1024, driveL + ":\\", ref a);
            Format();
        }
예제 #6
0
        /// <summary>
        /// remove a mount point
        /// </summary>
        /// <param name="driveLetter">drive letter. Example : 'A', 'B', 'C', 'D', ..., 'Z'.</param>
        /// <returns>true if success, false if failure</returns>
        public static bool RemoveMountPoint(char driveLetter)
        {
            #region args check

            if (!Char.IsLetter(driveLetter))
            {
                throw new ArgumentException("Must be a letter from A to Z.", "driveLetter");
            }

            #endregion
            string mountPoint = GetMountPoint(driveLetter);
            if (!Load())
            {
                return(false);
            }
            try
            {
                ImDiskAPI.RemoveMountPoint(mountPoint);  // Path to empty directory on an NTFS volume, or a drive letter followed by a colon.
                return(true);
            }
            catch (Exception) { }
            return(false);
        }
예제 #7
0
        /// <summary>
        /// remove a device
        /// </summary>
        /// <param name="driveLetter">drive letter. Example : 'A', 'B', 'C', 'D', ..., 'Z'.</param>
        /// <param name="deviceNumber">number of the device to remove</param>
        /// <returns>true if success, false if failure</returns>
        public static bool RemoveDevice(char driveLetter, uint deviceNumber = 0)
        {
            #region args check

            if (!Char.IsLetter(driveLetter))
            {
                throw new ArgumentException("Must be a letter from A to Z.", "driveLetter");
            }

            #endregion
            string mountPoint = GetMountPoint(driveLetter);
            if (!Load())
            {
                return(false);
            }
            try
            {
                ImDiskAPI.RemoveDevice(mountPoint); // Mount point in the form of a drive letter and colon to create for newly created virtual disk. If this parameter is Nothing/null the virtual disk will be created without a drive letter.
                ImDiskAPI.ForceRemoveDevice(deviceNumber);
                return(true);
            }
            catch (Exception) { }
            return(false);
        }
예제 #8
0
 public static void Umount()
 {
     ImDiskAPI.RemoveDevice(driveL + ":\\");
 }