@@ -223,8 +223,8 @@ createFile_flags_setup(int flags, int mode, struct createFile_flags* cf_flags) {
223
223
if (c_s_flags & O_EXCL )
224
224
cf_flags -> dwCreationDisposition = CREATE_NEW ;
225
225
else
226
- cf_flags -> dwCreationDisposition = OPEN_ALWAYS ;
227
- }
226
+ cf_flags -> dwCreationDisposition = CREATE_ALWAYS ;
227
+ }
228
228
229
229
if (c_s_flags & O_APPEND )
230
230
cf_flags -> dwDesiredAccess = FILE_APPEND_DATA ;
@@ -301,7 +301,7 @@ VOID CALLBACK ReadCompletionRoutine(
301
301
/* initiate an async read */
302
302
/* TODO: make this a void func, store error in context */
303
303
int
304
- fileio_ReadFileEx (struct w32_io * pio ) {
304
+ fileio_ReadFileEx (struct w32_io * pio , unsigned int bytes_requested ) {
305
305
debug2 ("ReadFileEx io:%p" , pio );
306
306
307
307
if (pio -> read_details .buf == NULL ) {
@@ -311,9 +311,13 @@ fileio_ReadFileEx(struct w32_io* pio) {
311
311
debug2 ("ReadFileEx - ERROR: %d, io:%p" , errno , pio );
312
312
return -1 ;
313
313
}
314
- pio -> read_details .buf_size = READ_BUFFER_SIZE ;
315
314
}
316
315
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
+
317
321
if (ReadFileEx (WINHANDLE (pio ), pio -> read_details .buf , pio -> read_details .buf_size ,
318
322
& pio -> read_overlapped , & ReadCompletionRoutine ))
319
323
pio -> read_details .pending = TRUE;
@@ -353,7 +357,7 @@ fileio_read(struct w32_io* pio, void *dst, unsigned int max) {
353
357
return -1 ;
354
358
}
355
359
else {
356
- if (-1 == fileio_ReadFileEx (pio )) {
360
+ if (-1 == fileio_ReadFileEx (pio , max )) {
357
361
if ((FILETYPE (pio ) == FILE_TYPE_PIPE )
358
362
&& (errno == ERROR_BROKEN_PIPE )) {
359
363
/* write end of the pipe closed */
@@ -560,8 +564,8 @@ fileio_lseek(struct w32_io* pio, long offset, int origin) {
560
564
return -1 ;
561
565
}
562
566
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 ;
565
569
return 0 ;
566
570
}
567
571
@@ -625,7 +629,7 @@ fileio_on_select(struct w32_io* pio, BOOL rd) {
625
629
}
626
630
}
627
631
else {
628
- if (fileio_ReadFileEx (pio ) != 0 ) {
632
+ if (fileio_ReadFileEx (pio , INT_MAX ) != 0 ) {
629
633
pio -> read_details .error = errno ;
630
634
errno = 0 ;
631
635
return ;
0 commit comments