debuggers.hg

view tools/xenpaging/file_ops.c @ 22848:6341fe0f4e5a

Added tag 4.1.0-rc2 for changeset 9dca60d88c63
author Keir Fraser <keir@xen.org>
date Tue Jan 25 14:06:55 2011 +0000 (2011-01-25)
parents 779c0ef9682c
children
line source
1 /******************************************************************************
2 * tools/xenpaging/file_ops.c
3 *
4 * Common file operations.
5 *
6 * Copyright (c) 2009 by Citrix Systems, Inc. (Patrick Colp)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
24 #include <unistd.h>
25 #include <stdarg.h>
26 #include <xc_private.h>
29 #define page_offset(_pfn) (((off_t)(_pfn)) << PAGE_SHIFT)
32 static int file_op(int fd, void *page, int i,
33 ssize_t (*fn)(int, const void *, size_t))
34 {
35 off_t seek_ret;
36 int total;
37 int bytes;
38 int ret;
40 seek_ret = lseek(fd, i << PAGE_SHIFT, SEEK_SET);
42 total = 0;
43 while ( total < PAGE_SIZE )
44 {
45 bytes = fn(fd, page + total, PAGE_SIZE - total);
46 if ( bytes <= 0 )
47 {
48 ret = -errno;
49 goto err;
50 }
52 total += bytes;
53 }
55 return 0;
57 err:
58 return ret;
59 }
61 static ssize_t my_read(int fd, const void *buf, size_t count)
62 {
63 return read(fd, (void *)buf, count);
64 }
66 int read_page(int fd, void *page, int i)
67 {
68 return file_op(fd, page, i, &my_read);
69 }
71 int write_page(int fd, void *page, int i)
72 {
73 return file_op(fd, page, i, &write);
74 }
77 /*
78 * Local variables:
79 * mode: C
80 * c-set-style: "BSD"
81 * c-basic-offset: 4
82 * indent-tabs-mode: nil
83 * End:
84 */