1 /*
2  * This file has been modified as part of the FreeMiNT project. See
3  * the file Changes.MH for details and dates.
4  */
5 
6 /*
7  * Copyright 1991,1992 Eric R. Smith.
8  * Copyright 1992,1993,1994 Atari Corporation.
9  * All rights reserved.
10  */
11 
12 # ifndef _mint_fsops_h
13 # define _mint_fsops_h
14 
15 #include "mint/stat.h"
16 
17 typedef struct file FILEPTR;
18 typedef struct filesys FILESYS;
19 typedef struct fcookie fcookie;
20 typedef struct dirstruct DIR;
21 typedef struct devdrv DEVDRV;
22 typedef struct ilock LOCK;
23 
24 struct fcookie
25 {
26 	FILESYS	*fs;		/* filesystem that knows about this cookie */
27 	ushort	dev;		/* device info (e.g. Rwabs device number) */
28 	ushort	aux;		/* extra data that the file system may want */
29 	long	index;		/* this+dev uniquely identifies a file */
30 };
31 
32 /* structure for opendir/readdir/closedir */
33 struct dirstruct
34 {
35 	fcookie fc;		/* cookie for this directory */
36 	ushort	index;		/* index of the current entry */
37 	ushort	flags;		/* flags (e.g. tos or not) */
38 # define TOS_SEARCH	0x01
39 	char	fsstuff[60];	/* anything else the file system wants */
40 				/* NOTE: this must be at least 45 bytes */
41 	DIR	*next;		/* linked together so we can close them
42 				 * on process termination */
43 	short	fd;		/* associated fd, for use with dirfd */
44 };
45 
46 struct devdrv
47 {
48 	long _cdecl (*open)	(FILEPTR *f);
49 	long _cdecl (*write)	(FILEPTR *f, const char *buf, long bytes);
50 	long _cdecl (*read)	(FILEPTR *f, char *buf, long bytes);
51 	long _cdecl (*lseek)	(FILEPTR *f, long where, int whence);
52 	long _cdecl (*ioctl)	(FILEPTR *f, int mode, void *buf);
53 	long _cdecl (*datime)	(FILEPTR *f, ushort *timeptr, int rwflag);
54 	long _cdecl (*close)	(FILEPTR *f, int pid);
55 	long _cdecl (*select)	(FILEPTR *f, long proc, int mode);
56 	void _cdecl (*unselect)	(FILEPTR *f, long proc, int mode);
57 
58 	/* extensions, check dev_descr.drvsize (size of DEVDRV struct) before calling:
59 	 * fast RAW tty byte io
60 	 */
61 	long _cdecl (*writeb)	(FILEPTR *f, const char *buf, long bytes);
62 	long _cdecl (*readb)	(FILEPTR *f, char *buf, long bytes);
63 
64 	/* what about: scatter/gather io for DMA devices...
65 	 * long _cdecl (*writev)(FILEPTR *f, const struct iovec *iov, long cnt);
66 	 * long _cdecl (*readv)	(FILEPTR *f, struct iovec *iov, long cnt);
67 	 */
68 };
69 
70 struct filesys
71 {
72 	/* kernel data
73 	 */
74 	FILESYS	*next;			/* link to next file system on chain */
75 	long	fsflags;
76 # define FS_KNOPARSE		0x0001	/* kernel shouldn't do parsing */
77 # define FS_CASESENSITIVE	0x0002	/* file names are case sensitive */
78 # define FS_NOXBIT		0x0004	/* if a file can be read, it can be executed */
79 # define FS_LONGPATH		0x0008	/* file system understands "size" argument to "getname" */
80 # define FS_NO_C_CACHE		0x0010	/* don't cache cookies for this filesystem */
81 # define FS_DO_SYNC		0x0020	/* file system has a sync function */
82 # define FS_OWN_MEDIACHANGE	0x0040	/* filesystem control self media change (dskchng) */
83 # define FS_REENTRANT_L1	0x0080	/* fs is level 1 reentrant */
84 # define FS_REENTRANT_L2	0x0100	/* fs is level 2 reentrant */
85 # define FS_EXT_1		0x0200	/* extensions level 1 - mknod & unmount */
86 # define FS_EXT_2		0x0400	/* extensions level 2 - additional place at the end */
87 # define FS_EXT_3		0x0800	/* extensions level 3 - stat & native UTC timestamps */
88 
89 	/* filesystem functions
90 	 */
91 	long	_cdecl (*root)		(int drv, fcookie *fc);
92 	long	_cdecl (*lookup)	(fcookie *dir, const char *name, fcookie *fc);
93 	long	_cdecl (*creat)		(fcookie *dir, const char *name, unsigned mode, int attrib, fcookie *fc);
94 	DEVDRV*	_cdecl (*getdev)	(fcookie *file, long *devspecial);
95 	long	_cdecl (*getxattr)	(fcookie *file, XATTR *xattr);
96 	long	_cdecl (*chattr)	(fcookie *file, int attr);
97 	long	_cdecl (*chown)		(fcookie *file, int uid, int gid);
98 	long	_cdecl (*chmode)	(fcookie *file, unsigned mode);
99 	long	_cdecl (*mkdir)		(fcookie *dir, const char *name, unsigned mode);
100 	long	_cdecl (*rmdir)		(fcookie *dir, const char *name);
101 	long	_cdecl (*remove)	(fcookie *dir, const char *name);
102 	long	_cdecl (*getname)	(fcookie *relto, fcookie *dir, char *pathname, int size);
103 	long	_cdecl (*rename)	(fcookie *olddir, char *oldname, fcookie *newdir, const char *newname);
104 	long	_cdecl (*opendir)	(DIR *dirh, int tosflag);
105 	long	_cdecl (*readdir)	(DIR *dirh, char *name, int namelen, fcookie *fc);
106 	long	_cdecl (*rewinddir)	(DIR *dirh);
107 	long	_cdecl (*closedir)	(DIR *dirh);
108 	long	_cdecl (*pathconf)	(fcookie *dir, int which);
109 	long	_cdecl (*dfree)		(fcookie *dir, long *buf);
110 	long	_cdecl (*writelabel)	(fcookie *dir, const char *name);
111 	long	_cdecl (*readlabel)	(fcookie *dir, char *name, int namelen);
112 	long	_cdecl (*symlink)	(fcookie *dir, const char *name, const char *to);
113 	long	_cdecl (*readlink)	(fcookie *dir, char *buf, int len);
114 	long	_cdecl (*hardlink)	(fcookie *fromdir, const char *fromname, fcookie *todir, const char *toname);
115 	long	_cdecl (*fscntl)	(fcookie *dir, const char *name, int cmd, long arg);
116 	long	_cdecl (*dskchng)	(int drv, int mode);
117 	long	_cdecl (*release)	(fcookie *);
118 	long	_cdecl (*dupcookie)	(fcookie *new, fcookie *old);
119 	long	_cdecl (*sync)		(void);
120 	long	_cdecl (*mknod)		(fcookie *dir, const char *name, ulong mode);
121 	long	_cdecl (*unmount)	(int drv);
122 	long	_cdecl (*stat64)	(fcookie *file, STAT *stat);
123 
124 	long	res1, res2, res3;	/* reserved */
125 
126 	/* experimental extension
127 	 */
128 	ulong	lock;			/* for non-blocking DMA */
129 	ulong	sleepers;		/* sleepers on this filesystem */
130 	void	_cdecl (*block)		(FILESYS *fs, ushort dev, const char *);
131 	void	_cdecl (*deblock)	(FILESYS *fs, ushort dev, const char *);
132 };
133 
134 
135 /* various character constants and defines for TTY's */
136 # define MiNTEOF	0x0000ff1a	/* 1a == ^Z */
137 
138 /* defines for tty_read */
139 # define RAW		0
140 # define COOKED		0x1
141 # define NOECHO		0
142 # define ECHO		0x2
143 # define ESCSEQ		0x04		/* cursor keys, etc. get escape sequences */
144 
145 
146 /* terminal control constants (tty.sg_flags)
147  */
148 # define T_CRMOD	0x0001
149 # define T_CBREAK	0x0002
150 # define T_ECHO		0x0004
151 # define T_XTABS_notyet	0x0008		/* unimplemented */
152 # define T_RAW		0x0010
153 # define T_LCASE_notyet	0x0020		/* unimplemented */
154 
155 # define T_NOFLSH	0x0040		/* don't flush buffer when signals
156 					   are received */
157 # define T_TOS		0x0080
158 # define T_TOSTOP	0x0100
159 # define T_XKEY		0x0200		/* Fread returns escape sequences for
160 					   cursor keys, etc. */
161 # define T_ECHOCTL	0x0400		/* echo ctl chars as ^x */
162 /* 0x0800 still available */
163 
164 # define T_TANDEM	0x1000
165 # define T_RTSCTS	0x2000
166 # define T_EVENP	0x4000		/* EVENP and ODDP are mutually exclusive */
167 # define T_ODDP		0x8000
168 
169 # define TF_FLAGS	0xF000
170 
171 /* some flags for TIOC[GS]FLAGS */
172 # define TF_BRKINT	0x0080		/* allow breaks interrupt (like ^C) */
173 # define TF_CAR		0x0800		/* nonlocal mode, require carrier */
174 # define TF_NLOCAL	TF_CAR
175 
176 # define TF_STOPBITS	0x0003
177 # define TF_1STOP	 0x001
178 # define TF_15STOP	 0x002
179 # define TF_2STOP	 0x003
180 
181 # define TF_CHARBITS	0x000C
182 # define TF_8BIT	 0x000
183 # define TF_7BIT	 0x004
184 # define TF_6BIT	 0x008
185 # define TF_5BIT	 0x00C
186 
187 /* the following are terminal status flags (tty.state) */
188 /* (the low byte of tty.state indicates a part of an escape sequence still
189  * hasn't been read by Fread, and is an index into that escape sequence)
190  */
191 # define TS_ESC		0x00ff
192 # define TS_BLIND	0x0800		/* tty is `blind' i.e. has no carrier
193 					   (cleared in local mode) */
194 # define TS_HOLD	0x1000		/* hold (e.g. ^S/^Q) */
195 # define TS_HPCL	0x4000		/* hang up on close */
196 # define TS_COOKED	0x8000		/* interpret control chars */
197 
198 /* structures for terminals
199  */
200 struct tchars
201 {
202 	char	t_intrc;
203 	char	t_quitc;
204 	char	t_startc;
205 	char	t_stopc;
206 	char	t_eofc;
207 	char	t_brkc;
208 };
209 
210 struct ltchars
211 {
212 	char	t_suspc;
213 	char	t_dsuspc;
214 	char	t_rprntc;
215 	char	t_flushc;
216 	char	t_werasc;
217 	char	t_lnextc;
218 };
219 
220 struct sgttyb
221 {
222 	char	sg_ispeed;
223 	char	sg_ospeed;
224 	char	sg_erase;
225 	char	sg_kill;
226 	ushort	sg_flags;
227 };
228 
229 struct winsize
230 {
231 	short	ws_row;
232 	short	ws_col;
233 	short	ws_xpixel;
234 	short	ws_ypixel;
235 };
236 
237 struct xkey
238 {
239 	short	xk_num;
240 	char	xk_def[8];
241 };
242 
243 struct tty
244 {
245 	short		pgrp;		/* process group of terminal */
246 	short		state;		/* terminal status, e.g. stopped */
247 	short		use_cnt;	/* number of times terminal is open */
248 	short		aux_cnt;	/* number of times terminal is open as /dev/aux */
249 	struct sgttyb 	sg;
250 	struct tchars 	tc;
251 	struct ltchars 	ltc;
252 	struct winsize	wsiz;
253 	long		rsel;		/* selecting process for read */
254 	long		wsel;		/* selecting process for write */
255 	char		*xkey;		/* extended keyboard table */
256 	long		hup_ospeed;	/* saved ospeed while hanging up */
257 	ushort		vmin, vtime;	/* min chars, timeout for RAW reads */
258 	long		resrvd[1];	/* for future expansion */
259 };
260 
261 
262 /* number of BIOS drives */
263 # define NDRIVES		32
264 # define NUM_DRIVES		NDRIVES
265 
266 # define BIOSDRV		(NUM_DRIVES)
267 # define PIPEDRV		(BIOSDRV + 1)
268 # define PROCDRV		(PIPEDRV + 1)
269 # ifndef NO_RAMFS
270 # define RAM_DRV		(PROCDRV + 1)
271 # define SHM_DRV		(RAM_DRV + 1)
272 # else
273 # define SHM_DRV		(PROCDRV + 1)
274 # endif
275 
276 # define UNIDRV			('U' - 'A')
277 # define PSEUDODRVS		((1L << UNIDRV))
278 
279 /* various fields for the "rdev" device numbers */
280 # define BIOS_DRIVE_RDEV 	0x0000
281 # define BIOS_RDEV		0x0100
282 # define FAKE_RDEV		0x0200
283 # define PIPE_RDEV		0x7e00
284 # define UNK_RDEV		0x7f00
285 # define PROC_RDEV_BASE		0xa000
286 
287 
288 # endif /* _mint_fsops_h */
289