1 | /*
|
---|
2 | * Copyright (c) 2016 Jakub Jermar
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup fs
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * @file vfs_pager.c
|
---|
35 | * @brief VFS pager operations.
|
---|
36 | */
|
---|
37 |
|
---|
38 | #include "vfs.h"
|
---|
39 | #include <async.h>
|
---|
40 | #include <fibril_synch.h>
|
---|
41 | #include <errno.h>
|
---|
42 | #include <as.h>
|
---|
43 |
|
---|
44 | void vfs_page_in(cap_call_handle_t rid, ipc_call_t *request)
|
---|
45 | {
|
---|
46 | aoff64_t offset = IPC_GET_ARG1(*request);
|
---|
47 | size_t page_size = IPC_GET_ARG2(*request);
|
---|
48 | int fd = IPC_GET_ARG3(*request);
|
---|
49 | void *page;
|
---|
50 | errno_t rc;
|
---|
51 |
|
---|
52 | page = as_area_create(AS_AREA_ANY, page_size,
|
---|
53 | AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE,
|
---|
54 | AS_AREA_UNPAGED);
|
---|
55 |
|
---|
56 | if (page == AS_MAP_FAILED) {
|
---|
57 | async_answer_0(rid, ENOMEM);
|
---|
58 | return;
|
---|
59 | }
|
---|
60 |
|
---|
61 | rdwr_io_chunk_t chunk = {
|
---|
62 | .buffer = page,
|
---|
63 | .size = page_size
|
---|
64 | };
|
---|
65 |
|
---|
66 | size_t total = 0;
|
---|
67 | aoff64_t pos = offset;
|
---|
68 | do {
|
---|
69 | rc = vfs_rdwr_internal(fd, pos, true, &chunk);
|
---|
70 | if (rc != EOK)
|
---|
71 | break;
|
---|
72 | if (chunk.size == 0)
|
---|
73 | break;
|
---|
74 | total += chunk.size;
|
---|
75 | pos += chunk.size;
|
---|
76 | chunk.buffer += chunk.size;
|
---|
77 | chunk.size = page_size - total;
|
---|
78 | } while (total < page_size);
|
---|
79 |
|
---|
80 | async_answer_1(rid, rc, (sysarg_t) page);
|
---|
81 |
|
---|
82 | /*
|
---|
83 | * FIXME:
|
---|
84 | * This is just for now until we implement proper page cache
|
---|
85 | * management. Not keeping the pages around in a cache results in
|
---|
86 | * inherently non-coherent private mappings.
|
---|
87 | */
|
---|
88 | as_area_destroy(page);
|
---|
89 | }
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * @}
|
---|
93 | */
|
---|