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