@@ -277,93 +277,6 @@ _wapi_dirname (const gchar *filename)
277
277
return ret ;
278
278
}
279
279
280
- static gboolean
281
- _wapi_lock_file_region (gint fd , off_t offset , off_t length )
282
- {
283
- struct flock lock_data ;
284
- gint ret ;
285
-
286
- if (offset < 0 || length < 0 ) {
287
- mono_w32error_set_last (ERROR_INVALID_PARAMETER );
288
- return FALSE;
289
- }
290
-
291
- lock_data .l_type = F_WRLCK ;
292
- lock_data .l_whence = SEEK_SET ;
293
- lock_data .l_start = offset ;
294
- lock_data .l_len = length ;
295
-
296
- do {
297
- ret = fcntl (fd , F_SETLK , & lock_data );
298
- } while (ret == -1 && errno == EINTR );
299
-
300
- mono_trace (G_LOG_LEVEL_DEBUG , MONO_TRACE_IO_LAYER_FILE , "%s: fcntl returns %d" , __func__ , ret );
301
-
302
- if (ret == -1 ) {
303
- /*
304
- * if locks are not available (NFS for example),
305
- * ignore the error
306
- */
307
- if (errno == ENOLCK
308
- #ifdef EOPNOTSUPP
309
- || errno == EOPNOTSUPP
310
- #endif
311
- #ifdef ENOTSUP
312
- || errno == ENOTSUP
313
- #endif
314
- ) {
315
- return TRUE;
316
- }
317
-
318
- mono_w32error_set_last (ERROR_LOCK_VIOLATION );
319
- return FALSE;
320
- }
321
-
322
- return TRUE;
323
- }
324
-
325
- static gboolean
326
- _wapi_unlock_file_region (gint fd , off_t offset , off_t length )
327
- {
328
- struct flock lock_data ;
329
- gint ret ;
330
-
331
- lock_data .l_type = F_UNLCK ;
332
- lock_data .l_whence = SEEK_SET ;
333
- lock_data .l_start = offset ;
334
- lock_data .l_len = length ;
335
-
336
- do {
337
- ret = fcntl (fd , F_SETLK , & lock_data );
338
- } while (ret == -1 && errno == EINTR );
339
-
340
- mono_trace (G_LOG_LEVEL_DEBUG , MONO_TRACE_IO_LAYER_FILE , "%s: fcntl returns %d" , __func__ , ret );
341
-
342
- if (ret == -1 ) {
343
- /*
344
- * if locks are not available (NFS for example),
345
- * ignore the error
346
- */
347
- if (errno == ENOLCK
348
- #ifdef EOPNOTSUPP
349
- || errno == EOPNOTSUPP
350
- #endif
351
- #ifdef ENOTSUP
352
- || errno == ENOTSUP
353
- #endif
354
- ) {
355
- return TRUE;
356
- }
357
-
358
- mono_w32error_set_last (ERROR_LOCK_VIOLATION );
359
- return FALSE;
360
- }
361
-
362
- return TRUE;
363
- }
364
-
365
- static gboolean lock_while_writing = FALSE;
366
-
367
280
static void
368
281
_wapi_set_last_error_from_errno (void )
369
282
{
@@ -402,7 +315,6 @@ static gboolean
402
315
file_write (FileHandle * filehandle , gpointer buffer , guint32 numbytes , guint32 * byteswritten )
403
316
{
404
317
gint ret ;
405
- off_t current_pos = 0 ;
406
318
MonoThreadInfo * info = mono_thread_info_current ();
407
319
408
320
if (byteswritten != NULL ) {
@@ -415,37 +327,13 @@ file_write (FileHandle *filehandle, gpointer buffer, guint32 numbytes, guint32 *
415
327
mono_w32error_set_last (ERROR_ACCESS_DENIED );
416
328
return (FALSE);
417
329
}
418
-
419
- if (lock_while_writing ) {
420
- /* Need to lock the region we're about to write to,
421
- * because we only do advisory locking on POSIX
422
- * systems
423
- */
424
- MONO_ENTER_GC_SAFE ;
425
- current_pos = lseek (((MonoFDHandle * ) filehandle )-> fd , (off_t )0 , SEEK_CUR );
426
- MONO_EXIT_GC_SAFE ;
427
- if (current_pos == -1 ) {
428
- mono_trace (G_LOG_LEVEL_DEBUG , MONO_TRACE_IO_LAYER_FILE , "%s: fd %d lseek failed: %s" , __func__ , ((MonoFDHandle * ) filehandle )-> fd , g_strerror (errno ));
429
- _wapi_set_last_error_from_errno ();
430
- return (FALSE);
431
- }
432
-
433
- if (_wapi_lock_file_region (((MonoFDHandle * ) filehandle )-> fd , current_pos , numbytes ) == FALSE) {
434
- /* The error has already been set */
435
- return (FALSE);
436
- }
437
- }
438
330
439
331
do {
440
332
MONO_ENTER_GC_SAFE ;
441
333
ret = write (((MonoFDHandle * ) filehandle )-> fd , buffer , numbytes );
442
334
MONO_EXIT_GC_SAFE ;
443
335
} while (ret == -1 && errno == EINTR &&
444
336
!mono_thread_info_is_interrupt_state (info ));
445
-
446
- if (lock_while_writing ) {
447
- _wapi_unlock_file_region (((MonoFDHandle * ) filehandle )-> fd , current_pos , numbytes );
448
- }
449
337
450
338
if (ret == -1 ) {
451
339
if (errno == EINTR ) {
@@ -650,9 +538,6 @@ mono_w32file_init (void)
650
538
mono_fdhandle_register (MONO_FDTYPE_PIPE , & file_data_callbacks );
651
539
652
540
mono_coop_mutex_init (& file_share_mutex );
653
-
654
- if (g_hasenv ("MONO_STRICT_IO_EMULATION" ))
655
- lock_while_writing = TRUE;
656
541
}
657
542
658
543
gpointer
0 commit comments