如何以编程方式扩展卷

时间:2017-05-22 09:35:17

标签: c windows winapi ntfs

我的要求是通过程序扩展驱动器量。当我在DeviceIO中使用IOCTL_DISK_GROW_PARTITION对其进行扩展时,磁盘管理显示新的修改大小,而此PC(我的电脑)中的驱动器大小保持不变。

   BOOL DeviceIoControl(
      (HANDLE) hDevice,            // handle to device
      IOCTL_DISK_GROW_PARTITION,   // dwIoControlCode
      (LPVOID) lpInBuffer,         // input buffer
      (DWORD) nInBufferSize,       // size of the input buffer
      NULL,                        // lpOutBuffer
      0,                           // nOutBufferSize 
      (LPDWORD) lpBytesReturned,   // number of bytes returned
      (LPOVERLAPPED) lpOverlapped  // OVERLAPPED structure
    );

通过一些分析,我发现在使用此API时,磁盘的MBR已被修改,但驱动器的集群位图未更改。我想知道使用此DeviceIO扩展卷或其他API以执行相同过程的正确方法。

1 个答案:

答案 0 :(得分:2)

需要了解不同的磁盘驱动程序,它维护有关磁盘布局和分区的信息(它的大小,偏离磁盘的开始,样式(gpt或mbr))和文件系统,它们安装此分区。

IOCTL_DISK_GROW_PARTITION - 此ioctl由磁盘驱动程序和扩展分区处理,但这对文件系统无效,后者无法处理此ioctl并且根本不知道扩展分区。所以你需要额外的ioctl使用FSCTL_EXTEND_VOLUME - 这个ioctl已经发送并处理文件系统。

所以如果我们必须做下一步

  1. 发送IOCTL_DISK_GROW_PARTITION DISK_GROW_PARTITION作为输入缓冲区
  2. 使用IOCTL_DISK_UPDATE_DRIVE_SIZE发送DISK_GEOMETRY 作为输出缓冲区
  3. 发送IOCTL_DISK_GET_PARTITION_INFO_EX PARTITION_INFORMATION_EX作为获取实际大小的输出 现在分区。
  4. 以扇区

    计算卷的新大小

    > use admin > db.adminCommand({setFeatureCompatibilityVersion: "3.4"}) { "ok" : 1 }

    dg 我们在第2步获得了 PartitionEntry 在第3步)

  5. 最后使用FSCTL_EXTEND_VOLUME

  6. 完整代码可以像下一个

        public static function rate($rate)
    {
        if (!is_null($rate)) {
    
         if ($rate == 0){
           echo "<i class='fa fa-star-o'></i>";
           echo "<i class='fa fa-star-o'></i>";
           echo "<i class='fa fa-star-o'></i>";
           echo "<i class='fa fa-star-o'></i>";
           echo "<i class='fa fa-star-o'></i>";
         }
         if ($rate >= 1 && $rate < 1.5){
          echo "<i class='fa fa-star'></i>";
           echo "<i class='fa fa-star-o'></i>";
           echo "<i class='fa fa-star-o'></i>";
           echo "<i class='fa fa-star-o'></i>";
           echo "<i class='fa fa-star-o'></i>";
         }
         if ($rate >= 1.5 && $rate < 2){
           echo "<i class='fa fa-star'></i>";
           echo "<i class='fa fa-star-half-o'></i>";
           echo "<i class='fa fa-star-o'></i>";
           echo "<i class='fa fa-star-o'></i>";
           echo "<i class='fa fa-star-o'></i>";
         }
         if ($rate >= 2 && $rate < 2.5){
           echo "<i class='fa fa-star'></i>";
           echo "<i class='fa fa-star'></i>";
           echo "<i class='fa fa-star-o'></i>";
           echo "<i class='fa fa-star-o'></i>";
           echo "<i class='fa fa-star-o'></i>";
         }
         if ($rate >= 2.5 && $rate < 3){
           echo "<i class='fa fa-star'></i>";
           echo "<i class='fa fa-star'></i>";
           echo "<i class='fa fa-star-half-o'></i>";
           echo "<i class='fa fa-star-o'></i>";
           echo "<i class='fa fa-star-o'></i>";
         }
         if ($rate >= 3 && $rate < 3.5){
           echo "<i class='fa fa-star'></i>";
           echo "<i class='fa fa-star'></i>";
           echo "<i class='fa fa-star'></i>";
           echo "<i class='fa fa-star-o'></i>";
           echo "<i class='fa fa-star-o'></i>";
         }
         if ($rate >= 3.5 && $rate < 4){
           echo "<i class='fa fa-star'></i>";
           echo "<i class='fa fa-star'></i>";
           echo "<i class='fa fa-star'></i>";
           echo "<i class='fa fa-star-half-o'></i>";
           echo "<i class='fa fa-star-o'></i>";
         }
         if ($rate >= 4 && $rate < 4.5){
           echo "<i class='fa fa-star'></i>";
           echo "<i class='fa fa-star'></i>";
           echo "<i class='fa fa-star'></i>";
           echo "<i class='fa fa-star'></i>";
           echo "<i class='fa fa-star-o'></i>";
         }
         if ($rate >= 4.5 && $rate < 5){
           echo "<i class='fa fa-star'></i>";
           echo "<i class='fa fa-star'></i>";
           echo "<i class='fa fa-star'></i>";
           echo "<i class='fa fa-star'></i>";
           echo "<i class='fa fa-star-half-o'></i>";
         }
         if ($rate >= 5){
           echo "<i class='fa fa-star'></i>";
           echo "<i class='fa fa-star'></i>";
           echo "<i class='fa fa-star'></i>";
           echo "<i class='fa fa-star'></i>";
           echo "<i class='fa fa-star'></i>";
         }
    }
    else
    {
      echo "<i style='color: red'>Not Yet rated</i>";
    }
    }