eata_pio_proc.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:4k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /*
  2.  * eata_set_info
  3.  * buffer : pointer to the data that has been written to the hostfile
  4.  * length : number of bytes written to the hostfile
  5.  * HBA_ptr: pointer to the Scsi_Host struct
  6.  */
  7. int eata_pio_set_info(char *buffer, int length, struct Scsi_Host *HBA_ptr)
  8. {
  9.     DBG(DBG_PROC_WRITE, printk("%sn", buffer));
  10.     return(-ENOSYS);  /* Currently this is a no-op */
  11. }
  12. /*
  13.  * eata_proc_info
  14.  * inout : decides on the direction of the dataflow and the meaning of the 
  15.  *         variables
  16.  * buffer: If inout==FALSE data is being written to it else read from it
  17.  * *start: If inout==FALSE start of the valid data in the buffer
  18.  * offset: If inout==FALSE offset from the beginning of the imaginary file 
  19.  *         from which we start writing into the buffer
  20.  * length: If inout==FALSE max number of bytes to be written into the buffer 
  21.  *         else number of bytes in the buffer
  22.  */
  23. int eata_pio_proc_info(char *buffer, char **start, off_t offset, int length, 
  24.        int hostno, int inout)
  25. {
  26.     Scsi_Device *scd;
  27.     struct Scsi_Host *HBA_ptr;
  28.     static u8 buff[512];
  29.     int i; 
  30.     int   size, len = 0;
  31.     off_t begin = 0;
  32.     off_t pos = 0;
  33.     HBA_ptr = first_HBA;
  34.     for (i = 1; i <= registered_HBAs; i++) {
  35. if (HBA_ptr->host_no == hostno)
  36.     break;
  37. HBA_ptr = SD(HBA_ptr)->next;
  38.     }        
  39.     if(inout == TRUE) /* Has data been written to the file ? */ 
  40. return(eata_pio_set_info(buffer, length, HBA_ptr));
  41.     if (offset == 0)
  42. memset(buff, 0, sizeof(buff));
  43.     size = sprintf(buffer+len, "EATA (Extended Attachment) PIO driver version: "
  44.    "%d.%d%sn",VER_MAJOR, VER_MINOR, VER_SUB);
  45.     len += size; pos = begin + len;
  46.     size = sprintf(buffer + len, "queued commands:     %10ldn"
  47.    "processed interrupts:%10ldn", queue_counter, int_counter);
  48.     len += size; pos = begin + len;
  49.     
  50.     size = sprintf(buffer + len, "nscsi%-2d: HBA %.10sn",
  51.    HBA_ptr->host_no, SD(HBA_ptr)->name);
  52.     len += size; 
  53.     pos = begin + len;
  54.     size = sprintf(buffer + len, "Firmware revision: v%sn", 
  55.    SD(HBA_ptr)->revision);
  56.     len += size;
  57.     pos = begin + len;
  58.     size = sprintf(buffer + len, "IO: PIOn");
  59.     len += size; 
  60.     pos = begin + len;
  61.     size = sprintf(buffer + len, "Base IO : %#.4xn", (u32) HBA_ptr->base);
  62.     len += size; 
  63.     pos = begin + len;
  64.     size = sprintf(buffer + len, "Host Bus: %sn", 
  65.    (SD(HBA_ptr)->bustype == 'P')?"PCI ":
  66.    (SD(HBA_ptr)->bustype == 'E')?"EISA":"ISA ");
  67.     
  68.     len += size; 
  69.     pos = begin + len;
  70.     
  71.     if (pos < offset) {
  72. len = 0;
  73. begin = pos;
  74.     }
  75.     if (pos > offset + length)
  76. goto stop_output;
  77.     
  78.     size = sprintf(buffer+len,"Attached devices: %sn", 
  79.    (HBA_ptr->host_queue)?"":"none");
  80.     len += size; 
  81.     pos = begin + len;
  82.     
  83.     for(scd = HBA_ptr->host_queue; scd; scd = scd->next) {
  84.     proc_print_scsidevice(scd, buffer, &size, len);
  85.     len += size; 
  86.     pos = begin + len;
  87.     
  88.     if (pos < offset) {
  89. len = 0;
  90. begin = pos;
  91.     }
  92.     if (pos > offset + length)
  93. goto stop_output;
  94.     }
  95.     
  96.  stop_output:
  97.     DBG(DBG_PROC, printk("2pos: %ld offset: %ld len: %dn", pos, offset, len));
  98.     *start=buffer+(offset-begin);   /* Start of wanted data */
  99.     len-=(offset-begin);            /* Start slop */
  100.     if(len>length)
  101. len = length;               /* Ending slop */
  102.     DBG(DBG_PROC, printk("3pos: %ld offset: %ld len: %dn", pos, offset, len));
  103.     
  104.     return (len);     
  105. }
  106. /*
  107.  * Overrides for Emacs so that we follow Linus's tabbing style.
  108.  * Emacs will notice this stuff at the end of the file and automatically
  109.  * adjust the settings for this buffer only.  This must remain at the end
  110.  * of the file.
  111.  * ---------------------------------------------------------------------------
  112.  * Local variables:
  113.  * c-indent-level: 4
  114.  * c-brace-imaginary-offset: 0
  115.  * c-brace-offset: -4
  116.  * c-argdecl-indent: 4
  117.  * c-label-offset: -4
  118.  * c-continued-statement-offset: 4
  119.  * c-continued-brace-offset: 0
  120.  * tab-width: 8
  121.  * End:
  122.  */