Skip to content

Commit d82d905

Browse files
committed
io/ompio: file file_seek calculation
fix the file_seek calculations when using SEEK_END. Thanks @tukss for reporting the issue. Fixes #12952 Signed-off-by: Edgar Gabriel <[email protected]>
1 parent 88cd4a5 commit d82d905

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

ompi/mca/io/ompio/io_ompio_file_open.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,19 +414,21 @@ static void mca_io_ompio_file_get_eof_offset (ompio_file_t *fh,
414414
in_offset -= fh->f_fview.f_disp;
415415
if ( fh->f_fview.f_view_size > 0 ) {
416416
/* starting offset of the current copy of the filew view */
417-
start_offset = in_offset / fh->f_fview.f_view_extent;
417+
start_offset = (in_offset / fh->f_fview.f_view_extent) * fh->f_fview.f_view_extent;
418418

419419
index_in_file_view = 0;
420420
/* determine block id that the offset is located in and
421421
the starting offset of that block */
422-
while ( offset <= in_offset && index_in_file_view < fh->f_fview.f_iov_count) {
423-
prev_offset = offset;
422+
while (offset <= in_offset && index_in_file_view < fh->f_fview.f_iov_count) {
424423
offset = start_offset + (OMPI_MPI_OFFSET_TYPE)(intptr_t) fh->f_fview.f_decoded_iov[index_in_file_view++].iov_base;
424+
if (offset <= in_offset) {
425+
prev_offset = offset;
426+
}
425427
}
426428

427429
offset = prev_offset;
428430
blocklen = fh->f_fview.f_decoded_iov[index_in_file_view-1].iov_len;
429-
while ( offset <= in_offset && k <= blocklen ) {
431+
while (offset <= in_offset && k <= blocklen) {
430432
prev_offset = offset;
431433
offset += fh->f_fview.f_etype_size;
432434
k += fh->f_fview.f_etype_size;

0 commit comments

Comments
 (0)