Example #1
0
CNdasUnitDevice*
CNdasUnitDeviceCreator::CreateUnitDevice()
{
    CNdasUnitDevice* pUnitDevice = NULL;

    m_pDevice->Lock();
    NDASID_EXT_DATA ndasIdExtension = m_pDevice->GetNdasIdExtension();
    m_pDevice->Unlock();

    BOOL fSuccess = m_devComm.Connect();
    if (!fSuccess)
    {
        XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR,
                  "devComm.Connect failed, device=%s, unit=%d, error=0x%X\n",
                  m_pDevice->ToStringA(), m_dwUnitNo,
                  GetLastError());

        return NULL;
    }

    //
    // Discover unit device information
    //
    ZeroMemory(&m_udinfo, sizeof(NDAS_UNITDEVICE_HARDWARE_INFO));
    m_udinfo.Size = sizeof(NDAS_UNITDEVICE_HARDWARE_INFO);
    fSuccess = m_devComm.GetUnitDeviceInformation(&m_udinfo);

    //
    // Seagate Extension
    //
    if (ndasIdExtension.VID == NDAS_VID_SEAGATE)
    {
        if (m_udinfo.Model[0] != 'S' || m_udinfo.Model[1] != 'T')
        {
            XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR,
                      "VID Restriction to %s[%d]: Model=%ls\n",
                      m_pDevice->ToStringA(), m_dwUnitNo, m_udinfo.Model);

            return _CreateUnknownUnitDiskDevice(NDAS_UNITDEVICE_ERROR_SEAGATE_RESTRICTION);
        }
    }

    if (!fSuccess)
    {
        XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR,
                  "GetUnitDeviceInformation failed, device=%s, unit=%d, error=0x%X\n",
                  m_pDevice->ToStringA(), m_dwUnitNo, GetLastError());

        return _CreateUnknownUnitDevice();
    }


    if (NDAS_UNITDEVICE_MEDIA_TYPE_BLOCK_DEVICE == m_udinfo.MediaType)
    {
        pUnitDevice = CreateUnitDiskDevice();
    }
    else if (NDAS_UNITDEVICE_MEDIA_TYPE_COMPACT_BLOCK_DEVICE == m_udinfo.MediaType)
    {

        // Not implemented yet
        // pUnitDevice = CreateCompactBlockDevice()

        NDAS_LOGICALDEVICE_GROUP ldGroup = {0};
        ldGroup.nUnitDevices = 1;
        ldGroup.nUnitDevicesSpare = 0;
        ldGroup.Type = NDAS_LOGICALDEVICE_TYPE_FLASHCARD;
        ldGroup.UnitDevices[0].DeviceId = m_pDevice->GetDeviceId();
        ldGroup.UnitDevices[0].UnitNo = m_dwUnitNo;

        pUnitDevice = new CNdasUnitDevice(
            m_pDevice,
            m_dwUnitNo,
            NDAS_UNITDEVICE_TYPE_COMPACT_BLOCK,
            CNdasUnitDevice::CreateSubType(NDAS_UNITDEVICE_COMPACT_BLOCK_TYPE_FLASHCARD),
            m_udinfo,
            ldGroup,
            0);

    }
    else if (NDAS_UNITDEVICE_MEDIA_TYPE_CDROM_DEVICE == m_udinfo.MediaType)
    {
        NDAS_LOGICALDEVICE_GROUP ldGroup = {0};
        ldGroup.nUnitDevices = 1;
        ldGroup.nUnitDevicesSpare = 0;
        ldGroup.Type = NDAS_LOGICALDEVICE_TYPE_DVD;
        ldGroup.UnitDevices[0].DeviceId = m_pDevice->GetDeviceId();
        ldGroup.UnitDevices[0].UnitNo = m_dwUnitNo;

        pUnitDevice = new CNdasUnitDevice(
            m_pDevice,
            m_dwUnitNo,
            NDAS_UNITDEVICE_TYPE_CDROM,
            CNdasUnitDevice::CreateSubType(NDAS_UNITDEVICE_CDROM_TYPE_DVD),
            m_udinfo,
            ldGroup,
            0);
    }
    else if (NDAS_UNITDEVICE_MEDIA_TYPE_OPMEM_DEVICE == m_udinfo.MediaType)
    {

        NDAS_LOGICALDEVICE_GROUP ldGroup = {0};
        ldGroup.nUnitDevices = 1;
        ldGroup.nUnitDevicesSpare = 0;
        ldGroup.Type = NDAS_LOGICALDEVICE_TYPE_DVD;
        ldGroup.UnitDevices[0].DeviceId = m_pDevice->GetDeviceId();
        ldGroup.UnitDevices[0].UnitNo = m_dwUnitNo;

        pUnitDevice = new CNdasUnitDevice(
            m_pDevice,
            m_dwUnitNo,
            NDAS_UNITDEVICE_TYPE_OPTICAL_MEMORY,
            CNdasUnitDevice::CreateSubType(NDAS_UNITDEVICE_OPTICAL_MEMORY_TYPE_MO),
            m_udinfo,
            ldGroup,
            0);
    }
    else
    {
        XTLASSERT(FALSE);
        pUnitDevice = NULL;
    }

    return pUnitDevice;
}
CNdasUnitDevice*
CNdasUnitDeviceCreator::CreateUnitDevice()
{
	CNdasUnitDevice* pUnitDevice = NULL;

	BOOL fSuccess = m_devComm.Connect();
	if (!fSuccess) 
	{
		DBGPRT_ERR_EX(
			_FT("Communication initialization to %s[%d] failed: "),
			m_pDevice->ToString(), 
			m_dwUnitNo);
		return NULL;
	}

	//
	// Discover unit device information
	//
	::ZeroMemory(&m_udinfo, sizeof(NDAS_UNITDEVICE_HARDWARE_INFO));
	m_udinfo.Size = sizeof(NDAS_UNITDEVICE_HARDWARE_INFO);
	fSuccess = m_devComm.GetUnitDeviceInformation(&m_udinfo);

	if (!fSuccess) 
	{
		DBGPRT_ERR_EX(_FT("GetUnitDeviceInformation of %s[%d] failed: "), 
			m_pDevice->ToString(), 
			m_dwUnitNo);
		return _CreateUnknownUnitDevice();
	}


	if (NDAS_UNITDEVICE_MEDIA_TYPE_BLOCK_DEVICE == m_udinfo.MediaType) 
	{
		pUnitDevice = CreateUnitDiskDevice();
	}
	else if (NDAS_UNITDEVICE_MEDIA_TYPE_COMPACT_BLOCK_DEVICE == m_udinfo.MediaType) 
	{

		// Not implemented yet
		// pUnitDevice = CreateCompactBlockDevice()

		NDAS_LOGICALDEVICE_GROUP ldGroup = {0};
		ldGroup.nUnitDevices = 1;
		ldGroup.nUnitDevicesSpare = 0;
		ldGroup.Type = NDAS_LOGICALDEVICE_TYPE_FLASHCARD;
		ldGroup.UnitDevices[0].DeviceId = m_pDevice->GetDeviceId();
		ldGroup.UnitDevices[0].UnitNo = m_dwUnitNo;

		pUnitDevice = new CNdasUnitDevice(
			m_pDevice,
			m_dwUnitNo,
			NDAS_UNITDEVICE_TYPE_COMPACT_BLOCK,
			CNdasUnitDevice::CreateSubType(NDAS_UNITDEVICE_COMPACT_BLOCK_TYPE_FLASHCARD),
			m_udinfo,
			ldGroup,
			0);

	}
	else if (NDAS_UNITDEVICE_MEDIA_TYPE_CDROM_DEVICE == m_udinfo.MediaType) 
	{
		NDAS_LOGICALDEVICE_GROUP ldGroup = {0};
		ldGroup.nUnitDevices = 1;
		ldGroup.nUnitDevicesSpare = 0;
		ldGroup.Type = NDAS_LOGICALDEVICE_TYPE_DVD;
		ldGroup.UnitDevices[0].DeviceId = m_pDevice->GetDeviceId();
		ldGroup.UnitDevices[0].UnitNo = m_dwUnitNo;

		pUnitDevice = new CNdasUnitDevice(
			m_pDevice,
			m_dwUnitNo,
			NDAS_UNITDEVICE_TYPE_CDROM,
			CNdasUnitDevice::CreateSubType(NDAS_UNITDEVICE_CDROM_TYPE_DVD),
			m_udinfo,
			ldGroup,
			0);
	}
	else if (NDAS_UNITDEVICE_MEDIA_TYPE_OPMEM_DEVICE == m_udinfo.MediaType) 
	{

		NDAS_LOGICALDEVICE_GROUP ldGroup = {0};
		ldGroup.nUnitDevices = 1;
		ldGroup.nUnitDevicesSpare = 0;
		ldGroup.Type = NDAS_LOGICALDEVICE_TYPE_DVD;
		ldGroup.UnitDevices[0].DeviceId = m_pDevice->GetDeviceId();
		ldGroup.UnitDevices[0].UnitNo = m_dwUnitNo;

		pUnitDevice = new CNdasUnitDevice(
			m_pDevice,
			m_dwUnitNo,
			NDAS_UNITDEVICE_TYPE_OPTICAL_MEMORY,
			CNdasUnitDevice::CreateSubType(NDAS_UNITDEVICE_OPTICAL_MEMORY_TYPE_MO),
			m_udinfo,
			ldGroup,
			0);
	}
	else 
	{
		XTLASSERT(FALSE);
		pUnitDevice = NULL;
	}

	return pUnitDevice;
}