Ejemplo n.º 1
0
  FT_New_Memory( void )
  {
    FT_Memory  memory;


#ifdef __amigaos4__
    memory = (FT_Memory)AllocVec( sizeof ( *memory ), MEMF_SHARED );
#else
    memory = (FT_Memory)AllocVec( sizeof ( *memory ), MEMF_PUBLIC );
#endif
    if ( memory )
    {
#ifdef __amigaos4__
      memory->user = CreatePool( MEMF_SHARED, 16384, 16384 );
#else
      memory->user = CreatePool( MEMF_PUBLIC, 16384, 16384 );
#endif
      if ( memory->user == NULL )
      {
        FreeVec( memory );
        memory = NULL;
      }
      else
      {
        memory->alloc   = ft_alloc;
        memory->realloc = ft_realloc;
        memory->free    = ft_free;
#ifdef FT_DEBUG_MEMORY
        ft_mem_debug_init( memory );
#endif
      }
    }

    return memory;
  }
Ejemplo n.º 2
0
DOH *DohObjMalloc(DohObjInfo *type, void *data) {
  DohBase *obj;
  if (!pools_initialized)
    InitPools();
#ifndef DOH_DEBUG_MEMORY_POOLS
  if (FreeList) {
    obj = FreeList;
    FreeList = (DohBase *) obj->data;
  } else {
#endif
    while (Pools->current == Pools->len) {
      CreatePool();
    }
    obj = Pools->ptr + Pools->current;
    ++Pools->current;
#ifndef DOH_DEBUG_MEMORY_POOLS
  }
#endif
  obj->type = type;
  obj->data = data;
  obj->meta = 0;
  obj->refcount = 1;
  obj->flag_intern = 0;
  obj->flag_marked = 0;
  obj->flag_user = 0;
  obj->flag_usermark = 0;
  return (DOH *) obj;
}
Ejemplo n.º 3
0
	/**
	 * Get an allocated message buffer from the free pool.  The ownership of the buffer
	 * is the responsibility of the caller until they are finished and call ReturnToPool.
	 * @param Function function signature that defines the kind of buffer to return
	 * 
	 * @return allocated buffer ready to be filled with data
	 */
	MessagePoolElem* GetNextFree(UFunction* Function)
	{
		// Create or allocate the appropriate pool to get a buffer from
		MessagePoolElem* NextMsg = NULL;
		TWeakObjectPtr<UFunction> FuncPtr(Function);
		PoolMapping* FuncPool = Pool.Find(FuncPtr);
		if (!FuncPool)
		{
			FuncPool = CreatePool(Function);
		}

		if (FuncPool)
		{
			if (FuncPool->FreeList)
			{
				// Retrieve and clear an existing allocation
				NextMsg = FuncPool->FreeList;
				FuncPool->FreeList = NextMsg->Next();

				NextMsg->Unlink();
				(**NextMsg).Msg->Clear();
			}
			else
			{
				// Create a new allocation from the head prototype
				NextMsg = new MessagePoolElem();
				(**NextMsg).OwnerFunc = FuncPtr;
				(**NextMsg).Msg = FuncPool->Prototype.Msg->New();
			}
		}

		return NextMsg;
	}
Ejemplo n.º 4
0
  FT_New_Memory( void )
  {
    FT_Memory  memory;


//  memory = (FT_Memory)malloc( sizeof ( *memory ) );
    memory = (FT_Memory)AllocVec( sizeof ( *memory ), MEMF_PUBLIC );
    if ( memory )
    {
//    memory->user = 0;
#ifdef __GNUC__
      memory->user = CreatePool( MEMF_PUBLIC, 2048, 2048 );
#else
      memory->user = AsmCreatePool( MEMF_PUBLIC, 2048, 2048, SysBase );
#endif
      if ( memory->user == NULL )
      {
        FreeVec( memory );
        memory = NULL;
      }
      else
      {
        memory->alloc   = ft_alloc;
        memory->realloc = ft_realloc;
        memory->free    = ft_free;
#ifdef FT_DEBUG_MEMORY
        ft_mem_debug_init( memory );
#endif
      }
    }

    return memory;
  }
