2 * This hook is called after dos.library wakes up.
3 * Its job is to load all queued filesystems and add to the system.
6 #include <aros/asmcall.h>
7 #include <aros/debug.h>
8 #include <exec/resident.h>
9 #include <resources/filesysres.h>
10 #include <proto/alib.h>
11 #include <proto/dos.h>
12 #include <proto/exec.h>
13 #include <proto/partition.h>
15 #include "partition_support.h"
18 static struct FileSysEntry
*FindResidentFS(struct FileSysResource
*fsr
, ULONG dostype
, ULONG version
)
20 struct FileSysEntry
*fsrnode
;
22 ForeachNode(&fsr
->fsr_FileSysEntries
, fsrnode
)
24 if (fsrnode
->fse_DosType
== dostype
&& fsrnode
->fse_Version
>= version
)
31 ULONG
AddFS(struct Library
*PartitionBase
, struct FileSysHandle
*fs
)
33 struct DosLibrary
*DOSBase
= (struct DosLibrary
*)((struct PartitionBase_intern
*)PartitionBase
)->pb_DOSBase
;
34 struct FileSysResource
*fsr
;
35 struct FileSysEntry
*fsrnode
;
39 fsr
= OpenResource("FileSystem.resource");
41 return ERROR_INVALID_RESIDENT_LIBRARY
;
43 GetFileSystemAttrs(&fs
->ln
, FST_ID
, &dostype
, FST_VERSION
, &version
, TAG_DONE
);
46 * First we want to check if we already have this filesystem in the resource.
47 * Unfortunately the resource doesn't have any locking, so we have to use
48 * Forbid()/Permit() pair. In order not to hold it for a while, we repeat
49 * the check below after loading the handler (to eliminate race condition
50 * when someone loads newer version of the filesystem that we are loading
54 fsrnode
= FindResidentFS(fsr
, dostype
, version
);
58 return ERROR_OBJECT_EXISTS
;
60 fsrnode
= AllocVec(sizeof(struct FileSysEntry
), MEMF_PUBLIC
| MEMF_CLEAR
);
62 return ERROR_NO_FREE_STORE
;
64 GetFileSystemAttrs(&fs
->ln
, FST_FSENTRY
, fsrnode
, TAG_DONE
);
65 fsrnode
->fse_SegList
= LoadFileSystem(&fs
->ln
);
68 * FIXME: Name of the filesystem is currently not filled in.
69 * I left it this way just because this was originally done in m68k-specific hack.
70 * May be it should be added?
73 if (fsrnode
->fse_SegList
)
75 struct FileSysEntry
*dup
;
78 * Repeat checking, and insert the filesystem only if still not found.
79 * If found, unload our seglist and return error.
80 * This really sucks but nothing can be done with it. Even if we implement
81 * a global semaphore on the resource original m68k software won't know
86 dup
= FindResidentFS(fsr
, dostype
, version
);
89 * Entries in the list are not sorted by priority.
90 * Adding to head makes them sorted by version.
92 AddHead(&fsr
->fsr_FileSysEntries
, &fsrnode
->fse_Node
);
98 UnLoadSeg(fsrnode
->fse_SegList
);
101 return ERROR_OBJECT_EXISTS
;
107 /* InternalLoadSeg() will leave its error code in IoErr() */