[4355] in Athena Bugs

home help back first fref pref prev next nref lref last post

dosread error messages

daemon@ATHENA.MIT.EDU (John Carr)
Wed Feb 28 23:11:58 1990

To: bugs@ATHENA.MIT.EDU
Date: Wed, 28 Feb 90 23:11:12 EST
From: John Carr <jfc@ATHENA.MIT.EDU>

Here are some patches to make the dos programs print better error
messages.  I've verified that these compile, but I don't have any bad
disks to test them on.

*** /source/bsd-4.3/common/ibm/dosread.c	Wed Jul 27 18:15:03 1988
--- dosread.c	Wed Feb 28 23:05:56 1990
***************
*** 405,411 ****
  {
      register u_char *tfat = dir_buff;	/* temporary buffer */
      register struct disk_info *diskinfo;
!     register int    i;
      int             got_info = 0;
  
      if (pflg)
--- 405,411 ----
  {
      register u_char *tfat = dir_buff;	/* temporary buffer */
      register struct disk_info *diskinfo;
!     register int    i, ret;
      int             got_info = 0;
  
      if (pflg)
***************
*** 417,423 ****
  	if (!Iflg)
  	    got_info = read_boot_info();
  	LSEEK(fd, FAT_POS, 0);	/* point to FAT on disk */
! 	if (read(fd, tfat, BSIZE) != BSIZE) {
  		fprintf(stderr,"could not read FAT\n");
  		exit(1);
  	}
--- 417,425 ----
  	if (!Iflg)
  	    got_info = read_boot_info();
  	LSEEK(fd, FAT_POS, 0);	/* point to FAT on disk */
! 	if ((ret = read(fd, tfat, BSIZE)) != BSIZE) {
! 		if (ret == -1)
! 			perror("read");
  		fprintf(stderr,"could not read FAT\n");
  		exit(1);
  	}
***************
*** 428,434 ****
  	if (tfat[0] == 0x29 && !pflg && get_partition(0))
  	{
  	    LSEEK(fd, FAT_POS, 0);	/* point to FAT on disk */
! 	    if (read(fd, tfat, BSIZE) != BSIZE) {
  		    fprintf(stderr,"could not read FAT\n");
  		    exit(1);
  	    }
--- 430,438 ----
  	if (tfat[0] == 0x29 && !pflg && get_partition(0))
  	{
  	    LSEEK(fd, FAT_POS, 0);	/* point to FAT on disk */
! 	    if ((ret = read(fd, tfat, BSIZE)) != BSIZE) {
! 		    if (ret == -1)
! 			perror("read");
  		    fprintf(stderr,"could not read FAT\n");
  		    exit(1);
  	    }
***************
*** 487,494 ****
  		printf("reading next %d bytes of fat\n", fat_length - BSIZE);
  	    LSEEK(fd, FAT_POS + BSIZE, 0);	/* point to next FAT sector
  						 * on disk */
! 	    if (read(fd, fat + BSIZE, fat_length - BSIZE) !=
  		fat_length - BSIZE) {
  		    fprintf(stderr,"could not read all of FAT\n");
  		    exit(1);
  	    }
--- 491,500 ----
  		printf("reading next %d bytes of fat\n", fat_length - BSIZE);
  	    LSEEK(fd, FAT_POS + BSIZE, 0);	/* point to next FAT sector
  						 * on disk */
! 	    if ((ret = read(fd, fat + BSIZE, fat_length - BSIZE)) !=
  		fat_length - BSIZE) {
+ 		    if (ret == -1)
+ 			perror("read");
  		    fprintf(stderr,"could not read all of FAT\n");
  		    exit(1);
  	    }
***************
*** 535,541 ****
      char           *filename;	/* filename.ext */
      struct dir      curdir;	/* a local copy of directory entry */
      int		    gotdir = 0;	/* if we've already checked for directory */
!     int		    namelen;
  
  /*
   * prepare place to build full pathname of each file in the directory 
--- 541,547 ----
      char           *filename;	/* filename.ext */
      struct dir      curdir;	/* a local copy of directory entry */
      int		    gotdir = 0;	/* if we've already checked for directory */
!     int		    namelen, ret;
  
  /*
   * prepare place to build full pathname of each file in the directory 
***************
*** 573,579 ****
  	    cur_dir = dir_sector + i;	/* current directory sector */
  	}
  	LSEEK(fd, cur_dir * BSIZE, 0);	/* seek to directory */
! 	if (read(fd, dir_buff, BSIZE) != BSIZE){
  		fprintf(stderr,"directory read error\n");
  		exit(1);
  	}
--- 579,587 ----
  	    cur_dir = dir_sector + i;	/* current directory sector */
  	}
  	LSEEK(fd, cur_dir * BSIZE, 0);	/* seek to directory */
! 	if ((ret = read(fd, dir_buff, BSIZE)) != BSIZE){
! 		if (ret == -1)
! 			perror("read");
  		fprintf(stderr,"directory read error\n");
  		exit(1);
  	}
***************
*** 724,729 ****
--- 732,738 ----
      register int    i;
      char            buff[BSIZE];
      char            lastc = 0;
+     int		    ret;
  
      if (vflg)
  	printf("x %s\n", name);
***************
*** 742,748 ****
  	sector = cvt_cluster(cluster);
  	LSEEK(fd, sector * BSIZE, 0);
  	for (i = 0; i < cluster_size; ++i) {
! 		if (read(fd, buff, BSIZE) != BSIZE) {
  			fprintf(stderr,"floppy read error\n");
  			exit(1);
  		}
--- 751,759 ----
  	sector = cvt_cluster(cluster);
  	LSEEK(fd, sector * BSIZE, 0);
  	for (i = 0; i < cluster_size; ++i) {
! 		if ((ret = read(fd, buff, BSIZE)) != BSIZE) {
! 			if (ret == -1)
! 				perror("read");
  			fprintf(stderr,"floppy read error\n");
  			exit(1);
  		}
***************
*** 755,761 ****
  			break;
  	}
      }
!     awrite(ofd, buff, 0);	/* flush the buffer */
      fclose(ofd);
  }
  
--- 766,772 ----
  			break;
  	}
      }
