📄 dtwrite.c
字号:
if ( (status == FAILURE) && (error_count >= error_limit) ) break; } /* * For variable length records, adjust the next record size. */ if (min_size) { if (variable_flag) { dsize = get_variable (dip); } else { dsize += incr_count; if (dsize > max_size) dsize = min_size; } } dip->di_records_written++; dip->di_volume_records++; if (io_dir == FORWARD) { dip->di_offset += count; /* Maintain our own position too! */ } else if ( (io_type == SEQUENTIAL_IO) && (dip->di_offset == (off_t) file_position) ) { set_Eof(dip); break; } if (step_offset) { if (io_dir == FORWARD) { dip->di_offset = incr_position (dip, step_offset); } else if ((dip->di_offset -= step_offset) <= (off_t) file_position) { set_Eof(dip); break; } } } return (status);}/************************************************************************ * * * check_write() - Check status of last write operation. * * * * Inputs: dip = The device information pointer. * * count = Number of bytes read. * * size = Number of bytes expected. * * * * Outputs: Returns SUCCESS/FAILURE/WARNING = Ok/Error/Warning * * * ************************************************************************/intcheck_write (struct dinfo *dip, ssize_t count, size_t size){ int status = SUCCESS; if ((size_t)count != size) { if (count == FAILURE) { report_error ("write", FALSE); ReportDeviceInfo (dip, 0, 0, (bool)(errno == EIO)); } else { /* * For writes at end of file or writes at end of block * devices, we'll write less than the requested count. * In this case, we'll treat this as a warning since * this is to be expected. * * NOTE: The raw device should be used for disks. */ if ( (debug_flag || verbose_flag || ((size_t)count > size)) && (io_mode == TEST_MODE) /*&& (io_type == SEQUENTIAL_IO)*/ ) { Printf( "WARNING: Record #%lu, attempted to write %lu bytes, wrote only %lu bytes.\n", (dip->di_records_written + 1), size, count); } if ((size_t)count < size) { /* Partial write is a warning. */ warning_errors++; return (WARNING); } ReportDeviceInfo (dip, count, 0, FALSE); } (void)RecordError(); dip->di_write_errors++; status = FAILURE; } return (status);}/************************************************************************ * * * copy_record() - Copy record to device or file. * * * * Inputs: dip = The device information pointer. * * buffer = The data buffer to write. * * bsize = The number of bytes to write. * * * * Outputs: Returns SUCCESS/FAILURE/WARNING = Ok/Error/Warning * * * ************************************************************************/intcopy_record ( struct dinfo *dip, u_char *buffer, size_t bsize ){ ssize_t count; int status; count = write_record (dip, buffer, bsize, bsize, &status); /* TODO: Get this into write_record() where it belongs! */ if (count > (ssize_t) 0) dip->di_records_written++; return (status);}/************************************************************************ * * * write_record() - Write record to device or file. * * * * Inputs: dip = The device information pointer. * * buffer = The data buffer to write. * * bsize = The number of bytes to write. * * dsize = The users' requested size. * * status = Pointer to status variable. * * * * Outputs: status = SUCCESS/FAILURE/WARNING = Ok/Error/Warning * * Return value is number of bytes from write() request. * * * ************************************************************************/ssize_twrite_record( struct dinfo *dip, u_char *buffer, size_t bsize, size_t dsize, int *status ){ ssize_t count;retry: *status = SUCCESS; count = write (dip->di_fd, buffer, bsize);#if defined(EEI) if ( (count == FAILURE) && (dip->di_dtype->dt_dtype == DT_TAPE) ) { if ( (errno == EIO) && eei_resets) { if ( HandleTapeResets(dip) ) { goto retry; } } else if (eei_flag) { (void) get_eei_status(dip->di_fd, dip->di_mt); } }#endif /* defined(EEI) */ if ( is_Eof (dip, count, status) ) { if (multi_flag) { *status = HandleMultiVolume (dip); dip->di_offset = (off_t) 0; if (*status == SUCCESS) goto retry; } } else { if (count > (ssize_t) 0) { dip->di_dbytes_written += count; dip->di_fbytes_written += count; dip->di_vbytes_written += count; if ((size_t)count == dsize) { records_processed++; } else { partial_records++; } } *status = check_write (dip, count, bsize); } return (count);}/************************************************************************ * * * write_verify() - Verify the record just written. * * * * Inputs: dip = The device information pointer. * * buffer = The data buffer written. * * bsize = The number of bytes written. * * dsize = The users' requested size. * * pos = The starting device/file position. * * * * Outputs: status = SUCCESS/FAILURE/WARNING = Ok/Error/Warning * * * ************************************************************************/intwrite_verify( struct dinfo *dip, u_char *buffer, size_t bsize, size_t dsize, off_t pos ){ u_char *vbuffer = verify_buffer; ssize_t count; u_int32 lba = 0; int status = SUCCESS; if (rdelay_count) { /* Optional read delay. */ mySleep (rdelay_count); } if (dip->di_dtype->dt_dtype == DT_TAPE) {#if !defined(__NUTC__) && !defined(__QNXNTO__) && !defined(AIX) status = DoBackwardSpaceRecord(dip, 1); if (status) return (status);#endif /* !defined(__NUTC__) && !defined(__QNXNTO__) && !defined(AIX) */ } else { /* assume random access */ off_t npos = set_position (dip, pos); if (npos != pos) { Fprintf("ERROR: Wrong seek position, (npos " FUF " != pos)" FUF "!\n", npos, (pos - bsize)); return (FAILURE); } } if (iot_pattern || lbdata_flag) { lba = make_lbdata(dip, (off_t)(dip->di_volume_bytes + pos)); } if (rotate_flag) { vbuffer = (verify_buffer + ((rotate_offset -1) % ROTATE_SIZE)); } /* * If we'll be doing a data compare after the read, then * fill the data buffer with the inverted pattern to ensure * the buffer actually gets written into (driver debug mostly). */ if ((io_mode == TEST_MODE) && compare_flag) { init_buffer (vbuffer, bsize, ~pattern); init_padbytes (vbuffer, bsize, ~pattern); if (iot_pattern) { lba = init_iotdata (bsize, lba, lbdata_size); } } if (Debug_flag) { u_int32 iolba = NO_LBA; if (dip->di_random_access) { iolba = (get_position(dip) / dip->di_dsize); } else if (lbdata_flag || iot_pattern) { iolba = make_lbdata (dip, (off_t)(dip->di_volume_bytes + pos)); } report_record(dip, (dip->di_files_written + 1), (dip->di_records_read + 1), iolba, READ_MODE, vbuffer, bsize); } count = read_record (dip, vbuffer, bsize, dsize, &status); if (end_of_file) { report_error ("read", FALSE); ReportDeviceInfo (dip, 0, 0, FALSE); (void)RecordError(); if (dip->di_dtype->dt_dtype != DT_TAPE) { (void) set_position (dip, pos); } return (FAILURE); } /* * Verify the data (unless disabled). */ if ( (status != FAILURE) && compare_flag && (io_mode == TEST_MODE) ) { ssize_t vsize = count; if (iot_pattern || lbdata_flag) { status = verify_lbdata(dip, buffer, vbuffer, vsize, &lba); } if (status == SUCCESS) { status = verify_buffers(dip, buffer, vbuffer, vsize); } /* * Verify the pad bytes (if enabled). */ if ( (status == SUCCESS) && pad_check) { (void) verify_padbytes (dip, vbuffer, vsize, ~pattern, bsize); } } /* * We expect to read as much as we wrote, or else we've got a problem! */ if ((size_t)count < bsize) { /* check_read() reports info regarding the short record read. */ ReportDeviceInfo (dip, count, 0, FALSE); (void)RecordError(); status = FAILURE; if (dip->di_dtype->dt_dtype != DT_TAPE) { (void) set_position (dip, pos); } } dip->di_records_read++; return (status);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -