source: buchla-68k/libcio/fsinit.c@ fa50076

Last change on this file since fa50076 was f261cc8, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Minor cleanup.

  • Property mode set to 100644
File size: 4.7 KB
Line 
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
10int32_t *Stdbufs; /* buffer chain pointer */
11
12int8_t Wrkbuf[BPSEC]; /* sector work buffer */
13
14int32_t Stdbuf[MAXDFILE][BUFSIZL]; /* standard buffers */
15
16FILE Cbuffs[NSTREAMS]; /* stream file control table */
17
18struct fcb _fcbtab[MAXDFILE]; /* fcb table */
19
20struct 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
26int16_t _b_tbuf[9][256]; /* the track buffer */
27
28int16_t _b_trak; /* current track */
29int16_t _b_side; /* current side */
30int16_t _b_sect; /* current sector */
31int16_t _b_tsec; /* current base sector of current track */
32
33#endif
34
35/*
36 ============================================================================
37 _badfio() -- set "bad fd" error on I/O
38 ============================================================================
39*/
40
41int16_t _badfio(io_arg arg, void *buff, int16_t len)
42{
43 (void)arg;
44 (void)buff;
45 (void)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
57int16_t _badfc(io_arg arg)
58{
59 (void)arg;
60
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
71int16_t _nopo(int8_t *name, uint16_t flags, struct channel *chp, struct devtabl *dp)
72{
73 (void)name;
74 (void)flags;
75 (void)chp;
76 (void)dp;
77
78 return(SUCCESS); /* return with a non-error indication */
79}
80
81/*
82 ============================================================================
83 _nopc() -- null close with no error condition
84 ============================================================================
85*/
86
87int16_t _nopc(io_arg arg)
88{
89 (void)arg;
90
91 return(SUCCESS); /* return with a non-error indication */
92}
93
94/*
95 ============================================================================
96 InitCH() -- Initialize chantab structure entry
97 ============================================================================
98*/
99
100void InitCH(struct channel *cp, int16_t rdi, int16_t wri, int16_t ioi, int16_t ski, chclo cfp, io_arg charg)
101{
102 cp->c_read = rdi;
103 cp->c_write = wri;
104 cp->c_ioctl = ioi;
105 cp->c_seek = ski;
106 cp->c_close = cfp;
107 cp->c_arg = charg;
108}
109
110/*
111 ============================================================================
112 Init_CB() -- Initialize Cbuff structure entry
113 ============================================================================
114*/
115
116void Init_CB(FILE *fp, uint8_t flags, int16_t unit, int32_t *bufad, int16_t bufsize)
117{
118 fp->_bp = (int8_t *)0L;
119 fp->_bend = (int8_t *)0L;
120 fp->_buff = (int8_t *)bufad;
121 fp->_flags = flags;
122 fp->_unit = unit;
123 fp->_bytbuf = 0;
124 fp->_buflen = bufsize;
125}
126
127/*
128 ============================================================================
129 InitFS() -- Initialize file system
130 ============================================================================
131*/
132
133void InitFS(void)
134{
135 register int16_t i;
136
137 memset(_fcbtab, 0, sizeof _fcbtab); /* clear fcb table */
138 memsetw(Stdbuf, 0, sizeof Stdbuf / 2); /* clear buffers */
139
140 Init_CB(stdin, _BUSY, 0, NULL, BUFSIZ); /* stdin */
141 Init_CB(stdout, _BUSY, 1, NULL, 1); /* stdout */
142 Init_CB(stderr, _BUSY, 2, NULL, 1); /* stderr */
143
144 for (i = 3; i < NSTREAMS; i++)
145 Init_CB(&Cbuffs[i], 0, 0, NULL, 0);
146
147 Stdbuf[0][0] = 0L; /* initialize the buffer list */
148
149 for (i = 1; i < MAXDFILE; i++)
150 Stdbuf[i][0] = (int32_t)Stdbuf[i-1];
151
152 Stdbufs = Stdbuf[MAXDFILE-1];
153
154 InitCH(&chantab[0], 2, 0, 1, 0, _nopc, (io_arg)CON_DEV ); /* 0 - stdin */
155 InitCH(&chantab[1], 0, 2, 1, 0, _nopc, (io_arg)CON_DEV ); /* 1 - stdout */
156 InitCH(&chantab[2], 0, 2, 1, 0, _nopc, (io_arg)CON_DEV ); /* 2 - stderr */
157
158 for (i = 3; i < MAXCHAN; i++) /* 3..MAXCHAN-1 - not preassigned */
159 InitCH(&chantab[i], 0, 0, 0, 0, _badfc, (io_arg)-1 );
160
161 _bpbin = FALSE; /* BPB isn't in memory */
162 _dirin = FALSE; /* directory isn't in memory */
163 _fatin = FALSE; /* FAT isn't in memory */
164 _fatmod = FALSE; /* FAT hasn't been changed */
165 _dirmod = FALSE; /* directory hasn't been changed */
166
167#if TBUFFER
168 _b_trak = -1; /* no track in the buffer */
169 _b_side = -1; /* ... */
170#endif
171}
172
Note: See TracBrowser for help on using the repository browser.