Init control word to zero, cdrom-handler reads this and will crash if it is non-zero...
[AROS.git] / rom / partition / fsloader.c
blob534be70c259301f5b1281c4acd0e6412befcfd9e
1 /*
2 * This hook is called after dos.library wakes up.
3 * Its job is to load all queued filesystems and add to the system.
4 */
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"
16 #include "fsloader.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)
25 return fsrnode;
28 return NULL;
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;
36 ULONG dostype;
37 ULONG version;
39 fsr = OpenResource("FileSystem.resource");
40 if (!fsr)
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
51 * at the moment.
53 Forbid();
54 fsrnode = FindResidentFS(fsr, dostype, version);
55 Permit();
57 if (fsrnode)
58 return ERROR_OBJECT_EXISTS;
60 fsrnode = AllocVec(sizeof(struct FileSysEntry), MEMF_PUBLIC | MEMF_CLEAR);
61 if (!fsrnode)
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
82 * about it.
84 Forbid();
86 dup = FindResidentFS(fsr, dostype, version);
87 if (!dup)
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);
94 Permit();
96 if (dup)
98 UnLoadSeg(fsrnode->fse_SegList);
99 FreeVec(fsrnode);
101 return ERROR_OBJECT_EXISTS;
104 return 0;
107 /* InternalLoadSeg() will leave its error code in IoErr() */
108 return IoErr();