Beispiel #1
0
char *mmc_strdup(const char *str)
{
	char *res = strdup(str);
	if (!res)
	{
		mmc_error("Memory allocation failed.");
	}
	return res;
}
Beispiel #2
0
void *mmc_realloc(void *old_mem, size_t size)
{
	void *mem = mmc_tryrealloc(old_mem, size);
	if (! mem)
	{
		mmc_error("Cannot allocate memory of %d bytes", (int) size);
	}
	return mem;
}
Beispiel #3
0
//Memory allocation functions
void *mmc_alloc(size_t size)
{
	void *mem = mmc_tryalloc(size);
	if (! mem)
	{
		mmc_error("Cannot allocate memory of %d bytes", (int) size);
	}
	return mem;
}
Beispiel #4
0
static void mmc_inquiry(SIM_HBA *hba)
{
	SIM_MMC_EXT		*ext;
	CCB_SCSIIO		*ccb;
	SCSI_INQUIRY	*iptr;
	char			buf[8];

	ext		= (SIM_MMC_EXT *)hba->ext;
	ccb		= ext->nexus;
	iptr	= (SCSI_INQUIRY *)ccb->cam_data.cam_data_ptr;

	if (ccb->cam_ch.cam_flags & CAM_DATA_PHYS) {
		mmc_error(hba, CAM_PROVIDE_FAIL);
		return;
	}

	if (ext->state == MMCSD_STATE_IDENT)
		return;

	memset(iptr, 0, sizeof(*iptr));

	iptr->peripheral	= D_DIR_ACC | INQ_QUAL_AVAIL;
	iptr->rmb			= CAM_TRUE;		// removable
	iptr->version		= 1;
	iptr->adlen			= 32;

	if (!(ext->eflags & MMC_EFLAG_READY)) {
		mmc_sense(hba, SK_NOT_RDY, ASC_MEDIA_NOT_PRESENT, 0);
		return;
	}

	if (ext->version < MMC_VERSION_1) {
		/* Vendor ID */
		strcpy((char *)&iptr->vend_id[0], "SD:");
		ultoa(ext->cid.sd_cid.mid, buf, 10);
		iptr->vend_id[3] = buf[0];
		iptr->vend_id[4] = buf[1];
		iptr->vend_id[5] = buf[2];

		/* Product ID */
		strcpy((char *)&iptr->prod_id[0], (char *)ext->cid.sd_cid.pnm);

		/* Product revision level, BCD code */
		iptr->prod_rev[0] = (ext->cid.sd_cid.prv >> 4) + '0';
		iptr->prod_rev[1] = '.';
		iptr->prod_rev[2] = (ext->cid.sd_cid.prv & 0x0F) + '0';
	} else {
Beispiel #5
0
void *mmc_alloc2(size_t size1, size_t size2, void **mem2_return)
{
	void *mem1;
	
	//mem2 must be aligned to size of two pointers.
	//Adjust size1 for that.
	size1 = mmc_offset_align(size1);
	
	//Now allocate
	mem1 = mmc_tryalloc(size1 + size2);
	if (! mem1)
	{
		mmc_error("Cannot allocate memory of %d bytes", (int) (size1 + size2));
	}
	
	*mem2_return = MMC_PTR_ADD(mem1, size1);
	return mem1;
}