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