Ejemplo n.º 5
0
//------------------------------------------------------------------------
CProjectile *CWeaponSystem::UseFromPool(IEntityClass *pClass, const SAmmoParams *pAmmoParams)
{
	TAmmoPoolMap::iterator it=m_pools.find(pClass);

	if(it==m_pools.end())
	{
		CreatePool(pClass);
		it=m_pools.find(pClass);
	}

	SAmmoPoolDesc &desc=it->second;

	if(!desc.frees.empty())
	{
		CProjectile *pProjectile=desc.frees.front();
		desc.frees.pop_front();

		pProjectile->GetEntity()->Hide(false);
		pProjectile->ReInitFromPool();
		return pProjectile;
	}
	else
	{
		CProjectile *pProjectile=DoSpawnAmmo(pClass, false, pAmmoParams);
		++desc.size;

		return pProjectile;
	}
}
Ejemplo n.º 6
0
static void InitPools() {
  if (pools_initialized)
    return;
  CreatePool();			/* Create initial pool */
  pools_initialized = 1;
  DohNone = NewVoid(0, 0);	/* Create the None object */
  DohIntern(DohNone);
}
Ejemplo n.º 7
0
/* call global constructors in data section pointed to by a4 */
VOID SetupGlobals(VOID)
{
	ULONG i;

	MemPool = CreatePool(MEMF_PUBLIC, CAPS_PUDDLESIZE, CAPS_THRESHOLDSIZE);

	for (i = (ULONG)__CTOR_LIST__[0]; i >= 1; i--)
		__CTOR_LIST__[i]();
}
Ejemplo n.º 8
0
void ResetAtomPool(AtomPoolT *atomPool) {
  if (atomPool->pool)
    DeletePool(atomPool->pool);

  atomPool->pool = CreatePool(MEMF_PUBLIC,
                              atomPool->atomSize * atomPool->perChunk,
                              atomPool->atomSize);

  if (!atomPool->pool)
    PANIC("CreatePool(%ld, %ld) failed.",
          atomPool->atomSize * atomPool->perChunk, atomPool->atomSize);
}
Ejemplo n.º 9
0
IPTR Ascii__OM_NEW(Class * cl, Object *o, struct opSet *msg)
{
    IPTR retval;
    
    if ((retval = DoSuperMethodA (cl, o, (Msg)msg)))
    {
         struct AsciiData 	*data;
         IPTR 			len, estlines, poolsize;
         BOOL 			success = FALSE;
         STRPTR 		buffer;

         /* Get a pointer to the object data */
         data = INST_DATA (cl, (Object *) retval);

         /* Get the attributes that we need to determine
	  * memory pool size */
         GetDTAttrs ((Object *) retval,
                     TDTA_Buffer	, (IPTR)&buffer,
                     TDTA_BufferLen	, (IPTR)&len,
                     TAG_DONE);

	D(bug("AsciiDataType_new: buffer = %x  bufferlen = %d\n", buffer, len));

         /* Make sure we have a text buffer */
         if (buffer && len)
         {
             /* Estimate the pool size that we will need */
             estlines = (len / 80) + 1;
             estlines = (estlines > 200) ? 200 : estlines;
             poolsize = sizeof (struct Line) * estlines;

             /* Create a memory pool for the line list */
             if ((data->Pool = CreatePool (MEMF_CLEAR | MEMF_PUBLIC, poolsize, poolsize)))
                 success = TRUE;
	     else
		 SetIoErr (ERROR_NO_FREE_STORE);
         }
         else
         {
	     /* Indicate that something was missing that we
	      * needed */
             SetIoErr (ERROR_REQUIRED_ARG_MISSING);
         }

         if (!success)
         {
             CoerceMethod (cl, (Object *) retval, OM_DISPOSE);
             retval = 0;
         }
     }
     
     return retval;     
}
Ejemplo n.º 10
0
APTR ami_misc_itempool_create(int size)
{
#ifdef __amigaos4__
	return AllocSysObjectTags(ASOT_ITEMPOOL,
		ASOITEM_MFlags, MEMF_PRIVATE,
		ASOITEM_ItemSize, size,
		ASOITEM_GCPolicy, ITEMGC_AFTERCOUNT,
		ASOITEM_GCParameter, 100,
		TAG_DONE);
#else
	return CreatePool(MEMF_ANY, 20 * size, size);
#endif
}
Ejemplo n.º 11
0
		// -------------------------------------------------------------------------------------------------------
		void* AllocatorMT::Alloc( SizeT size )
		{
			UInt32 threadID = (UInt32)GetCurrentThreadId();
			MemPool* pool = FindPool(threadID);
			if (pool == 0)
			{
				CreatePool(threadID);
				pool = FindPool(threadID);
				A_ASSERT(pool != 0, "Unable to create pool for this thread!");
			}
			
			return pool->Alloc(size);
		}
Ejemplo n.º 12
0
struct AVLNode *resetTree()
{
    if (mempool)
	DeletePool(mempool);
    mempool = CreatePool(0, sizeof(struct testnode)*32, sizeof(struct testnode)*32);

    if (mempool == NULL) {
	fprintf(stdout, "CreatePool failed\n");
	fflush(stdout);
	exit(EXIT_FAILURE);
    }

    return NULL;
}
Ejemplo n.º 13
0
ULONG run_constructors(void)
{
	static int sorted = 0;
	struct CTDT *ctdt = (struct CTDT *)__ctdtlist;

	if (constructors_done)
		return 1;

	if (!mempool)
	{
		mempool = CreatePool(MEMF_CLEAR | MEMF_SEM_PROTECTED, 12*1024, 6*1024);

		if (!mempool)
        {
			return 0;
        }
	}

	if (!sorted)
	{
		struct HunkSegment *seg;

		sorted = 1;
		seg = (struct HunkSegment *)(((unsigned int)ctdt) - sizeof(struct HunkSegment));
		last_ctdt = (struct CTDT *)(((unsigned int)seg) + seg->Size);

		qsort((struct CTDT *)ctdt, last_ctdt - ctdt, sizeof(*ctdt), (int (*)(const void *, const void *))comp_ctdt);
	}

	while (ctdt < last_ctdt)
	{
		if (ctdt->priority >= 0)
		{
			if(ctdt->fp() != 0)
			{
				return 0;
			}
		}
		ctdt++;
	}

	//malloc(0);

	__HandleConstructors((void (**)(void)) __ctrslist);

	constructors_done = 1;

    return 1;
}
Ejemplo n.º 14
0
Archivo: dev.c Proyecto: michalsc/AROS
static int devInit(LIBBASETYPEPTR base) {
    KPRINTF(10, ("devInit base: 0x%p SysBase: 0x%p\n", base, SysBase));

    base->hd_MemPool = CreatePool(MEMF_PUBLIC | MEMF_CLEAR | MEMF_SEM_PROTECTED, 16384, 4096);
    if(base->hd_MemPool) {
        NEWLIST(&base->hd_Units);
        KPRINTF(10, ("devInit: Ok\n"));
    } else {
        KPRINTF(10, ("devInit: CreatePool() failed!\n"));
        return FALSE;
    }

    KPRINTF(10, ("devInit: openCnt = %ld\n", base->hd_Library.lib_OpenCnt));
    return TRUE;
}
Ejemplo n.º 15
0
static struct ph_packet *packet_alloc(void) {
    APTR pool;
    struct ph_packet *pkt;

