tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / rom / filesys / CDVDFS / src / volumes.c
blob1eeb10f94aa8e02bc2e06fd8f3fa857f45ccb71a
1 /* volumes.c:
3 * Volume management.
5 * ----------------------------------------------------------------------
6 * This code is (C) Copyright 1993,1994 by Frank Munkert.
7 * (C) Copyright 2002-2010 The AROS Development Team
8 * All rights reserved.
9 * This software may be freely distributed and redistributed for
10 * non-commercial purposes, provided this notice is included.
11 * ----------------------------------------------------------------------
12 * History:
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>
24 #include <stdlib.h>
25 #include <string.h>
27 #include "volumes.h"
28 #include "cdrom.h"
29 #include "device.h"
30 #include "devsupp.h"
31 #include "generic.h"
32 #include "debug.h"
33 #include "path.h"
34 #include "globals.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
40 * volume.
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;
47 t_lock_node *new;
48 BUG(char pathname[300];)
50 BUG
52 if (!Full_Path_Name (obj_p, pathname, sizeof (pathname))) {
53 dbprintf (global, "[Cannot install lock / cannot determine pathname]");
54 return;
58 new = (t_lock_node*) AllocMem (sizeof (t_lock_node), MEMF_PUBLIC);
59 if (!new) {
60 BUG(dbprintf (global, "[Cannot install lock on '%s']", pathname);)
61 return;
64 new->pathlist = Copy_Path_List (obj_p->pathlist, FALSE);
66 new->vol_name = (char*) AllocMem (strlen (global->g_vol_name+1) + 1,
67 MEMF_PUBLIC);
68 if (!new->vol_name) {
69 BUG(dbprintf ("[Cannot install lock on '%s']", pathname);)
70 FreeMem (new, sizeof (t_lock_node));
71 return;
73 strcpy (new->vol_name, global->g_vol_name+1);
75 new->lock = p_lock;
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) {
94 BUG
96 if (!Path_Name_From_Path_List (ptr->pathlist, pathname,
97 sizeof (pathname))) {
98 dbprintf (global, "[cannot determine pathname]");
99 return;
101 dbprintf (global, "[Removing lock from '%s']", pathname);
103 if (old)
104 old->next = ptr->next;
105 else
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));
110 return;
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)
125 t_lock_node *ptr;
126 CDROM_OBJ* obj;
127 int result = 0;
128 char pathname[300];
130 for (ptr=global->g_lock_list; ptr; ptr = ptr->next) {
131 if (strcmp (global->g_vol_name+1, ptr->vol_name) == 0) {
132 result++;
133 if (!Path_Name_From_Path_List (ptr->pathlist, pathname, sizeof (pathname))) {
134 BUG(dbprintf (global, "[cannot determine pathname]");)
135 break;
137 BUG(dbprintf (global, "[Reinstalling lock on '%s'", pathname);)
138 obj = Open_Object (global->g_top_level_obj, pathname);
139 if (obj) {
140 BUG(dbprintf (global, "]\n");)
141 } else {
142 BUG(dbprintf (global, "(FAILED) ]\n");)
143 continue;
145 ptr->lock->fl_Link = (BPTR)obj;
148 return result;
151 /* Associate p_obj with the pathname of the associated disk object on the current
152 * volume.
155 void Register_File_Handle(CDROM_OBJ *p_obj)
157 struct CDVDBase *global = p_obj->global;
158 t_fh_node *new;
160 new = (t_fh_node*) AllocMem (sizeof (t_fh_node), MEMF_PUBLIC);
161 if (!new)
163 return;
166 new->vol_name = (char*) AllocMem (StrLen (global->g_vol_name+1) + 1, MEMF_PUBLIC);
167 if (!new->vol_name)
169 FreeMem (new, sizeof (t_fh_node));
170 return;
172 StrCpy (new->vol_name, global->g_vol_name+1);
174 new->obj = p_obj;
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)
191 if (old)
192 old->next = ptr->next;
193 else
194 global->g_fh_list = ptr->next;
195 FreeMem (ptr->vol_name, StrLen (ptr->vol_name) + 1);
196 FreeMem (ptr, sizeof (t_fh_node));
197 return;
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)
209 t_fh_node *ptr;
210 int result = 0;
212 for (ptr=global->g_fh_list; ptr; ptr = ptr->next) {
213 if (StrCmp (global->g_vol_name+1, ptr->vol_name) == 0) {
214 result++;
215 ptr->obj->volume = global->g_volume;
218 return result;
221 struct DeviceList *Find_Dev_List (CDROM_OBJ *p_obj) {
222 struct CDVDBase *global = p_obj->global;
223 t_fh_node *ptr;
225 for (ptr=global->g_fh_list; ptr; ptr = ptr->next)
227 if (ptr->obj == p_obj)
229 return ptr->devlist;
232 return NULL;
235 /* Register a volume node as owned by this handler.
238 void Register_Volume_Node(struct CDVDBase *global, struct DeviceList *p_volume, char *Name) {
239 t_vol_reg_node *new;
240 int len;
242 new = (t_vol_reg_node*) AllocMem (sizeof (t_vol_reg_node), MEMF_PUBLIC);
243 if (!new)
244 return;
246 new->volume = p_volume;
247 len = strlen(Name) + 1;
248 new->name = (char*) AllocMem (len, MEMF_PUBLIC);
249 if (!new)
251 FreeMem (new, sizeof (t_vol_reg_node));
252 return;
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)
269 if (old)
270 old->next = ptr->next;
271 else
272 global->g_volume_list = ptr->next;
273 FreeMem (ptr->name, StrLen (ptr->name) + 1);
274 FreeMem (ptr, sizeof (t_vol_reg_node));
275 return;
280 /* Find a volume node with a matching name.
283 struct DeviceList *Find_Volume_Node(struct CDVDBase *global, char *p_name) {
284 t_vol_reg_node *ptr;
286 for (ptr=global->g_volume_list; ptr; ptr=ptr->next)
288 if (Stricmp (ptr->name, p_name) == 0)
289 return ptr->volume;
291 return NULL;