ftape-proc.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:6k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  *      Copyright (C) 1997 Claus-Justus Heine
  3.  This program is free software; you can redistribute it and/or modify
  4.  it under the terms of the GNU General Public License as published by
  5.  the Free Software Foundation; either version 2, or (at your option)
  6.  any later version.
  7.  This program is distributed in the hope that it will be useful,
  8.  but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10.  GNU General Public License for more details.
  11.  You should have received a copy of the GNU General Public License
  12.  along with this program; see the file COPYING.  If not, write to
  13.  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  14.  *
  15.  * $Source: /homes/cvs/ftape-stacked/ftape/lowlevel/ftape-proc.c,v $
  16.  * $Revision: 1.11 $
  17.  * $Date: 1997/10/24 14:47:37 $
  18.  *
  19.  *      This file contains the procfs interface for the
  20.  *      QIC-40/80/3010/3020 floppy-tape driver "ftape" for Linux.
  21.  * Old code removed, switched to dynamic proc entry.
  22.  */
  23. #include <linux/config.h>
  24. #if defined(CONFIG_PROC_FS) && defined(CONFIG_FT_PROC_FS)
  25. #include <linux/proc_fs.h>
  26. #include <linux/ftape.h>
  27. #include <linux/init.h>
  28. #include <linux/qic117.h>
  29. #include "../lowlevel/ftape-io.h"
  30. #include "../lowlevel/ftape-ctl.h"
  31. #include "../lowlevel/ftape-proc.h"
  32. #include "../lowlevel/ftape-tracing.h"
  33. static size_t get_driver_info(char *buf)
  34. {
  35. const char *debug_level[] = { "bugs"  ,
  36.       "errors",
  37.       "warnings",
  38.       "informational",
  39.       "noisy",
  40.       "program flow",
  41.       "fdc and dma",
  42.       "data flow",
  43.       "anything" };
  44. return sprintf(buf,
  45.        "version       : %sn"
  46.        "used data rate: %d kbit/secn"
  47.        "dma memory    : %d kbn"
  48.        "debug messages: %sn",
  49.        FTAPE_VERSION,
  50.        ft_data_rate,
  51.        FT_BUFF_SIZE * ft_nr_buffers >> 10,
  52.        debug_level[TRACE_LEVEL]);
  53. }
  54. static size_t get_tapedrive_info(char *buf)
  55. return sprintf(buf,
  56.        "vendor id : 0x%04xn"
  57.        "drive name: %sn"
  58.        "wind speed: %d ipsn"
  59.        "wakeup    : %sn"
  60.        "max. rate : %d kbit/secn",
  61.        ft_drive_type.vendor_id,
  62.        ft_drive_type.name,
  63.        ft_drive_type.speed,
  64.        ((ft_drive_type.wake_up == no_wake_up)
  65. ? "No wakeup needed" :
  66. ((ft_drive_type.wake_up == wake_up_colorado)
  67.  ? "Colorado" :
  68.  ((ft_drive_type.wake_up == wake_up_mountain)
  69.   ? "Mountain" :
  70.   ((ft_drive_type.wake_up == wake_up_insight)
  71.    ? "Motor on" :
  72.    "Unknown")))),
  73.        ft_drive_max_rate);
  74. }
  75. static size_t get_cartridge_info(char *buf)
  76. {
  77. if (ftape_init_drive_needed) {
  78. return sprintf(buf, "uninitializedn");
  79. }
  80. if (ft_no_tape) {
  81. return sprintf(buf, "no cartridge insertedn");
  82. }
  83. return sprintf(buf,
  84.        "segments  : %5dn"
  85.        "tracks    : %5dn"
  86.        "length    : %5dftn"
  87.        "formatted : %3sn"
  88.        "writable  : %3sn"
  89.        "QIC spec. : QIC-%sn"
  90.        "fmt-code  : %1dn",
  91.        ft_segments_per_track,
  92.        ft_tracks_per_tape,
  93.        ftape_tape_len,
  94.        (ft_formatted == 1) ? "yes" : "no",
  95.        (ft_write_protected == 1) ? "no" : "yes",
  96.        ((ft_qic_std == QIC_TAPE_QIC40) ? "40" :
  97. ((ft_qic_std == QIC_TAPE_QIC80) ? "80" :
  98.  ((ft_qic_std == QIC_TAPE_QIC3010) ? "3010" :
  99.   ((ft_qic_std == QIC_TAPE_QIC3020) ? "3020" :
  100.    "???")))),
  101.        ft_format_code);
  102. }
  103. static size_t get_controller_info(char *buf)
  104. {
  105. const char  *fdc_name[] = { "no fdc",
  106.     "i8272",
  107.     "i82077",
  108.     "i82077AA",
  109.     "Colorado FC-10 or FC-20",
  110.     "i82078",
  111.     "i82078_1" };
  112. return sprintf(buf,
  113.        "FDC type  : %sn"
  114.        "FDC base  : 0x%03xn"
  115.        "FDC irq   : %dn"
  116.        "FDC dma   : %dn"
  117.        "FDC thr.  : %dn"
  118.        "max. rate : %d kbit/secn",
  119.        ft_mach2 ? "Mountain MACH-2" : fdc_name[fdc.type],
  120.        fdc.sra, fdc.irq, fdc.dma,
  121.        ft_fdc_threshold, ft_fdc_max_rate);
  122. }
  123. static size_t get_history_info(char *buf)
  124. {
  125.         size_t len;
  126. len  = sprintf(buf,
  127.        "nFDC isr statisticsn"
  128.        " id_am_errors     : %3dn"
  129.        " id_crc_errors    : %3dn"
  130.        " data_am_errors   : %3dn"
  131.        " data_crc_errors  : %3dn"
  132.        " overrun_errors   : %3dn"
  133.        " no_data_errors   : %3dn"
  134.        " retries          : %3dn",
  135.        ft_history.id_am_errors,   ft_history.id_crc_errors,
  136.        ft_history.data_am_errors, ft_history.data_crc_errors,
  137.        ft_history.overrun_errors, ft_history.no_data_errors,
  138.        ft_history.retries);
  139. len += sprintf(buf + len,
  140.        "nECC statisticsn"
  141.        " crc_errors       : %3dn"
  142.        " crc_failures     : %3dn"
  143.        " ecc_failures     : %3dn"
  144.        " sectors corrected: %3dn",
  145.        ft_history.crc_errors,   ft_history.crc_failures,
  146.        ft_history.ecc_failures, ft_history.corrected);
  147. len += sprintf(buf + len,
  148.        "ntape quality statisticsn"
  149.        " media defects    : %3dn",
  150.        ft_history.defects);
  151. len += sprintf(buf + len,
  152.        "ntape motion statisticsn"
  153.        " repositions      : %3dn",
  154.        ft_history.rewinds);
  155. return len;
  156. }
  157. int ftape_read_proc(char *page, char **start, off_t off,
  158.     int count, int *eof, void *data)
  159. {
  160. char *ptr = page;
  161. size_t len;
  162. ptr += sprintf(ptr, "Kernel Drivernn");
  163. ptr += get_driver_info(ptr);
  164. ptr += sprintf(ptr, "nTape Drivenn");
  165. ptr += get_tapedrive_info(ptr);
  166. ptr += sprintf(ptr, "nFDC Controllernn");
  167. ptr += get_controller_info(ptr);
  168. ptr += sprintf(ptr, "nTape Cartridgenn");
  169. ptr += get_cartridge_info(ptr);
  170. ptr += sprintf(ptr, "nHistory Recordnn");
  171. ptr += get_history_info(ptr);
  172. len = strlen(page);
  173. *start = 0;
  174. if (off+count >= len) {
  175. *eof = 1;
  176. } else {
  177. *eof = 0;
  178. }
  179. return len;
  180. }
  181. int __init ftape_proc_init(void)
  182. {
  183. return create_proc_read_entry("ftape", 0, &proc_root,
  184. ftape_read_proc, NULL) != NULL;
  185. }
  186. #ifdef MODULE
  187. void ftape_proc_destroy(void)
  188. {
  189. remove_proc_entry("ftape", &proc_root);
  190. }
  191. #endif
  192. #endif /* defined(CONFIG_PROC_FS) && defined(CONFIG_FT_PROC_FS) */