    pool = CreatePool(MEMF_PUBLIC | MEMF_CLEAR, 1024, 256);
    if (pool == NULL) {
        SetIoErr(ERROR_NO_FREE_STORE);
        return NULL;
    }

    pkt = AllocPooled(pool, sizeof(struct ph_packet));

    pkt->dp.dp_Link = (struct Message *) pkt;
    pkt->msg.mn_Node.ln_Name = (char *) &(pkt->dp);

    pkt->pool = pool;

    return pkt;
}
Ejemplo n.º 16
0
void ConnectPoolCluster::AddPool(const std::string& addr, UInt32 max)
{
    OSMutexLocker locker(&m_lock);

    std::vector<SharedPtr<ConnectPool> >::iterator it = m_pools.begin();
    for(; it != m_pools.end(); ++it)
    {
        if(addr == (*it)->GetAddr())
        {
            return ;
        }
    }

    SharedPtr<ConnectPool> pool = CreatePool(addr, max);
    pool->SetRetryInterval(m_retry_inter);
    pool->Init();
    m_pools.push_back(pool);
    LOG_DEBUG("Add one service, addr: %s, count: %u", addr.c_str(), max);
}
Ejemplo n.º 17
0
int main()
{
    struct timeval  tv_start, 
                    tv_end;
    int             count   = 100000000;
    double          elapsed = 0.0;
    int             i;
    APTR            pool;
    APTR            memory;
    
    pool = CreatePool(MEMF_ANY, 4 * 100, 100);
    AllocPooled(pool, 100); // Avoid bad behaviour of FreePooled()
    
    gettimeofday(&tv_start, NULL);
    
    for(i = 0; i < count; i++)
    {    
        memory = AllocPooled(pool, 100);
        if (memory) FreePooled(pool, memory, 100);
    }
    
    gettimeofday(&tv_end, NULL);
    
    DeletePool(pool);
    
    elapsed = ((double)(((tv_end.tv_sec * 1000000) + tv_end.tv_usec) 
            - ((tv_start.tv_sec * 1000000) + tv_start.tv_usec)))/1000000.;
    
    printf
    (
        "Elapsed time:           %f seconds\n"
        "Number of allocations:  %d\n"
        "Allocations per second: %f\n"
        "Seconds per allocation: %f\n",
        elapsed, count, (double) count / elapsed, (double) elapsed / count
    );
   
    return 0;
}
Ejemplo n.º 18
0
ULONG InitPrefs(STRPTR filename, BOOL use, BOOL save)
{
    D(bug("[serial prefs] InitPrefs\n"));
    mempool = CreatePool(MEMF_PUBLIC | MEMF_CLEAR, 2048, 2048);
    if (!mempool) 
    {
	ShowMsg("Out of memory!");
	return 0;
    }

    if (!LoadPrefs(filename))
    {
    	if (!DefaultPrefs())
	{
	    CleanupPrefs();
	    ShowMsg("Panic! Cannot setup default prefs!");
	    return 0;
	}
    }
    
    restore_prefs = serialprefs;
    
    if (use || save)
    {
    	SavePrefs((CONST STRPTR) CONFIGNAME_ENV);
    }
    
    if (save)
    {
    	SavePrefs((CONST STRPTR) CONFIGNAME_ENVARC);
    }
    
    if (use || save) CleanupPrefs();

    return 1;
}
Ejemplo n.º 19
0
ULONG initBase(struct LibraryHeader *lib)
{
  ENTER();

  if((DOSBase = (APTR)OpenLibrary("dos.library", 37)) != NULL &&
     GETINTERFACE(IDOS, DOSBase))
  {
    if((UtilityBase = (APTR)OpenLibrary("utility.library", 37)) != NULL &&
       GETINTERFACE(IUtility, UtilityBase))
    {
      // we have to please the internal utilitybase
      // pointers of libnix and clib2
      #if !defined(__NEWLIB__) && !defined(__AROS__)
        __UtilityBase = (APTR)UtilityBase;
        #if defined(__amigaos4__)
        __IUtility = IUtility;
        #endif
      #endif

      // setup the debugging stuff
      #if defined(DEBUG)
      SetupDebug();
      #endif

      #if defined(__amigaos4__)
      if((DiskfontBase = OpenLibrary("diskfont.library", 50)) != NULL &&
        GETINTERFACE(IDiskfont, DiskfontBase))
      {
      #endif
        #if defined(__amigaos4__)
        lib->pool = AllocSysObjectTags(ASOT_MEMPOOL, ASOPOOL_MFlags, MEMF_SHARED,
                                                     ASOPOOL_Puddle, 4096,
                                                     ASOPOOL_Threshold, 512,
                                                     ASOPOOL_Name, "codesets.library pool",
                                                     ASOPOOL_LockMem, FALSE,
                                                     TAG_DONE);
        #else
        lib->pool = CreatePool(MEMF_ANY, 4096, 512);
        #endif
        if(lib->pool != NULL)
        {
          if(codesetsInit(&lib->codesets) == TRUE)
          {
            lib->systemCodeset = (struct codeset *)GetHead((struct List *)&lib->codesets);

            if((LocaleBase = (APTR)OpenLibrary("locale.library", 37)) != NULL &&
               GETINTERFACE(ILocale, LocaleBase))
            {
              getSystemCodeset(lib);
            }

            RETURN(TRUE);
            return TRUE;
          }
        }
      #if defined(__amigaos4__)
      }
      #endif
    }
  }

  freeBase(lib);

  RETURN(FALSE);
  return FALSE;
}
Ejemplo n.º 20
0
/*
    Here shall we start. Make function static as it shouldn't be visible from
    outside.
*/
static int ata_init(struct ataBase *ATABase)
{
    OOP_Object *storageRoot;
    struct BootLoaderBase	*BootLoaderBase;

    D(bug("[ATA--] ata_init: ata.device Initialization\n"));

    ATABase->ata_UtilityBase = OpenLibrary("utility.library", 36);
    if (!ATABase->ata_UtilityBase)
        return FALSE;

    /*
     * I've decided to use memory pools again. Alloc everything needed from 
     * a pool, so that we avoid memory fragmentation.
     */
    ATABase->ata_MemPool = CreatePool(MEMF_CLEAR | MEMF_PUBLIC | MEMF_SEM_PROTECTED , 8192, 4096);
    if (ATABase->ata_MemPool == NULL)
        return FALSE;

    D(bug("[ATA--] ata_init: MemPool @ %p\n", ATABase->ata_MemPool));

    if (OOP_ObtainAttrBasesArray(&ATABase->unitAttrBase, attrBaseIDs))
        return FALSE;

    /* This is our own method base, so no check needed */
    if (OOP_ObtainMethodBasesArray(&ATABase->hwMethodBase, &attrBaseIDs[ATA_METHOD_ID_START]))
        return FALSE;

    storageRoot = OOP_NewObject(NULL, CLID_Hidd_Storage, NULL);
    if (!storageRoot)
        storageRoot = OOP_NewObject(NULL, CLID_HW_Root, NULL);
    if (!storageRoot)
        return FALSE;

    if (!HW_AddDriver(storageRoot, ATABase->ataClass, NULL))
        return FALSE;

    /* Set default ata.device config options */
    ATABase->ata_32bit   = FALSE;
    ATABase->ata_NoMulti = FALSE;
    ATABase->ata_NoDMA   = FALSE;
    ATABase->ata_Poll    = FALSE;

    /*
     * start initialization: 
     * obtain kernel parameters
     */
    BootLoaderBase = OpenResource("bootloader.resource");
    D(bug("[ATA--] ata_init: BootloaderBase = %p\n", BootLoaderBase));
    if (BootLoaderBase != NULL)
    {
        struct List *list;
        struct Node *node;

        list = (struct List *)GetBootInfo(BL_Args);
        if (list)
        {
            ForeachNode(list, node)
            {
                if (strncmp(node->ln_Name, "ATA=", 4) == 0)
                {
                    const char *CmdLine = &node->ln_Name[4];

                    if (strstr(CmdLine, "32bit"))
                    {
                        D(bug("[ATA  ] ata_init: Using 32-bit IO transfers\n"));
                        ATABase->ata_32bit = TRUE;
                    }
		    if (strstr(CmdLine, "nomulti"))
		    {
			D(bug("[ATA  ] ata_init: Disabled multisector transfers\n"));
			ATABase->ata_NoMulti = TRUE;
		    }
                    if (strstr(CmdLine, "nodma"))
                    {
                        D(bug("[ATA  ] ata_init: Disabled DMA transfers\n"));
                        ATABase->ata_NoDMA = TRUE;
                    }
                    if (strstr(CmdLine, "poll"))
                    {
                        D(bug("[ATA  ] ata_init: Using polling to detect end of busy state\n"));
                        ATABase->ata_Poll = TRUE;
                    }
                }
            }
        }
    }

    /* Try to setup daemon task looking for diskchanges */
    NEWLIST(&ATABase->Daemon_ios);
    InitSemaphore(&ATABase->DaemonSem);
    InitSemaphore(&ATABase->DetectionSem);
    ATABase->daemonParent = FindTask(NULL);
    SetSignal(0, SIGF_SINGLE);

    if (!NewCreateTask(TASKTAG_PC, DaemonCode,
                       TASKTAG_NAME       , "ATA.daemon",
                       TASKTAG_STACKSIZE  , STACK_SIZE,
                       TASKTAG_TASKMSGPORT, &ATABase->DaemonPort,
                       TASKTAG_PRI        , TASK_PRI - 1,	/* The daemon should have a little bit lower Pri than handler tasks */
                       TASKTAG_ARG1       , ATABase,
                       TAG_DONE))
    {
        D(bug("[ATA  ] Failed to start up daemon!\n"));
        return FALSE;
    }

    /* Wait for handshake */
    Wait(SIGF_SINGLE);
    D(bug("[ATA  ] Daemon task set to 0x%p\n", ATABase->ata_Daemon));

    return ATABase->ata_Daemon ? TRUE : FALSE;
}
Ejemplo n.º 21
0
struct DiskIO *DIO_Setup(CONST_STRPTR name, const struct TagItem *tags) {
	DEBUGF("DIO_Setup('%s', %#p)\n", name, tags);

