2 * Copyright (C) 2009-2010 Red Hat Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef GUESTFS_INTERNAL_H_
20 #define GUESTFS_INTERNAL_H_
22 #define STREQ(a,b) (strcmp((a),(b)) == 0)
23 #define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0)
24 #define STRNEQ(a,b) (strcmp((a),(b)) != 0)
25 #define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0)
26 #define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0)
27 #define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0)
28 #define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0)
29 #define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0)
30 #define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0)
34 #define _(str) dgettext(PACKAGE, (str))
35 #define N_(str) dgettext(PACKAGE, (str))
42 #define CAN_CHECK_PEER_EUID 1
44 #define CAN_CHECK_PEER_EUID 0
47 #define UNIX_PATH_MAX 108
50 #define MAX(a,b) ((a)>(b)?(a):(b))
54 #define xdr_uint32_t xdr_u_int32_t
57 /* Network configuration of the appliance. Note these addresses are
58 * only meaningful within the context of the running appliance. QEMU
59 * translates network connections to these magic addresses into
60 * userspace calls on the host (eg. connect(2)). qemu-doc has a nice
61 * diagram which is also useful to refer to.
63 * NETWORK: The network.
65 * ROUTER: The address of the "host", ie. this library.
67 * [Note: If you change NETWORK and ROUTER then you also have to
68 * change the network configuration in appliance/init].
70 * GUESTFWD_ADDR, GUESTFWD_PORT: The guestfwd feature of qemu
71 * magically connects this pseudo-address to the guestfwd channel. In
72 * typical Linux configurations of libguestfs, guestfwd is not
73 * actually used any more.
75 #define NETWORK "169.254.0.0/16"
76 #define ROUTER "169.254.2.2"
77 #define GUESTFWD_ADDR "169.254.2.4"
78 #define GUESTFWD_PORT "6666"
80 /* GuestFS handle and connection. */
81 enum state { CONFIG, LAUNCHING, READY, BUSY, NO_HANDLE };
85 struct guestfs_h *next; /* Linked list of open handles. */
87 /* State: see the state machine diagram in the man page guestfs(3). */
90 int fd[2]; /* Stdin/stdout of qemu. */
91 int sock; /* Daemon communications socket. */
92 pid_t pid; /* Qemu PID. */
93 pid_t recoverypid; /* Recovery process PID. */
95 struct timeval launch_t; /* The time that we called guestfs_launch. */
97 char *tmpdir; /* Temporary directory containing socket. */
99 char *qemu_help, *qemu_version; /* Output of qemu -help, qemu -version. */
101 char **cmdline; /* Qemu command line. */
110 char *path; /* Path to kernel, initrd. */
111 char *qemu; /* Qemu binary. */
112 char *append; /* Append to kernel command line. */
114 int memsize; /* Size of RAM (megabytes). */
116 int selinux; /* selinux enabled? */
121 guestfs_abort_cb abort_cb;
122 guestfs_error_handler_cb error_cb;
123 void * error_cb_data;
124 guestfs_log_message_cb log_message_cb;
125 void * log_message_cb_data;
126 guestfs_subprocess_quit_cb subprocess_quit_cb;
127 void * subprocess_quit_cb_data;
128 guestfs_launch_done_cb launch_done_cb;
129 void * launch_done_cb_data;
130 guestfs_close_cb close_cb;
131 void * close_cb_data;
136 struct guestfs_message_header;
137 struct guestfs_message_error;
139 extern void guestfs_error (guestfs_h *g, const char *fs, ...)
140 __attribute__((format (printf,2,3)));
141 extern void guestfs_perrorf (guestfs_h *g, const char *fs, ...)
142 __attribute__((format (printf,2,3)));
143 extern void *guestfs_safe_realloc (guestfs_h *g, void *ptr, int nbytes);
144 extern char *guestfs_safe_strdup (guestfs_h *g, const char *str);
145 extern char *guestfs_safe_strndup (guestfs_h *g, const char *str, size_t n);
146 extern void *guestfs_safe_memdup (guestfs_h *g, void *ptr, size_t size);
147 extern void guestfs___print_timestamped_message (guestfs_h *g, const char *fs, ...);
148 extern const char *guestfs___tmpdir (void);
149 extern int guestfs___set_busy (guestfs_h *g);
150 extern int guestfs___end_busy (guestfs_h *g);
151 extern int guestfs___send (guestfs_h *g, int proc_nr, xdrproc_t xdrp, char *args);
152 extern int guestfs___recv (guestfs_h *g, const char *fn, struct guestfs_message_header *hdr, struct guestfs_message_error *err, xdrproc_t xdrp, char *ret);
153 extern int guestfs___send_file (guestfs_h *g, const char *filename);
154 extern int guestfs___recv_file (guestfs_h *g, const char *filename);
155 extern int guestfs___send_to_daemon (guestfs_h *g, const void *v_buf, size_t n);
156 extern int guestfs___recv_from_daemon (guestfs_h *g, uint32_t *size_rtn, void **buf_rtn);
157 extern int guestfs___accept_from_daemon (guestfs_h *g);
159 #define error guestfs_error
160 #define perrorf guestfs_perrorf
161 #define safe_malloc guestfs_safe_malloc
162 #define safe_realloc guestfs_safe_realloc
163 #define safe_strdup guestfs_safe_strdup
164 #define safe_strndup guestfs_safe_strndup
165 #define safe_memdup guestfs_safe_memdup
167 #endif /* GUESTFS_INTERNAL_H_ */