1.1 --- a/libfsclient/lib/src/client.cc Sat May 01 01:46:33 2021 +0200
1.2 +++ b/libfsclient/lib/src/client.cc Sat May 01 22:37:16 2021 +0200
1.3 @@ -126,9 +126,11 @@
1.4
1.5 /* Strict conditions for region navigation in pipes. */
1.6
1.7 - else if ((position != file->end_pos) ||
1.8 - (client_next_region(file) == NULL))
1.9 - return -L4_EIO;
1.10 + else
1.11 + {
1.12 + if ((position != file->end_pos) || (client_next_region(file) == NULL))
1.13 + return -L4_EIO;
1.14 + }
1.15 }
1.16
1.17 /* Otherwise, flush any written data in the current region and update the
1.18 @@ -136,15 +138,26 @@
1.19
1.20 else
1.21 {
1.22 - err = client_flush(file);
1.23 -
1.24 - if (err)
1.25 - return err;
1.26 + if (file->can_mmap)
1.27 + {
1.28 + err = client_flush(file);
1.29 + if (err)
1.30 + return err;
1.31 + }
1.32 + else
1.33 + {
1.34 + if (client_current_region(file) == NULL)
1.35 + return -L4_EIO;
1.36 + }
1.37 }
1.38
1.39 /* Update the current data offset. */
1.40
1.41 - file->data_current = position - file->start_pos;
1.42 + if (file->has_size)
1.43 + file->data_current = position - file->start_pos;
1.44 + else
1.45 + file->data_current = 0;
1.46 +
1.47 return L4_EOK;
1.48 }
1.49
1.50 @@ -200,6 +213,24 @@
1.51
1.52
1.53
1.54 +/* Ensure that memory is mapped for accessing the given file, using the
1.55 + indicated count as a region size hint. */
1.56 +
1.57 +static void *_map_memory(file_t *file, offset_t count)
1.58 +{
1.59 + if (file->memory == NULL)
1.60 + {
1.61 + if (file->can_mmap)
1.62 + return client_mmap(file, client_tell(file), count);
1.63 + else if (pipe_current(file))
1.64 + return NULL;
1.65 + }
1.66 +
1.67 + return file->memory;
1.68 +}
1.69 +
1.70 +
1.71 +
1.72 /* Read from the filesystem object into the buffer provided. */
1.73
1.74 offset_t client_read(file_t *file, void *buf, offset_t count)
1.75 @@ -209,7 +240,7 @@
1.76
1.77 /* Map memory if none has been mapped so far. */
1.78
1.79 - if ((file->memory == NULL) && (client_mmap(file, client_tell(file), count) == NULL))
1.80 + if (_map_memory(file, count) == NULL)
1.81 return 0;
1.82
1.83 /* Amount available in the descriptor buffer already. */
1.84 @@ -348,7 +379,7 @@
1.85
1.86 /* Map memory if none has been mapped so far. */
1.87
1.88 - if ((file->memory == NULL) && (client_mmap(file, client_tell(file), count) == NULL))
1.89 + if (_map_memory(file, count) == NULL)
1.90 return 0;
1.91
1.92 /* Attempt to ensure that the file can accept the amount of data to be
1.93 @@ -357,12 +388,15 @@
1.94
1.95 offset_t needed_size = file_data_current_position(file) + count;
1.96
1.97 - if (file->size < needed_size)
1.98 + if (file->has_size)
1.99 {
1.100 - file_resize(file, needed_size);
1.101 + if (file->size < needed_size)
1.102 + {
1.103 + file_resize(file, needed_size);
1.104
1.105 - if (file->size < needed_size)
1.106 - count = file->size - file_data_current_position(file);
1.107 + if (file->size < needed_size)
1.108 + count = file->size - file_data_current_position(file);
1.109 + }
1.110 }
1.111
1.112 /* Space remaining in the descriptor buffer. */