	if (name == NULL || name[0] == '\0' || name[0] == ':') {
		DEBUGF("DIO_Setup: No valid name argument specified.\n");
		return NULL;
	}

	struct DiskIO *dio;
	struct TagItem *tstate;
	const struct TagItem *tag;
#ifndef DISABLE_DOSTYPE_CHECK
	ULONG check_dostype = 0;
	ULONG dostype_mask = ~0;
#endif
	struct DosList *dol;
	struct DeviceNode *dn = NULL;
	struct FileSysStartupMsg *fssm = NULL;
	struct DosEnvec *de = NULL;
	struct MsgPort *mp = NULL;
	struct IOExtTD *iotd = NULL;
	char devname[256];
	struct NSDeviceQueryResult nsdqr;
	int error = DIO_ERROR_UNSPECIFIED;
	int *error_storage;

	dio = AllocMem(sizeof(*dio), MEMF_PUBLIC|MEMF_CLEAR);
	if (dio == NULL) {
		error = DIO_ERROR_NOMEM;
		goto cleanup;
	}

	tstate = (struct TagItem *)tags;
	while ((tag = NextTagItem(&tstate)) != NULL) {
		switch (tag->ti_Tag) {
#ifndef DISABLE_BLOCK_CACHE
			case DIOS_Cache:
				dio->no_cache = !tag->ti_Data;
				break;
			case DIOS_WriteCache:
				dio->no_write_cache = !tag->ti_Data;
				break;
#endif
			case DIOS_Inhibit:
				dio->inhibit = !!tag->ti_Data;
				break;
#ifndef DISABLE_DOSTYPE_CHECK
			case DIOS_DOSType:
				check_dostype = tag->ti_Data;
				break;
			case DIOS_DOSTypeMask:
				dostype_mask = tag->ti_Data;
				break;
#endif
			case DIOS_ReadOnly:
				dio->read_only = !!tag->ti_Data;
				break;
		}
	}

