ia64/xen-unstable

view tools/libxc/xg_private.c @ 6489:1f46fafb7221

Fix build failure due to missing unistd.h
Signed-off-by: Michal Ostrowski <mostrows@watson.ibm.com>
author kaf24@firebug.cl.cam.ac.uk
date Tue Aug 30 13:16:05 2005 +0000 (2005-08-30)
parents 9312a3e8a6f8
children b043928b0873
line source
1 /******************************************************************************
2 * xg_private.c
3 *
4 * Helper functions for the rest of the library.
5 */
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <zlib.h>
11 #include "xg_private.h"
13 char *xc_read_kernel_image(const char *filename, unsigned long *size)
14 {
15 int kernel_fd = -1;
16 gzFile kernel_gfd = NULL;
17 char *image = NULL;
18 unsigned int bytes;
20 if ( (kernel_fd = open(filename, O_RDONLY)) < 0 )
21 {
22 PERROR("Could not open kernel image");
23 goto out;
24 }
26 if ( (*size = xc_get_filesz(kernel_fd)) == 0 )
27 {
28 PERROR("Could not read kernel image");
29 goto out;
30 }
32 if ( (kernel_gfd = gzdopen(kernel_fd, "rb")) == NULL )
33 {
34 PERROR("Could not allocate decompression state for state file");
35 goto out;
36 }
38 if ( (image = malloc(*size)) == NULL )
39 {
40 PERROR("Could not allocate memory for kernel image");
41 goto out;
42 }
44 if ( (bytes = gzread(kernel_gfd, image, *size)) != *size )
45 {
46 PERROR("Error reading kernel image, could not"
47 " read the whole image (%d != %ld).", bytes, *size);
48 free(image);
49 image = NULL;
50 }
52 out:
53 if ( kernel_gfd != NULL )
54 gzclose(kernel_gfd);
55 else if ( kernel_fd >= 0 )
56 close(kernel_fd);
57 return image;
58 }
60 /*******************/
62 int pin_table(
63 int xc_handle, unsigned int type, unsigned long mfn, domid_t dom)
64 {
65 struct mmuext_op op;
67 op.cmd = type;
68 op.mfn = mfn;
70 if ( xc_mmuext_op(xc_handle, &op, 1, dom) < 0 )
71 return 1;
73 return 0;
74 }
76 /* This is shared between save and restore, and may generally be useful. */
77 unsigned long csum_page (void * page)
78 {
79 int i;
80 unsigned long *p = page;
81 unsigned long long sum=0;
83 for ( i = 0; i < (PAGE_SIZE/sizeof(unsigned long)); i++ )
84 sum += p[i];
86 return sum ^ (sum>>32);
87 }