Module Name:    othersrc
Committed By:   agc
Date:           Thu Feb 16 04:06:57 UTC 2012

Modified Files:
        othersrc/external/bsd/httpdev/dist: httpdev.8 main.c

Log Message:
Don't hardcode a blocksize of 512 bytes.

Add a blocksize argument to httpdev (-b blocksize).

Bump default blocksize to 4KB.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 othersrc/external/bsd/httpdev/dist/httpdev.8 \
    othersrc/external/bsd/httpdev/dist/main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: othersrc/external/bsd/httpdev/dist/httpdev.8
diff -u othersrc/external/bsd/httpdev/dist/httpdev.8:1.2 othersrc/external/bsd/httpdev/dist/httpdev.8:1.3
--- othersrc/external/bsd/httpdev/dist/httpdev.8:1.2	Wed Feb 15 09:03:38 2012
+++ othersrc/external/bsd/httpdev/dist/httpdev.8	Thu Feb 16 04:06:57 2012
@@ -1,4 +1,4 @@
-.\" $NetBSD: httpdev.8,v 1.2 2012/02/15 09:03:38 wiz Exp $
+.\" $NetBSD: httpdev.8,v 1.3 2012/02/16 04:06:57 agc Exp $
 .\"
 .\" Copyright (c) 2012 Alistair Crooks <[email protected]>
 .\" All rights reserved.
@@ -23,7 +23,7 @@
 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd February 14, 2012
+.Dd February 15, 2012
 .Dt HTTPDEV 8
 .Os
 .Sh NAME
@@ -31,6 +31,7 @@
 .Nd utility to make a remote file appear as local via HTTP
 .Sh SYNOPSIS
 .Nm
+.Op Fl b Ar blocksize
 .Op Fl n Ar name
 .Ar URI
 .Ar mount_point
@@ -77,6 +78,10 @@ for the storage to be presented.
 The
 .Fl n Ar name
 argument allows the name of the subdirectory of the mount point to be specified.
+The
+.Fl b Ar blocksize
+argument sets the number of bytes which will be done in one HTTP request.
+The default blocksize is 512 bytes.
 .Sh EXAMPLES
 .Bd -literal
 # httpdev http://nyftp.netbsd.org/pub/NetBSD-daily/HEAD/201202061530Z/iso/NetBSD-5.99.64-amd64.iso /mnt \*[Am]
