2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
6 /******************************************************************************
29 Command is called in Startup-Sequence.
41 ******************************************************************************/
43 #include <aros/debug.h>
45 #include <dos/rdargs.h>
46 #include <exec/lists.h>
47 #include <exec/memory.h>
48 #include <libraries/expansion.h>
49 #include <libraries/expansionbase.h>
50 #include <proto/alib.h>
51 #include <proto/arossupport.h>
52 #include <proto/dos.h>
53 #include <proto/exec.h>
54 #include <proto/expansion.h>
67 struct MinList handlerlist
;
70 LONG
parsePrefs(char *buffer
, LONG size
)
72 struct CSource csrc
= {buffer
, size
, 0};
77 D(bug("[Automount] parsePrefs()\n"));
79 while (csrc
.CS_CurChr
< csrc
.CS_Length
)
81 struct HandlerNode
*tn
;
85 ULONG mask
= 0xFFFFFFFF;
87 DB2(bug("[parsePrefs] Cur %d, Length %d\n", csrc
.CS_CurChr
, csrc
.CS_Length
));
89 res
= ReadItem(ident
, 256, &csrc
);
98 /* Skip over to the end of line */
99 while ((csrc
.CS_CurChr
< csrc
.CS_Length
) && (buffer
[csrc
.CS_CurChr
] != '\n'))
107 for (i
= 0; i
< 4; i
++)
113 Printf("LINE %ld: Mailformed filesystem ID\n", line
);
121 c
= strtoul(p
, &p
, 16);
125 mask
&= ~(0xFF000000 >> (i
<< 3));
135 Printf("LINE %ld: Missing filesystem ID\n", line
);
139 res
= ReadItem(ident
, 256, &csrc
);
140 if (res
== ITEM_ERROR
)
143 if (res
!= ITEM_EQUAL
)
145 Printf("LINE %ld: Unexpected item after filesystem ID\n", line
);
149 res
= ReadItem(ident
, 256, &csrc
);
150 if (res
== ITEM_ERROR
)
153 if ((res
!= ITEM_QUOTED
) && (res
!= ITEM_UNQUOTED
))
155 Printf("LINE %ld: Missing handler name\n", line
);
160 tn
= AllocPooled(pool
, sizeof(struct HandlerNode
) + res
);
162 return ERROR_NO_FREE_STORE
;
166 CopyMem(ident
, tn
->handler
, res
+ 1);
168 AddTail((struct List
*)&handlerlist
, (struct Node
*)tn
);
172 * Intentional ReadItem() bug workaround.
173 * Ungets '\n' every time, causing an infinite loop without this adjustment.
175 if ((csrc
.CS_CurChr
< csrc
.CS_Length
) && (buffer
[csrc
.CS_CurChr
] == '\n'))
185 static LONG
LoadPrefs(STRPTR filename
)
187 struct FileInfoBlock fib
;
193 D(bug("[Automount] LoadPrefs('%s')\n", filename
));
195 fh
= Open(filename
, MODE_OLDFILE
);
198 if (ExamineFH(fh
, &fib
))
202 buffer
= AllocMem(fib
.fib_Size
, MEMF_PUBLIC
| MEMF_CLEAR
);
205 size
= Read(fh
, buffer
, fib
.fib_Size
);
206 if (size
== fib
.fib_Size
)
207 retval
= parsePrefs(buffer
, size
);
211 FreeMem(buffer
, fib
.fib_Size
);
214 retval
= ERROR_NO_FREE_STORE
;
226 static struct HandlerNode
*FindHandler(ULONG id
)
228 struct HandlerNode
*n
;
230 ForeachNode(&handlerlist
, n
)
232 if (n
->id
== (id
& n
->mask
))
239 static BOOL
IsMounted(struct DeviceNode
*dn
)
242 struct DosList
*dl
= LockDosList(LDF_DEVICES
|LDF_READ
);
244 while ((dl
= NextDosEntry(dl
, LDF_DEVICES
)))
246 if (dl
== (struct DosList
*)dn
)
253 UnLockDosList(LDF_DEVICES
|LDF_READ
);
257 int __nocommandline
= 1;
263 pool
= CreatePool(1024, 1024, MEMF_ANY
);
266 PrintFault(ERROR_NO_FREE_STORE
, "Automount");
270 NewList((struct List
*)&handlerlist
);
271 res
= LoadPrefs("L:automount-config");
277 ForeachNode(&((struct ExpansionBase
*)ExpansionBase
)->MountList
, n
)
279 struct DeviceNode
*dn
= n
->bn_DeviceNode
;
281 D(bug("[Automount] Checking BootNode %b...\n", dn
->dn_Name
));
283 if ((!dn
->dn_Task
) && (!dn
->dn_SegList
) && (!dn
->dn_Handler
) && dn
->dn_Startup
)
285 struct FileSysStartupMsg
*fssm
= BADDR(dn
->dn_Startup
);
287 D(bug("[Automount] Not mounted\n"));
289 if (fssm
->fssm_Environ
)
291 struct DosEnvec
*de
= BADDR(fssm
->fssm_Environ
);
295 struct HandlerNode
*hn
= FindHandler(de
->de_DosType
);
299 Printf("Mounting %b with %s\n", dn
->dn_Name
, hn
->handler
);
301 dn
->dn_Handler
= CreateBSTR(hn
->handler
);
304 res
= ERROR_NO_FREE_STORE
;
310 D(bug("[Automount] Adding DOS entry...\n"));
311 AddDosEntry((struct DosList
*)dn
);
314 if (n
->bn_Flags
& ADNF_STARTPROC
)
318 D(bug("[Automount] Starting up...\n"));
320 res
= AROS_BSTR_strlen(dn
->dn_Name
);
321 buf
= AllocMem(res
+ 2, MEMF_ANY
);
324 res
= ERROR_NO_FREE_STORE
;
328 CopyMem(AROS_BSTR_ADDR(dn
->dn_Name
), buf
, res
);
342 PrintFault(res
, "Automount");