Newsgroups: comp.sys.sgi
Path: utzoo!censor!geac!alias!dino!chk
From: chk%alias@csri.toronto.edu (C. Harald Koch)
Subject: bug in reading from disk partitions
Message-ID: <1990Nov27.031543.16150@alias.uucp>
Sender: chk@dino.alias.uucp
Reply-To: chk%alias@csri.toronto.edu (C. Harald Koch)
Organization: Alias Research, Inc. Toronto ON Canada
Date: 27 Nov 90 03:03:38 GMT


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@csri.utoronto.ca      chk@gpu.utcs.toronto.edu      chk@chk.mef.org
"Open the Zamboni! We're coming out!" - Kathrin Garland and Anson James, 2299
