# HG changeset patch # User Paul Boddie # Date 1615935547 -3600 # Node ID 862b530319c48116785c9ae25b5689d7a907e1c9 # Parent aa622c059ccd1b0a3e1ee15224bc66057a5b0850 Introduced the flush operation and the file interface to mapped files. Currently, the flush operation changes file sizes in a fixed way, whereas this should be configurable. diff -r aa622c059ccd -r 862b530319c4 Makefile --- a/Makefile Tue Mar 16 23:55:32 2021 +0100 +++ b/Makefile Tue Mar 16 23:59:07 2021 +0100 @@ -19,7 +19,7 @@ # Compound interfaces. mapped_file_object_NAME = MappedFileObject -mapped_file_object_INTERFACES = dataspace mapped_file +mapped_file_object_INTERFACES = dataspace file mapped_file opener_context_object_NAME = OpenerContextObject opener_context_object_INTERFACES = dataspace opener_context @@ -28,7 +28,7 @@ # Individual interfaces. -CLIENT_INTERFACES_CC = dataspace mapped_file opener opener_context +CLIENT_INTERFACES_CC = dataspace file mapped_file opener opener_context SERVER_INTERFACES_CC = opener $(call common_interfaces,$(COMP_INTERFACES_CC)) diff -r aa622c059ccd -r 862b530319c4 accessor.cc --- a/accessor.cc Tue Mar 16 23:55:32 2021 +0100 +++ b/accessor.cc Tue Mar 16 23:59:07 2021 +0100 @@ -12,6 +12,13 @@ return _size; } +/* Update the size of the file. */ + +void Accessor::set_size(offset_t size) +{ + _size = size; +} + /* Perform any closing operation on the file. */ void Accessor::close() diff -r aa622c059ccd -r 862b530319c4 accessor.h --- a/accessor.h Tue Mar 16 23:55:32 2021 +0100 +++ b/accessor.h Tue Mar 16 23:59:07 2021 +0100 @@ -16,6 +16,8 @@ virtual offset_t get_size(); + virtual void set_size(offset_t size); + virtual void close(); virtual void open(); diff -r aa622c059ccd -r 862b530319c4 file_pager.cc --- a/file_pager.cc Tue Mar 16 23:55:32 2021 +0100 +++ b/file_pager.cc Tue Mar 16 23:59:07 2021 +0100 @@ -19,6 +19,11 @@ return (ipc_server_handler_type) handle_MappedFileObject; } +long FilePager::flush(offset_t populated_size, offset_t *size) +{ + return Pager::flush(populated_size, size); +} + long FilePager::mmap(offset_t position, offset_t length, offset_t *start_pos, offset_t *end_pos, offset_t *data_end) { /* Set the limits of the paged region. */ diff -r aa622c059ccd -r 862b530319c4 file_pager.h --- a/file_pager.h Tue Mar 16 23:55:32 2021 +0100 +++ b/file_pager.h Tue Mar 16 23:59:07 2021 +0100 @@ -21,6 +21,10 @@ void *interface() { return static_cast(this); } + /* File methods. */ + + virtual long flush(offset_t populated_size, offset_t *size); + /* Pager and mapped file methods. */ virtual long map(unsigned long offset, l4_addr_t hot_spot, flags_t flags, l4_snd_fpage_t *region); diff -r aa622c059ccd -r 862b530319c4 page_mapper.cc --- a/page_mapper.cc Tue Mar 16 23:55:32 2021 +0100 +++ b/page_mapper.cc Tue Mar 16 23:59:07 2021 +0100 @@ -97,6 +97,13 @@ return _accessor->get_size(); } +/* Set the maximum extent of the mapped resource. */ + +void PageMapper::set_data_size(offset_t size) +{ + _accessor->set_size(size); +} + /* Internal flexpage retrieval methods. */ /* Find an existing flexpage for 'offset'. Where the accessor has registered a diff -r aa622c059ccd -r 862b530319c4 page_mapper.h --- a/page_mapper.h Tue Mar 16 23:55:32 2021 +0100 +++ b/page_mapper.h Tue Mar 16 23:59:07 2021 +0100 @@ -42,6 +42,8 @@ offset_t get_data_size(); + void set_data_size(offset_t size); + /* Data transfer methods, implementing PageOwner. */ void fill(Flexpage *flexpage); diff -r aa622c059ccd -r 862b530319c4 pager.cc --- a/pager.cc Tue Mar 16 23:55:32 2021 +0100 +++ b/pager.cc Tue Mar 16 23:59:07 2021 +0100 @@ -15,6 +15,26 @@ _mapper->detach(); } +/* Flush data to the file. */ + +long Pager::flush(offset_t populated_size, offset_t *size) +{ + offset_t limit = _start + populated_size; + offset_t file_size = _mapper->get_data_size(); + + /* Extend the file if the populated size of the region goes beyond the + current size. */ + + if (limit > file_size) + { + file_size = limit; + _mapper->set_data_size(file_size); + } + + *size = file_size; + return L4_EOK; +} + /* Expose a region of the file. */ long Pager::mmap(offset_t position, offset_t length, offset_t *start_pos, offset_t *end_pos, offset_t *data_end) diff -r aa622c059ccd -r 862b530319c4 pager.h --- a/pager.h Tue Mar 16 23:55:32 2021 +0100 +++ b/pager.h Tue Mar 16 23:59:07 2021 +0100 @@ -29,6 +29,10 @@ offset_t get_data_size(); + /* File methods. */ + + virtual long flush(offset_t populated_size, offset_t *size); + /* Mapped file methods. */ virtual long mmap(offset_t position, offset_t length, offset_t *start_pos, offset_t *end_pos, offset_t *data_end);