1.1 --- a/libfsclient/lib/src/client.cc Tue May 04 00:19:19 2021 +0200
1.2 +++ b/libfsclient/lib/src/client.cc Wed May 05 00:09:11 2021 +0200
1.3 @@ -108,42 +108,51 @@
1.4
1.5
1.6
1.7 -/* Flush data conditionally to the filesystem object. */
1.8 +/* Access the given position and synchronise state with the file object. */
1.9
1.10 -static long _flush(file_t *file, offset_t position)
1.11 +static long _access(file_t *file, offset_t position)
1.12 {
1.13 long err;
1.14
1.15 - /* Where the position is outside the current region, re-map. */
1.16 + if (file->can_mmap)
1.17 + {
1.18 + /* Where the position is outside the current region, re-map. */
1.19
1.20 - if ((position < file->start_pos) || (position >= file->end_pos))
1.21 - {
1.22 - if (file->can_mmap)
1.23 + if ((position < file->start_pos) || (position >= file->end_pos))
1.24 {
1.25 if (file_mmap(file, position, file_span(file)))
1.26 return -L4_EIO;
1.27 }
1.28
1.29 - /* Strict conditions for region navigation in pipes. */
1.30 + /* Otherwise, flush any written data in the current region and update the
1.31 + file size details. */
1.32
1.33 else
1.34 {
1.35 - if ((position != file->end_pos) || (client_next_region(file) == NULL))
1.36 - return -L4_EIO;
1.37 - }
1.38 - }
1.39 -
1.40 - /* Otherwise, flush any written data in the current region and update the
1.41 - file size details. */
1.42 -
1.43 - else
1.44 - {
1.45 - if (file->can_mmap)
1.46 - {
1.47 err = client_flush(file);
1.48 if (err)
1.49 return err;
1.50 }
1.51 + }
1.52 + else
1.53 + {
1.54 + /* Strict conditions for region navigation in pipes. */
1.55 +
1.56 + if ((position < file->start_pos) || (position > file->end_pos))
1.57 + {
1.58 + return -L4_EIO;
1.59 + }
1.60 +
1.61 + /* The next region is only available at the end of the mapped memory. */
1.62 +
1.63 + else if (position == file->end_pos)
1.64 + {
1.65 + if (client_next_region(file) == NULL)
1.66 + return -L4_EIO;
1.67 + }
1.68 +
1.69 + /* Within the current pipe region, synchronise with the pipe object. */
1.70 +
1.71 else
1.72 {
1.73 if (client_current_region(file) == NULL)
1.74 @@ -257,7 +266,7 @@
1.75 /* Flush any unwritten data, preparing to read from the file position at
1.76 the end of the data, and returning if no new data is available. */
1.77
1.78 - if (_flush(file, file_data_end_position(file)))
1.79 + if (_access(file, file_data_end_position(file)))
1.80 break;
1.81
1.82 available = file_data_available(file);
1.83 @@ -354,7 +363,7 @@
1.84
1.85 /* Handle unwritten data and reset the buffer for reading. */
1.86
1.87 - _flush(file, position);
1.88 + _access(file, position);
1.89 return position;
1.90 }
1.91
1.92 @@ -413,7 +422,7 @@
1.93 /* Flush any unwritten data and continue writing from the current data
1.94 position. */
1.95
1.96 - if (_flush(file, file_data_current_position(file)))
1.97 + if (_access(file, file_data_current_position(file)))
1.98 break;
1.99
1.100 space = file_data_space(file);