[OpenAFS-devel] dumpstuff.c buffering: 2 questions
Peter Somogyi
psomogyi@gamax.hu
Tue, 15 Nov 2005 15:49:46 +0100
Hi,
I'm also involved in reading/writting a vnode, therefore I'm examining dumpstuff.c.
I've found the following code in src/volser/dumpstuff.c, function DumpFile:
static int
DumpFile(struct iod *iodp, int vnode, FdHandle_t * handleP)
{
...
n = (lcode ? 0 : FDH_READ(handleP, p, howMany));
...
/* If didn't read enough data, null padd the rest of the buffer. This
* can happen if, for instance, the media has some bad spots. We don't
* want to quit the dump, so we start null padding.
*/
if (n < howMany) {
...
memset(p + n, 0, howMany - n);
...
}
...
/* Now write the data out */
if (iod_Write(iodp, (char *)p, howMany) != howMany)
error = VOLSERDUMPERROR;
...
}
I've examined FDH_READ implementation, it's a standard read.
I've read its manual (man 2 read), and it tells "[...]it is not an error if this number is smaller than the number of bytes requested; this may happen
for example because fewer bytes are actually available right now (maybe because we were close to end-of-file, or
because we are reading from a pipe, or from a terminal)[...]".
So I think instead of null padding it should continue reading (if n>0, of course) - at least on Linux platform. Am I right?
Another question is about rx_Write(call, buf, nbytes): is it true that writting less (but >0) than nbytes means an error?
(in case of file write: it's also not an error)
Any feedback appreciated.
--
Peter Somogyi
Software Developer, Gamax Ltd.
1114 Budapest, Bartok B. u 15/d
Tel.: +36-1-381-0544
e-mail: psomogyi@gamax.hu