1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/file_pager.cc Sun Jan 24 01:29:41 2021 +0100
1.3 @@ -0,0 +1,27 @@
1.4 +#include "file_pager.h"
1.5 +
1.6 +/* Initialise a pager for a file with a unique file identifier and shared page
1.7 + mapper for moderating access to loaded pages. */
1.8 +
1.9 +FilePager::FilePager(fileid_t fileid, PageMapper *mapper)
1.10 +: Pager(mapper), fileid(fileid)
1.11 +{
1.12 +}
1.13 +
1.14 +long FilePager::mmap(size_t position, size_t length, size_t *start_pos, size_t *end_pos, size_t *data_end)
1.15 +{
1.16 + /* Set the limits of the paged region. */
1.17 +
1.18 + Pager::mmap(position, length, start_pos, end_pos, data_end);
1.19 +
1.20 + /* Obtain the amount of the region that is populated with file data. */
1.21 +
1.22 + *data_end = get_data_size() - _start;
1.23 +
1.24 + if (*data_end > _size)
1.25 + *data_end = _size;
1.26 +
1.27 + return L4_EOK;
1.28 +}
1.29 +
1.30 +// vim: tabstop=4 expandtab shiftwidth=4
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/file_pager.h Sun Jan 24 01:29:41 2021 +0100
2.3 @@ -0,0 +1,17 @@
2.4 +#pragma once
2.5 +
2.6 +#include "pager.h"
2.7 +
2.8 +/* A pager abstraction for a file. */
2.9 +
2.10 +class FilePager : public Pager
2.11 +{
2.12 +public:
2.13 + fileid_t fileid;
2.14 +
2.15 + explicit FilePager(fileid_t fileid, PageMapper *mapper);
2.16 +
2.17 + virtual long mmap(size_t position, size_t length, size_t *start_pos, size_t *end_pos, size_t *data_end);
2.18 +};
2.19 +
2.20 +// vim: tabstop=4 expandtab shiftwidth=4