Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / libs / nonvolatile / nvdisk / nvdisk_init.c
blobd3cbc5c57e43bdb2cc2ff5cc762a21b20eefba81
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Nonvolatile disk based storage library initialization code.
6 Lang: English
7 */
10 #define DEBUG 1
12 #include "nvdisk_intern.h"
14 #include <aros/debug.h>
16 #include <exec/types.h>
17 #include <exec/resident.h>
18 #include <proto/exec.h>
19 #include <proto/dos.h>
20 #include <devices/timer.h>
21 #include <aros/symbolsets.h>
23 #include <exec/libraries.h>
24 #include <exec/memory.h>
25 #include <exec/alerts.h>
26 #include LC_LIBDEFS_FILE
29 static int Init(LIBBASETYPEPTR LIBBASE)
32 This function is single-threaded by exec by calling Forbid.
33 If you break the Forbid() another task may enter this function
34 at the same time. Take care.
37 BOOL error = TRUE; // Notice the initialization to 'TRUE' here.
38 char *temp = NULL;
39 BPTR locFile;
41 LIBBASE->nvd_DOSBase = OpenLibrary("dos.library",0);
42 if (LIBBASE->nvd_DOSBase == NULL)
43 return 0;
45 D(bug("Init nvdisk.library\n"));
47 locFile = Open("SYS:prefs/env-archive/sys/nv_location", MODE_OLDFILE);
49 D(bug("Getting location\n"));
51 if(locFile != BNULL)
53 D(bug("Location file exists!\n"));
55 temp = AllocVec(512, MEMF_CLEAR);
57 if(temp != NULL)
59 int i = 0; // Loop variable
61 Read(locFile, temp, 512);
63 // End string if a carriage return is encountered
64 while(temp[i] != 0)
66 if(temp[i] == '\n')
68 temp[i] = 0;
69 break;
72 i++;
75 nvdBase->nvd_location = Lock(temp, SHARED_LOCK);
77 D(bug("NV location = %s\n", temp));
79 FreeVec(temp);
81 Close(locFile);
82 } else {
83 /* Volatile mode, if we have no nv_location file */
84 UnLock(CreateDir("RAM:NVRAM"));
85 nvdBase->nvd_location = Lock("RAM:NVRAM", SHARED_LOCK);
88 D(bug("Got lock = %p\n", nvdBase->nvd_location));
90 if(nvdBase->nvd_location != BNULL)
92 error = FALSE;
95 return !error;
98 static int Expunge(LIBBASETYPEPTR LIBBASE)
101 This function is single-threaded by exec by calling Forbid.
102 Never break the Forbid() or strange things might happen.
105 UnLock(nvdBase->nvd_location);
107 CloseLibrary(nvdBase->nvd_DOSBase);
109 return TRUE;
112 ADD2INITLIB(Init, 0);
113 ADD2EXPUNGELIB(Expunge, 0);