added tdd
authortridge <>
Thu, 30 May 2002 17:55:00 +0000 (17:55 +0000)
committertridge <>
Thu, 30 May 2002 17:55:00 +0000 (17:55 +0000)
tdd/Makefile [new file with mode: 0644]
tdd/tdd.c [new file with mode: 0644]
tserver/files/diagnostics.html

diff --git a/tdd/Makefile b/tdd/Makefile
new file mode 100644 (file)
index 0000000..0d6bc4f
--- /dev/null
@@ -0,0 +1,7 @@
+CFLAGS=-Wall -O
+
+all: tdd
+
+clean:
+       /bin/rm -f *.o *~ tdd
+
diff --git a/tdd/tdd.c b/tdd/tdd.c
new file mode 100644 (file)
index 0000000..54f5983
--- /dev/null
+++ b/tdd/tdd.c
@@ -0,0 +1,257 @@
+/* simple dd with large offsets
+
+   tridge@samba.org, September 2000
+
+   released under the Gnu General Public License version 2 of later
+*/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <asm/unistd.h>
+
+#ifndef O_LARGEFILE
+#define O_LARGEFILE 0
+#endif
+
+#ifndef MIN
+#define MIN(a,b) ((a)<(b)?(a):(b))
+#endif
+
+#ifndef MAX
+#define MAX(a,b) ((a)>(b)?(a):(b))
+#endif
+
+_syscall5(int , _llseek, 
+         int, fd, 
+         unsigned long , offset_high,
+         unsigned long , offset_low,
+         loff_t *, result,
+         unsigned int, origin)
+
+static loff_t llseek(int fd, loff_t offset, unsigned origin)
+{
+       loff_t ofs=0;
+       int ret;
+
+       ret = _llseek(fd, offset>>32, offset&0xffffffff, &ofs, origin);
+       if (ret == 0) return ofs;
+       return ret;
+}
+
+static loff_t getval(char *s)
+{
+       char *p;
+       int i;
+       loff_t ret;
+       struct {
+               char *s;
+               loff_t m;
+       } multipliers[] = {
+               {"c", 1},
+               {"w", 2},
+               {"b", 512},
+               {"kD", 1000},
+               {"MD", 1000*1000},
+               {"GD", 1000*1000*1000},
+               {"k", 1<<10},
+               {"K", 1<<10},
+               {"M", 1<<20},
+               {"G", 1<<30},
+               {NULL, 0}
+       };
+
+       ret = strtoll(s,&p,0);
+
+       if (p && !*p) return ret;
+
+       for (i=0; multipliers[i].s; i++) {
+               if (strcmp(p, multipliers[i].s)==0) {
+                       ret *= multipliers[i].m;
+                       return ret;
+               }
+       }
+
+       fprintf(stderr,"Unknown multiplier %s\n", p);
+       exit(1);
+       return ret;
+}
+
+static void swap_bytes(char *p, int n)
+{
+       char c;
+       while (n) {
+               c = p[0];
+               p[0] = p[1];
+               p[1] = c;
+               n -= 2;
+               p += 2;
+       }
+}
+
+
+static void usage(void)
+{
+       printf("tdd has the same options as dd plus some additional options:\n");
+       printf("-v      increase verbosity\n");
+}
+
+
+int main(int argc, char *argv[])
+{
+       char *inf=NULL, *outf=NULL;
+       loff_t count=-1, iseek=0, skip=0, total_in=0, total_out=0, n=0;
+       loff_t bytes_in=0, bytes_out=0;
+       int bswap = 0;
+       int fd1=0, fd2=1, i;
+       char *buf;
+       int ibs = 512;
+       int obs = 512;
+       int ret = -1;
+       extern char *optarg;
+       extern int optind;
+       int c;
+       int verbose = 0;
+
+       while ((c = getopt(argc, argv, "vh")) != -1 ){
+               switch (c) {
+               case 'v':
+                       verbose++;
+                       break;
+                       
+               case 'h':
+               default:
+                       usage();
+                       exit(1);
+               }
+       }
+
+       for (i=optind;i<argc;i++) {
+               char *a = argv[i];
+               if (strncmp(a, "bs=", 3) == 0) {
+                       ibs = obs = getval(a+3);
+               } else if (strncmp(a,"ibs=", 4) == 0) {
+                       ibs = getval(a+4);
+               } else if (strncmp(a,"obs=", 4) == 0) {
+                       obs = getval(a+4);
+               } else if (strncmp(a,"if=", 3) == 0) {
+                       inf = a+3;
+               } else if (strncmp(a,"of=", 3) == 0) {
+                       outf = a+3;
+               } else if (strncmp(a,"seek=", 5) == 0) {
+                       iseek = getval(a+5);
+               } else if (strncmp(a,"skip=", 4) == 0) {
+                       skip = getval(a+5);
+               } else if (strncmp(a,"count=", 6) == 0) {
+                       count = getval(a+6);
+               } else if (strncmp(a,"conv=", 4) == 0) {
+                       if (strcmp(a+5, "swab")) {
+                               fprintf(stderr,"%s not supported\n", a);
+                               exit(1);
+                       }
+                       bswap = 1;
+               } else {
+                       fprintf(stderr,"unknown option %s\n", a);
+                       exit(1);
+               }
+       }
+
+       if (bswap && (ibs & 1)) {
+               fprintf(stderr,"ibs must be even for swab\n");
+               exit(1);
+       }
+
+       buf = (char *)malloc(ibs==obs?ibs:ibs+obs);
+       if (!buf) {
+               fprintf(stderr,"failed to allocate buffer\n");
+               exit(1);
+       }
+
+       if (inf) fd1 = open(inf,O_RDONLY|O_LARGEFILE);
+       if (fd1 == -1) {
+               perror(inf);
+               exit(1);
+       }
+
+       if (outf) fd2 = open(outf,O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE,0666);
+       if (fd2 == -1) {
+               perror(outf);
+               exit(1);
+       }
+
+       if (iseek) {
+               if (llseek(fd2, iseek*obs, SEEK_CUR) != iseek*obs) {
+                       fprintf(stderr,"failed to seek to %lld\n", iseek*obs);
+                       exit(1);
+               }
+       }
+
+       while (skip) {
+               loff_t n = read(fd1, buf, ibs);
+               if (n <= 0) {
+                       fprintf(stderr,"read on input gave %lld\n", n);
+                       exit(1);
+               }
+               skip--;
+       }
+       
+       while (count == -1 || count != total_in) {
+               loff_t nread;
+
+               nread = read(fd1, buf+n, ibs);
+               if (nread == -1) {
+                       fprintf(stderr,"read failure");
+                       goto out1;
+               }
+               if (nread == 0) goto out1;
+
+               total_in++;
+               bytes_in += nread;
+
+               if (bswap) {
+                       swap_bytes(buf+n, nread);
+               }
+
+               n += nread;
+
+               while (n >= obs) {
+                       loff_t nwritten = write(fd2, buf, obs);
+                       if (nwritten > 0) bytes_out += nwritten;
+                       if (nwritten != obs) {
+                               fprintf(stderr,"write failure\n");
+                               goto out2;
+                       }
+                       n -= nwritten;
+                       if (n > 0) {
+                               memmove(buf, buf+obs, n);
+                       }
+                       total_out++;
+                       if (verbose) {
+                               printf("%lld M\r", bytes_out/(1<<20));
+                       }
+               }               
+       }
+
+       ret = 0;
+
+ out1:
+       if (n) {
+               loff_t nwritten = write(fd2, buf, n);
+               if (nwritten > 0) bytes_out += nwritten;
+       }
+
+ out2:
+       close(fd1);
+       close(fd2);
+
+       printf("%lld+%d records in\n", bytes_in/ibs, bytes_in%ibs?1:0);
+       printf("%lld+%d records out\n", bytes_out/obs, bytes_out%obs?1:0);
+       
+       return ret;
+}
index 18ae19f54a60bfda82389822bf3bb784d3edc03a..a9d3017f4991c5a7073e37bebe0ea2307cd1e9f8 100644 (file)
@@ -5,6 +5,12 @@
 This page shows some basic hardware information which may be useful in
 diagnosing problems with your Snapserver
 
+
+<h3>The environment</h3>
+<pre>
+{{ ! printenv }}
+</pre>
+
 <h3>PCI Devices</h3>
 
 <small>
@@ -32,11 +38,13 @@ diagnosing problems with your Snapserver
 {{ !
    cd /proc/ide || exit 1;
    for d in hd*; do
-      echo "<tr align=right>"
-      echo "<td>$d</td>";
-      echo "<td>"`cat $d/model`"</td>";
-      echo "<td>"`cat $d/capacity 2> /dev/null`"</td>"
-      echo "</tr>"
+cat << EOF
+      <tr align=right>
+      <td>$d</td>
+      <td>`cat $d/model`</td>
+      <td>`cat $d/capacity 2> /dev/null`</td>
+      </tr>
+EOF
    done
 }}
 </table>