Index: othersrc/external/bsd/httpdev/dist/main.c
diff -u othersrc/external/bsd/httpdev/dist/main.c:1.2 othersrc/external/bsd/httpdev/dist/main.c:1.3
--- othersrc/external/bsd/httpdev/dist/main.c:1.2	Wed Feb 15 15:56:07 2012
+++ othersrc/external/bsd/httpdev/dist/main.c	Thu Feb 16 04:06:57 2012
@@ -75,6 +75,14 @@ typedef struct smalltgt_t {
 #define __UNCONST(x)	(x)
 #endif
 
+#ifndef KB
+#define KB(x)	((x) * 1024)
+#endif
+
+#ifndef DEFAULT_BLOCKSIZE
+#define DEFAULT_BLOCKSIZE	KB(4)
+#endif
+
 /* read the capacity (maximum LBA and blocksize) from the target */
 static int 
 read_capacity(const char *uri, uint64_t *size, uint64_t *maxlba, uint32_t *blocklen)
@@ -87,7 +95,9 @@ read_capacity(const char *uri, uint64_t 
 	if ((s = strstr(buf, "Content-Length:")) == NULL) {
 		return 0;
 	}
-	*blocklen = 512;
+	if (*blocklen == 0) {
+		*blocklen = DEFAULT_BLOCKSIZE;
+	}
 	*size = (int64_t)strtoll(s + 16, NULL, 10);
 	*maxlba = *size / *blocklen;
 	return 1;
@@ -116,7 +126,7 @@ inquiry(const char *uri, targetinfo_t *i
 
 /* read info from the target - method depends on size of data being read */
 static int 
-targetop(const char *uri, uint64_t offset, uint32_t length, char *buf, int writing)
+targetop(const char *uri, uint64_t offset, uint32_t length, char *buf, const int writing)
 {
 	if (writing) {
 		return http_post(buf, length, uri, offset, offset + length);
@@ -224,12 +234,13 @@ httpdev_read(const char *path, char *buf
 {
 	virt_dirent_t	*ep;
 	smalltgt_t	*smalltgt;
+	const int	 reading = 0;
 
 	if ((ep = virtdir_find(&httpdev, path, strlen(path))) == NULL) {
 		return -ENOENT;
 	}
 	smalltgt = (smalltgt_t *)ep->tgt;
-	if (targetop(smalltgt->uri, offset, size, buf, 0) < 0) {
+	if (targetop(smalltgt->uri, offset, size, buf, reading) < 0) {
 		return -EPERM;
 	}
 	return size;
@@ -242,12 +253,13 @@ httpdev_write(const char *path, const ch
 {
 	virt_dirent_t	*ep;
         smalltgt_t	*smalltgt;
+	const int	 writing = 1;
 
 	if ((ep = virtdir_find(&httpdev, path, strlen(path))) == NULL) {
 		return -ENOENT;
 	}
 	smalltgt = (smalltgt_t *)ep->tgt;
-	if (targetop(smalltgt->uri, offset, size, __UNCONST(buf), 1) < 0) {
+	if (targetop(smalltgt->uri, offset, size, __UNCONST(buf), writing) < 0) {
 		return -EPERM;
 	}
 	return size;
@@ -384,18 +396,20 @@ static void
 setup_virtdir(targetinfo_t *target, smalltgt_t *smalltgt)
 {
 	ssize_t	cc;
-	char	f[1024];
+	char	buf[1024];
 
-	cc = snprintf(f, sizeof(f), "/%s", target->name);
-	virtdir_add(&httpdev, f, cc, 'd', f, cc);
+	cc = snprintf(buf, sizeof(buf), "/%s", target->name);
+	virtdir_add(&httpdev, buf, cc, 'd', buf, cc);
 	setup_entry(target->name, "address", 'l', target->address, -1);
-	setup_entry(target->name, "storage", 'f', smalltgt, sizeof(*smalltgt));
+	cc = snprintf(buf, sizeof(buf), "%u", target->blocksize);
+	setup_entry(target->name, "blocksize", 'l', buf, cc);
 	setup_entry(target->name, "hostname", 'l', target->host, -1);
+	setup_entry(target->name, "pid", 'l', target->pid, -1);
+	setup_entry(target->name, "product", 'l', target->product, -1);
 	setup_entry(target->name, "service", 'l', target->service, -1);
+	setup_entry(target->name, "storage", 'f', smalltgt, sizeof(*smalltgt));
 	setup_entry(target->name, "targetname", 'l', target->name, -1);
 	setup_entry(target->name, "vendor", 'l', target->vendor, -1);
-	setup_entry(target->name, "pid", 'l', target->pid, -1);
-	setup_entry(target->name, "product", 'l', target->product, -1);
 	setup_entry(target->name, "version", 'l', target->version, -1);
 }
 
@@ -412,8 +426,11 @@ main(int argc, char **argv)
 	(void) memset(&smalltgt, 0x0, sizeof(smalltgt));
 	(void) stat("/etc/hosts", &smalltgt.st);
 	targetname = NULL;
-	while ((i = getopt(argc, argv, "n:")) != -1) {
+	while ((i = getopt(argc, argv, "b:n:")) != -1) {
 		switch(i) {
+		case 'b':
+			target.blocksize = (uint32_t)strtol(optarg, NULL, 0);
+			break;
 		case 'n':
 			targetname = optarg;
 			break;

Reply via email to