paul@6 | 1 | #include "dataspace_server.h" |
paul@6 | 2 | #include "ipc.h" |
paul@6 | 3 | #include "pager.h" |
paul@6 | 4 | |
paul@6 | 5 | |
paul@6 | 6 | |
paul@86 | 7 | /* Initialise the pager with a page mapper and the given flags controlling |
paul@86 | 8 | access to a file. */ |
paul@86 | 9 | |
paul@54 | 10 | Pager::Pager(PageMapper *mapper, flags_t flags) |
paul@48 | 11 | : _start(0), _size(0), _mapper(mapper), _flags(flags) |
paul@6 | 12 | { |
paul@65 | 13 | /* Some pagers may not be initialised with a mapper. */ |
paul@65 | 14 | |
paul@65 | 15 | if (_mapper != NULL) |
paul@65 | 16 | _mapper->attach(); |
paul@6 | 17 | } |
paul@6 | 18 | |
paul@79 | 19 | /* Close the pager. */ |
paul@79 | 20 | |
paul@6 | 21 | void Pager::close() |
paul@6 | 22 | { |
paul@65 | 23 | if (_mapper != NULL) |
paul@65 | 24 | _mapper->detach(); |
paul@6 | 25 | } |
paul@6 | 26 | |
paul@53 | 27 | /* Flush data to the file. */ |
paul@53 | 28 | |
paul@53 | 29 | long Pager::flush(offset_t populated_size, offset_t *size) |
paul@53 | 30 | { |
paul@55 | 31 | _mapper->flush_all(_start, populated_size); |
paul@53 | 32 | |
paul@55 | 33 | *size = _mapper->get_data_size(); |
paul@55 | 34 | return L4_EOK; |
paul@55 | 35 | } |
paul@53 | 36 | |
paul@55 | 37 | /* Resize the underlying file. */ |
paul@53 | 38 | |
paul@55 | 39 | long Pager::resize(offset_t *size) |
paul@55 | 40 | { |
paul@55 | 41 | _mapper->set_data_size(*size); |
paul@55 | 42 | |
paul@55 | 43 | *size = _mapper->get_data_size(); |
paul@53 | 44 | return L4_EOK; |
paul@53 | 45 | } |
paul@53 | 46 | |
paul@7 | 47 | /* Expose a region of the file. */ |
paul@7 | 48 | |
paul@30 | 49 | long Pager::mmap(offset_t position, offset_t length, offset_t *start_pos, offset_t *end_pos, offset_t *data_end) |
paul@6 | 50 | { |
paul@7 | 51 | _start = trunc(position, PAGE_SIZE); |
paul@7 | 52 | _size = round(position + length, PAGE_SIZE) - _start; |
paul@6 | 53 | |
paul@7 | 54 | *start_pos = _start; |
paul@7 | 55 | *end_pos = _start + _size; |
paul@7 | 56 | *data_end = 0; |
paul@7 | 57 | |
paul@7 | 58 | return L4_EOK; |
paul@6 | 59 | } |
paul@6 | 60 | |
paul@6 | 61 | /* Map a flexpage corresponding to the dataspace 'offset' involving a 'hot_spot' |
paul@6 | 62 | (flexpage offset). */ |
paul@6 | 63 | |
paul@54 | 64 | long Pager::map(offset_t offset, l4_addr_t hot_spot, flags_t flags, l4_snd_fpage_t *region) |
paul@6 | 65 | { |
paul@6 | 66 | offset_t file_offset = _start + offset; |
paul@6 | 67 | offset_t max_offset = _start + _size; |
paul@11 | 68 | Flexpage *flexpage = _mapper->get(file_offset, flags); |
paul@6 | 69 | |
paul@6 | 70 | /* Issue the flexpage via the IPC system. */ |
paul@6 | 71 | |
paul@86 | 72 | long err = ipc_prepare_flexpage(flexpage, file_offset, max_offset, hot_spot, |
paul@86 | 73 | flags, region); |
paul@6 | 74 | |
paul@37 | 75 | if (!err) |
paul@37 | 76 | err = complete_Dataspace_map(*region); |
paul@6 | 77 | |
paul@6 | 78 | /* After the flexpage is issued, it is queued for future reuse. */ |
paul@6 | 79 | |
paul@6 | 80 | _mapper->queue(flexpage); |
paul@6 | 81 | |
paul@37 | 82 | if (err) |
paul@37 | 83 | return err; |
paul@37 | 84 | |
paul@6 | 85 | return IPC_MESSAGE_SENT; |
paul@6 | 86 | } |
paul@6 | 87 | |
paul@6 | 88 | /* Return the total size of the data. */ |
paul@6 | 89 | |
paul@6 | 90 | offset_t Pager::get_data_size() |
paul@6 | 91 | { |
paul@6 | 92 | return _mapper->get_data_size(); |
paul@6 | 93 | } |
paul@6 | 94 | |
paul@6 | 95 | // vim: tabstop=4 expandtab shiftwidth=4 |