Added pfsdoctor. Includes PFS3 v19 large partition and file size support.
[AROS.git] / rom / filesys / pfs3 / fs / dostohandlerinterface.c
blobe181675e2972b76a39829578ee39a43bc4fd9511
1 /* $Id$ */
2 /* $Log: dostohandlerinterface.c $
3 * Revision 13.10 1999/05/14 11:31:34 Michiel
4 * Long filename support implemented; bugfixes
6 * Revision 13.9 1999/02/22 16:22:35 Michiel
7 * ACTION_SET_DELDIR added
9 * Revision 13.8 1998/05/31 16:27:42 Michiel
10 * added ACTION_IS_PFS2
12 * Revision 13.7 1997/03/03 22:04:04 Michiel
13 * Release 16.21
15 * Revision 13.6 1995/12/29 11:04:12 Michiel
16 * ACTION_SET_ROLLOVER
18 * Revision 13.4 1995/08/21 04:20:43 Michiel
19 * added some extrapackets
21 * Revision 13.3 1995/08/16 14:28:28 Michiel
22 * fixed function table bug
23 * added ACTION_KILL_EMPTY (after being forgotten earlier)
24 * added ACTION_REMOVE_DIRENTRY
26 * Revision 13.2 1995/08/12 12:14:31 Michiel
27 * fixed
28 * */
30 #define __USE_SYSBASE
32 /* system includes */
33 #include <exec/memory.h>
34 #include <exec/types.h>
35 #include <exec/interrupts.h>
36 #include <dos/filehandler.h>
37 #include <dos/notify.h>
38 #if MULTIUSER
39 #include <proto/multiuser.h>
40 #endif
41 #include <string.h>
42 #include <math.h>
43 #include "debug.h"
45 /* own includes */
46 #include "versionhistory.doc"
47 #include "blocks.h"
48 #include "struct.h"
49 #include "directory_protos.h"
50 #include "disk_protos.h"
51 #include "lock_protos.h"
52 #include "volume_protos.h"
53 #include "format_protos.h"
54 #include "update_protos.h"
55 #include "lru_protos.h"
56 #include "ass_protos.h"
57 #include "anodes_protos.h"
58 #include "init_protos.h"
60 /* from boot.c */
61 void ReturnPacket(struct DosPacket *, struct MsgPort *, globaldata *g);
63 #ifdef DEBUG
64 extern BOOL debug;
65 static UBYTE debugbuf[120];
66 #define DebugOn debug++
67 #define DebugOff debug = 0
68 #define DebugMsg(msg) NormalErrorMsg(msg, NULL);
69 #define DebugMsgNum(msg, num) sprintf(debugbuf, "%s 0x%08lx.", msg, num); \
70 if(debug) {NormalErrorMsg(debugbuf, NULL);debug=0;}
71 #define DebugMsgName(msg, name) sprintf(debugbuf, "%s >%s<.", msg, name); \
72 if(debug) {NormalErrorMsg(debugbuf, NULL);debug=0;}
73 #else
74 #define DebugOn
75 #define DebugOff
76 #define DebugMsg(m)
77 #define DebugMsgNum(msg,num)
78 #define DebugMsgName(msg, name)
79 #endif
82 /**********************
83 * Prototypes
86 void NormalCommands(struct DosPacket *, globaldata *);
87 void InhibitedCommands(struct DosPacket *, globaldata *);
88 #if EXTRAPACKETS
89 void SleepCommands (struct DosPacket *action, globaldata *g);
90 #endif
92 /**********************
93 * lower levels
96 #define RES1(p) (p->dp_Res1)
97 #define RES2(p) (p->dp_Res2)
98 #define BARG1(p) BADDR(p->dp_Arg1)
99 #define BARG2(p) BADDR(p->dp_Arg2)
100 #define BARG3(p) BADDR(p->dp_Arg3)
101 #define BARG4(p) BADDR(p->dp_Arg4)
103 #include "dd_support.c"
104 #include "dd_funcs.c"
107 /**********************
108 * structures and globals
111 struct functable
113 SIPTR (*function)(struct DosPacket *, globaldata *);
114 ULONG timeout;
117 static const struct functable functiontable0[] =
119 {NotKnown, 0}, /* ACTION_NIL 0 */
120 {NotKnown, 0},
121 {NotKnown, 0}, /* ACTION_GET_BLOCK 2 */
122 {NotKnown, 0},
123 {NotKnown, 0}, /* ACTION_SET_MAP 4 */
124 {dd_Quit, 0}, /* ACTION_DIE 5 */
125 {NotKnown, 0}, /* ACTION_EVENT 6 */
126 {dd_CurrentVolume, 0}, /* ACTION_CURRENT_VOLUME 7 */
127 {dd_Lock, 1}, /* ACTION_LOCATE_OBJECT 8 */
128 {dd_Relabel, 1}, /* ACTION_RENAME_DISK 9 */
129 {NotKnown, 0},
130 {NotKnown, 0},
131 {NotKnown, 0},
132 {NotKnown, 0},
133 {NotKnown, 0},
134 {dd_Unlock, 0}, /* ACTION_FREE_LOCK 15 */
135 {dd_DeleteObject, 1}, /* ACTION_DELETE_OBJECT 16 */
136 {dd_Rename, 1}, /* ACTION_RENAME_OBJECT 17 */
137 {dd_AddBuffers, 0}, /* ACTION_MORE_CACHE 18 */
138 {dd_DupLock, 1}, /* ACTION_COPY_DIR 19 */
139 {NotKnown, 0}, /* ACTION_WAIT_CHAR 20 */
140 {dd_SetProperty, 1}, /* ACTION_SET_PROTECT 21 */
141 {dd_CreateDir, 1}, /* ACTION_CREATE_DIR 22 */
142 {dd_Examine, 1}, /* ACTION_EXAMINE_OBJECT 23 */
143 {dd_Examine, 1}, /* ACTION_EXAMINE_NEXT 24 */
144 {dd_Info, 0}, /* ACTION_DISK_INFO 25 */
145 {dd_Info, 0}, /* ACTION_INFO 26 */
146 {dd_Flush, 0}, /* ACTION_FLUSH 27 */
147 {dd_SetProperty, 1}, /* ACTION_SET_COMMENT 28 */
148 {dd_Parent, 1}, /* ACTION_PARENT 29 */
149 {NotKnown, 0}, /* ACTION_TIMER 30 */
150 {dd_InhibitOn, 0}, /* ACTION_INHIBIT 31 */
151 {NotKnown, 0}, /* ACTION_DISK_TYPE 32 */
152 {NotKnown, 0}, /* ACTION_DISK_CHANGE 33 */
153 {dd_SetProperty, 1}, /* ACTION_SET_DATE 34 */
154 {NotKnown, 0},
155 {NotKnown, 0},
156 {NotKnown, 0},
157 {NotKnown, 0},
158 {NotKnown, 0},
159 {dd_SameLock, 0} /* ACTION_SAME_LOCK 40 */
162 static const struct functable functiontable1000[] =
164 {NotKnown, 0},
165 {NotKnown, 0}, /* ACTION_READ_RETURN 1001 */
166 {NotKnown, 0}, /* ACTION_WRITE_RETURN 1002 */
167 {NotKnown, 0},
168 {dd_Open, 3}, /* ACTION_FINDUPDATE 1004 */
169 {dd_Open, 3}, /* ACTION_FINDINPUT 1005 */
170 {dd_Open, 3}, /* ACTION_FINDOUTPUT 1006 */
171 {dd_Close, 0}, /* ACTION_END 1007 */
172 {dd_SeekRead, 3}, /* ACTION_SEEK 1008 */
173 {NotKnown, 0},
174 {NotKnown, 0},
175 {NotKnown, 0},
176 {NotKnown, 0},
177 {NotKnown, 0},
178 {NotKnown, 0},
179 {NotKnown, 0},
180 {NotKnown, 0},
181 {NotKnown, 0},
182 {NotKnown, 0},
183 {NotKnown, 0},
184 {NotKnown, 0}, /* ACTION_FORMAT 1020 (inhibited only) */
185 {dd_MakeLink, 1}, /* ACTION_MAKE_LINK 1021 */
186 {dd_WriteSFS, 3}, /* ACTION_SET_FILE_SIZE 1022 */
187 {dd_WriteProtect, 0}, /* ACTION_WRITE_PROTECT 1023 */
188 {dd_ReadLink, 1}, /* ACTION_READ_LINK 1024 */
189 {NotKnown, 0},
190 {dd_OpenFromLock, 3}, /* ACTION_FH_FROM_LOCK 1026 */
191 {dd_IsFileSystem, 0}, /* ACTION_IS_FILESYSTEM 1027 */
192 {dd_ChangeMode, 1}, /* ACTION_CHANGE_MODE 1028 */
193 {NotKnown, 0},
194 {dd_DupLock, 1}, /* ACTION_COPY_DIR_FH 1030 */
195 {dd_Parent, 1}, /* ACTION_PARENT_FH 1031 */
196 {NotKnown, 0},
197 {dd_ExamineAll, 1}, /* ACTION_EXAMINE_ALL 1033 */
198 {dd_Examine, 1}, /* ACTION_EXAMINE_FH 1034 */
199 {NotYetImplemented, 0}, /* ACTION_EXAMINE_ALL_END 1035 */
200 {dd_SetProperty, 1}, /* ACTION_SET_OWNER 1036 */
205 /**********************
206 * Normal, not-inhibited packet processor
209 /* NormalCommands funtion: normal commandmode
211 * This function executes the operation specified by the passed packet. Can be
212 * called from a testenviroment and from the Handler. The Handler has to take
213 * care of receiving and answering the DOS packet.
215 * This function does not contain initialisation. Its sole purpose is the
216 * execution of commands on an already active filesystem.
218 * pre: filesystem ready; dos- and intuition open; unitdata ready
219 * post: command executed.
221 void NormalCommands(struct DosPacket *action, globaldata *g)
223 ULONG packettype;
225 /* clear error field */
226 action->dp_Res2 = 0;
228 packettype = action->dp_Type;
229 if (packettype == ACTION_WRITE)
231 action->dp_Res1 = dd_WriteSFS (action, g);
232 g->timeout |= 3;
234 else if (packettype == ACTION_READ)
236 action->dp_Res1 = dd_SeekRead (action, g);
237 g->timeout |= 3;
239 else if (packettype <= ACTION_SAME_LOCK)
241 action->dp_Res1 = functiontable0[packettype].function(action, g);
242 g->timeout |= functiontable0[packettype].timeout;
244 else if (packettype >= 1000 && packettype <= ACTION_SET_OWNER)
246 action->dp_Res1 = functiontable1000[packettype-1000].function(action, g);
247 g->timeout |= functiontable1000[packettype-1000].timeout;
249 else switch (packettype)
251 case ACTION_LOCK_RECORD:
252 case ACTION_FREE_RECORD:
253 action->dp_Res1 = NotYetImplemented(action, g);
254 break;
256 case ACTION_ADD_NOTIFY:
257 action->dp_Res1 = dd_AddNotify(action, g);
258 break;
260 case ACTION_REMOVE_NOTIFY:
261 action->dp_Res1 = dd_RemoveNotify(action, g);
262 break;
265 * Own packets
267 case ACTION_KILL_EMPTY:
268 action->dp_Res1 = dd_KillEmpty(action, g);
269 break;
271 case ACTION_REMOVE_DIRENTRY:
272 action->dp_Res1 = dd_RemoveDirEntry(action, g);
273 break;
275 case ACTION_SLEEP:
276 action->dp_Res1 = dd_Sleep(action, g);
277 break;
279 case ACTION_CREATE_ROLLOVER:
280 action->dp_Res1 = dd_MakeRollover(action, g);
281 g->timeout |= 1;
282 break;
284 case ACTION_SET_ROLLOVER:
285 action->dp_Res1 = dd_SetRollover(action, g);
286 g->timeout |= 1;
287 break;
289 case ACTION_IS_PFS2:
290 action->dp_Res1 = dd_IsPFS2(action, g);
291 break;
293 case ACTION_ADD_IDLE_SIGNAL:
294 action->dp_Res1 = dd_SignalIdle(action, g);
295 g->timeout |= 1;
296 break;
298 case ACTION_SET_DELDIR:
299 action->dp_Res1 = dd_SetDeldir(action, g);
300 break;
302 case ACTION_SET_FNSIZE:
303 action->dp_Res1 = dd_SetFileSize(action, g);
304 break;
306 #if EXTENDED_PACKETS_OS4
307 case ACTION_CHANGE_FILE_POSITION64:
308 dd_ChangeFilePosition64(action, g);
309 break;
310 case ACTION_GET_FILE_POSITION64:
311 dd_GetFilePosition64(action, g);
312 break;
313 case ACTION_CHANGE_FILE_SIZE64:
314 dd_ChangeFileSize64(action, g);
315 break;
316 case ACTION_GET_FILE_SIZE64:
317 dd_GetFileSize64(action, g);
318 break;
319 #endif
321 #if EXTENDED_PACKETS_MORPHOS
323 * Note: If we ever support file sizes between 2^31 to 2^32-2 then SEEK64 needs
324 * to be implemented. - Piru
326 case ACTION_SEEK64:
327 case ACTION_SET_FILE_SIZE64:
328 case ACTION_LOCK_RECORD64:
329 case ACTION_FREE_RECORD64:
330 case ACTION_EXAMINE_OBJECT64:
331 case ACTION_EXAMINE_NEXT64:
332 case ACTION_EXAMINE_FH64:
333 action->dp_Res1 = NotKnown(action, g);
334 break;
336 #if defined(__MORPHOS__)
337 case ACTION_NEW_READ_LINK:
339 * This really ought to be implemented at some point.
340 * It'd mostly require support for reading hardlink destination.
341 * - Piru
343 action->dp_Res1 = NotKnown(action, g);
344 break;
346 case ACTION_QUERY_ATTR:
347 action->dp_Res1 = dd_MorphOSQueryAttr(action, g);
348 break;
349 #endif
350 #endif
351 case ACTION_SERIALIZE_DISK: // Inhibited only
352 default:
353 action->dp_Res1 = NotKnown(action, g);
354 break;
359 /**********************
360 * Inhibited packet processor
363 void InhibitedCommands(struct DosPacket *action, globaldata *g)
365 /* clear error field */
366 action->dp_Res2 = 0;
368 switch (action->dp_Type)
370 case ACTION_INHIBIT:
371 action->dp_Res1 = dd_InhibitOff(action, g);
372 break;
374 case ACTION_FORMAT: // Format(fs,vol,type) 2.0
375 action->dp_Res1 = dd_Format(action, g);
376 break;
378 case ACTION_FREE_LOCK: // UnLock()
379 action->dp_Res1 = dd_Unlock(action, g);
380 break;
382 case ACTION_CURRENT_VOLUME: // <sendpkt only>
383 action->dp_Res1 = 0;
384 break;
386 case ACTION_DISK_INFO: // Info(..)
387 case ACTION_INFO:
388 action->dp_Res1 = dd_Info(action, g);
389 break;
391 case ACTION_IS_FILESYSTEM: // IsFileSystem(devname)
392 action->dp_Res1 = DOSTRUE;
393 break;
395 case ACTION_FLUSH: // <sendpkt only>
396 // UpdateDisk(g);
397 action->dp_Res1 = DOSTRUE;
398 break;
400 case ACTION_DIE: // <sendpkt only>
401 g->dieing = TRUE;
402 action->dp_Res1 = dd_Quit(action, g);
403 break;
405 case ACTION_SERIALIZE_DISK: // zie dosextens.h regel 220
406 action->dp_Res1 = dd_SerializeDisk(action, g);
407 break;
409 case ACTION_IS_PFS2:
410 action->dp_Res1 = dd_IsPFS2(action, g);
411 break;
413 case ACTION_SET_FNSIZE:
414 case ACTION_FINDINPUT: // Open(.., MODE_OLDFILE)
415 case ACTION_FINDOUTPUT: // Open(.., MODE_NEWFILE)
416 case ACTION_FINDUPDATE: // Open(.., MODE_READWRITE)
417 case ACTION_EXAMINE_FH: // ExamineFH(fh,fib)
418 case ACTION_EXAMINE_OBJECT: // Examine(..)
419 case ACTION_EXAMINE_NEXT: // ExNext(..)
420 case ACTION_CREATE_DIR: // CreateDir(..)
421 case ACTION_DELETE_OBJECT: // DeleteFile(..)
422 case ACTION_RENAME_OBJECT: // Rename(..)
423 case ACTION_WRITE: // Write(..)
424 case ACTION_LOCATE_OBJECT: // Lock(..)
425 case ACTION_COPY_DIR_FH:
426 case ACTION_COPY_DIR: // DupLock(..) COULD be implemented ?
427 case ACTION_PARENT_FH: // ParentOfFH(fh)
428 case ACTION_PARENT: // Parent(..)
429 case ACTION_SET_PROTECT: // SetProtection(..)
430 case ACTION_SET_COMMENT: // SetComment(..)
431 case ACTION_SET_DATE: // SetFileDate(..)
432 case ACTION_FH_FROM_LOCK: // OpenFromLock(lock)
433 case ACTION_CHANGE_MODE: // ChangeMode(type,obj,mode)
434 case ACTION_RENAME_DISK: // Relabel(..)
435 case ACTION_EXAMINE_ALL: // ExAll(lock,buff,size,type,ctl)
436 case ACTION_SET_FILE_SIZE: // SetFileSize(file,off,mode)
437 case ACTION_SAME_LOCK: // SameLock(lock1, lock2)
438 case ACTION_MAKE_LINK: // MakeLink(name,targ,mode)
439 case ACTION_READ_LINK: // ReadLink(port,lck,nam,buf,len)
440 case ACTION_ADD_NOTIFY: // StartNotify(NotifyRequest)
441 case ACTION_REMOVE_NOTIFY: // EndNotify(NotifyRequest)
442 case ACTION_MORE_CACHE: // AddBuffers(..)
443 case ACTION_WRITE_PROTECT: // <sendpkt only>
444 case ACTION_END: // Close(..)
445 case ACTION_CREATE_ROLLOVER:
447 #if EXTENDED_PACKETS_OS4
448 case ACTION_CHANGE_FILE_POSITION64:
449 case ACTION_GET_FILE_POSITION64:
450 case ACTION_CHANGE_FILE_SIZE64:
451 case ACTION_GET_FILE_SIZE64:
452 #endif
454 action->dp_Res2 = ERROR_NOT_A_DOS_DISK;
455 action->dp_Res1 = DOSFALSE;
456 break;
458 case ACTION_READ: // Read(..)
459 case ACTION_SEEK: // Seek(..)
460 action->dp_Res2 = ERROR_NOT_A_DOS_DISK;
461 action->dp_Res1 = -1;
462 break;
464 #if EXTENDED_PACKETS_MORPHOS
465 case ACTION_SEEK64:
466 case ACTION_SET_FILE_SIZE64:
467 case ACTION_LOCK_RECORD64:
468 case ACTION_FREE_RECORD64:
469 case ACTION_EXAMINE_OBJECT64:
470 case ACTION_EXAMINE_NEXT64:
471 case ACTION_EXAMINE_FH64:
472 #if defined(__MORPHOS__)
473 case ACTION_NEW_READ_LINK:
474 action->dp_Res2 = ERROR_NOT_A_DOS_DISK;
475 action->dp_Res1 = DOSFALSE;
476 break;
477 case ACTION_QUERY_ATTR:
478 action->dp_Res1 = dd_MorphOSQueryAttr(action, g);
479 break;
480 #endif
481 #endif
483 default:
484 NotKnown(action, g);
485 break;
490 #if EXTRAPACKETS
492 /**********************
493 * MODE_SLEEP packet processor
497 * Packethandler during MODE_SLEEP
499 void SleepCommands(struct DosPacket *action, globaldata *g)
501 /* clear error field */
502 action->dp_Res2 = 0;
504 switch (action->dp_Type)
506 case ACTION_FREE_LOCK: // UnLock()
507 action->dp_Res1 = dd_Unlock(action, g);
508 break;
510 case ACTION_CURRENT_VOLUME: // <sendpkt only>
511 action->dp_Res1 = dd_CurrentVolume(action, g);
512 break;
514 case ACTION_DISK_INFO: // Info(..)
515 case ACTION_INFO:
516 action->dp_Res1 = dd_Info(action, g);
517 break;
519 case ACTION_IS_FILESYSTEM: // IsFileSystem(devname)
520 action->dp_Res1 = DOSTRUE;
521 break;
523 case ACTION_FLUSH: // <sendpkt only>
524 action->dp_Res1 = DOSTRUE;
525 break;
528 * special sleep packets
530 case ACTION_SLEEP:
531 action->dp_Res1 = dd_Sleep(action, g);
532 break;
534 case ACTION_UPDATE_ANODE:
535 action->dp_Res1 = dd_UpdateAnode(action, g);
536 break;
539 * otherwise wake up
541 default:
542 Alarm(g);
543 NormalCommands(action, g);
547 #endif