bug in reading from disk partitions

C. Harald Koch chk%alias at csri.toronto.edu
Tue Nov 27 14:03:38 AEST 1990


I was writing a program to copy disk partitions with verbose output because
of a failing drive.

I discovered the following problem:

I open the partition read-only.

when I attempt a read() system call where the current offset is within the
partition, but the length of the read passes the end of the partition, the
read fails without reading any information. Thus a 'standard' copy loop
of the form

	while((size = read(fd, buf, BUFSIZE)) > 0) {
		write(newfd, buf, size);
	}

fails at the end of file *without* copying the last partial buffer.
(Normally, the read should return 'BUFSIZE' for all reads except the one
described, where it should return the number of bytes between the current
offset and the end of the partition. The next read after that should return
0, signifying the end of the partition. This is standard UNIX read()
semantics...)

On a SCSI drive, it failes with 'ENOSPC', while on an ESDI drive it fails
with 'ENXIO'.

This happens with both the character and block special devices, on both SCSI
and ESDI drives. I am running under IRIX 3.3.1.

If it were important, I would like to write a program to figure out the size
of the partition and copy exactly the right amount of data, but I don't know
how to figure out the raw size of a partition. Can anyone at SGI tell me how
to do this?

For now, I am just going to copy the last partial block using dd(1) and a
512 byte buffer...

--
C. Harald Koch  VE3TLA                Alias Research, Inc., Toronto ON Canada
chk%alias at csri.utoronto.ca      chk at gpu.utcs.toronto.edu      chk at chk.mef.org
"Open the Zamboni! We're coming out!" - Kathrin Garland and Anson James, 2299



More information about the Comp.sys.sgi mailing list