Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/dd Add two new operands: "rif" and "rof". They operate ...
details: https://anonhg.NetBSD.org/src/rev/263becc2049a
branches: trunk
changeset: 758971:263becc2049a
user: pooka <pooka%NetBSD.org@localhost>
date: Mon Nov 22 21:04:27 2010 +0000
description:
Add two new operands: "rif" and "rof". They operate exactly like
"if" and "of" with the exception that the communicate with a rump
kernel instead of the host kernel.
For example, to write stdout to /tmp/file.txt in a rump kernel namespace:
dd rof=/tmp/file.txt
copy /file1 to /file2 inside a rump kernel:
dd rif=/file1 rof=/file2
copy a snippet from /dev/rmd0d on the rump kernel to the host fs:
dd rif=/dev/rmd0d of=save seek=1000 count=3
Eat that, usermode OS.
(I'll document the operands one I have some manpage to refer to
for rump client use).
diffstat:
bin/dd/Makefile | 6 ++-
bin/dd/args.c | 61 +++++++++++++++++++++++++++++++++++++++--
bin/dd/dd.c | 79 +++++++++++++++++++++++++++++++++++-------------------
bin/dd/dd.h | 35 +++++++++++++++++++++++-
bin/dd/extern.h | 4 +-
bin/dd/position.c | 19 ++++++------
6 files changed, 158 insertions(+), 46 deletions(-)
diffs (truncated from 522 to 300 lines):
diff -r 83dcc96cc4fd -r 263becc2049a bin/dd/Makefile
--- a/bin/dd/Makefile Mon Nov 22 20:42:19 2010 +0000
+++ b/bin/dd/Makefile Mon Nov 22 21:04:27 2010 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.12 2007/10/05 07:23:09 lukem Exp $
+# $NetBSD: Makefile,v 1.13 2010/11/22 21:04:27 pooka Exp $
# @(#)Makefile 8.1 (Berkeley) 5/31/93
PROG= dd
@@ -8,9 +8,11 @@
LDADD+= -lutil
.ifdef SMALLPROG
-CPPFLAGS+= -DNO_CONV
+CPPFLAGS+= -DNO_CONV -DSMALL
.else
SRCS+= conv_tab.c
+DPADD+= ${LIBRUMPCLIENT}
+LDADD+= -lrumpclient
.endif
.include <bsd.prog.mk>
diff -r 83dcc96cc4fd -r 263becc2049a bin/dd/args.c
--- a/bin/dd/args.c Mon Nov 22 20:42:19 2010 +0000
+++ b/bin/dd/args.c Mon Nov 22 21:04:27 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: args.c,v 1.26 2006/01/09 10:17:05 apb Exp $ */
+/* $NetBSD: args.c,v 1.27 2010/11/22 21:04:27 pooka Exp $ */
/*-
* Copyright (c) 1991, 1993, 1994
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)args.c 8.3 (Berkeley) 4/2/94";
#else
-__RCSID("$NetBSD: args.c,v 1.26 2006/01/09 10:17:05 apb Exp $");
+__RCSID("$NetBSD: args.c,v 1.27 2010/11/22 21:04:27 pooka Exp $");
#endif
#endif /* not lint */
@@ -55,6 +55,10 @@
#include "dd.h"
#include "extern.h"
+#ifndef SMALL
+#include <rump/rumpclient.h>
+#endif
+
static int c_arg(const void *, const void *);
#ifndef NO_CONV
static int c_conv(const void *, const void *);
@@ -72,6 +76,11 @@
static void f_skip(char *);
static void f_progress(char *);
+#ifndef SMALL
+static void f_rif(char *);
+static void f_rof(char *);
+#endif
+
static const struct arg {
const char *name;
void (*f)(char *);
@@ -85,10 +94,14 @@
{ "count", f_count, C_COUNT, C_COUNT },
{ "files", f_files, C_FILES, C_FILES },
{ "ibs", f_ibs, C_IBS, C_BS|C_IBS },
- { "if", f_if, C_IF, C_IF },
+ { "if", f_if, C_IF, C_IF|C_RIF },
{ "obs", f_obs, C_OBS, C_BS|C_OBS },
- { "of", f_of, C_OF, C_OF },
+ { "of", f_of, C_OF, C_OF|C_ROF },
{ "progress", f_progress, 0, 0 },
+#ifndef SMALL
+ { "rif", f_rif, C_RIF|C_RUMP, C_RIF|C_IF },
+ { "rof", f_rof, C_ROF|C_RUMP, C_ROF|C_ROF },
+#endif
{ "seek", f_seek, C_SEEK, C_SEEK },
{ "skip", f_skip, C_SKIP, C_SKIP },
};
@@ -185,6 +198,12 @@
* if (in.offset > INT_MAX/in.dbsz || out.offset > INT_MAX/out.dbsz)
* errx(1, "seek offsets cannot be larger than %d", INT_MAX);
*/
+
+#ifndef SMALL
+ if (ddflags & C_RUMP)
+ if (rumpclient_init() == -1)
+ err(1, "rumpclient init failed");
+#endif
}
static int
@@ -257,6 +276,40 @@
out.name = arg;
}
+#ifndef SMALL
+#include <rump/rump.h>
+#include <rump/rump_syscalls.h>
+
+static const struct ddfops ddfops_rump = {
+ .op_open = rump_sys_open,
+ .op_close = rump_sys_close,
+ .op_fcntl = rump_sys_fcntl,
+ .op_ioctl = rump_sys_ioctl,
+ .op_fstat = rump_sys_fstat,
+ .op_fsync = rump_sys_fsync,
+ .op_ftruncate = rump_sys_ftruncate,
+ .op_lseek = rump_sys_lseek,
+ .op_read = rump_sys_read,
+ .op_write = rump_sys_write,
+};
+
+static void
+f_rif(char *arg)
+{
+
+ in.name = arg;
+ in.ops = &ddfops_rump;
+}
+
+static void
+f_rof(char *arg)
+{
+
+ out.name = arg;
+ out.ops = &ddfops_rump;
+}
+#endif
+
static void
f_seek(char *arg)
{
diff -r 83dcc96cc4fd -r 263becc2049a bin/dd/dd.c
--- a/bin/dd/dd.c Mon Nov 22 20:42:19 2010 +0000
+++ b/bin/dd/dd.c Mon Nov 22 21:04:27 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dd.c,v 1.43 2009/02/14 07:13:40 lukem Exp $ */
+/* $NetBSD: dd.c,v 1.44 2010/11/22 21:04:27 pooka Exp $ */
/*-
* Copyright (c) 1991, 1993, 1994
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)dd.c 8.5 (Berkeley) 4/2/94";
#else
-__RCSID("$NetBSD: dd.c,v 1.43 2009/02/14 07:13:40 lukem Exp $");
+__RCSID("$NetBSD: dd.c,v 1.44 2010/11/22 21:04:27 pooka Exp $");
#endif
#endif /* not lint */
@@ -70,7 +70,7 @@
static void dd_close(void);
static void dd_in(void);
static void getfdtype(IO *);
-static int redup_clean_fd(int);
+static void redup_clean_fd(IO *);
static void setup(void);
int main(int, char *[]);
@@ -87,6 +87,21 @@
const u_char *ctab; /* conversion table */
sigset_t infoset; /* a set blocking SIGINFO */
+static const struct ddfops ddfops_host = {
+ .op_open = open,
+ .op_close = close,
+ .op_fcntl = fcntl,
+ .op_ioctl = ioctl,
+ .op_fstat = fstat,
+ .op_fsync = fsync,
+ .op_ftruncate = ftruncate,
+ .op_lseek = lseek,
+ .op_read = read,
+ .op_write = write,
+};
+
+#include <rump/rumpclient.h>
+
int
main(int argc, char *argv[])
{
@@ -127,17 +142,21 @@
setup(void)
{
+ if (in.ops == NULL)
+ in.ops = &ddfops_host;
+ if (out.ops == NULL)
+ out.ops = &ddfops_host;
if (in.name == NULL) {
in.name = "stdin";
in.fd = STDIN_FILENO;
} else {
- in.fd = open(in.name, O_RDONLY, 0);
+ in.fd = ddop_open(in, in.name, O_RDONLY, 0);
if (in.fd < 0)
err(EXIT_FAILURE, "%s", in.name);
/* NOTREACHED */
/* Ensure in.fd is outside the stdio descriptor range */
- in.fd = redup_clean_fd(in.fd);
+ redup_clean_fd(&in);
}
getfdtype(&in);
@@ -154,14 +173,15 @@
} else {
#define OFLAGS \
(O_CREAT | (ddflags & (C_SEEK | C_NOTRUNC) ? 0 : O_TRUNC))
- out.fd = open(out.name, O_RDWR | OFLAGS, DEFFILEMODE);
+ out.fd = ddop_open(out, out.name, O_RDWR | OFLAGS, DEFFILEMODE);
/*
* May not have read access, so try again with write only.
* Without read we may have a problem if output also does
* not support seeks.
*/
if (out.fd < 0) {
- out.fd = open(out.name, O_WRONLY | OFLAGS, DEFFILEMODE);
+ out.fd = ddop_open(out, out.name, O_WRONLY | OFLAGS,
+ DEFFILEMODE);
out.flags |= NOREAD;
}
if (out.fd < 0) {
@@ -170,7 +190,7 @@
}
/* Ensure out.fd is outside the stdio descriptor range */
- out.fd = redup_clean_fd(out.fd);
+ redup_clean_fd(&out);
}
getfdtype(&out);
@@ -205,7 +225,7 @@
* kinds of output files, tapes, for example.
*/
if ((ddflags & (C_OF | C_SEEK | C_NOTRUNC)) == (C_OF | C_SEEK))
- (void)ftruncate(out.fd, (off_t)out.offset * out.dbsz);
+ (void)ddop_ftruncate(out, out.fd, (off_t)out.offset * out.dbsz);
/*
* If converting case at the same time as another conversion, build a
@@ -251,13 +271,15 @@
struct mtget mt;
struct stat sb;
- if (fstat(io->fd, &sb)) {
+ if (io->ops->op_fstat(io->fd, &sb)) {
err(EXIT_FAILURE, "%s", io->name);
/* NOTREACHED */
}
if (S_ISCHR(sb.st_mode))
- io->flags |= ioctl(io->fd, MTIOCGET, &mt) ? ISCHR : ISTAPE;
- else if (lseek(io->fd, (off_t)0, SEEK_CUR) == -1 && errno == ESPIPE)
+ io->flags |= io->ops->op_ioctl(io->fd, MTIOCGET, &mt)
+ ? ISCHR : ISTAPE;
+ else if (io->ops->op_lseek(io->fd, (off_t)0, SEEK_CUR) == -1
+ && errno == ESPIPE)
io->flags |= ISPIPE; /* XXX fixed in 4.4BSD */
}
@@ -267,29 +289,29 @@
* accidentally outputting completion or error messages into the
* output file that were intended for the tty.
*/
-static int
-redup_clean_fd(int fd)
+static void
+redup_clean_fd(IO *io)
{
+ int fd = io->fd;
int newfd;
if (fd != STDIN_FILENO && fd != STDOUT_FILENO &&
fd != STDERR_FILENO)
/* File descriptor is ok, return immediately. */
- return fd;
+ return;
/*
* 3 is the first descriptor greater than STD*_FILENO. Any
* free descriptor valued 3 or above is acceptable...
*/
- newfd = fcntl(fd, F_DUPFD, 3);
+ newfd = io->ops->op_fcntl(fd, F_DUPFD, 3);
if (newfd < 0) {
err(EXIT_FAILURE, "dupfd IO");
/* NOTREACHED */
}
- close(fd);
-
- return newfd;
+ io->ops->op_close(fd);
+ io->fd = newfd;
}
static void
@@ -316,7 +338,7 @@
Home |
Main Index |
Thread Index |
Old Index