1 /*
2  * The ARAnyM BetaDOS driver.
3  *
4  * 2001/2002 STan
5  *
6  * Based on:
7  * @(#)cookiefs/dosmain.c
8  *
9  * Copyright (c) Julian F. Reschke, 28. November 1995
10  * All rights reserved.
11  *
12  **/
13 
14 #include "hostfs.h"
15 #include "nf_ops.h"
16 #include <osbind.h>
17 #include "hostfs/hostfs_dev.h"
18 #include "hostfs/hostfs_xfs.h"
19 #include "global.h"
20 
21 
22 #define DEVNAME "ARAnyM Host Filesystem"
23 #define VERSION "0.60"
24 
25 char DriverName[] = DEVNAME" "VERSION;
26 long ldp;
27 
28 long _cdecl (*nf_call)(long id, ...) = 0L;
29 
30 void _cdecl ShowBanner( void );
31 void* _cdecl InitDevice( long bosDevID, long dosDevID );
32 
33 /* Diverse Utility-Funktionen */
34 
ShowBanner(void)35 void _cdecl ShowBanner( void )
36 {
37 	(void) Cconws (
38             "\r\n\033p "DEVNAME" "VERSION" \033q "
39             "\r\nCopyright (c) ARAnyM Development Team, "__DATE__"\r\n"
40             );
41 }
42 
43 struct cookie
44 {
45 	long tag;
46 	long value;
47 };
48 
get_cookie(ulong tag)49 static ulong get_cookie (ulong tag)
50 {
51 	struct cookie *cookie = *(struct cookie **)0x5a0;
52 	if (!cookie) return 0;
53 
54 	while (cookie->tag) {
55 		if (cookie->tag == tag) return cookie->value;
56 		cookie++;
57 	}
58 
59 	return 0;
60 }
61 
set_cookie(ulong tag,ulong val)62 static long set_cookie (ulong tag, ulong val)
63 {
64 	struct cookie *cookie = *(struct cookie **)0x5a0;
65 	long count, size;
66 
67 	if (!cookie) return 0;
68 
69 	count = 0;
70 	while (cookie->tag)
71 	{
72 		cookie++;
73 		count++;
74 	}
75 	count += 2;
76 	size = cookie->value;
77 	if (count >= size)
78 		return 0;
79 	cookie->tag = tag;
80 	cookie->value = val;
81 	cookie++;
82 	cookie->tag = 0;
83 	cookie->value = size;
84 	return 1;
85 }
86 
87 
InitDevice(long bosDevID,long dosDevID)88 void* _cdecl InitDevice( long bosDevID, long dosDevID )
89 {
90 	char mountPoint[] = "A:";
91 	mountPoint[0] += (dosDevID = (dosDevID&0x1f)); /* mask out bad values of the dosDevID */
92 
93 	/* check the NF HOSTFS avialability */
94 	if ( ! hostfs_init() ) {
95 		return (void*)-1;
96 	}
97 
98 	/*
99 	 * Hack to get the drive table the same for all hostfs.dos
100 	 * instances loaded by BetaDOS into memory.
101      *
102 	 * Note: This is definitely not MP friendly, but FreeMiNT
103 	 *       doesn't support B(M)etaDOS anyway, so: Do not do
104 	 *       this when using 'MiNT' or 'MagX' it crashes then.
105 	 */
106 	if (!get_cookie(0x4D694E54L /*'MiNT'*/) &&
107 	    !get_cookie(0x4D616758L /*'MagX'*/))
108 	{
109  		/* BetaDOS Host Filesystem cookie */
110 		ulong p = get_cookie(0x42446866L /*'BDfh'*/);
111 		if ( p ) curproc = (void*)p;
112 		else set_cookie(0x42446866L /*'BDfh'*/, (ulong)curproc);
113 	}
114 
115 	/*
116 	 * We _must_ use the bosDevID to define the drive letter here
117 	 * because MetaDOS (in contrary to BetaDOS) does not provide
118 	 * the dosDevID
119 	 */
120 	DEBUG(("InitDevice: %s [dosDev=%ld, bosDev=%ld] addr: %lx", mountPoint, dosDevID, bosDevID, &hostfs_filesys ));
121 
122 	/* map the BetaDOS drive to some bosDrive | 0x6000 so that the mapping would
123 	   not colide with the MiNT one */
124 	fs_native_init( dosDevID | 0x6000, mountPoint, "/tmp", 1,
125 					&hostfs_filesys, &hostfs_fs_devdrv );
126 	timezone = hostfs_filesys.res1;
127 
128 	hostfs_filesys.root( dosDevID | 0x6000, &curproc->p_cwd->root[dosDevID] );
129 
130 #ifdef DEBUG_INFO
131 	{
132 		fcookie *relto = &curproc->p_cwd->root[dosDevID];
133 		DEBUG (("InitDevice: root (%08lx, %08lx, %04x)", relto->fs, relto->index, relto->dev));
134 	}
135 #endif
136 
137 	return &ldp;
138 }
139 
140 
141 
142 /**
143  * Revision 1.12  2006/02/06 20:58:17  standa
144  * Sync with the FreeMiNT CVS. The make.sh now only builds the BetaDOS
145  * hostfs.dos.
146  *
147  * Revision 1.11  2006/02/04 21:03:03  standa
148  * Complete isolation of the metados fake mint VFS implemenation in the
149  * metados folder. No #ifdef ARAnyM_MetaDOS in the hostfs folder files
150  * themselves.
151  *
152  * Revision 1.10  2006/01/31 15:57:39  standa
153  * More of the initialization reworked to work with the new nf_ops. This time
154  * I have tested it.
155  *
156  * Revision 1.9  2005/09/26 22:18:05  standa
157  * Build warnings removal.
158  *
159  * Revision 1.8  2004/05/07 11:31:07  standa
160  * The BDhf cookie is not used in MagiC or MiNT because it was causing
161  * ARAnyM to crash.
162  *
163  * Revision 1.7  2004/04/26 07:14:04  standa
164  * Adjusted to the recent FreeMiNT CVS state to compile and also made
165  * BetaDOS only. No more MetaDOS compatibility attempts.
166  *
167  * Dfree() fix - for Calamus to be able to save its documents.
168  *
169  * Some minor bugfix backports from the current FreeMiNTs CVS version.
170  *
171  * The mountpoint entries are now shared among several hostfs.dos instances
172  * using a 'BDhf' cookie entry (atari/hostfs/metados/main.c).
173  *
174  * Revision 1.6  2003/03/24 08:58:53  joy
175  * aranymfs.xfs renamed to hostfs.xfs
176  *
177  * Revision 1.5  2003/03/20 21:27:22  standa
178  * The .xfs mapping to the U:\G mountpouints (single letter) implemented.
179  *
180  * Revision 1.4  2003/03/05 09:30:45  standa
181  * mountPath declaration fixed.
182  *
183  * Revision 1.3  2003/03/03 20:39:44  standa
184  * Parameter passing fixed.
185  *
186  * Revision 1.2  2002/12/11 08:05:54  standa
187  * The /tmp/calam host fs mount point changed to /tmp one.
188  *
189  * Revision 1.1  2002/12/10 20:47:21  standa
190  * The HostFS (the host OS filesystem access via NatFeats) implementation.
191  *
192  *
193  **/
194