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

##### Functions

    dir_read          X
    fill_chain        X
    reset_chain       X
    unix_name         X

##### Variables

    dir_buf           X
    dir_chain         X
    dir_dirty         X

       1: #include <stdio.h>
       2: #include "msdos.h"
       3:
       4: long dir_chain[MAX_DIR_SECS];       /* chain of sectors in directory */
       5: unsigned char *dir_buf;         /* the directory buffer */
       6: int dir_dirty;              /* is the buffer dirty? */
       7:
       8: extern int dir_len, dir_start, clus_size, dir_entries, fat_error;
       9: extern unsigned int last_fat;
      10:
      11: /*
      12:  * Read a directory entry, return a pointer a static structure.
      13:  */
      14:
      15: struct directory *
      16: dir_read(num)
      17: int num;
      18: {
      19:     char *memcpy();
      20:     unsigned char *offset;
      21:     static struct directory dir;
      22:
      23:     offset = dir_buf + (num * MDIR_SIZE);
      24:     memcpy((char *) &dir, (char *) offset, MDIR_SIZE);
      25:     return(&dir);
      26: }
      27:
      28: /*
      29:  * Fill in the global variable dir_chain[].  Argument is the starting
      30:  * cluster number.  Returns -1 on error.
      31:  */
      32:
      33: int
      34: fill_chain(num)
      35: unsigned int num;
      36: {
      37:     register int i, length;
      38:     unsigned int next, fat_decode();
      39:     unsigned char *offset;
      40:     char *malloc();
      41:     void free(), perror(), exit(), disk_read(), dir_flush();
      42:
      43:     length = 0;
      44:     /* CONSTCOND */
      45:     while (1) {
      46:         dir_chain[length] = (long) (num - 2) * clus_size + dir_start + dir_len;
      47:         length++;
      48:                     /* sectors, not clusters! */
      49:         for (i = 1; i < clus_size; i++) {
      50:             dir_chain[length] = dir_chain[length - 1] + 1L;
      51:             length++;
      52:         }
      53:
      54:         if (length >= MAX_DIR_SECS) {
      55:             fprintf(stderr, "fill_chain: directory too large\n");
      56:             return(-1);
      57:         }
      58:                     /* get next cluster number */
      59:         next = fat_decode(num);
      60:         if (next == 1) {
      61:             fprintf(stderr, "fill_chain: FAT problem\n");
      62:             fat_error++;
      63:             return(-1);
      64:         }
      65:                     /* end of cluster chain */
      66:         if (next >= last_fat)
      67:             break;
      68:         num = next;
      69:     }
      70:     if (dir_dirty)
      71:         dir_flush();
      72:                     /* fill the dir_buf */
      73:     free((char *) dir_buf);
      74:     dir_buf = (unsigned char *) malloc((unsigned int) length * MSECTOR_SIZE);
      75:     if (dir_buf == NULL) {
      76:         perror("fill_chain: malloc");
      77:         exit(1);
      78:     }
      79:
      80:     for (i = 0; i < length; i++) {
      81:         offset = dir_buf + (i * MSECTOR_SIZE);
      82:         disk_read(dir_chain[i], offset, MSECTOR_SIZE);
      83:     }
      84:
      85:     dir_entries = length * 16;
      86:     return(0);
      87: }
      88:
      89: /*
      90:  * Reset the global variable dir_chain[] to the root directory.
      91:  */
      92:
      93: void
      94: reset_chain(code)
      95: int code;
      96: {
      97:     register int i;
      98:     char *malloc();
      99:     void free(), disk_read(), dir_flush(), exit(), perror();
     100:
     101:     if (dir_dirty)
     102:         dir_flush();
     103:
     104:     for (i = 0; i < dir_len; i++)
     105:         dir_chain[i] = (long) dir_start + i;
     106:
     107:     if (code == OLD)
     108:         free((char *) dir_buf);
     109:
     110:     dir_buf = (unsigned char *) malloc((unsigned int) dir_len * MSECTOR_SIZE);
     111:     if (dir_buf == NULL) {
     112:         perror("reset_chain: malloc");
     113:         exit(1);
     114:     }
     115:     disk_read((long) dir_start, dir_buf, dir_len * MSECTOR_SIZE);
     116:
     117:     dir_entries = dir_len * 16;
     118:     return;
     119: }
     120:
     121: /*
     122:  * Get rid of spaces in an MSDOS 'raw' name (one that has come from the
     123:  * directory structure) so that it can be used for regular expression
     124:  * matching with a unix filename.  Also used to 'unfix' a name that has
     125:  * been altered by dos_name().  Returns a pointer a static buffer.
     126:  */
     127:
     128: char *
     129: unix_name(name, ext)
     130: unsigned char *name, *ext;
     131: {
     132:     char *s, tname[9], text[4], *strcpy(), *strcat(), *strchr();
     133:     char *strncpy();
     134:     static char ans[13];
     135:
     136:     strncpy(tname, (char *) name, 8);
     137:     tname[8] = '\0';
     138:     if (s = strchr(tname, ' '))
     139:         *s = '\0';
     140:
     141:     strncpy(text, (char *) ext, 3);
     142:     text[3] = '\0';
     143:     if (s = strchr(text, ' '))
     144:         *s = '\0';
     145:
     146:     if (*text) {
     147:         strcpy(ans, tname);
     148:         strcat(ans, ".");
     149:         strcat(ans, text);
     150:     }
     151:     else
     152:         strcpy(ans, tname);
     153:     return(ans);
     154: }

