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