Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/rump_allserver Use "size=e" as a way say "if the und...
details: https://anonhg.NetBSD.org/src/rev/af8294e21535
branches: trunk
changeset: 762210:af8294e21535
user: pooka <pooka%NetBSD.org@localhost>
date: Thu Feb 17 16:59:46 2011 +0000
description:
Use "size=e" as a way say "if the underlying file is preexisting
regular file, use whatever size it has".
diffstat:
usr.bin/rump_allserver/rump_allserver.1 | 11 +++++++-
usr.bin/rump_allserver/rump_allserver.c | 42 +++++++++++++++++++++++++-------
2 files changed, 42 insertions(+), 11 deletions(-)
diffs (124 lines):
diff -r f0815a46432f -r af8294e21535 usr.bin/rump_allserver/rump_allserver.1
--- a/usr.bin/rump_allserver/rump_allserver.1 Thu Feb 17 16:57:46 2011 +0000
+++ b/usr.bin/rump_allserver/rump_allserver.1 Thu Feb 17 16:59:46 2011 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: rump_allserver.1,v 1.13 2011/02/17 16:03:05 pooka Exp $
+.\" $NetBSD: rump_allserver.1,v 1.14 2011/02/17 16:59:46 pooka Exp $
.\"
.\" Copyright (c) 2010 Antti Kantee. All rights reserved.
.\"
@@ -86,10 +86,17 @@
If the file does not exist, it will be created.
.It Ar size
Size of the mapping.
-The host file will be truncated to the size indicated.
Similar to
.Xr dd 1 ,
this argument accepts a suffix as the multiplier for the number.
+The special value
+.Dq e
+indicates that the current size of
+.Ar hostpath
+will be used.
+It is assumed that
+.Ar hostpath
+exists and is a regular file.
.It OR
.It Ar disklabel
Use a disklabel partition identifier to specify the offset and size
diff -r f0815a46432f -r af8294e21535 usr.bin/rump_allserver/rump_allserver.c
--- a/usr.bin/rump_allserver/rump_allserver.c Thu Feb 17 16:57:46 2011 +0000
+++ b/usr.bin/rump_allserver/rump_allserver.c Thu Feb 17 16:59:46 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rump_allserver.c,v 1.17 2011/02/17 16:03:05 pooka Exp $ */
+/* $NetBSD: rump_allserver.c,v 1.18 2011/02/17 16:59:46 pooka Exp $ */
/*-
* Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved.
@@ -27,7 +27,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: rump_allserver.c,v 1.17 2011/02/17 16:03:05 pooka Exp $");
+__RCSID("$NetBSD: rump_allserver.c,v 1.18 2011/02/17 16:59:46 pooka Exp $");
#endif /* !lint */
#include <sys/types.h>
@@ -82,6 +82,7 @@
#define DFILE 1
"hostpath",
#define DSIZE 2
+#define DSIZE_E -1
"size",
#define DOFFSET 3
"offset",
@@ -174,9 +175,20 @@
"size already given\n");
usage();
}
- /* XXX: off_t max? */
- flen = strsuftoll("-d size", value,
- 0, LLONG_MAX);
+ if (strcmp(value, "e") == 0) {
+ if (foffset != 0) {
+ fprintf(stderr,
+ "cannot specify "
+ "offset with "
+ "size=e\n");
+ usage();
+ }
+ flen = DSIZE_E;
+ } else {
+ /* XXX: off_t max? */
+ flen = strsuftoll("-d size",
+ value, 0, LLONG_MAX);
+ }
break;
case DOFFSET:
if (foffset != 0) {
@@ -184,6 +196,12 @@
"offset already given\n");
usage();
}
+ if (flen == DSIZE_E) {
+ fprintf(stderr, "cannot "
+ "specify offset with "
+ "size=e\n");
+ usage();
+ }
/* XXX: off_t max? */
foffset = strsuftoll("-d offset", value,
0, LLONG_MAX);
@@ -330,11 +348,12 @@
struct disklabel dl;
struct stat sb;
off_t foffset, flen, fendoff;
- int fd;
+ int fd, oflags;
- fd = open(etfs[i].hostpath, O_RDWR | O_CREAT, 0644);
+ oflags = etfs[i].flen == DSIZE_E ? 0 : O_CREAT;
+ fd = open(etfs[i].hostpath, O_RDWR | oflags, 0644);
if (fd == -1)
- die(sflag, errno, "etfs hostpath create");
+ die(sflag, errno, "etfs hostpath open");
if (etfs[i].partition) {
int partition = etfs[i].partition - 'a';
@@ -354,10 +373,15 @@
foffset = etfs[i].foffset;
flen = etfs[i].flen;
}
- fendoff = foffset + flen;
if (fstat(fd, &sb) == -1)
die(sflag, errno, "fstat etfs hostpath");
+ if (flen == DSIZE_E) {
+ if (!S_ISREG(sb.st_mode))
+ die(sflag, EINVAL, "size=e requires reg file");
+ flen = sb.st_size;
+ }
+ fendoff = foffset + flen;
if (S_ISREG(sb.st_mode) && sb.st_size < fendoff) {
if (ftruncate(fd, fendoff) == -1)
die(sflag, errno, "truncate");
Home |
Main Index |
Thread Index |
Old Index