#### Defined functions

dir_read defined in line 15; used 25 times

- in /usr/src/local/mtools/is_dir.c line 17, 23
- in /usr/src/local/mtools/mattrib.c line 36, 109
- in /usr/src/local/mtools/mdel.c line 35, 80
- in /usr/src/local/mtools/mdir.c line 37, 94, 155
- in /usr/src/local/mtools/mlabel.c line 33, 66
- in /usr/src/local/mtools/mmd.c line 38, 92
- in /usr/src/local/mtools/mrd.c line 35, 74
- in /usr/src/local/mtools/mread.c line 51, 116
- in /usr/src/local/mtools/mren.c line 33, 81
- in /usr/src/local/mtools/mtype.c line 35, 79
- in /usr/src/local/mtools/mwrite.c line 47, 135
- in /usr/src/local/mtools/subdir.c line 57, 64

fill_chain defined in line 33; used 1 times

- in /usr/src/local/mtools/subdir.c line 92

reset_chain defined in line 93; used 7 times

- in /usr/src/local/mtools/init.c line 37, 232
- in /usr/src/local/mtools/subdir.c line 20, 27, 58, 88, 104

unix_name defined in line 128; used 25 times

- in /usr/src/local/mtools/is_dir.c line 16, 34
- in /usr/src/local/mtools/mattrib.c line 33, 120
- in /usr/src/local/mtools/mdel.c line 32, 91
- in /usr/src/local/mtools/mdir.c line 34, 166
- in /usr/src/local/mtools/mmd.c line 35, 82, 110
- in /usr/src/local/mtools/mrd.c line 33, 85
- in /usr/src/local/mtools/mread.c line 47, 127
- in /usr/src/local/mtools/mren.c line 28, 63, 92
- in /usr/src/local/mtools/mtype.c line 32, 90
- in /usr/src/local/mtools/mwrite.c line 43, 127, 160
- in /usr/src/local/mtools/subdir.c line 56, 75

#### Defined variables

dir_buf defined in line 5; used 16 times

- in line 23, 73-75(3), 81, 108-115(4)
- in /usr/src/local/mtools/dir_make.c line 63-68(4)
- in /usr/src/local/mtools/dir_write.c line 23, 46
- in /usr/src/local/mtools/init.c line 45

dir_chain defined in line 4; used 8 times

- in line 46-50(3), 82, 105
- in /usr/src/local/mtools/dir_make.c line 59, 69
- in /usr/src/local/mtools/dir_write.c line 47

dir_dirty defined in line 6; used 6 times

- in line 70, 101
- in /usr/src/local/mtools/dir_write.c line 25, 41, 49
- in /usr/src/local/mtools/init.c line 231

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