2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
9 /*****************************************************************************
13 #include "nvdisk_intern.h"
15 #include <exec/memory.h>
16 #include <exec/nodes.h>
17 #include <exec/lists.h>
18 #include <exec/libraries.h>
19 #include <proto/dos.h>
20 #include <proto/exec.h>
21 #include <libraries/nonvolatile.h>
25 void FreeAll(struct MinList
*ml
, struct Library
*nvdBase
);
28 AROS_LH1(struct MinList
*, GetNVDItemList
,
32 AROS_LHA(STRPTR
, appName
, A0
),
36 struct Library
*, nvdBase
, 10, NVDisk
)
40 Get a list of the data stored in the nonvolatile memory by the
41 'appName' application.
45 appName -- the application the data of which to query about
49 A list of the data items saved by application 'appName'.
63 November 2000, SDuvan -- implemented
65 ******************************************************************************/
67 /* The size of a combined NVEntry and the name associated with it;
68 32 is due to the maximum length of the 'itemName' string being 31 */
69 #define NV_NODESIZE (sizeof(struct NVEntry) + 32)
76 struct MinList
*minList
= (struct MinList
*)AllocVec(sizeof(struct MinList
),
79 struct FileInfoBlock
*fib
;
85 fib
= AllocDosObject(DOS_FIB
, NULL
);
93 oldCDir
= CurrentDir(GPB(nvdBase
)->nvd_location
);
95 NEWLIST((struct List
*)minList
);
97 lock
= Lock(appName
, SHARED_LOCK
);
101 if(Examine(lock
, fib
))
103 while(ExNext(lock
, fib
))
105 // Data is stored as _files_
106 if(fib
->fib_DirEntryType
< 0)
108 struct NVEntry
*entry
= AllocVec(NV_NODESIZE
,
113 FreeAll(minList
, nvdBase
);
118 entry
->nve_Name
= (STRPTR
)(((char *)entry
) + sizeof(struct NVEntry
));
119 strncpy(entry
->nve_Name
, fib
->fib_FileName
, 32);
120 entry
->nve_Size
= fib
->fib_Size
;
121 entry
->nve_Protection
= fib
->fib_Protection
;
122 AddTail((struct List
*)minList
, (struct Node
*)entry
);
130 FreeDosObject(DOS_FIB
, fib
);
134 ListLength(minList
, length
);
135 entries
= AllocVec(sizeof(struct MinList
) + length
*NV_NODESIZE
,
139 /* We store the whole list in one memory block to make it possible to
140 free the memory by calling nonvolatile.library/FreeNVData() */
143 struct Node
*node
; /* Temporary variable */
144 ULONG offset
= sizeof(struct MinList
); /* Offset into the memory
146 NEWLIST((struct List
*)entries
);
148 for(node
= GetHead((struct List
*)minList
); node
!= NULL
;
149 node
= GetSucc(node
))
151 /* 1. Copy the NVEntry plus string
152 2. Add the memory as a node in the list
153 3. Set the name to point to the copied memory */
155 CopyMem(node
, entries
+ offset
, NV_NODESIZE
);
156 AddTail((struct List
*)entries
, (struct Node
*)(entries
+ offset
));
157 SetNodeName(entries
+ offset
, entries
+ offset
+
158 sizeof(struct NVEntry
));
159 offset
+= NV_NODESIZE
;
164 FreeAll(minList
, nvdBase
);
168 FreeAll(minList
, nvdBase
);
169 return (struct MinList
*)entries
;
175 /* Free all the nodes in a list together with the list structure itself. */
176 void FreeAll(struct MinList
*ml
, struct Library
*nvdBase
)
180 while((node
= GetHead((struct List
*)ml
)) != NULL
)