static void writeData(char *data, afs_int32 size) { int rc; u_int nwritten; if (!ofdIsOpen) return; rc = USD_WRITE(ofd, data, (u_int) size, &nwritten); if (rc != 0) { fprintf(stderr, "Unable to write volume data to file. Code = %d\n", rc); } return; }
/* dataBlock * write a block of data on tape * entry: * blocksize - size of block in bytes */ int dataBlock(usd_handle_t hTape, afs_int32 reqSize) { static char *dB_buffer = 0; static afs_int32 dB_buffersize = 0; static int dB_count = 0; int *ptr; afs_int32 code = 0; afs_uint32 xferd; /* dbBuffersize is only valid when dB_buffer is non-zero */ if ((dB_buffer != 0) && (dB_buffersize != reqSize) ) { free(dB_buffer); dB_buffer = 0; } if (dB_buffer == 0) { dB_buffer = (char *)malloc(reqSize); if (dB_buffer == 0) ERROR(-1); dB_buffersize = reqSize; memset(dB_buffer, 0, dB_buffersize); } ptr = (int *)dB_buffer; *ptr = dB_count++; code = USD_WRITE(hTape, dB_buffer, dB_buffersize, &xferd); if (code || xferd != dB_buffersize) ERROR(-1); error_exit: return (code); }
static afs_int32 WriteTapeBlock(struct butm_tapeInfo *info, char *buffer, /* assumed to be 16384 bytes with data in it */ afs_int32 length, /* amount data in buffer */ afs_int32 blockType) { afs_int32 code = 0, rc = 0; afs_uint32 wsize; struct tapeLabel *label; struct fileMark *fmark; struct blockMark *bmark; struct progress *p; afs_int32 error = 0; p = (struct progress *)info->tmRock; if (blockType == BLOCK_DATA) { /* Data Block */ if (length == 0) ERROR_EXIT(0); bmark = (struct blockMark *)buffer; memset(bmark, 0, sizeof(struct blockMark)); bmark->magic = htonl(BLOCK_MAGIC); bmark->count = htonl(length); } else if (blockType == BLOCK_FMBEGIN) { /* Filemark - begin */ fmark = (struct fileMark *)buffer; fmark->magic = htonl(FILE_MAGIC); fmark->nBytes = htonl(FILE_BEGIN); } else if (blockType == BLOCK_FMEND) { /* Filemark - end */ fmark = (struct fileMark *)buffer; fmark->magic = htonl(FILE_MAGIC); fmark->nBytes = htonl(FILE_FMEND); } else if (blockType == BLOCK_LABEL) { /* Label */ label = (struct tapeLabel *)buffer; label->magic = htonl(TAPE_MAGIC); } else if (blockType == BLOCK_EOD) { /* Filemark - EOD mark */ fmark = (struct fileMark *)buffer; fmark->magic = htonl(FILE_MAGIC); fmark->nBytes = htonl(FILE_EOD); } /* Write the tape block */ /* -------------------- */ rc = USD_WRITE(p->fid, buffer, BUTM_BLOCKSIZE, &wsize); if ((rc == 0) && (wsize > 0)) { incPosition(info, p->fid, wsize); /* record whats written */ p->writing++; } if (wsize != BUTM_BLOCKSIZE) { info->status |= BUTM_STATUS_WRITEERROR; if (rc != 0) { error = rc; ERROR_EXIT(BUTM_IO); } else ERROR_EXIT(BUTM_EOT); } if (isafile) info->position++; /* Write trailing EOF marker for some block types */ /* ---------------------------------------------- */ if ((blockType == BLOCK_FMEND) || (blockType == BLOCK_LABEL) || (blockType == BLOCK_EOD)) { POLL(); error = WriteEOF(p->fid, 1); POLL(); if (error) { info->status |= BUTM_STATUS_WRITEERROR; ERROR_EXIT(BUTM_IOCTL); } incSize(info, config.fileMarkSize); if (!isafile) info->position++; p->writing = 0; } error_exit: if (error) info->error = error; return (code); }