Subject: diskpart
To: None <current-users@NetBSD.ORG>
From: Patrick Welche <prlw1@cam.ac.uk>
List: current-users
Date: 05/30/1997 17:39:41
I am having a problem with writing a disktab entry. Among other
things, I don't know what to do about
Sectors per Track: 108 to 180.
Indeed, it is a Quantum Atlas II, 4.5Gb SCSI drive, and from the data
sheet, I can't get the exact number of bytes on the thing, just
formatted capacity = 4550 Mb where 1Mb = 1e6 bytes. Any help on what I
should do about that would be appreciated, but now on to a subsidiary
problem:

I thought I would try diskpart, and found that it didn't work, as it
would compare a string returned by fgets with its trailing carriage
return with a string without the carriage return. After that, it gives
a floating point error, apparently at 
	howmany(x,y);
which is defined as
	(x+y-1)/y
with y=0. The particular line is
	curcyl+=howmany(defpart[def][part],spc);
I don't know what spc means => I don't know what to do. Maybe someone
with more knowledge would like to take it up. Next follows a patch for
/usr/src/usr.sbin/diskpart/diskpart.c v1.7 1997/03/08
in my dodgy programming style to help find the problem...


Enjoy,

  Patrick

==========================================================================
*** diskpart.c	Fri May 30 17:24:46 1997
--- diskpart.new	Fri May 30 17:18:30 1997
***************
*** 112,117 ****
--- 112,135 ----
  
  struct	disklabel *promptfordisk();
  
+ void chomp (char *s)
+ {
+   while(*s!='\0')
+     {
+       switch(*s)
+         {
+           case '\n':
+           case '\r':
+           case '\t':
+             *s='\0';
+             break;
+           default:
+             ++s;
+             break;
+         }
+     }
+ } 
+ 
  main(argc, argv)
  	int argc;
  	char *argv[];
***************
*** 192,197 ****
--- 210,217 ----
  	for (def = 0; def < NDEFAULTS; def++) {
  		curcyl = 0;
  		for (part = PART('a'); part < NPARTITIONS; part++)
+ fprintf(stderr,"curcyl: %i  def: %i  part: %i  defpart: %i  spc: %i\n",
+   curcyl,def,part,defpart[def][part],spc);
  			curcyl += howmany(defpart[def][part], spc);
  		if (curcyl < dp->d_ncylinders - threshhold)
  			break;
***************
*** 375,380 ****
--- 395,401 ----
  	for (;;) {
  		fprintf(stderr, "Disk/controller type (%s)? ", dktypenames[1]);
  		(void) fgets(buf, BUFSIZ, stdin);
+                 chomp(buf);
  		if (buf[0] == 0) {
  			dp->d_type = 1;
  			break;
***************
*** 384,390 ****
  			break;
  		}
  		fprintf(stderr, "%s: unrecognized controller type\n", buf);
! 		fprintf(stderr, "use one of:\n", buf);
  		for (tp = dktypenames; *tp; tp++)
  			if (strchr(*tp, ' ') == 0)
  				fprintf(stderr, "\t%s\n", *tp);
--- 405,411 ----
  			break;
  		}
  		fprintf(stderr, "%s: unrecognized controller type\n", buf);
! 		fprintf(stderr, "use one of:\n");
  		for (tp = dktypenames; *tp; tp++)
  			if (strchr(*tp, ' ') == 0)
  				fprintf(stderr, "\t%s\n", *tp);
***************
*** 393,398 ****
--- 414,420 ----
  	dp->d_flags = 0;
  	fprintf(stderr, "type (winchester|removable|simulated)? ");
  	(void) fgets(buf, BUFSIZ, stdin);
+         chomp(buf);
  	if (strcmp(buf, "removable") == 0)
  		dp->d_flags = D_REMOVABLE;
  	else if (strcmp(buf, "simulated") == 0)
***************
*** 416,421 ****
--- 438,444 ----
  			fprintf(stderr, "(%s)", fp->f_defaults);
  		fprintf(stderr, "? ");
  		cp = fgets(buf, BUFSIZ, stdin);
+                 chomp(buf);
  		if (*cp == '\0') {
  			if (fp->f_defaults == NULL) {
  				fprintf(stderr, "no default value\n");