如何操作系统的文件分配表和文件目录表??要求编程实现??

解决方案 »

  1.   

    太难了,看看以前的DOS编程书吧,如深入DOS编程。
      

  2.   

    http://www.chinaoak.com/download/sources/system/hardware/bootmaster.zip
      

  3.   

    int CHardDiskInformation::ReadPhysicalDriveInNT()
    {
       int done = FALSE;
       int drive = 0;   for (drive = 0; drive < MAX_IDE_DRIVES; drive++)
       {
          HANDLE hPhysicalDriveIOCTL = 0;         //  Try to get a handle to PhysicalDrive IOCTL, report failure
             //  and exit if can't.
          char driveName [256];      sprintf (driveName, "\\\\.\\PhysicalDrive%d", drive);         //  Windows NT, Windows 2000, must have admin rights
          hPhysicalDriveIOCTL = CreateFile (driveName,
                                   GENERIC_READ | GENERIC_WRITE, 
                                   FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
                                   OPEN_EXISTING, 0, NULL);
          // if (hPhysicalDriveIOCTL == INVALID_HANDLE_VALUE)
          //    printf ("Unable to open physical drive %d, error code: 0x%lX\n",
          //            drive, GetLastError ());      if (hPhysicalDriveIOCTL != INVALID_HANDLE_VALUE)
          {
             GETVERSIONOUTPARAMS VersionParams;
             DWORD               cbBytesReturned = 0;            // Get the version, etc of PhysicalDrive IOCTL
             memset ((void*) &VersionParams, 0, sizeof(VersionParams));         if ( ! DeviceIoControl (hPhysicalDriveIOCTL, DFP_GET_VERSION,
                       NULL, 
                       0,
                       &VersionParams,
                       sizeof(VersionParams),
                       &cbBytesReturned, NULL) )
             {         
                // printf ("DFP_GET_VERSION failed for drive %d\n", i);
                // continue;
             }            // If there is a IDE device at number "i" issue commands
                // to the device
             if (VersionParams.bIDEDeviceMap > 0)
             {
                BYTE             bIDCmd = 0;   // IDE or ATAPI IDENTIFY cmd
                SENDCMDINPARAMS  scip;
                //SENDCMDOUTPARAMS OutCmd; // Now, get the ID sector for all IDE devices in the system.
                   // If the device is ATAPI use the IDE_ATAPI_IDENTIFY command,
                   // otherwise use the IDE_ATA_IDENTIFY command
                bIDCmd = (VersionParams.bIDEDeviceMap >> drive & 0x10) ? \
                          IDE_ATAPI_IDENTIFY : IDE_ATA_IDENTIFY;            memset (&scip, 0, sizeof(scip));
                memset (IdOutCmd, 0, sizeof(IdOutCmd));            if ( DoIDENTIFY (hPhysicalDriveIOCTL, 
                           &scip, 
                           (PSENDCMDOUTPARAMS)&IdOutCmd, 
                           (BYTE) bIDCmd,
                           (BYTE) drive,
                           &cbBytesReturned))
                {
                   DWORD diskdata [256];
                   int ijk = 0;
                   USHORT *pIdSector = (USHORT *)
                                 ((PSENDCMDOUTPARAMS) IdOutCmd) -> bBuffer;               for (ijk = 0; ijk < 256; ijk++)
                      diskdata [ijk] = pIdSector [ijk];               PrintIdeInfo (drive, diskdata);               done = TRUE;
                }
        }         CloseHandle (hPhysicalDriveIOCTL);
          }
       }   return done;
    }
      

  4.   

    如下取得physical Drive的句柄
    CreateFile(_T("\\\\.\\PHYSICALDRIVE1"), ...)用DeviceIoControl访问IOCTL_DISK_GET_DRIVE_LAYOUT服务(MSDN上的记载有问题)
    BOOL DeviceIoControl(
      (HANDLE) hDevice,             // handle to device
      IOCTL_DISK_GET_DRIVE_LAYOUT,  // dwIoControlCode operation
      NULL,                         // lpInBuffer
      0,                            // nInBufferSize
      (LPVOID) lpOutBuffer,         // input buffer 
      (DWORD) nOutBufferSize,       // size of the input buffer
      (LPDWORD) lpBytesReturned,    // number of bytes returned
      (LPOVERLAPPED) lpOverlapped   // OVERLAPPED structure
    );lpOutBuffer是一个 DRIVE_LAYOUT_INFORMATION 结构:
    typedef struct _DRIVE_LAYOUT_INFORMATION { 
      DWORD  PartitionCount; 
      DWORD  Signature; 
      PARTITION_INFORMATION  PartitionEntry[];   // A variable-sized array of PARTITION_INFORMATION
    } DRIVE_LAYOUT_INFORMATION, *PDRIVE_LAYOUT_INFORMATION; 因为不止一个分区,所以BufferSize要预先分配多一些。
      

  5.   

    .用Google查把,耐心点.
    查的时候注意几个关键字: 硬盘分区表,系统引导区,主引导区,FAT32,NTFS
    工具: diskman(diskgen) diskedit 网上有下载.用Google找.