Beispiel #1
0
/* Read a tape block of size 16K */
afs_int32
readblock(char *buffer)
{
    u_int nread, total = 0;
    int rc, fmcount = 0;

    while (total < BUTM_BLOCKSIZE) {
	rc = USD_READ(fd, buffer + total, BUTM_BLOCKSIZE - total, &nread);
	if (rc != 0) {
	    return (rc);
	} else if ((nread == 0) && (total == 0)) {
	    if (verbose)
		fprintf(stderr, "Hardware file mark\n");
	    if (++fmcount > 3) {
		if (verbose)
		    fprintf(stderr,
			    "Greater than 3 hardware file marks in a row - done\n");
		return -1;
	    }
	} else if (nread == 0) {
	    fprintf(stderr, "Reached unexpected end of dump file\n");
	    return -1;
	} else {
	    total += nread;
	}
    }
    return 0;
}
Beispiel #2
0
afs_int32
readData(usd_handle_t fid, char *data, afs_uint32 totalSize, afs_int32 *errorP)
{
    afs_int32 toread;		/* Number of bytes to read */
    afs_uint32 rSize;		/* Total bytes read so far */
    afs_uint32 tSize;		/* Temporary size */
    afs_int32 rc;		/* return code */

    toread = totalSize;		/* First, try to read all the data */

    rc = USD_READ(fid, &data[0], toread, &rSize);
    if (rc != 0) {
	*errorP = rc;
	return -1;
    }
    if (rSize == 0)		/* reached EOF */
	return rSize;

    if (rSize != TapeBlockSize) {	/* Tape block size has changed */
	TapeBlockSize = rSize;
	printf("Tape blocks read in %d Byte chunks.\n", TapeBlockSize);
    }

    /* Read the rest of the data in */
    while (rSize < totalSize) {
	toread =
	    ((totalSize - rSize) <
	     TapeBlockSize ? (totalSize - rSize) : TapeBlockSize);
	rc = USD_READ(fid, &data[rSize], toread, &tSize);
	if (rc)
	    *errorP = rc;
	else
	    rSize += tSize;
	if (tSize != toread)
	    break;
    }

    if (rSize > totalSize)
	printf("readData - Read > 16K data block - continuing.\n");

    return (rSize);
}