2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
7 * This hook is called after dos.library wakes up.
8 * Its job is to load all queued filesystems and add to the system.
11 #include <aros/asmcall.h>
12 #include <aros/debug.h>
13 #include <exec/resident.h>
14 #include <resources/filesysres.h>
15 #include <proto/alib.h>
16 #include <proto/dos.h>
17 #include <proto/exec.h>
18 #include <proto/partition.h>
20 #include "partition_support.h"
23 static struct FileSysEntry
*FindResidentFS(struct FileSysResource
*fsr
, ULONG dostype
, ULONG version
)
25 struct FileSysEntry
*fsrnode
;
27 ForeachNode(&fsr
->fsr_FileSysEntries
, fsrnode
)
29 if (fsrnode
->fse_DosType
== dostype
&& fsrnode
->fse_Version
>= version
)
36 ULONG
AddFS(struct Library
*PartitionBase
, struct FileSysHandle
*fs
)
38 struct DosLibrary
*DOSBase
= (struct DosLibrary
*)((struct PartitionBase_intern
*)PartitionBase
)->pb_DOSBase
;
39 struct FileSysResource
*fsr
;
40 struct FileSysEntry
*fsrnode
;
44 fsr
= OpenResource("FileSystem.resource");
46 return ERROR_INVALID_RESIDENT_LIBRARY
;
48 GetFileSystemAttrs(&fs
->ln
, FST_ID
, &dostype
, FST_VERSION
, &version
, TAG_DONE
);
51 * First we want to check if we already have this filesystem in the resource.
52 * Unfortunately the resource doesn't have any locking, so we have to use
53 * Forbid()/Permit() pair. In order not to hold it for a while, we repeat
54 * the check below after loading the handler (to eliminate race condition
55 * when someone loads newer version of the filesystem that we are loading
59 fsrnode
= FindResidentFS(fsr
, dostype
, version
);
63 return ERROR_OBJECT_EXISTS
;
65 fsrnode
= AllocVec(sizeof(struct FileSysEntry
), MEMF_PUBLIC
| MEMF_CLEAR
);
67 return ERROR_NO_FREE_STORE
;
69 GetFileSystemAttrs(&fs
->ln
, FST_FSENTRY
, fsrnode
, TAG_DONE
);
70 fsrnode
->fse_SegList
= LoadFileSystem(&fs
->ln
);
73 * FIXME: Name of the filesystem is currently not filled in.
74 * I left it this way just because this was originally done in m68k-specific hack.
75 * May be it should be added?
78 if (fsrnode
->fse_SegList
)
80 struct FileSysEntry
*dup
;
83 * Repeat checking, and insert the filesystem only if still not found.
84 * If found, unload our seglist and return error.
85 * This really sucks but nothing can be done with it. Even if we implement
86 * a global semaphore on the resource original m68k software won't know
91 dup
= FindResidentFS(fsr
, dostype
, version
);
94 * Entries in the list are not sorted by priority.
95 * Adding to head makes them sorted by version.
97 AddHead(&fsr
->fsr_FileSysEntries
, &fsrnode
->fse_Node
);
103 UnLoadSeg(fsrnode
->fse_SegList
);
106 return ERROR_OBJECT_EXISTS
;
112 /* InternalLoadSeg() will leave its error code in IoErr() */