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

ToutEnMasm

  • 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

Quote
   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
   .if eax != INVALID_HANDLE_VALUE
      invoke FindClose,eax
   .else
      invoke RetrouveMessageErreur,SADR("CreateFile")
      jmp FindeDetectSectorSize
   .endif
   ;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
      .endif
      mov edx,0
      mov ecx,disk.BytesPerSector
      mul ecx
      ;eax new size in sector
      
   .else
      ;sizeof file = 1 sector
      mov eax,disk.BytesPerSector
   .endif   
   mov sizeoffileInSector,eax
   ;-------------- size , aligned by
   invoke _aligned_malloc,sizeoffileInSector,disk.BytesPerSector
   .if eax != NULL
      mov pmem,eax

      invoke CreateFile,addr filetoopen,GENERIC_READ,\
         FILE_SHARE_READ + FILE_SHARE_WRITE,\
         NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL+FILE_FLAG_NO_BUFFERING,NULL
      .if eax == INVALID_HANDLE_VALUE
         invoke RetrouveMessageErreur,SADR("CreateFile")
         jmp FindeDetectSectorSize
      .endif
      mov hFile,eax
      INVOKE     ReadFile, hFile,pmem ,sizeoffileInSector ,\
                  addr NumberOfBytesRead , 0            
      .if eax == 0
         invoke RetrouveMessageErreur,SADR("ReadFile")
      .endif                  
      mov edx,pmem      
      invoke _aligned_free,pmem
   .endif
 FindeDetectSectorSize:
   .if hFile != 0
      invoke   CloseHandle,hFile
   .endif

Fa is a musical note to play with CL