The problem of "read" system call

Toshitsugu Futagami futagami at nttspl.ntt.junet
Fri Mar 14 08:14:08 AEST 1986


Dear Sirs:

	Our VAX-11/750 stops on the point of "read" in the following program.
This process remains the status "D" of process runnability and we cannot kill
the process. We find that it often stops after reading a tape mark. 

	Is it a bug of 4.2BSD? Or our mt equipment has any troubles? If you can,
please run this program and tell me the result.

	If you know anything, please tell me them, wouldn't you? Thank you.

+--------+---------+---------+---------+---------+---------+---------+---------+
| NTT			      Toshitsugu Futagami			   NTT |
| NTT	      ( NTT Software Production Technology Labs. JAPAN)		   NTT |
| NTT			JUNET:  futagami at nttspl.ntt.junet		   NTT |
| NTT			UUCP :  ..!kddlab!nttlab!nttspl!futagami	   NTT |
| NTT			PHONE:  ( 0422 ) 59 - 3518			   NTT |
+--------+---------+---------+---------+---------+---------+---------+---------+

---------------------------------------------------------------
#include <ctype.h>
#include <sys/param.h>
#include <sys/file.h>
#include <sys/mtio.h>
#include <sys/ioctl.h>
#include <stdio.h>
main()
{
	int  i,mfd;
	int  r;
        int  k;
	char buf[4100];
	struct mtop mtbl;
	
        k=1;
	if ((mfd=open("/dev/rmt12",O_RDONLY,00777)) == -1) {
		printf("open err\n");
		exit();
	}
	while(1) {
		r = read(mfd,buf,4100);
		if ( r == -1) {
			printf("read err\n"); 
			exit();
		}
		if (r == 0) {
			printf("<TM>\n");
			if (close(mfd) == -1) { 
				printf("close err\n");
				exit();
			}
			if ((mfd=open("/dev/rmt12",O_RDONLY,00777)) == -1) {
				printf("open err\n");
				exit();
			}
			r = read(mfd,buf,4100);
			if (r == -1) {
				printf("read err\n");
				exit();
			}
			if (r == 0) { 
				printf("<TM>\n");
				if (close(mfd) == -1) {
					printf("close err\n");
					exit();
				}
				break;
			}
			for (i=0;i<r;i++) 
				putchar(buf[i]);
			printf("<EOB>\n");
			continue;
		}
		for (i=0;i<r;i++) 
			putchar(buf[i]);
		printf("<EOB>\n");
		continue;
	}
	printf("<fin>\n");
	if ((mfd=open("/dev/rmt12",O_RDONLY,00777)) == -1) {
		printf("open err\n");
		exit();
	}
	mtbl.mt_op = MTREW;
	mtbl.mt_count = 1;
	if (ioctl(mfd, MTIOCTOP, &mtbl) == -1) {
	  printf("ioctl error\n");
	  exit();
	}
	if (close(mfd) == -1) {
		printf("close err\n");
		exit();
	}
}
---------------------------------------------------------------



More information about the Comp.unix mailing list