# HG changeset patch # User Paul Boddie # Date 1620166151 -7200 # Node ID 13859678adc286f0dc46ed04c2c66cad415cb318 # Parent 6e84d8639c638ba2579a810d64f1e546aa6413c7 Somewhat reorganised and also renamed the internal flush/access function. diff -r 6e84d8639c63 -r 13859678adc2 libfsclient/lib/src/client.cc --- a/libfsclient/lib/src/client.cc Tue May 04 00:19:19 2021 +0200 +++ b/libfsclient/lib/src/client.cc Wed May 05 00:09:11 2021 +0200 @@ -108,42 +108,51 @@ -/* Flush data conditionally to the filesystem object. */ +/* Access the given position and synchronise state with the file object. */ -static long _flush(file_t *file, offset_t position) +static long _access(file_t *file, offset_t position) { long err; - /* Where the position is outside the current region, re-map. */ + if (file->can_mmap) + { + /* Where the position is outside the current region, re-map. */ - if ((position < file->start_pos) || (position >= file->end_pos)) - { - if (file->can_mmap) + if ((position < file->start_pos) || (position >= file->end_pos)) { if (file_mmap(file, position, file_span(file))) return -L4_EIO; } - /* Strict conditions for region navigation in pipes. */ + /* Otherwise, flush any written data in the current region and update the + file size details. */ else { - if ((position != file->end_pos) || (client_next_region(file) == NULL)) - return -L4_EIO; - } - } - - /* Otherwise, flush any written data in the current region and update the - file size details. */ - - else - { - if (file->can_mmap) - { err = client_flush(file); if (err) return err; } + } + else + { + /* Strict conditions for region navigation in pipes. */ + + if ((position < file->start_pos) || (position > file->end_pos)) + { + return -L4_EIO; + } + + /* The next region is only available at the end of the mapped memory. */ + + else if (position == file->end_pos) + { + if (client_next_region(file) == NULL) + return -L4_EIO; + } + + /* Within the current pipe region, synchronise with the pipe object. */ + else { if (client_current_region(file) == NULL) @@ -257,7 +266,7 @@ /* Flush any unwritten data, preparing to read from the file position at the end of the data, and returning if no new data is available. */ - if (_flush(file, file_data_end_position(file))) + if (_access(file, file_data_end_position(file))) break; available = file_data_available(file); @@ -354,7 +363,7 @@ /* Handle unwritten data and reset the buffer for reading. */ - _flush(file, position); + _access(file, position); return position; } @@ -413,7 +422,7 @@ /* Flush any unwritten data and continue writing from the current data position. */ - if (_flush(file, file_data_current_position(file))) + if (_access(file, file_data_current_position(file))) break; space = file_data_space(file);