source: mainline/uspace/srv/vfs/vfs_pager.c@ 930f5c3

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 930f5c3 was c577a9a, checked in by Jakub Jermar <jakub@…>, 8 years ago

Merge from lp:~zarevucky-jiri/helenos/vfs-2.5 revisions 1929-1930

  • Property mode set to 100644
File size: 2.8 KB
Line 
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
44void vfs_page_in(ipc_callid_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 int rc;
51
52 vfs_file_t *file = vfs_file_get(fd);
53 if (!file) {
54 async_answer_0(rid, ENOENT);
55 return;
56 }
57
58 page = as_area_create(AS_AREA_ANY, page_size,
59 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE,
60 AS_AREA_UNPAGED);
61
62 if (page == AS_MAP_FAILED) {
63 vfs_file_put(file);
64 async_answer_0(rid, ENOMEM);
65 return;
66 }
67
68 rdwr_io_chunk_t chunk = {
69 .buffer = page,
70 .size = page_size
71 };
72
73 file->pos = offset;
74
75 size_t total = 0;
76 do {
77 rc = vfs_rdwr_internal(fd, true, &chunk);
78 if (rc != EOK)
79 break;
80 if (chunk.size == 0)
81 break;
82 total += chunk.size;
83 chunk.buffer += chunk.size;
84 chunk.size = page_size - total;
85 } while (total < page_size);
86
87 vfs_file_put(file);
88
89 async_answer_1(rid, rc, (sysarg_t) page);
90
91 /*
92 * FIXME:
93 * This is just for now until we implement proper page cache
94 * management. Not keeping the pages around in a cache results in
95 * inherently non-coherent private mappings.
96 */
97 as_area_destroy(page);
98}
99
100/**
101 * @}
102 */
Note: See TracBrowser for help on using the repository browser.