| 1 | /*
|
|---|
| 2 | ============================================================================
|
|---|
| 3 | fsinit.c -- Initialize file system
|
|---|
| 4 | Version 9 -- 1988-01-31 -- D.N. Lynx Crowe
|
|---|
| 5 | ============================================================================
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #define _FS_DEF_ /* define so that stdio.h and io.h get things right */
|
|---|
| 9 |
|
|---|
| 10 | #include "biosdefs.h"
|
|---|
| 11 | #include "errno.h"
|
|---|
| 12 | #include "io.h"
|
|---|
| 13 | #include "stdio.h"
|
|---|
| 14 | #include "stddefs.h"
|
|---|
| 15 |
|
|---|
| 16 | extern int _bpbin, _dirin, _fatin, _dirmod, _fatmod;
|
|---|
| 17 |
|
|---|
| 18 | int _badfd(), _noper();
|
|---|
| 19 |
|
|---|
| 20 | char *Stdbufs; /* buffer chain pointer */
|
|---|
| 21 |
|
|---|
| 22 | char Wrkbuf[BPSEC]; /* sector work buffer */
|
|---|
| 23 |
|
|---|
| 24 | long Stdbuf[MAXDFILE][BUFSIZL]; /* standard buffers */
|
|---|
| 25 |
|
|---|
| 26 | FILE Cbuffs[NSTREAMS]; /* stream file control table */
|
|---|
| 27 |
|
|---|
| 28 | struct fcb _fcbtab[MAXDFILE]; /* fcb table */
|
|---|
| 29 |
|
|---|
| 30 | struct channel chantab[MAXCHAN]; /* channel table: relates fd's to devices */
|
|---|
| 31 |
|
|---|
| 32 | #if TBUFFER
|
|---|
| 33 |
|
|---|
| 34 | /* WARNING: this ONLY works for 512 byte sectors, 9 sectors per track */
|
|---|
| 35 |
|
|---|
| 36 | short _b_tbuf[9][256]; /* the track buffer */
|
|---|
| 37 |
|
|---|
| 38 | short _b_trak; /* current track */
|
|---|
| 39 | short _b_side; /* current side */
|
|---|
| 40 | short _b_sect; /* current sector */
|
|---|
| 41 | short _b_tsec; /* current base sector of current track */
|
|---|
| 42 |
|
|---|
| 43 | #endif
|
|---|
| 44 |
|
|---|
| 45 | /* |
|---|
| 46 |
|
|---|
| 47 | */
|
|---|
| 48 |
|
|---|
| 49 | /*
|
|---|
| 50 | ============================================================================
|
|---|
| 51 | _badfd() -- set "bad fd" error
|
|---|
| 52 | ============================================================================
|
|---|
| 53 | */
|
|---|
| 54 |
|
|---|
| 55 | int
|
|---|
| 56 | _badfd()
|
|---|
| 57 | {
|
|---|
| 58 | errno = EBADF; /* set bad fd code */
|
|---|
| 59 | return(FAILURE); /* return with an error indication */
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | /*
|
|---|
| 63 | ============================================================================
|
|---|
| 64 | _noper() -- null return with no error condition
|
|---|
| 65 | ============================================================================
|
|---|
| 66 | */
|
|---|
| 67 |
|
|---|
| 68 | int
|
|---|
| 69 | _noper()
|
|---|
| 70 | {
|
|---|
| 71 | return(SUCCESS); /* return with a non-error indication */
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | /* |
|---|
| 75 |
|
|---|
| 76 | */
|
|---|
| 77 |
|
|---|
| 78 | /*
|
|---|
| 79 | ============================================================================
|
|---|
| 80 | InitCH() -- Initialize chantab structure entry
|
|---|
| 81 | ============================================================================
|
|---|
| 82 | */
|
|---|
| 83 |
|
|---|
| 84 | InitCH(cp, rdi, wri, ioi, ski, cfp, charg)
|
|---|
| 85 | register struct channel *cp;
|
|---|
| 86 | char rdi, wri, ioi, ski;
|
|---|
| 87 | int (*cfp)();
|
|---|
| 88 | io_arg charg;
|
|---|
| 89 | {
|
|---|
| 90 | cp->c_read = rdi;
|
|---|
| 91 | cp->c_write = wri;
|
|---|
| 92 | cp->c_ioctl = ioi;
|
|---|
| 93 | cp->c_seek = ski;
|
|---|
| 94 | cp->c_close = cfp;
|
|---|
| 95 | cp->c_arg = charg;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | /*
|
|---|
| 99 | ============================================================================
|
|---|
| 100 | Init_CB() -- Initialize Cbuff structure entry
|
|---|
| 101 | ============================================================================
|
|---|
| 102 | */
|
|---|
| 103 |
|
|---|
| 104 | Init_CB(fp, flags, unit, bufad, bufsize)
|
|---|
| 105 | register FILE *fp;
|
|---|
| 106 | char unit, flags;
|
|---|
| 107 | long *bufad;
|
|---|
| 108 | int bufsize;
|
|---|
| 109 | {
|
|---|
| 110 | fp->_bp = (char *)0L;
|
|---|
| 111 | fp->_bend = (char *)0L;
|
|---|
| 112 | fp->_buff = (char *)bufad;
|
|---|
| 113 | fp->_flags = flags;
|
|---|
| 114 | fp->_unit = unit;
|
|---|
| 115 | fp->_bytbuf = 0;
|
|---|
| 116 | fp->_buflen = bufsize;
|
|---|
| 117 | };
|
|---|
| 118 |
|
|---|
| 119 | /* |
|---|
| 120 |
|
|---|
| 121 | */
|
|---|
| 122 |
|
|---|
| 123 | /*
|
|---|
| 124 | ============================================================================
|
|---|
| 125 | InitFS() -- Initialize file system
|
|---|
| 126 | ============================================================================
|
|---|
| 127 | */
|
|---|
| 128 |
|
|---|
| 129 | InitFS()
|
|---|
| 130 | {
|
|---|
| 131 | register int i;
|
|---|
| 132 |
|
|---|
| 133 | memset(_fcbtab, 0, sizeof _fcbtab); /* clear fcb table */
|
|---|
| 134 | memsetw(Stdbuf, 0, sizeof Stdbuf / 2); /* clear buffers */
|
|---|
| 135 |
|
|---|
| 136 | Init_CB(stdin, _BUSY, 0, (char *)0L, BUFSIZ); /* stdin */
|
|---|
| 137 | Init_CB(stdout, _BUSY, 1, (char *)0L, 1); /* stdout */
|
|---|
| 138 | Init_CB(stderr, _BUSY, 2, (char *)0L, 1); /* stderr */
|
|---|
| 139 |
|
|---|
| 140 | for (i = 3; i < NSTREAMS; i++)
|
|---|
| 141 | Init_CB(&Cbuffs[i], 0, 0, (char *)0L, 0);
|
|---|
| 142 |
|
|---|
| 143 | Stdbuf[0][0] = 0L; /* initialize the buffer list */
|
|---|
| 144 |
|
|---|
| 145 | for (i = 1; i < MAXDFILE; i++)
|
|---|
| 146 | Stdbuf[i][0] = (long)Stdbuf[i-1];
|
|---|
| 147 |
|
|---|
| 148 | Stdbufs = Stdbuf[MAXDFILE-1];
|
|---|
| 149 |
|
|---|
| 150 | InitCH(&chantab[0], 2, 0, 1, 0, _noper, (io_arg)CON_DEV ); /* 0 - stdin */
|
|---|
| 151 | InitCH(&chantab[1], 0, 2, 1, 0, _noper, (io_arg)CON_DEV ); /* 1 - stdout */
|
|---|
| 152 | InitCH(&chantab[2], 0, 2, 1, 0, _noper, (io_arg)CON_DEV ); /* 2 - stderr */
|
|---|
| 153 |
|
|---|
| 154 | for (i = 3; i < MAXCHAN; i++) /* 3..MAXCHAN-1 - not preassigned */
|
|---|
| 155 | InitCH(&chantab[i], 0, 0, 0, 0, _badfd, (io_arg)0L );
|
|---|
| 156 |
|
|---|
| 157 | _bpbin = FALSE; /* BPB isn't in memory */
|
|---|
| 158 | _dirin = FALSE; /* directory isn't in memory */
|
|---|
| 159 | _fatin = FALSE; /* FAT isn't in memory */
|
|---|
| 160 | _fatmod = FALSE; /* FAT hasn't been changed */
|
|---|
| 161 | _dirmod = FALSE; /* directory hasn't been changed */
|
|---|
| 162 |
|
|---|
| 163 | #if TBUFFER
|
|---|
| 164 | _b_trak = -1; /* no track in the buffer */
|
|---|
| 165 | _b_side = -1; /* ... */
|
|---|
| 166 | #endif
|
|---|
| 167 | }
|
|---|