# HG changeset patch # User Paul Boddie # Date 1715384873 -7200 # Node ID d7e231b756a5ee9342c5c4f720c877ad2b592b50 # Parent cb08608b37fd49bd578fdc478af4e6201f957741 Added support for the refresh operation to files. Tidied client code somewhat. diff -r cb08608b37fd -r d7e231b756a5 libfsclient/include/fsclient/file.h --- a/libfsclient/include/fsclient/file.h Sat May 11 00:49:24 2024 +0200 +++ b/libfsclient/include/fsclient/file.h Sat May 11 01:47:53 2024 +0200 @@ -114,13 +114,17 @@ /* File and region operations. */ long file_flush(file_t *file); +long file_refresh(file_t *file); + long file_mmap(file_t *file, offset_t position, offset_t length, offset_t start_visible, offset_t end_visible, rm_flags_t region_flags); long file_mmap_only(file_t *file, offset_t position, offset_t length, offset_t start_visible, offset_t end_visible); + flags_t file_opening_flags(rm_flags_t rm_flags); rm_flags_t file_region_flags(flags_t flags); + long file_resize(file_t *file, offset_t size); /* File and region properties. */ diff -r cb08608b37fd -r d7e231b756a5 libfsclient/lib/src/client.cc --- a/libfsclient/lib/src/client.cc Sat May 11 00:49:24 2024 +0200 +++ b/libfsclient/lib/src/client.cc Sat May 11 01:47:53 2024 +0200 @@ -281,10 +281,7 @@ /* Synchronise the state of the stream, testing for pipe-based access and switching to memory mapped access if not supported. */ - long err = client_sync_stream(stream); - - if (err == -L4_EBADPROTO) - stream->object_flags |= OBJECT_SUPPORTS_MMAP; + client_sync_stream(stream); /* Enforce blocking if necessary. NOTE: Ignoring any event subscription error. */ @@ -314,7 +311,13 @@ if (!client_opened(file)) return -L4_EINVAL; - return pipe_current(file, 1); + long err = pipe_current(file, 1); + + if (err != -L4_EBADPROTO) + return err; + + file->object_flags |= OBJECT_SUPPORTS_MMAP; + return file_refresh(file); } diff -r cb08608b37fd -r d7e231b756a5 libfsclient/lib/src/file.cc --- a/libfsclient/lib/src/file.cc Sat May 11 00:49:24 2024 +0200 +++ b/libfsclient/lib/src/file.cc Sat May 11 01:47:53 2024 +0200 @@ -62,6 +62,11 @@ else file->data_end = 0; + + /* Reset the current position if a region is empty. */ + + if (!file->data_end) + file->data_current = 0; } @@ -361,6 +366,24 @@ return L4_EOK; } +/* Refresh position and size data from the file or pipe. */ + +long file_refresh(file_t *file) +{ + if (l4_is_invalid_cap(file->ref)) + return -L4_EINVAL; + + client_Flush _file(file->ref); + long err = _file.refresh(&file->data_current, &file->size, &file->end_pos); + + if (err) + return err; + + _update_extent(file); + + return L4_EOK; +} + /* Map a region of the given file to a memory region, obtaining an updated file size and populated data details. Unmap any previously mapped region. */ @@ -695,11 +718,6 @@ if (sync) pipe->data_current = data_current; - /* Handle any case where the current region has been exhausted. */ - - if (!file_populated_span(pipe)) - pipe->data_current = 0; - /* Attach memory if necessary. */ if (pipe->memory == NULL) diff -r cb08608b37fd -r d7e231b756a5 libfsserver/include/fsserver/file_pager.h --- a/libfsserver/include/fsserver/file_pager.h Sat May 11 00:49:24 2024 +0200 +++ b/libfsserver/include/fsserver/file_pager.h Sat May 11 01:47:53 2024 +0200 @@ -34,6 +34,7 @@ protected: FileProvider *_provider; flags_t _flags; + offset_t _data_current; /* Notification endpoint for event subscription. */ @@ -61,10 +62,15 @@ void *interface() { return static_cast(this); } - /* File methods. */ + /* Flush methods. */ virtual long flush(offset_t position, offset_t *size); + virtual long refresh(offset_t *position, offset_t *populated_size, + offset_t *region_size); + + /* File methods. */ + virtual long reopen(flags_t flags, offset_t *size, l4_cap_idx_t *file, object_flags_t *object_flags); diff -r cb08608b37fd -r d7e231b756a5 libfsserver/lib/files/file_pager.cc --- a/libfsserver/lib/files/file_pager.cc Sat May 11 00:49:24 2024 +0200 +++ b/libfsserver/lib/files/file_pager.cc Sat May 11 01:47:53 2024 +0200 @@ -37,6 +37,10 @@ : Pager(provider->mapper(), file_region_flags(flags)), _provider(provider), _flags(flags), fileid(fileid) { + /* Initialise any recorded position in the mapped region for this + endpoint. */ + + _data_current = 0; } ipc_server_default_config_type FilePager::config() @@ -62,12 +66,14 @@ -/* File-specific operations. */ +/* Flush operations. */ long FilePager::flush(offset_t position, offset_t *size) { long err = Pager::flush(position, size); + _data_current = position; + if (_resized) { _provider->notify_others(_notifier, NOTIFY_CONTENT_AVAILABLE, NOTIFY_VALUES_NULL); @@ -77,6 +83,20 @@ return err; } +long FilePager::refresh(offset_t *position, offset_t *size, + offset_t *region_size) +{ + *position = _data_current; + *size = _mapper->get_data_size(); + *region_size = _size; + + return L4_EOK; +} + + + +/* File-specific operations. */ + long FilePager::reopen(flags_t flags, offset_t *size, l4_cap_idx_t *file, object_flags_t *object_flags) { diff -r cb08608b37fd -r d7e231b756a5 libfsserver/lib/pipes/pipe_pager.cc --- a/libfsserver/lib/pipes/pipe_pager.cc Sat May 11 00:49:24 2024 +0200 +++ b/libfsserver/lib/pipes/pipe_pager.cc Sat May 11 01:47:53 2024 +0200 @@ -36,7 +36,8 @@ _size = _paging->region_size(); - /* Initialise any recorded position in the region. */ + /* Initialise any recorded position in the mapped region for this + endpoint. */ _data_current = 0;