5 * ----------------------------------------------------------------------
6 * This code is (C) Copyright 1993,1994 by Frank Munkert.
7 * (C) Copyright 2002-2010 The AROS Development Team
9 * This software may be freely distributed and redistributed for
10 * non-commercial purposes, provided this notice is included.
11 * ----------------------------------------------------------------------
14 * 11-Aug-10 sonic - Fixed for 64-bit compatibility
15 * 27-Aug-07 sonic - Register_Volume_Node() now takes separate pointer to a volume name.
16 * 19-Sep-94 fmu Fixed bug in Reinstall_Locks()
17 * 22-May-94 fmu Performance improvement for lock+filehandle processing.
18 * 09-Jul-02 sheutlin various changes when porting to AROS
19 * - global variables are now in a struct Globals *global
22 #include <proto/exec.h>
23 #include <proto/utility.h>
36 #include "aros_stuff.h"
37 #include "clib_stuff.h"
39 /* Associate p_lock with the pathname of the locked object on the current
43 void Register_Lock (LOCK
*p_lock
)
45 CDROM_OBJ
*obj_p
= (CDROM_OBJ
*)p_lock
->fl_Link
;
46 struct CDVDBase
*global
= obj_p
->global
;
48 BUG(char pathname
[300];)
52 if (!Full_Path_Name (obj_p
, pathname
, sizeof (pathname
))) {
53 dbprintf (global
, "[Cannot install lock / cannot determine pathname]");
58 new = (t_lock_node
*) AllocMem (sizeof (t_lock_node
), MEMF_PUBLIC
);
60 BUG(dbprintf (global
, "[Cannot install lock on '%s']", pathname
);)
64 new->pathlist
= Copy_Path_List (obj_p
->pathlist
, FALSE
);
66 new->vol_name
= (char*) AllocMem (strlen (global
->g_vol_name
+1) + 1,
69 BUG(dbprintf ("[Cannot install lock on '%s']", pathname
);)
70 FreeMem (new, sizeof (t_lock_node
));
73 strcpy (new->vol_name
, global
->g_vol_name
+1);
76 new->next
= global
->g_lock_list
;
77 global
->g_lock_list
= new;
79 BUG(dbprintf ("[CDVDFS]\tInstalling lock on '%s'", pathname
);)
82 /* Remove the entry for p_lock in the list g_lock_list.
85 void Unregister_Lock (LOCK
*p_lock
)
87 CDROM_OBJ
*obj_p
= (CDROM_OBJ
*)p_lock
->fl_Link
;
88 struct CDVDBase
*global
= obj_p
->global
;
89 t_lock_node
*ptr
, *old
;
90 BUG(char pathname
[300];)
92 for (ptr
=global
->g_lock_list
, old
= NULL
; ptr
; old
= ptr
, ptr
= ptr
->next
)
93 if (ptr
->lock
== p_lock
) {
96 if (!Path_Name_From_Path_List (ptr
->pathlist
, pathname
,
98 dbprintf (global
, "[cannot determine pathname]");
101 dbprintf (global
, "[Removing lock from '%s']", pathname
);
104 old
->next
= ptr
->next
;
106 global
->g_lock_list
= ptr
->next
;
107 Free_Path_List (ptr
->pathlist
);
108 FreeMem (ptr
->vol_name
, strlen (ptr
->vol_name
) + 1);
109 FreeMem (ptr
, sizeof (t_lock_node
));
112 BUG(dbprintf (global
, "[Lock cannot be removed %p]", p_lock
);)
115 /* Update the fl_Link values for all locks that have been
116 * registered for a volume with the name g_vol_name.
117 * The fl_Link value is a pointer to a CDROM_OBJ object which
118 * respresents the locked file or directory.
120 * Returns the number of locks on the volume.
123 int Reinstall_Locks (struct CDVDBase
*global
)
130 for (ptr
=global
->g_lock_list
; ptr
; ptr
= ptr
->next
) {
131 if (strcmp (global
->g_vol_name
+1, ptr
->vol_name
) == 0) {
133 if (!Path_Name_From_Path_List (ptr
->pathlist
, pathname
, sizeof (pathname
))) {
134 BUG(dbprintf (global
, "[cannot determine pathname]");)
137 BUG(dbprintf (global
, "[Reinstalling lock on '%s'", pathname
);)
138 obj
= Open_Object (global
->g_top_level_obj
, pathname
);
140 BUG(dbprintf (global
, "]\n");)
142 BUG(dbprintf (global
, "(FAILED) ]\n");)
145 ptr
->lock
->fl_Link
= (BPTR
)obj
;
151 /* Associate p_obj with the pathname of the associated disk object on the current
155 void Register_File_Handle(CDROM_OBJ
*p_obj
)
157 struct CDVDBase
*global
= p_obj
->global
;
160 new = (t_fh_node
*) AllocMem (sizeof (t_fh_node
), MEMF_PUBLIC
);
166 new->vol_name
= (char*) AllocMem (StrLen (global
->g_vol_name
+1) + 1, MEMF_PUBLIC
);
169 FreeMem (new, sizeof (t_fh_node
));
172 StrCpy (new->vol_name
, global
->g_vol_name
+1);
175 new->devlist
= global
->DevList
;
176 new->next
= global
->g_fh_list
;
177 global
->g_fh_list
= new;
181 /* Remove the entry for the file handle p_obj in the list g_fh_list.
184 void Unregister_File_Handle(CDROM_OBJ
*p_obj
) {
185 t_fh_node
*ptr
, *old
;
186 struct CDVDBase
*global
= p_obj
->global
;
188 for (ptr
=global
->g_fh_list
, old
= NULL
; ptr
; old
= ptr
, ptr
= ptr
->next
)
189 if (ptr
->obj
== p_obj
&& StrCmp (global
->g_vol_name
+1, ptr
->vol_name
) == 0)
192 old
->next
= ptr
->next
;
194 global
->g_fh_list
= ptr
->next
;
195 FreeMem (ptr
->vol_name
, StrLen (ptr
->vol_name
) + 1);
196 FreeMem (ptr
, sizeof (t_fh_node
));
201 /* Update the volume pointer for all CDROM_OBJs which are used as
202 * filehandles for the current volume.
204 * Returns the number of file handles on the volume.
207 int Reinstall_File_Handles (struct CDVDBase
*global
)
212 for (ptr
=global
->g_fh_list
; ptr
; ptr
= ptr
->next
) {
213 if (StrCmp (global
->g_vol_name
+1, ptr
->vol_name
) == 0) {
215 ptr
->obj
->volume
= global
->g_volume
;
221 struct DeviceList
*Find_Dev_List (CDROM_OBJ
*p_obj
) {
222 struct CDVDBase
*global
= p_obj
->global
;
225 for (ptr
=global
->g_fh_list
; ptr
; ptr
= ptr
->next
)
227 if (ptr
->obj
== p_obj
)
235 /* Register a volume node as owned by this handler.
238 void Register_Volume_Node(struct CDVDBase
*global
, struct DeviceList
*p_volume
, char *Name
) {
242 new = (t_vol_reg_node
*) AllocMem (sizeof (t_vol_reg_node
), MEMF_PUBLIC
);
246 new->volume
= p_volume
;
247 len
= strlen(Name
) + 1;
248 new->name
= (char*) AllocMem (len
, MEMF_PUBLIC
);
251 FreeMem (new, sizeof (t_vol_reg_node
));
254 CopyMem(Name
, new->name
, len
);
255 new->next
= global
->g_volume_list
;
256 global
->g_volume_list
= new;
259 /* Remove the registration for the volume node.
262 void Unregister_Volume_Node(struct CDVDBase
*global
, struct DeviceList
*p_volume
) {
263 t_vol_reg_node
*ptr
, *old
;
265 for (ptr
=global
->g_volume_list
, old
=NULL
; ptr
; old
=ptr
, ptr
=ptr
->next
)
267 if (p_volume
== ptr
->volume
)
270 old
->next
= ptr
->next
;
272 global
->g_volume_list
= ptr
->next
;
273 FreeMem (ptr
->name
, StrLen (ptr
->name
) + 1);
274 FreeMem (ptr
, sizeof (t_vol_reg_node
));
280 /* Find a volume node with a matching name.
283 struct DeviceList
*Find_Volume_Node(struct CDVDBase
*global
, char *p_name
) {
286 for (ptr
=global
->g_volume_list
; ptr
; ptr
=ptr
->next
)
288 if (Stricmp (ptr
->name
, p_name
) == 0)