@@ -223,8 +223,8 @@ createFile_flags_setup(int flags, int mode, struct createFile_flags* cf_flags) {
223223 if (c_s_flags & O_EXCL )
224224 cf_flags -> dwCreationDisposition = CREATE_NEW ;
225225 else
226- cf_flags -> dwCreationDisposition = OPEN_ALWAYS ;
227- }
226+ cf_flags -> dwCreationDisposition = CREATE_ALWAYS ;
227+ }
228228
229229 if (c_s_flags & O_APPEND )
230230 cf_flags -> dwDesiredAccess = FILE_APPEND_DATA ;
@@ -301,7 +301,7 @@ VOID CALLBACK ReadCompletionRoutine(
301301/* initiate an async read */
302302/* TODO: make this a void func, store error in context */
303303int
304- fileio_ReadFileEx (struct w32_io * pio ) {
304+ fileio_ReadFileEx (struct w32_io * pio , unsigned int bytes_requested ) {
305305 debug2 ("ReadFileEx io:%p" , pio );
306306
307307 if (pio -> read_details .buf == NULL ) {
@@ -311,9 +311,13 @@ fileio_ReadFileEx(struct w32_io* pio) {
311311 debug2 ("ReadFileEx - ERROR: %d, io:%p" , errno , pio );
312312 return -1 ;
313313 }
314- pio -> read_details .buf_size = READ_BUFFER_SIZE ;
315314 }
316315
316+ if (FILETYPE (pio ) == FILE_TYPE_DISK )
317+ pio -> read_details .buf_size = min (bytes_requested , READ_BUFFER_SIZE );
318+ else
319+ pio -> read_details .buf_size = READ_BUFFER_SIZE ;
320+
317321 if (ReadFileEx (WINHANDLE (pio ), pio -> read_details .buf , pio -> read_details .buf_size ,
318322 & pio -> read_overlapped , & ReadCompletionRoutine ))
319323 pio -> read_details .pending = TRUE;
@@ -353,7 +357,7 @@ fileio_read(struct w32_io* pio, void *dst, unsigned int max) {
353357 return -1 ;
354358 }
355359 else {
356- if (-1 == fileio_ReadFileEx (pio )) {
360+ if (-1 == fileio_ReadFileEx (pio , max )) {
357361 if ((FILETYPE (pio ) == FILE_TYPE_PIPE )
358362 && (errno == ERROR_BROKEN_PIPE )) {
359363 /* write end of the pipe closed */
@@ -560,8 +564,8 @@ fileio_lseek(struct w32_io* pio, long offset, int origin) {
560564 return -1 ;
561565 }
562566
563- //NO-OP as we automatically move file pointer in async io callbacks for files
564- //assert current postion in overlapped struct
567+ pio -> read_overlapped . Offset = offset ;
568+ pio -> write_overlapped . Offset = offset ;
565569 return 0 ;
566570}
567571
@@ -625,7 +629,7 @@ fileio_on_select(struct w32_io* pio, BOOL rd) {
625629 }
626630 }
627631 else {
628- if (fileio_ReadFileEx (pio ) != 0 ) {
632+ if (fileio_ReadFileEx (pio , INT_MAX ) != 0 ) {
629633 pio -> read_details .error = errno ;
630634 errno = 0 ;
631635 return ;
0 commit comments