[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 |
|
---|
| 37 | */
|
---|
| 38 |
|
---|
| 39 | /*
|
---|
| 40 | ============================================================================
|
---|
| 41 | _badfd() -- set "bad fd" error
|
---|
| 42 | ============================================================================
|
---|
| 43 | */
|
---|
[7258c6a] | 44 |
|
---|
[f40a309] | 45 | int16_t _badfd(void)
|
---|
| 46 | {
|
---|
| 47 | errno = EBADF; /* set bad fd code */
|
---|
| 48 | return(FAILURE); /* return with an error indication */
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | /*
|
---|
| 52 | ============================================================================
|
---|
| 53 | _noper() -- null return with no error condition
|
---|
| 54 | ============================================================================
|
---|
| 55 | */
|
---|
[7258c6a] | 56 |
|
---|
[f40a309] | 57 | int16_t _noper(void)
|
---|
| 58 | {
|
---|
| 59 | return(SUCCESS); /* return with a non-error indication */
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | /* |
---|
| 63 |
|
---|
| 64 | */
|
---|
| 65 |
|
---|
| 66 | /*
|
---|
| 67 | ============================================================================
|
---|
| 68 | InitCH() -- Initialize chantab structure entry
|
---|
| 69 | ============================================================================
|
---|
[7258c6a] | 70 | */
|
---|
[f40a309] | 71 |
|
---|
| 72 | void InitCH(struct channel *cp, int8_t rdi, int8_t wri, int8_t ioi, int8_t ski, int16_t (*cfp)(), io_arg charg)
|
---|
| 73 | {
|
---|
| 74 | cp->c_read = rdi;
|
---|
| 75 | cp->c_write = wri;
|
---|
| 76 | cp->c_ioctl = ioi;
|
---|
| 77 | cp->c_seek = ski;
|
---|
| 78 | cp->c_close = cfp;
|
---|
| 79 | cp->c_arg = charg;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | /*
|
---|
| 83 | ============================================================================
|
---|
| 84 | Init_CB() -- Initialize Cbuff structure entry
|
---|
| 85 | ============================================================================
|
---|
[7258c6a] | 86 | */
|
---|
[f40a309] | 87 |
|
---|
[7258c6a] | 88 | void Init_CB(FILE *fp, int8_t unit, int8_t flags, int32_t *bufad, int16_t bufsize)
|
---|
| 89 | {
|
---|
| 90 | fp->_bp = (int8_t *)0L;
|
---|
[f40a309] | 91 | fp->_bend = (int8_t *)0L;
|
---|
| 92 | fp->_buff = (int8_t *)bufad;
|
---|
| 93 | fp->_flags = flags;
|
---|
| 94 | fp->_unit = unit;
|
---|
| 95 | fp->_bytbuf = 0;
|
---|
| 96 | fp->_buflen = bufsize;
|
---|
| 97 | };
|
---|
| 98 |
|
---|
| 99 | /* |
---|
| 100 |
|
---|
| 101 | */
|
---|
| 102 |
|
---|
| 103 | /*
|
---|
| 104 | ============================================================================
|
---|
| 105 | InitFS() -- Initialize file system
|
---|
[0580615] | 106 | ============================================================================
|
---|
[f40a309] | 107 | */
|
---|
[7258c6a] | 108 |
|
---|
[f40a309] | 109 | void InitFS(void)
|
---|
| 110 | {
|
---|
| 111 | register int16_t i;
|
---|
| 112 |
|
---|
[7258c6a] | 113 | memset(_fcbtab, 0, sizeof _fcbtab); /* clear fcb table */
|
---|
| 114 | memsetw(Stdbuf, 0, sizeof Stdbuf / 2); /* clear buffers */
|
---|
| 115 |
|
---|
[f40a309] | 116 | Init_CB(stdin, _BUSY, 0, (int8_t *)0L, BUFSIZ); /* stdin */
|
---|
| 117 | Init_CB(stdout, _BUSY, 1, (int8_t *)0L, 1); /* stdout */
|
---|
[7258c6a] | 118 | Init_CB(stderr, _BUSY, 2, (int8_t *)0L, 1); /* stderr */
|
---|
[f40a309] | 119 |
|
---|
| 120 | for (i = 3; i < NSTREAMS; i++)
|
---|
| 121 | Init_CB(&Cbuffs[i], 0, 0, (int8_t *)0L, 0);
|
---|
| 122 |
|
---|
[7258c6a] | 123 | Stdbuf[0][0] = 0L; /* initialize the buffer list */
|
---|
[f40a309] | 124 |
|
---|
| 125 | for (i = 1; i < MAXDFILE; i++)
|
---|
| 126 | Stdbuf[i][0] = (int32_t)Stdbuf[i-1];
|
---|
| 127 |
|
---|
| 128 | Stdbufs = Stdbuf[MAXDFILE-1];
|
---|
| 129 |
|
---|
| 130 | InitCH(&chantab[0], 2, 0, 1, 0, _noper, (io_arg)CON_DEV ); /* 0 - stdin */
|
---|
| 131 | InitCH(&chantab[1], 0, 2, 1, 0, _noper, (io_arg)CON_DEV ); /* 1 - stdout */
|
---|
| 132 | InitCH(&chantab[2], 0, 2, 1, 0, _noper, (io_arg)CON_DEV ); /* 2 - stderr */
|
---|
| 133 |
|
---|
| 134 | for (i = 3; i < MAXCHAN; i++) /* 3..MAXCHAN-1 - not preassigned */
|
---|
| 135 | InitCH(&chantab[i], 0, 0, 0, 0, _badfd, (io_arg)0L );
|
---|
| 136 |
|
---|
| 137 | _bpbin = FALSE; /* BPB isn't in memory */
|
---|
| 138 | _dirin = FALSE; /* directory isn't in memory */
|
---|
| 139 | _fatin = FALSE; /* FAT isn't in memory */
|
---|
| 140 | _fatmod = FALSE; /* FAT hasn't been changed */
|
---|
| 141 | _dirmod = FALSE; /* directory hasn't been changed */
|
---|
| 142 |
|
---|
| 143 | #if TBUFFER
|
---|
| 144 | _b_trak = -1; /* no track in the buffer */
|
---|
[6262b5c] | 145 | _b_side = -1; /* ... */
|
---|
| 146 | #endif
|
---|
| 147 | }
|
---|
| 148 |
|
---|