summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd.c3
-rw-r--r--net/tap-bsd.c39
-rw-r--r--net/tap.c3
-rw-r--r--pc-bios/optionrom/optionrom.h5
-rw-r--r--qemu-io.c173
5 files changed, 133 insertions, 90 deletions
diff --git a/cmd.c b/cmd.c
index 3c89a0527..cc70311b9 100644
--- a/cmd.c
+++ b/cmd.c
@@ -21,13 +21,12 @@
#include <ctype.h>
#include <errno.h>
#include <sys/time.h>
+#include <getopt.h>
#include "cmd.h"
#define _(x) x /* not gettext support yet */
-extern int optind;
-
/* from libxcmd/command.c */
cmdinfo_t *cmdtab;
diff --git a/net/tap-bsd.c b/net/tap-bsd.c
index ac84383f0..0f8ad4ad7 100644
--- a/net/tap-bsd.c
+++ b/net/tap-bsd.c
@@ -49,16 +49,55 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required
char *dev;
struct stat s;
+#ifdef __FreeBSD__
+ /* if no ifname is given, always start the search from tap0. */
+ int i;
+ char dname[100];
+
+ for (i = 0; i < 10; i++) {
+ if (*ifname) {
+ snprintf(dname, sizeof dname, "/dev/%s", ifname);
+ } else {
+ snprintf(dname, sizeof dname, "/dev/tap%d", i);
+ }
+ TFR(fd = open(dname, O_RDWR));
+ if (fd >= 0) {
+ break;
+ }
+ else if (errno == ENXIO || errno == ENOENT) {
+ break;
+ }
+ if (*ifname) {
+ break;
+ }
+ }
+ if (fd < 0) {
+ qemu_error("warning: could not open %s (%s): no virtual network emulation\n", dname, strerror(errno));
+ return -1;
+ }
+#else
TFR(fd = open("/dev/tap", O_RDWR));
if (fd < 0) {
fprintf(stderr, "warning: could not open /dev/tap: no virtual network emulation\n");
return -1;
}
+#endif
fstat(fd, &s);
dev = devname(s.st_rdev, S_IFCHR);
pstrcpy(ifname, ifname_size, dev);
+ if (*vnet_hdr) {
+ /* BSD doesn't have IFF_VNET_HDR */
+ *vnet_hdr = 0;
+
+ if (vnet_hdr_required && !*vnet_hdr) {
+ qemu_error("vnet_hdr=1 requested, but no kernel "
+ "support for IFF_VNET_HDR available");
+ close(fd);
+ return -1;
+ }
+ }
fcntl(fd, F_SETFL, O_NONBLOCK);
return fd;
}
diff --git a/net/tap.c b/net/tap.c
index 69c905cdc..b2e5908c3 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -399,6 +399,9 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan
}
fd = net_tap_init(opts, &vnet_hdr);
+ if (fd == -1) {
+ return -1;
+ }
}
s = net_tap_fd_init(vlan, "tap", name, fd, vnet_hdr);
diff --git a/pc-bios/optionrom/optionrom.h b/pc-bios/optionrom/optionrom.h
index 34d69af89..4dcb90645 100644
--- a/pc-bios/optionrom/optionrom.h
+++ b/pc-bios/optionrom/optionrom.h
@@ -66,7 +66,10 @@
outw %ax, (%dx); \
mov $BIOS_CFG_IOPORT_DATA, %dx; \
cld; \
- rep insb (%dx), %es:(%edi);
+ /* old as(1) doesn't like this insn so emit the bytes instead: \
+ rep insb (%dx), %es:(%edi); \
+ */ \
+ .dc.b 0x67,0xf3,0x6c
#define OPTION_ROM_START \
.code16; \
diff --git a/qemu-io.c b/qemu-io.c
index cac72e960..3f7f222a6 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -266,8 +266,6 @@ static int do_aio_writev(QEMUIOVector *qiov, int64_t offset, int *total)
}
-static const cmdinfo_t read_cmd;
-
static void
read_help(void)
{
@@ -291,6 +289,19 @@ read_help(void)
"\n");
}
+static int read_f(int argc, char **argv);
+
+static const cmdinfo_t read_cmd = {
+ .name = "read",
+ .altname = "r",
+ .cfunc = read_f,
+ .argmin = 2,
+ .argmax = -1,
+ .args = "[-abCpqv] [-P pattern [-s off] [-l len]] off len",
+ .oneline = "reads a number of bytes at a specified offset",
+ .help = read_help,
+};
+
static int
read_f(int argc, char **argv)
{
@@ -439,19 +450,6 @@ out:
return 0;
}
-static const cmdinfo_t read_cmd = {
- .name = "read",
- .altname = "r",
- .cfunc = read_f,
- .argmin = 2,
- .argmax = -1,
- .args = "[-abCpqv] [-P pattern [-s off] [-l len]] off len",
- .oneline = "reads a number of bytes at a specified offset",
- .help = read_help,
-};
-
-static const cmdinfo_t readv_cmd;
-
static void
readv_help(void)
{
@@ -472,6 +470,18 @@ readv_help(void)
"\n");
}
+static int readv_f(int argc, char **argv);
+
+static const cmdinfo_t readv_cmd = {
+ .name = "readv",
+ .cfunc = readv_f,
+ .argmin = 2,
+ .argmax = -1,
+ .args = "[-Cqv] [-P pattern ] off len [len..]",
+ .oneline = "reads a number of bytes at a specified offset",
+ .help = readv_help,
+};
+
static int
readv_f(int argc, char **argv)
{
@@ -563,18 +573,6 @@ out:
return 0;
}
-static const cmdinfo_t readv_cmd = {
- .name = "readv",
- .cfunc = readv_f,
- .argmin = 2,
- .argmax = -1,
- .args = "[-Cqv] [-P pattern ] off len [len..]",
- .oneline = "reads a number of bytes at a specified offset",
- .help = readv_help,
-};
-
-static const cmdinfo_t write_cmd;
-
static void
write_help(void)
{
@@ -595,6 +593,19 @@ write_help(void)
"\n");
}
+static int write_f(int argc, char **argv);
+
+static const cmdinfo_t write_cmd = {
+ .name = "write",
+ .altname = "w",
+ .cfunc = write_f,
+ .argmin = 2,
+ .argmax = -1,
+ .args = "[-abCpq] [-P pattern ] off len",
+ .oneline = "writes a number of bytes at a specified offset",
+ .help = write_help,
+};
+
static int
write_f(int argc, char **argv)
{
@@ -696,19 +707,6 @@ out:
return 0;
}
-static const cmdinfo_t write_cmd = {
- .name = "write",
- .altname = "w",
- .cfunc = write_f,
- .argmin = 2,
- .argmax = -1,
- .args = "[-abCpq] [-P pattern ] off len",
- .oneline = "writes a number of bytes at a specified offset",
- .help = write_help,
-};
-
-static const cmdinfo_t writev_cmd;
-
static void
writev_help(void)
{
@@ -727,6 +725,18 @@ writev_help(void)
"\n");
}
+static int writev_f(int argc, char **argv);
+
+static const cmdinfo_t writev_cmd = {
+ .name = "writev",
+ .cfunc = writev_f,
+ .argmin = 2,
+ .argmax = -1,
+ .args = "[-Cq] [-P pattern ] off len [len..]",
+ .oneline = "writes a number of bytes at a specified offset",
+ .help = writev_help,
+};
+
static int
writev_f(int argc, char **argv)
{
@@ -797,16 +807,6 @@ out:
return 0;
}
-static const cmdinfo_t writev_cmd = {
- .name = "writev",
- .cfunc = writev_f,
- .argmin = 2,
- .argmax = -1,
- .args = "[-Cq] [-P pattern ] off len [len..]",
- .oneline = "writes a number of bytes at a specified offset",
- .help = writev_help,
-};
-
struct aio_ctx {
QEMUIOVector qiov;
int64_t offset;
@@ -846,8 +846,6 @@ out:
free(ctx);
}
-static const cmdinfo_t aio_read_cmd;
-
static void
aio_read_done(void *opaque, int ret)
{
@@ -911,6 +909,18 @@ aio_read_help(void)
"\n");
}
+static int aio_read_f(int argc, char **argv);
+
+static const cmdinfo_t aio_read_cmd = {
+ .name = "aio_read",
+ .cfunc = aio_read_f,
+ .argmin = 2,
+ .argmax = -1,
+ .args = "[-Cqv] [-P pattern ] off len [len..]",
+ .oneline = "asynchronously reads a number of bytes",
+ .help = aio_read_help,
+};
+
static int
aio_read_f(int argc, char **argv)
{
@@ -976,18 +986,6 @@ aio_read_f(int argc, char **argv)
return 0;
}
-static const cmdinfo_t aio_read_cmd = {
- .name = "aio_read",
- .cfunc = aio_read_f,
- .argmin = 2,
- .argmax = -1,
- .args = "[-Cqv] [-P pattern ] off len [len..]",
- .oneline = "asynchronously reads a number of bytes",
- .help = aio_read_help,
-};
-
-static const cmdinfo_t aio_write_cmd;
-
static void
aio_write_help(void)
{
@@ -1009,6 +1007,17 @@ aio_write_help(void)
"\n");
}
+static int aio_write_f(int argc, char **argv);
+
+static const cmdinfo_t aio_write_cmd = {
+ .name = "aio_write",
+ .cfunc = aio_write_f,
+ .argmin = 2,
+ .argmax = -1,
+ .args = "[-Cq] [-P pattern ] off len [len..]",
+ .oneline = "asynchronously writes a number of bytes",
+ .help = aio_write_help,
+};
static int
aio_write_f(int argc, char **argv)
@@ -1072,16 +1081,6 @@ aio_write_f(int argc, char **argv)
return 0;
}
-static const cmdinfo_t aio_write_cmd = {
- .name = "aio_write",
- .cfunc = aio_write_f,
- .argmin = 2,
- .argmax = -1,
- .args = "[-Cq] [-P pattern ] off len [len..]",
- .oneline = "asynchronously writes a number of bytes",
- .help = aio_write_help,
-};
-
static int
aio_flush_f(int argc, char **argv)
{
@@ -1312,7 +1311,19 @@ open_help(void)
"\n");
}
-static const cmdinfo_t open_cmd;
+static int open_f(int argc, char **argv);
+
+static const cmdinfo_t open_cmd = {
+ .name = "open",
+ .altname = "o",
+ .cfunc = open_f,
+ .argmin = 1,
+ .argmax = -1,
+ .flags = CMD_NOFILE_OK,
+ .args = "[-Crsn] [path]",
+ .oneline = "open the file specified by path",
+ .help = open_help,
+};
static int
open_f(int argc, char **argv)
@@ -1355,18 +1366,6 @@ open_f(int argc, char **argv)
return openfile(argv[optind], flags, growable);
}
-static const cmdinfo_t open_cmd = {
- .name = "open",
- .altname = "o",
- .cfunc = open_f,
- .argmin = 1,
- .argmax = -1,
- .flags = CMD_NOFILE_OK,
- .args = "[-Crsn] [path]",
- .oneline = "open the file specified by path",
- .help = open_help,
-};
-
static int
init_args_command(
int index)