!     awrite(ofd, buff, 0, &lastc);/* flush the buffer */
      fclose(ofd);
  }
  
***************
*** 1106,1112 ****
  	cur_dir = dir_sector + i;	/* current directory sector */
  	LSEEK(fd, cur_dir * BSIZE, 0);	/* seek to directory */
  	if ((l = read(fd, dir_buff, BSIZE)) != BSIZE) {
! 		fprintf(stderr,"read returned %d instead of %d\n", l, BSIZE);
  		exit(1);
  	}
  	for (dirp = (struct dir *) dir_buff;
--- 1117,1126 ----
  	cur_dir = dir_sector + i;	/* current directory sector */
  	LSEEK(fd, cur_dir * BSIZE, 0);	/* seek to directory */
  	if ((l = read(fd, dir_buff, BSIZE)) != BSIZE) {
! 		if(l == -1)
! 			perror("read");
! 		else
! 			fprintf(stderr,"read returned %d instead of %d\n", l, BSIZE);
  		exit(1);
  	}
  	for (dirp = (struct dir *) dir_buff;
***************
*** 1237,1243 ****
      register int    c;
  
      if (!aflg)
! 	return (read(fileno(file), buff, length));
      for (end = buff + length; p < end;)
      {
  	if (c = next)
--- 1251,1262 ----
      register int    c;
  
      if (!aflg)
!       {
! 	register int ret = read(fileno(file), buff, length);
! 	if(ret == -1)
! 		perror("aread");
! 	return ret;
!       }
      for (end = buff + length; p < end;)
      {
  	if (c = next)
***************
*** 1324,1329 ****
--- 1343,1349 ----
  {
      char            buff[512];
      register struct disk_info *diskinfo;
+     int ret;
  
      if (isize == 0)
      {
***************
*** 1333,1342 ****
  		printf("trying size=%d blocks fat=0x%x\n", diskinfo->size,
  		       diskinfo->fat_type);
  	    LSEEK(fd, (long) ((diskinfo->size - 1) * BSIZE), 0);
! 	    if (read(fd, buff, 512) == 512)
  	    {
  		isize = diskinfo->size;
  		return (diskinfo->fat_type);
  	    }
  	}
      }
--- 1353,1369 ----
  		printf("trying size=%d blocks fat=0x%x\n", diskinfo->size,
  		       diskinfo->fat_type);
  	    LSEEK(fd, (long) ((diskinfo->size - 1) * BSIZE), 0);
! 	    if ((ret = read(fd, buff, 512)) == 512)
  	    {
  		isize = diskinfo->size;
  		return (diskinfo->fat_type);
+ 	    } else {
+ 		if(ret == -1)
+ 			perror("read(FAT)");
+ 		else
+ 			fprintf(stderr, "FAT short read (%d/512 bytes)\n",
+ 				ret);
+ 		exit(1);
  	    }
  	}
      }
***************
*** 1408,1419 ****
      } else if (vflg)
  	printf("installing bootstrap %s\n", bootname);
      if ((l = read(f, dir_buff, 512)) != 512){
! 	    fprintf(stderr,"boot block short read (%l)\n", l);
  	    exit(1);
      }
      LSEEK(fd, (long) 0, 0);
      if ((l = write(fd, dir_buff, 512)) != 512){
! 	    fprintf(stderr,"boot block - short write (%d)\n", l);
  	    exit(1);
      }
      close(f);
--- 1435,1452 ----
      } else if (vflg)
  	printf("installing bootstrap %s\n", bootname);
      if ((l = read(f, dir_buff, 512)) != 512){
! 	    if(l == -1)
! 		perror("read(boot block)");
! 	    else
! 		fprintf(stderr,"boot block short read (%l)\n", l);
  	    exit(1);
      }
      LSEEK(fd, (long) 0, 0);
      if ((l = write(fd, dir_buff, 512)) != 512){
! 	    if(l == -1)
! 		perror("write(boot block)");
! 	    else
! 		fprintf(stderr,"boot block - short write (%d)\n", l);
  	    exit(1);
      }
      close(f);
***************
*** 1459,1466 ****
  	    exit(1);
      }
      lseek(fd, (long) 0, 0);
!     if (read(fd, (char *) &block, sizeof block) != sizeof block) {
! 	    fprintf(stderr,"reading partition table (at block 0)\n");
  	    exit(1);
      }
      if (block.signature[0] != SIGNATURE_0 ||
--- 1492,1503 ----
  	    exit(1);
      }
      lseek(fd, (long) 0, 0);
!     if ((size = read(fd, (char *) &block, sizeof block)) != sizeof block) {
! 	    if(size == -1)
! 		perror("read(part table)");
! 	    else
! 		fprintf(stderr,"short read of partition table (%d/%d bytes)",
! 			size, sizeof (block));
  	    exit(1);
      }
      if (block.signature[0] != SIGNATURE_0 ||


home help back first fref pref prev next nref lref last post