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

##### Functions

    fat_encode        X
    fat_write         X

       1: #include <stdio.h>
       2: #include "msdos.h"
       3:
       4: extern int fd, dir_start, num_fat, fat_len, fat_error, fat_bits;
       5: extern unsigned char *fat_buf;
       6:
       7: /*
       8:  * Puts a code into the FAT table.  Is the opposite of fat_decode().  No
       9:  * sanity checking is done on the code.  Returns a 1 on error.
      10:  */
      11:
      12: int
      13: fat_encode(num, code)
      14: unsigned int num;
      15: unsigned int code;
      16: {
      17:     int start;
      18:
      19:     if (fat_bits == 12) {
      20:         /*
      21: 		 *	|    byte n     |   byte n+1    |   byte n+2    |
      22: 		 *	|7|6|5|4|3|2|1|0|7|6|5|4|3|2|1|0|7|6|5|4|3|2|1|0|
      23: 		 *	| | | | | | | | | | | | | | | | | | | | | | | | |
      24: 		 *	| n+0.0 | n+0.5 | n+1.0 | n+1.5 | n+2.0 | n+2.5 |
      25: 		 *	    \_____  \____   \______/________/_____   /
      26: 		 *	      ____\______\________/   _____/  ____\_/
      27: 		 *	     /     \      \          /       /     \
      28: 		 *	| n+1.5 | n+0.0 | n+0.5 | n+2.0 | n+2.5 | n+1.0 |
      29: 		 *	|      FAT entry k      |    FAT entry k+1      |
      30: 		 */
      31:                     /* which bytes contain the entry */
      32:         start = num * 3 / 2;
      33:         if (start <= 2 || start + 1 > (fat_len * MSECTOR_SIZE))
      34:             return(1);
      35:                     /* (odd) not on byte boundary */
      36:         if (num % 2) {
      37:             *(fat_buf + start) = (*(fat_buf + start) & 0x0f) + ((code << 4) & 0xf0);
      38:             *(fat_buf + start + 1) = (code >> 4) & 0xff;
      39:         }
      40:                     /* (even) on byte boundary */
      41:         else {
      42:             *(fat_buf + start) = code & 0xff;
      43:             *(fat_buf + start + 1) = (*(fat_buf + start + 1) & 0xf0) + ((code >> 8) & 0x0f);
      44:         }
      45:     }
      46:     else {
      47:         /*
      48: 		 *	|    byte n     |   byte n+1    |
      49: 		 *	|7|6|5|4|3|2|1|0|7|6|5|4|3|2|1|0|
      50: 		 *	| | | | | | | | | | | | | | | | |
      51: 		 *	|         FAT entry k           |
      52: 		 */
      53:                     /* which bytes contain the entry */
      54:         start = num * 2;
      55:         if (start <= 3 || start + 1 > (fat_len * MSECTOR_SIZE))
      56:             return(1);
      57:
      58:         *(fat_buf + start + 1) =  code / 0x100;
      59:         *(fat_buf + start) =  code % 0x100;
      60:     }
      61:     return(0);
      62: }
      63:
      64: /*
      65:  * Write the FAT table to the disk.  Up to now the FAT manipulation has
      66:  * been done in memory.  All errors are fatal.  (Might not be too smart
      67:  * to wait till the end of the program to write the table.  Oh well...)
      68:  */
      69:
      70: void
      71: fat_write()
      72: {
      73:     int fat_start, buflen, dups;
      74:     void disk_write();
      75:
      76:     if (fd < 0)
      77:         return;
      78:
      79:     fat_start = dir_start - (fat_len * num_fat);
      80:     buflen = fat_len * MSECTOR_SIZE;
      81:
      82:     disk_write((long) fat_start, fat_buf, buflen);
      83:
      84:     /*
      85: 	 * Only duplicate the FAT table if no errors were detected
      86: 	 */
      87:     if (!fat_error) {
      88:         dups = num_fat - 1;
      89:         while (dups--) {
      90:             fat_start += fat_len;
      91:             disk_write((long) fat_start, fat_buf, buflen);
      92:         }
      93:     }
      94:     return;
      95: }

#### Defined functions

fat_encode defined in line 12; used 8 times

- in /usr/src/local/mtools/dir_make.c line 45-46(2)
- in /usr/src/local/mtools/fat_free.c line 27
- in /usr/src/local/mtools/file_write.c line 34, 44, 51, 58
- in /usr/src/local/mtools/mmd.c line 148

fat_write defined in line 70; used 19 times

- in /usr/src/local/mtools/mdel.c line 34, 61, 123, 139-143(2)
- in /usr/src/local/mtools/mmd.c line 37, 68, 151, 200-204(2)
- in /usr/src/local/mtools/mrd.c line 34, 54, 117, 176-180(2)
- in /usr/src/local/mtools/mwrite.c line 46, 229, 321-325(2)

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