Subject: Re: anyone object to not having split sets in 1.4?
To: None <port-i386@netbsd.org, perry@piermont.com>
From: John F. Woods <jfw@jfwhome.funhouse.com>
List: port-i386
Date: 04/03/1999 18:29:14
OK, I now have code which parses a sets.txt file if you provide one, and
which gives the opportunity to declare that all chunks have been read.  In
doing a test install with a broken version of the parsing code, I found that
just saying "no more floppies for this tar file" went smoothly enough that
I'm not convinced that the complexity of the sets.txt idea is justified.

Here are the diffs, for those who'd like to try them (or at least read them
over).  It's not KNF, and I'm not really happy with the error handling in
the parsing code (yet another reason to just rip out the sets.txt code).

*** defs.h.orig	Fri Apr  2 22:20:36 1999
--- defs.h	Sat Apr  3 14:06:42 1999
***************
*** 291,296 ****
--- 291,297 ----
  int	ask_ynquestion __P((char *quest, char def, ...));
  void	run_makedev __P((void));
  int	get_via_floppy __P((void));
+ int	mount_the_right_floppy __P((char *, char *, int *, char *));
  int	get_via_cdrom __P((void));
  int	get_via_localfs __P((void));
  int	get_via_localdir __P((void));
*** util.c.orig	Fri Apr  2 22:19:22 1999
--- util.c	Sat Apr  3 14:34:37 1999
***************
*** 199,214 ****
  	char fname[STRSIZE];
  	char fullname[STRSIZE];
  	char catcmd[STRSIZE];
  	distinfo *list;
  	char post[4];
  	int  mounted = 0;
