debuggers.hg

view tools/xenpaging/file_ops.c @ 21067:b4a1832a916f

Update Xen version to 4.0.0-rc6
author Keir Fraser <keir.fraser@citrix.com>
date Tue Mar 09 18:18:05 2010 +0000 (2010-03-09)
parents 91d1d06d658e
children 779c0ef9682c
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 <xc_private.h>
28 #define page_offset(_pfn) (((off_t)(_pfn)) << PAGE_SHIFT)
31 static int file_op(int fd, void *page, int i,
32 ssize_t (*fn)(int, const void *, size_t))
33 {
34 off_t seek_ret;
35 int total;
36 int bytes;
37 int ret;
39 seek_ret = lseek(fd, i << PAGE_SHIFT, SEEK_SET);
41 total = 0;
42 while ( total < PAGE_SIZE )
43 {
44 bytes = fn(fd, page + total, PAGE_SIZE - total);
45 if ( bytes <= 0 )
46 {
47 ret = -errno;
48 goto err;
49 }
51 total += bytes;
52 }
54 return 0;
56 err:
57 return ret;
58 }
60 static ssize_t my_read(int fd, const void *buf, size_t count)
61 {
62 return read(fd, (void *)buf, count);
63 }
65 int read_page(int fd, void *page, int i)
66 {
67 return file_op(fd, page, i, &my_read);
68 }
70 int write_page(int fd, void *page, int i)
71 {
72 return file_op(fd, page, i, &write);
73 }
76 /*
77 * Local variables:
78 * mode: C
79 * c-set-style: "BSD"
80 * c-basic-offset: 4
81 * indent-tabs-mode: nil
82 * End:
83 */