Author Topic: reading a file with FILE_FLAG_NO_BUFFERING  (Read 2070 times)


  • Member
  • *****
  • Posts: 1189
    • EditMasm
reading a file with FILE_FLAG_NO_BUFFERING
« on: September 09, 2012, 06:32:56 PM »

Just a sample to fix idea

   invoke GetDiskFreeSpace,SADR("E:\"),addr disk.SectorsPerCluster,addr disk.BytesPerSector,\
            addr disk.NumberOfFreeClusters,addr disk.TotalNumberOfClusters
   ;get the size of of the file         
   invoke FindFirstFile,addr filetoopen,addr finddata
      invoke FindClose,eax
      invoke RetrouveMessageErreur,SADR("CreateFile")
      jmp FindeDetectSectorSize
   ;get the size of the file in sector
   mov eax,finddata.nFileSizeLow
   .if eax > disk.BytesPerSector
      mov ecx,disk.BytesPerSector
      mov edx,0      ;****** avoid overflow *****
      div ecx
      .if edx != 0
         inc eax
      mov edx,0
      mov ecx,disk.BytesPerSector
      mul ecx
      ;eax new size in sector
      ;sizeof file = 1 sector
      mov eax,disk.BytesPerSector
   mov sizeoffileInSector,eax
   ;-------------- size , aligned by
   invoke _aligned_malloc,sizeoffileInSector,disk.BytesPerSector
   .if eax != NULL
      mov pmem,eax

      invoke CreateFile,addr filetoopen,GENERIC_READ,\
      .if eax == INVALID_HANDLE_VALUE
         invoke RetrouveMessageErreur,SADR("CreateFile")
         jmp FindeDetectSectorSize
      mov hFile,eax
      INVOKE     ReadFile, hFile,pmem ,sizeoffileInSector ,\
                  addr NumberOfBytesRead , 0            
      .if eax == 0
         invoke RetrouveMessageErreur,SADR("ReadFile")
      mov edx,pmem      
      invoke _aligned_free,pmem
   .if hFile != 0
      invoke   CloseHandle,hFile

Fa is a musical note to play with CL