minor simplification.
[AROS.git] / rom / partition / fsloader.c
blobf59191b73e37bea23ea48644239e9e1a272bb6a5
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /*
7 * This hook is called after dos.library wakes up.
8 * Its job is to load all queued filesystems and add to the system.
9 */
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"
21 #include "fsloader.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)
30 return fsrnode;
33 return NULL;
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;
41 ULONG dostype;
42 ULONG version;
44 fsr = OpenResource("FileSystem.resource");
45 if (!fsr)
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
56 * at the moment.
58 Forbid();
59 fsrnode = FindResidentFS(fsr, dostype, version);
60 Permit();
62 if (fsrnode)
63 return ERROR_OBJECT_EXISTS;
65 fsrnode = AllocVec(sizeof(struct FileSysEntry), MEMF_PUBLIC | MEMF_CLEAR);
66 if (!fsrnode)
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
87 * about it.
89 Forbid();
91 dup = FindResidentFS(fsr, dostype, version);
92 if (!dup)
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);
99 Permit();
101 if (dup)
103 UnLoadSeg(fsrnode->fse_SegList);
104 FreeVec(fsrnode);
106 return ERROR_OBJECT_EXISTS;
109 return 0;
112 /* InternalLoadSeg() will leave its error code in IoErr() */
113 return IoErr();