1.1 --- a/libfsclient/lib/src/file.cc Sat May 11 01:47:53 2024 +0200
1.2 +++ b/libfsclient/lib/src/file.cc Sat May 11 19:17:09 2024 +0200
1.3 @@ -374,14 +374,38 @@
1.4 return -L4_EINVAL;
1.5
1.6 client_Flush _file(file->ref);
1.7 - long err = _file.refresh(&file->data_current, &file->size, &file->end_pos);
1.8 + long err;
1.9 +
1.10 + /* Unmap any existing region since the endpoint may have been reconfigured. */
1.11 +
1.12 + if (file->memory != NULL)
1.13 + {
1.14 + err = ipc_detach_dataspace(file->memory);
1.15 + if (err)
1.16 + return err;
1.17 +
1.18 + file->memory = NULL;
1.19 + }
1.20 +
1.21 + /* Obtain the new details for the region. */
1.22 +
1.23 + err = _file.refresh(&file->data_current, &file->start_pos, &file->end_pos,
1.24 + &file->size, &file->object_flags);
1.25
1.26 if (err)
1.27 return err;
1.28
1.29 _update_extent(file);
1.30
1.31 - return L4_EOK;
1.32 + /* Attempt to map any replacement region. */
1.33 +
1.34 + if (!file_span(file))
1.35 + return L4_EOK;
1.36 +
1.37 + return ipc_attach_dataspace_align(file->ref, file_span(file),
1.38 + L4RE_RM_F_SEARCH_ADDR | file_region_flags(file->flags),
1.39 + L4_PAGESHIFT,
1.40 + (void **) &file->memory);
1.41 }
1.42
1.43 /* Map a region of the given file to a memory region, obtaining an updated file
1.44 @@ -407,14 +431,10 @@
1.45 if (err)
1.46 return err;
1.47
1.48 - err = ipc_attach_dataspace_align(file->ref, file_span(file),
1.49 - L4RE_RM_F_SEARCH_ADDR | region_flags,
1.50 - L4_PAGESHIFT,
1.51 - (void **) &file->memory);
1.52 - if (err)
1.53 - return err;
1.54 -
1.55 - return L4_EOK;
1.56 + return ipc_attach_dataspace_align(file->ref, file_span(file),
1.57 + L4RE_RM_F_SEARCH_ADDR | region_flags,
1.58 + L4_PAGESHIFT,
1.59 + (void **) &file->memory);
1.60 }
1.61
1.62 /* Request access to a region of the given file, obtaining an updated file size
1.63 @@ -702,22 +722,22 @@
1.64
1.65 /* Access the current region for a pipe endpoint. */
1.66
1.67 -long pipe_current(file_t *pipe, int sync)
1.68 +long pipe_current(file_t *pipe)
1.69 {
1.70 client_Flush _pipe(pipe->ref);
1.71 +
1.72 + /* The current position and flags are not updated by the refresh operation. */
1.73 +
1.74 offset_t data_current;
1.75 - long err = _pipe.refresh(&data_current, &pipe->size, &pipe->end_pos);
1.76 + object_flags_t object_flags;
1.77 + long err = _pipe.refresh(&data_current, &pipe->start_pos, &pipe->end_pos,
1.78 + &pipe->size, &object_flags);
1.79
1.80 if (err)
1.81 return err;
1.82
1.83 _update_extent(pipe);
1.84
1.85 - /* Obtain the current position if synchronising position state. */
1.86 -
1.87 - if (sync)
1.88 - pipe->data_current = data_current;
1.89 -
1.90 /* Attach memory if necessary. */
1.91
1.92 if (pipe->memory == NULL)