! 	int  first;
! 	struct stat sb;
  
  	cd_dist_dir("unloading from floppy");
  
  	msg_prompt_add(MSG_fddev, fddev, fddev, STRSIZE);
  
  	list = dist_list;
  	while (list->name) {
  		strcpy(post, ".aa");
--- 199,312 ----
  	char fname[STRSIZE];
  	char fullname[STRSIZE];
  	char catcmd[STRSIZE];
+ 	char line[STRSIZE];
+         /* there better be fewer than 80 distribution tarballs... */
+ 	char limits[ STRSIZE ];
  	distinfo *list;
  	char post[4];
  	int  mounted = 0;
!         int  i = 0;
!         FILE *setf;
! 	int badfile = 0;
  
  	cd_dist_dir("unloading from floppy");
  
+         /* does this architecture support floppy sets? */
+         if (dist_list->fdlast == 0) {
+ 	        msg_display(MSG_nofd);
+ 		getchar();
+ 		puts(CL); /* just to make sure */
+ 		wrefresh(stdscr);
+ 		return 0;
+ 	}
+ 
  	msg_prompt_add(MSG_fddev, fddev, fddev, STRSIZE);
  
+ 	/* determine how large the sets are (if sets.txt is available) */
+ 	/* If not, rely on "no more floppies" response */
+ 
+         /* replace canned strings */
+ 	for (i = 0; dist_list[i].name != 0; i++) {
+ 	        dist_list[i].fdlast = limits+i*3;
+ 	        limits[i*3] = 'z';
+ 	        limits[i*3+1] = 'z';
+ 	        limits[i*3+2] = 0;
+ 	}
+ 
+         snprintf(fname, STRSIZE, "sets.txt");
+         snprintf(fullname, STRSIZE, "/mnt2/sets.txt");
+ 	if (!mount_the_right_floppy(fname, fullname, &mounted, fddev)) {
+ 	        if (!ignorerror) return 0;
+ 		/* otherwise rely on "no more floppies" choice */
+ 		goto doit;
+ 	}
+ 	if ((setf = fopen(fullname, "r")) == 0) {
+ 	        /* shouldn't happen, right? */
+ 	        msg_display(MSG_cantread, fullname);
+ 		sleep(5);
+ 		run_prog(0, 0, "/sbin/umount /mnt2");
+ 		return 0;
+ 	}
+ 	while (fgets(line, STRSIZE, setf) != NULL) {
+ 	        char *p;
+ 	        /* was line truncated? */
+ 	        int n = strlen(line);
+ 	        if (line[n-1] != '\n') {
+ 		        badfile = 1;
+ 			break;
+ 		}
+ 		/* if first character is #, ignore line */
+ 		if (line[0] == '#') continue;
+ 		/* otherwise, it must be the name of a set,
+ 		 * a space, and exactly two alpha characters.
+ 		 * XXX followed optionally by space and then a checksum?
+ 		 */
+ 		for (p = line; *p != ' ' && *p != 0; p++) ;
+ 		if (*p != ' ') {
+ 		        badfile = 2;
+ 			break;
+ 		}
+ 		if (p[1] < 'a' || p[1] > 'z'
+ 		||  p[2] < 'a' || p[2] > 'z'
+ 		||  p[3] != '\n') {
+ 		        badfile = 3;
+ 			break;
+ 		}
+ 		*p = 0;
+ 		for (list = dist_list; list->name != 0; list++) {
+ 		        if (!strcmp(list->name, line)) {
+ 			        list->fdlast[0] = p[1];
+ 			        list->fdlast[1] = p[2];
+ 				list->fdlast[2] = 0;
+ 				break; /* out of for */
+ 			}
+ 		}
+ 		if (list->name == 0) {
+ 		        /* unrecognized set, is that so bad? */
+ 		        badfile = 4;
+ 			break;
+ 		}
+ 	}
+ 	if (ferror(setf)) {
+ 	        fclose(setf);
+ 	        msg_display(MSG_cantread, fullname);
+ 		sleep(5);
+ 		run_prog(0, 0, "/sbin/umount /mnt2");
+ 		return 0;
+ 	}
+ 	fclose(setf);
+ 	if (badfile) {
+ 	        msg_display(MSG_nonsense_sets_txt, badfile);
+ 		process_menu(MENU_ok);
+ 		return 0;
+ 	}
+ 
+ 	run_prog(0, 0, "/sbin/umount /mnt2");
+ 	mounted = 0;
+ 
+  doit:
+ 	/* now for the sets */
+ 
  	list = dist_list;
  	while (list->name) {
  		strcpy(post, ".aa");
***************
*** 216,241 ****
  		while (list->getit && strcmp(&post[1],list->fdlast) <= 0) {
  			snprintf(fname, STRSIZE, "%s%s", list->name, post);
  			snprintf(fullname, STRSIZE, "/mnt2/%s", fname);
! 			first = 1;
! 			while (!mounted || stat(fullname, &sb)) {
!  				if (mounted) 
! 				  run_prog(0, 0,"/sbin/umount /mnt2");
! 				if (first)
! 					msg_display(MSG_fdmount, fname);
! 				else
! 					msg_display(MSG_fdnotfound, fname);
! 				process_menu(MENU_fdok);
! 				if (!yesno)
! 					return 0;
! 				while (run_prog(0, 0, "/sbin/mount -r -t %s %s /mnt2",
! 				    fdtype, fddev)) {
! 					msg_display(MSG_fdremount, fname);
! 					process_menu(MENU_fdremount);
! 					if (!yesno)
! 						return 0;
! 				}
! 				mounted = 1;
! 				first = 0;
  			}
  			sprintf(catcmd, "/bin/cat %s >> %s",
  				fullname, distname);
--- 314,322 ----
  		while (list->getit && strcmp(&post[1],list->fdlast) <= 0) {
  			snprintf(fname, STRSIZE, "%s%s", list->name, post);
  			snprintf(fullname, STRSIZE, "/mnt2/%s", fname);
!                         if (!mount_the_right_floppy(fname, fullname, &mounted, fddev)) {
! 			        if (ignorerror) goto next_tarball;
! 				else return 0;
  			}
  			sprintf(catcmd, "/bin/cat %s >> %s",
  				fullname, distname);
***************
*** 249,254 ****
--- 330,336 ----
  			else
  				post[2] = 'a', post[1]++;
  		}
+ next_tarball:
  		run_prog(0, 0, "/sbin/umount /mnt2");
  		mounted = 0;
  		list++;
***************
*** 257,262 ****
--- 339,381 ----
  	chdir("/");	/* back to current real root */
  #endif
  	return 1;
+ }
+ /*
+  * mount_the_right_floppy returns 0 to abort, 1 to signal there are no more
+  * floppies to be read (and that this is OK), and 2 to continue.
+  */
+ 
+ int
+ mount_the_right_floppy(fname, fullname, mounted, fddev)
+         char *fname; char *fullname; int *mounted; char *fddev;
+ {
+ 	int  first;
+ 	struct stat sb;
+ 
+ 	first = 1;
+ 	while (!*mounted || stat(fullname, &sb)) {
+ 	        if (*mounted) {
+ 		        run_prog(0, 0,"/sbin/umount /mnt2");
+                         *mounted = 0;
+                 }
+ 		if (first)
+ 			msg_display(MSG_fdmount, fname);
+ 		else
+ 			msg_display(MSG_fdnotfound, fname);
+ 		process_menu(MENU_fdok);
+ 		if (!yesno)
+ 			return yesno;
+ 		while (run_prog(0, 0, "/sbin/mount -r -t %s %s /mnt2",
+ 			        fdtype, fddev)) {
+ 			msg_display(MSG_fdremount, fname);
+ 			process_menu(MENU_fdremount);
+ 			if (!yesno)
+ 				return 0;
+ 		}
+ 		*mounted = 1;
+ 		first = 0;
+ 	}
+         return 2;
  }
  
  /*
*** menus.mi.eng.orig	Wed Mar 31 07:06:07 1999
--- menus.mi.eng	Sat Apr  3 12:39:25 1999
***************
*** 276,284 ****
  	option "Abort install", exit, action { yesno = 0; };
  
  menu fdok, title "  Hit enter to continue  ";
! 	option "OK", exit, action { yesno = 1; };
! 	option "Abort install", exit, action { yesno = 0; };
! 
  
  menu cdromsource, title "  Change";
  	display action
--- 276,287 ----
  	option "Abort install", exit, action { yesno = 0; };
  
  menu fdok, title "  Hit enter to continue  ";
! 	option "OK", exit, action
! 		{ yesno = 1; ignorerror = 1; };
!         option "There are no more floppies", exit, action
! 		{ yesno = 0; ignorerror = 1; };
! 	option "Abort install", exit, action
! 		{ yesno = 0; ignorerror = 0; };
  
  menu cdromsource, title "  Change";
  	display action
*** msg.mi.eng.orig	Wed Mar 31 07:06:07 1999
--- msg.mi.eng	Sat Apr  3 14:34:56 1999
***************
*** 589,594 ****
--- 589,597 ----
   Are you sure you installed all the required sets?
  }
  
+ message nofd
+ {Floppy install sets are not supported on this architecture.}
+ 
  message fddev
  {What floppy device do you want to use? }
  
***************
*** 606,611 ****
--- 609,620 ----
  
      Not load any more files from floppy and abort the process.
  }
+ 
+ message cantread
+ {Could not read the file named "%s".}
+ 
+ message nonsense_sets_txt
+ {The file "sets.txt" was not formatted correctly (%d).}
  
  message mntnetconfig
  {Is the network information you entered accurate for this machine