# 2.11BSD#431 - /usr/src/local/mtools/buf_read.c

##### Functions

    disk_read         X

##### Variables

    disk_buf          X
    disk_current      X
    disk_dirty        X
    disk_size         X

       1: /*
       2:  * Do full cylinder buffered reads from slow devices.  Uses a simple
       3:  * buffered read/delayed write algorithm.
       4:  */
       5:
       6: #include <stdio.h>
       7: #include "msdos.h"
       8:
       9: unsigned char *disk_buf;        /* disk read/write buffer */
      10: int disk_size;              /* size of read/write buffer */
      11: long disk_current;          /* first sector in buffer */
      12: int disk_dirty;             /* is the buffer dirty? */
      13:
      14: extern int fd;
      15: extern long disk_offset;
      16:
      17: void
      18: disk_read(start, buf, len)
      19: long start;
      20: unsigned char *buf;
      21: int len;
      22: {
      23:     register long i;
      24:     int length;
      25:     unsigned char *buf_ptr, *disk_ptr;
      26:     char *memcpy();
      27:     long where, tail, lseek();
      28:     void perror(), exit(), disk_flush();
      29:
      30:                     /* don't use cache? */
      31:     if (disk_size == 1) {
      32:         where = (start * MSECTOR_SIZE) + disk_offset;
      33:         if (lseek(fd, where, 0) < 0) {
      34:             perror("disk_read: lseek");
      35:             exit(1);
      36:         }
      37:                     /* read it! */
      38:         if (read(fd, (char *) buf, (unsigned int) len) != len) {
      39:             perror("disk_read: read");
      40:             exit(1);
      41:         }
      42:         return;
      43:     }
      44:
      45:     tail = start + (len / MSECTOR_SIZE) - 1;
      46:     for (i = start; i <= tail; i++) {
      47:                     /* a "cache" miss */
      48:         if (i < disk_current || i >= disk_current + disk_size) {
      49:
      50:             if (disk_dirty)
      51:                 disk_flush();
      52:
      53:             disk_current = (i / disk_size) * disk_size;
      54:             where = (disk_current * MSECTOR_SIZE) + disk_offset;
      55:             length = disk_size * MSECTOR_SIZE;
      56:
      57:                     /* move to next location */
      58:             if (lseek(fd, where, 0) < 0) {
      59:                 perror("disk_read: lseek");
      60:                 exit(1);
      61:             }
      62:                     /* read it! */
      63:             if (read(fd, (char *) disk_buf, (unsigned int) length) != length) {
      64:                 perror("disk_read: read");
      65:                 exit(1);
      66:             }
      67:         }
      68:                     /* a cache hit... */
      69:         buf_ptr = buf + ((i - start) * MSECTOR_SIZE);
      70:         disk_ptr = disk_buf + ((i - disk_current) * MSECTOR_SIZE);
      71:         memcpy((char *) buf_ptr, (char *) disk_ptr, MSECTOR_SIZE);
      72:     }
      73:     return;
      74: }

#### Defined functions

disk_read defined in line 17; used 12 times

- in /usr/src/local/mtools/dir_make.c line 25, 69
- in /usr/src/local/mtools/dir_read.c line 41, 82, 99, 115
- in /usr/src/local/mtools/fat_read.c line 81, 90
- in /usr/src/local/mtools/file_read.c line 23, 34
- in /usr/src/local/mtools/mrd.c line 138, 144

#### Defined variables

disk_buf defined in line 9; used 8 times

- in line 63, 70
- in /usr/src/local/mtools/buf_write.c line 69, 77, 106
- in /usr/src/local/mtools/init.c line 44, 219-220(2)

disk_current defined in line 11; used 14 times

- in line 48-54(4), 70
- in /usr/src/local/mtools/buf_write.c line 46(2), 57-60(3), 77, 96-99(2)
- in /usr/src/local/mtools/init.c line 225

disk_dirty defined in line 12; used 6 times

- in line 50
- in /usr/src/local/mtools/buf_write.c line 48, 79, 96, 110
- in /usr/src/local/mtools/init.c line 226

disk_size defined in line 10; used 20 times

- in line 31, 48-55(4)
- in /usr/src/local/mtools/buf_write.c line 29, 46, 57-61(5), 105, 127-132(3)
- in /usr/src/local/mtools/init.c line 207-209(2), 216-219(2)

Last modified: 1992-06-24 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 530 |