+#endif /*CDDEBUG*/
+ /*******************************************************\
+ * Check if we have resources allocated yet, if not *
+ * allocate and initialize them *
+ \*******************************************************/
+ if (next_cd_unit == 0)
+ {
+ cd_driver =
+ malloc(sizeof(struct cd_driver),M_DEVBUF,M_NOWAIT);
+ if(!cd_driver)
+ {
+ printf("cd%d: malloc failed for cd_driver\n",unit);
+ return(0);
+ }
+ bzero(cd_driver,sizeof(cd_driver));
+ cd_driver->size = 0;
+ }
+ /*******************************************************\
+ * allocate the resources for another drive *
+ * if we have already allocate a cd_data pointer we must *
+ * copy the old pointers into a new region that is *
+ * larger and release the old region, aka realloc *
+ \*******************************************************/
+ unit = next_cd_unit++;
+ /* XXX
+ * This if will always be true for now, but future code may
+ * preallocate more units to reduce overhead. This would be
+ * done by changing the malloc to be (next_cd_unit * x) and
+ * the cd_driver->size++ to be +x
+ */
+ if(unit >= cd_driver->size)
+ {
+ cdrealloc =
+ malloc(sizeof(cd_driver->cd_data) * next_cd_unit,
+ M_DEVBUF,M_NOWAIT);
+ if(!cdrealloc)
+ {
+ printf("cd%d: malloc failed for cdrealloc\n",unit);
+ return(0);
+ }
+ /* Make sure we have something to copy before we copy it */
+ bzero(cdrealloc,sizeof(cd_driver->cd_data) * next_cd_unit);
+ if(cd_driver->size)
+ {
+ bcopy(cd_driver->cd_data,cdrealloc,
+ sizeof(cd_driver->cd_data) * cd_driver->size);
+ free(cd_driver->cd_data,M_DEVBUF);
+ }
+ cd_driver->cd_data = cdrealloc;
+ cd_driver->cd_data[unit] = NULL;
+ cd_driver->size++;
+ }
+ if(cd_driver->cd_data[unit])
+ {
+ printf("cd%d: Already has storage!\n",unit);
+ return(0);
+ }