	/* Remove possible colon from name and anything else that might follow it */
	SplitName(name, ':', dio->devname, 0, sizeof(dio->devname));

	/* Find device node */
	dol = LockDosList(LDF_DEVICES|LDF_READ);
	if (dol != NULL) {
		dn = (struct DeviceNode *)FindDosEntry(dol, dio->devname, LDF_DEVICES|LDF_READ);
		UnLockDosList(LDF_DEVICES|LDF_READ);
	}
	if (dn == NULL) {
		error = DIO_ERROR_GETFSD;
		goto cleanup;
	}

	/* Add back trailing colon for Inhibit() */
	strlcat((char *)dio->devname, ":", sizeof(dio->devname));

	/* Check that device node has the necessary data */
	if ((fssm = BADDR(dn->dn_Startup)) == NULL ||
		(de = BADDR(fssm->fssm_Environ)) == NULL ||
		de->de_TableSize < DE_UPPERCYL)
	{
		error = DIO_ERROR_GETFSD;
		goto cleanup;
	}

	if (dio->inhibit) {
		if (!Inhibit(dio->devname, TRUE)) {
			error = DIO_ERROR_INHIBIT;
			goto cleanup;
		}

		dio->uninhibit = TRUE; /* So Cleanup() knows that it should uninhibit */
	}

	dio->diskmp = mp = CreateMsgPort();
	dio->diskiotd = iotd = CreateIORequest(dio->diskmp, sizeof(*iotd));
	if (iotd == NULL) {
		error = DIO_ERROR_NOMEM;
		goto cleanup;
	}

	FbxCopyStringBSTRToC(fssm->fssm_Device, (STRPTR)devname, sizeof(devname));
	if (OpenDevice((CONST_STRPTR)devname, fssm->fssm_Unit,
		(struct IORequest *)iotd, fssm->fssm_Flags) != 0)
	{
		DEBUGF("DIO_Setup: Failed to open %s unit %u using flags 0x%x.\n",
			fssm->fssm_Device,
			(unsigned int)fssm->fssm_Unit,
			(unsigned int)fssm->fssm_Flags);
		error = DIO_ERROR_OPENDEVICE;
		goto cleanup;
	}

	dio->disk_device = iotd->iotd_Req.io_Device;

	if (de->de_LowCyl == 0) {
		dio->use_full_disk = TRUE;
		DEBUGF("de_LowCyl == 0 => using full disk\n");
	} else {
		UQUAD sector_size = de->de_SizeBlock * sizeof(ULONG);
		UQUAD cylinder_size = (UQUAD)de->de_BlocksPerTrack * (UQUAD)de->de_Surfaces * sector_size;
		dio->use_full_disk = FALSE;
		SetSectorSize(dio, sector_size);
		dio->partition_start = (UQUAD)de->de_LowCyl * cylinder_size;
		dio->partition_size = (UQUAD)(de->de_HighCyl - de->de_LowCyl + 1) * cylinder_size;
		dio->total_sectors = dio->partition_size / dio->sector_size;
		DEBUGF("partiton start: %llu partition size: %llu cylinder size: %llu sector size: %lu total sectors: %llu\n",
			dio->partition_start, dio->partition_size, cylinder_size, dio->sector_size, dio->total_sectors);
	}

	DEBUGF("Trying NSD query command\n");
	iotd->iotd_Req.io_Command = NSCMD_DEVICEQUERY;
	iotd->iotd_Req.io_Data = &nsdqr;
	iotd->iotd_Req.io_Length = sizeof(nsdqr);
	bzero(&nsdqr, sizeof(nsdqr)); /* Required for usbscsi.device */
	if (DoIO((struct IORequest *)iotd) == 0) {
		if (nsdqr.DeviceType != NSDEVTYPE_TRACKDISK) {
			DEBUGF("Not a trackdisk device\n");
			error = DIO_ERROR_NSDQUERY;
			goto cleanup;
		}

		if (nsdqr.SupportedCommands != NULL) {
			UWORD cmd;
			int i = 0;
			while ((cmd = nsdqr.SupportedCommands[i++]) != CMD_INVALID) {
				if (cmd == CMD_READ)
					dio->cmd_support |= CMDSF_TD32;
				else if (cmd == ETD_READ)
					dio->cmd_support |= CMDSF_ETD32;
				else if (cmd == TD_READ64)
					dio->cmd_support |= CMDSF_TD64;
				else if (cmd == NSCMD_TD_READ64)
					dio->cmd_support |= CMDSF_NSD_TD64;
				else if (cmd == NSCMD_ETD_READ64)
					dio->cmd_support |= CMDSF_NSD_ETD64;
				else if (cmd == CMD_UPDATE)
					dio->cmd_support |= CMDSF_CMD_UPDATE;
				else if (cmd == ETD_UPDATE)
					dio->cmd_support |= CMDSF_ETD_UPDATE;
			}
		}
	} else if (iotd->iotd_Req.io_Error == IOERR_NOCMD) {
		DEBUGF("Not an NSD device\n");
		dio->cmd_support = CMDSF_TD32|CMDSF_CMD_UPDATE;

		DEBUGF("Checking for TD64 support\n");
		iotd->iotd_Req.io_Command = TD_READ64;
		iotd->iotd_Req.io_Data = NULL;
		iotd->iotd_Req.io_Actual = 0;
		iotd->iotd_Req.io_Offset = 0;
		iotd->iotd_Req.io_Length = 0;
		if (DoIO((struct IORequest *)iotd) != IOERR_NOCMD)
			dio->cmd_support |= CMDSF_TD64;
	} else {
		DEBUGF("NSD query command failed (error: %d)\n", (int)iotd->iotd_Req.io_Error);
		error = DIO_ERROR_NSDQUERY;
		goto cleanup;
	}

	if ((dio->cmd_support & (CMDSF_TD32|CMDSF_ETD32|CMDSF_TD64|CMDSF_NSD_TD64|CMDSF_NSD_ETD64)) == 0) {
		DEBUGF("No I/O commands supported\n");
		error = DIO_ERROR_NSDQUERY;
		goto cleanup;
	}

	if (dio->cmd_support & CMDSF_ETD_UPDATE)
		dio->update_cmd = ETD_UPDATE;
	else if (dio->cmd_support & CMDSF_CMD_UPDATE)
		dio->update_cmd = CMD_UPDATE;
	else
		dio->update_cmd = CMD_INVALID;

	dio->mempool = CreatePool(MEMF_PUBLIC, 4096, 1024);
	if (dio->mempool == NULL) {
		error = DIO_ERROR_NOMEM;
		goto cleanup;
	}

	DIO_Update(dio);

	DEBUGF("DIO_Setup: %#p\n", dio);
	return dio;

cleanup:
	if (dio != NULL) DIO_Cleanup(dio);

	error_storage = (int *)GetTagData(DIOS_Error, (Tag)NULL, tags);
	if (error_storage != NULL) *error_storage = error;

	DEBUGF("DIO_Setup failed (error: %d)\n", error);
	return NULL;
}
Ejemplo n.º 22
0
BOOL __asm __saveds OpenLibs(register __a6 struct PopupMenuBase *l)
{
	if(UtilityBase) return TRUE;

	l->pmb_UtilityBase=OpenLibrary("utility.library",37L);
	if(l->pmb_UtilityBase) {
		UtilityBase=l->pmb_UtilityBase;
		l->pmb_GfxBase=OpenLibrary("graphics.library",40L);
		if(!l->pmb_GfxBase) l->pmb_GfxBase=OpenLibrary("graphics.library",37L);
		else V40Gfx=TRUE;
		if(l->pmb_GfxBase) {
			GfxBase=(struct GfxBase *)l->pmb_GfxBase;
			l->pmb_IntuitionBase=OpenLibrary("intuition.library",37L);
			if(l->pmb_IntuitionBase) {
				IntuitionBase=(struct IntuitionBase *)l->pmb_IntuitionBase;
				l->pmb_DOSBase=OpenLibrary("dos.library",0L);
				if(l->pmb_DOSBase) {
					DOSBase=(struct DosLibrary *)l->pmb_DOSBase;
					l->pmb_ExecBase = (struct Library *)SysBase;
					l->pmb_CxBase=OpenLibrary("commodities.library",37L);
					if(l->pmb_CxBase) {
						CxBase=l->pmb_CxBase;
						LayersBase=OpenLibrary("layers.library",0);
						l->pmb_LayersBase=LayersBase;
						if(LayersBase) {
							CyberGfxBase=OpenLibrary("cybergraphics.library",39L);
							if(CyberGfxBase)
								CyberGfx=TRUE;
							l->pmb_CyberGfxBase=CyberGfxBase;
						#if defined(__AROS__) || defined(__MORPHOS)
							if((MemPool = CreatePool(MEMF_ANY | MEMF_CLEAR | MEMF_SEM_PROTECTED, 10240L, 10240L))) {
						#else
							if((MemPool = CreatePool(MEMF_ANY, 10240L, 10240L))) {
						#endif

								PM_Prefs_Load(PMP_PATH);

								return TRUE;
							}
						}
					}
				}
			}
		}
	}

	return FALSE;
}

//
// Library initializtion
//

int __asm __saveds __UserLibInit(register __a6 struct PopupMenuBase *l)
{
	//kprintf("UserLibInit, pmbase = %08lx\n", l);

#ifdef __AROS__
    	SysBase = (struct ExecBase *)l->pmb_ExecBase;
#else
	SysBase=*((struct ExecBase **)4);
#endif
	if(!OpenLibs(l)) return -1;

	//kprintf("UserLibInit failed\n");

	return 0;
}
Ejemplo n.º 23
0
/*** Methods ****************************************************************/
Object *AboutWindow__OM_NEW
(
    Class *CLASS, Object *self, struct opSet *message 
)
{
    struct AboutWindow_DATA *data              = NULL; 
    const struct TagItem    *tstate            = message->ops_AttrList;
    struct TagItem          *tag               = NULL, 
                            *authorsTags       = NULL,
                            *sponsorsTags      = NULL;
    struct Catalog          *catalog           = NULL;
    APTR                     pool;
    Object                  *rootGroup         = NULL,
                            *imageGroup        = NULL,
                            *imageObject       = NULL,
                            *versionObject     = NULL,
                            *copyrightObject   = NULL,
                            *descriptionGroup  = NULL,
                            *descriptionObject = NULL,
                            *authorsList       = NULL,
                            *sponsorsList      = NULL;
    
    STRPTR                   title             = NULL,
                             versionNumber     = NULL,
                             versionDate       = NULL,
                             versionExtra      = NULL,
                             description       = NULL,
                             copyright         = NULL;
                             
    CONST_STRPTR             pages[]           = { NULL, NULL, NULL }; 
    UBYTE                    nextPage          = 0;
    
    /* Allocate memory pool ------------------------------------------------*/
    pool = CreatePool(MEMF_ANY, 4096, 4096);
    if (pool == NULL) return NULL;
        
    /* Initialize locale ---------------------------------------------------*/
    catalog = OpenCatalogA
    (
        NULL, "System/Classes/Zune/AboutWindow.catalog", NULL
    );
        
    /* Parse initial attributes --------------------------------------------*/
    while ((tag = NextTagItem(&tstate)) != NULL)
    {
        switch (tag->ti_Tag)
        {
            case MUIA_AboutWindow_Image:
                imageObject = (Object *) tag->ti_Data;
                break;
            
            case MUIA_AboutWindow_Title:
                title = StrDup((STRPTR) tag->ti_Data);
                if (title == NULL) title = IGNORE;
                break;
                
            case MUIA_AboutWindow_Version_Number:
                versionNumber = StrDup((STRPTR) tag->ti_Data);
                if (versionNumber == NULL) versionNumber = IGNORE;
                break;
                
            case MUIA_AboutWindow_Version_Date:
                versionDate = StrDup((STRPTR) tag->ti_Data);
                if (versionDate == NULL) versionDate = IGNORE;
                break;
                
            case MUIA_AboutWindow_Version_Extra:
                versionExtra = StrDup((STRPTR) tag->ti_Data);
                if (versionExtra == NULL) versionExtra = IGNORE;
                break;
                
            case MUIA_AboutWindow_Copyright:
                copyright = StrDup((STRPTR) tag->ti_Data);
                if (copyright == NULL) copyright = IGNORE;
                break;
                
            case MUIA_AboutWindow_Description:
                description = StrDup((STRPTR) tag->ti_Data);
                if (description == NULL) description = IGNORE;
                break;
            
            case MUIA_AboutWindow_Authors:
                authorsTags = (struct TagItem *) tag->ti_Data;
                break; 
                
            case MUIA_AboutWindow_Sponsors:
                sponsorsTags = (struct TagItem *) tag->ti_Data;
                break;
                            
            default:
                continue; /* Don't supress non-processed tags */
        }
        
        tag->ti_Tag = TAG_IGNORE;
    }
    
    /* Setup image ---------------------------------------------------------*/
    if (imageObject == NULL)
    {
        TEXT path[512], program[1024]; path[0] = '\0'; program[0] = '\0';
        
        if (GetProgramName(program, 1024))
        {
            strlcat(path, "PROGDIR:", 512);
            strlcat(path, FilePart(program), 512);
            imageObject = (Object *)IconImageObject,
                MUIA_IconImage_File, (IPTR) path,
            End;
        }
        
        if (imageObject == NULL)
        {
            imageObject = HVSpace;
        }
    }

    /* Setup pages ---------------------------------------------------------*/
    if (authorsTags != NULL)
    {
        pages[nextPage] = _(MSG_AUTHORS);
        nextPage++;
    }
    
    if (sponsorsTags != NULL)
    {
        pages[nextPage] = _(MSG_SPONSORS);
        nextPage++;
    }
    
    self = (Object *) DoSuperNewTags
    (
        CLASS, self, NULL,
        
        MUIA_Window_Activate, TRUE,
        MUIA_Window_NoMenus,  TRUE,
        MUIA_Window_Height,   MUIV_Window_Height_Visible(25),
        MUIA_Window_Width,    MUIV_Window_Width_Visible(25),
        
        WindowContents, (IPTR) VGroup,
            GroupSpacing(6),
            
            Child, (IPTR) (imageGroup = (Object *)HGroup,
                MUIA_Weight,  0,
                
                Child, (IPTR) HVSpace,
                Child, (IPTR) imageObject,
                Child, (IPTR) HVSpace,
            End),
            Child, (IPTR) (versionObject = (Object *)TextObject,
                MUIA_Text_PreParse, (IPTR) MUIX_C,
                MUIA_Text_Contents, (IPTR) NULL,
            End),
            Child, (IPTR) (copyrightObject = (Object *)TextObject,
                MUIA_Text_PreParse, (IPTR) MUIX_C,
                MUIA_Text_Contents, (IPTR) NULL,
            End),
            Child, (IPTR) (descriptionGroup = (Object *)VGroup,
                Child, (IPTR) VSpace(6),
                Child, (IPTR) (descriptionObject = (Object *)TextObject,
                    MUIA_Text_PreParse, (IPTR) MUIX_I MUIX_C,
                    MUIA_Text_Contents, (IPTR) NULL,
                End),
            End),
            Child, (IPTR) VSpace(6),
            Child, (IPTR) RegisterGroup(pages),
                Child, (IPTR) ListviewObject,
                    MUIA_Listview_List, (IPTR) (authorsList = (Object *)ListObject,
                        ReadListFrame,
                    End),
                End,
                Child, (IPTR) ListviewObject,
                    MUIA_Listview_List, (IPTR) (sponsorsList = (Object *)ListObject,
                        ReadListFrame,
                    End),
                End,
            End, 
        End,
        
        TAG_MORE, (IPTR) message->ops_AttrList
    );
    
    if (self == NULL) goto error;
    
    data = INST_DATA(CLASS, self);
    data->awd_Catalog           = catalog;
    data->awd_Pool              = pool;
    data->awd_RootGroup         = rootGroup;
    data->awd_ImageGroup        = imageGroup;
    data->awd_ImageObject       = imageObject;
    data->awd_VersionObject     = versionObject;
    data->awd_CopyrightObject   = copyrightObject;
    data->awd_DescriptionGroup  = descriptionGroup;
    data->awd_DescriptionObject = descriptionObject;
    data->awd_Title             = title;
    data->awd_VersionNumber     = versionNumber;
    data->awd_VersionDate       = versionDate;
    data->awd_VersionExtra      = versionExtra;
    data->awd_Copyright         = copyright;
    data->awd_Description       = description;
    
    if (authorsTags != NULL)  NamesToList(authorsList, authorsTags, data);
    if (sponsorsTags != NULL) NamesToList(sponsorsList, sponsorsTags, data);
    
    /* Setup notifications */
    DoMethod
    ( 
        self, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, 
        (IPTR) self, 2, MUIA_Window_Open, FALSE
    );
        
    return self;
    
error:
    if (catalog != NULL) CloseCatalog(catalog);
    
    return NULL;
}
Ejemplo n.º 24
0
ULONG query(void)
{
    LONG which = (LONG)REG_D0;
#else
ULONG SAVEDS ASM query(REG(d0,LONG which))
{
#endif
    switch (which)
    {
        case 0:  return (ULONG)lib_class;
        default: return 0;
    }
}

/****************************************************************************/

void
freeBase(void)
{
    if (MUIMasterBase)
    {
        freeAttach();
        freeMCC();

        CloseLibrary(MUIMasterBase);
        MUIMasterBase = NULL;
    }

    if (IFFParseBase)
    {
        CloseLibrary((struct Library *)IFFParseBase);
        IFFParseBase = NULL;
    }

    if (LocaleBase)
    {
        if (lib_cat) CloseCatalog(lib_cat);
        CloseLibrary((struct Library *)LocaleBase);
    }

    if (UtilityBase)
    {
        CloseLibrary(UtilityBase);
        UtilityBase = NULL;
    }

    if (IntuitionBase)
    {
        CloseLibrary((struct Library *)IntuitionBase);
        IntuitionBase = NULL;
    }

    if (DOSBase)
    {
        CloseLibrary((struct Library *)DOSBase);
        DOSBase = NULL;
    }

    if (lib_pool)
    {
        DeletePool(lib_pool);
        lib_pool = NULL;
    }

    lib_flags &= ~(BASEFLG_Init|BASEFLG_MUI20);
}

/***********************************************************************/

ULONG
initBase(void)
{
    if ((DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",37)) &&
        (IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37)) &&
        (UtilityBase = OpenLibrary("utility.library",37)) &&
        (LocaleBase = (struct LocaleBase *)OpenLibrary("locale.library",37)) &&
        (IFFParseBase = OpenLibrary("iffparse.library",37)) &&
        (MUIMasterBase = OpenLibrary("muimaster.library",19)) &&
        (lib_pool = CreatePool(MEMF_ANY|MEMF_CLEAR,512,256)))
    {
        if (MUIMasterBase->lib_Version>=MUIVER20) lib_flags |= BASEFLG_MUI20;
        initStrings();

        if (initAttach() && initMCC())
        {
            lib_flags |= BASEFLG_Init;

            return TRUE;
        }
    }

    freeBase();

    return FALSE;
}