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