📄 ftape-read.c
字号:
/* * Copyright (C) 1993-1996 Bas Laarhoven, * (C) 1996-1997 Claus-Justus Heine. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-read.c,v $ * $Revision: 1.6 $ * $Date: 1997/10/21 14:39:22 $ * * This file contains the reading code * for the QIC-117 floppy-tape driver for Linux. * */#include <linux/string.h>#include <linux/errno.h>#include <linux/mm.h>#include <linux/ftape.h>#include <linux/qic117.h>#include "../lowlevel/ftape-tracing.h"#include "../lowlevel/ftape-read.h"#include "../lowlevel/ftape-io.h"#include "../lowlevel/ftape-ctl.h"#include "../lowlevel/ftape-rw.h"#include "../lowlevel/ftape-write.h"#include "../lowlevel/ftape-ecc.h"#include "../lowlevel/ftape-bsm.h"/* Global vars. *//* Local vars. */void ftape_zap_read_buffers(void){ int i; for (i = 0; i < ft_nr_buffers; ++i) {/* changed to "fit" with dynamic allocation of tape_buffer. --khp */ ft_buffer[i]->status = waiting; ft_buffer[i]->bytes = 0; ft_buffer[i]->skip = 0; ft_buffer[i]->retry = 0; }/* ftape_reset_buffer(); */}static SectorMap convert_sector_map(buffer_struct * buff){ int i = 0; SectorMap bad_map = ftape_get_bad_sector_entry(buff->segment_id); SectorMap src_map = buff->soft_error_map | buff->hard_error_map; SectorMap dst_map = 0; TRACE_FUN(ft_t_any); if (bad_map || src_map) { TRACE(ft_t_flow, "bad_map = 0x%08lx", (long) bad_map); TRACE(ft_t_flow, "src_map = 0x%08lx", (long) src_map); } while (bad_map) { while ((bad_map & 1) == 0) { if (src_map & 1) { dst_map |= (1 << i); } src_map >>= 1; bad_map >>= 1; ++i; } /* (bad_map & 1) == 1 */ src_map >>= 1; bad_map >>= 1; } if (src_map) { dst_map |= (src_map << i); } if (dst_map) { TRACE(ft_t_flow, "dst_map = 0x%08lx", (long) dst_map); } TRACE_EXIT dst_map;}static int correct_and_copy_fraction(buffer_struct *buff, __u8 * destination, int start, int size){ struct memory_segment mseg; int result; SectorMap read_bad; TRACE_FUN(ft_t_any); mseg.read_bad = convert_sector_map(buff); mseg.marked_bad = 0; /* not used... */ mseg.blocks = buff->bytes / FT_SECTOR_SIZE; mseg.data = buff->address; /* If there are no data sectors we can skip this segment. */ if (mseg.blocks <= 3) { TRACE_ABORT(0, ft_t_noise, "empty segment"); } read_bad = mseg.read_bad; ft_history.crc_errors += count_ones(read_bad); result = ftape_ecc_correct_data(&mseg); if (read_bad != 0 || mseg.corrected != 0) { TRACE(ft_t_noise, "crc error map: 0x%08lx", (unsigned long)read_bad); TRACE(ft_t_noise, "corrected map: 0x%08lx", (unsigned long)mseg.corrected); ft_history.corrected += count_ones(mseg.corrected); } if (result == ECC_CORRECTED || result == ECC_OK) { if (result == ECC_CORRECTED) { TRACE(ft_t_info, "ecc corrected segment: %d", buff->segment_id); } if(start < 0) { start= 0; } if((start+size) > ((mseg.blocks - 3) * FT_SECTOR_SIZE)) { size = (mseg.blocks - 3) * FT_SECTOR_SIZE - start; } if (size < 0) { size= 0; } if(size > 0) { memcpy(destination + start, mseg.data + start, size); } if ((read_bad ^ mseg.corrected) & mseg.corrected) { /* sectors corrected without crc errors set */ ft_history.crc_failures++; } TRACE_EXIT size; /* (mseg.blocks - 3) * FT_SECTOR_SIZE; */ } else { ft_history.ecc_failures++; TRACE_ABORT(-EAGAIN, ft_t_err, "ecc failure on segment %d", buff->segment_id); } TRACE_EXIT 0;}/* Read given segment into buffer at address. */int ftape_read_segment_fraction(const int segment_id, void *address, const ft_read_mode_t read_mode, const int start, const int size){ int result = 0; int retry = 0; int bytes_read = 0; int read_done = 0; TRACE_FUN(ft_t_flow); ft_history.used |= 1; TRACE(ft_t_data_flow, "segment_id = %d", segment_id); if (ft_driver_state != reading) { TRACE(ft_t_noise, "calling ftape_abort_operation"); TRACE_CATCH(ftape_abort_operation(),); ftape_set_state(reading); } for(;;) { buffer_struct *tail; /* Allow escape from this loop on signal ! */ FT_SIGNAL_EXIT(_DONT_BLOCK); /* Search all full buffers for the first matching the * wanted segment. Clear other buffers on the fly. */ tail = ftape_get_buffer(ft_queue_tail); while (!read_done && tail->status == done) { /* Allow escape from this loop on signal ! */ FT_SIGNAL_EXIT(_DONT_BLOCK); if (tail->segment_id == segment_id) { /* If out buffer is already full, * return its contents. */ TRACE(ft_t_flow, "found segment in cache: %d", segment_id); if (tail->deleted) { /* Return a value that * read_header_segment * understands. As this * should only occur when * searching for the header * segments it shouldn't be * misinterpreted elsewhere. */ TRACE_EXIT 0; } result = correct_and_copy_fraction( tail, address, start, size); TRACE(ft_t_flow, "segment contains (bytes): %d", result); if (result < 0) { if (result != -EAGAIN) { TRACE_EXIT result; } /* keep read_done == 0, will * trigger * ftape_abort_operation * because reading wrong * segment. */ TRACE(ft_t_err, "ecc failed, retry"); ++retry; } else { read_done = 1; bytes_read = result; } } else { TRACE(ft_t_flow,"zapping segment in cache: %d", tail->segment_id); } tail->status = waiting; tail = ftape_next_buffer(ft_queue_tail); } if (!read_done && tail->status == reading) { if (tail->segment_id == segment_id) { switch(ftape_wait_segment(reading)) { case 0: break; case -EINTR: TRACE_ABORT(-EINTR, ft_t_warn, "interrupted by " "non-blockable signal"); break; default: TRACE(ft_t_noise, "wait_segment failed"); ftape_abort_operation(); ftape_set_state(reading); break; } } else { /* We're reading the wrong segment, * stop runner. */ TRACE(ft_t_noise, "reading wrong segment"); ftape_abort_operation(); ftape_set_state(reading); } } /* should runner stop ? */ if (ft_runner_status == aborting) { buffer_struct *head = ftape_get_buffer(ft_queue_head); switch(head->status) { case error: ft_history.defects += count_ones(head->hard_error_map); case reading: head->status = waiting; break; default: break; } TRACE_CATCH(ftape_dumb_stop(),); } else { /* If just passed last segment on tape: wait * for BOT or EOT mark. Sets ft_runner_status to * idle if at lEOT and successful */ TRACE_CATCH(ftape_handle_logical_eot(),); } /* If we got a segment: quit, or else retry up to limit. * * If segment to read is empty, do not start runner for it, * but wait for next read call. */ if (read_done || ftape_get_bad_sector_entry(segment_id) == EMPTY_SEGMENT ) { /* bytes_read = 0; should still be zero */ TRACE_EXIT bytes_read; } if (retry > FT_RETRIES_ON_ECC_ERROR) { ft_history.defects++; TRACE_ABORT(-ENODATA, ft_t_err, "too many retries on ecc failure"); } /* Now at least one buffer is empty ! * Restart runner & tape if needed. */ TRACE(ft_t_any, "head: %d, tail: %d, ft_runner_status: %d", ftape_buffer_id(ft_queue_head), ftape_buffer_id(ft_queue_tail), ft_runner_status); TRACE(ft_t_any, "buffer[].status, [head]: %d, [tail]: %d", ftape_get_buffer(ft_queue_head)->status, ftape_get_buffer(ft_queue_tail)->status); tail = ftape_get_buffer(ft_queue_tail); if (tail->status == waiting) { buffer_struct *head = ftape_get_buffer(ft_queue_head);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -