Example #1
0
BOOL 
CNdasDeviceRegistrar::Unregister(const NDAS_DEVICE_ID& DeviceId)
{
	InstanceAutoLock autolock(this);

	XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_INFORMATION,
		"Unregister device %s\n", CNdasDeviceId(DeviceId).ToStringA());

	DeviceIdMap::iterator itrId = m_deviceIdMap.find(DeviceId);
	if (m_deviceIdMap.end() == itrId) 
	{
		::SetLastError(NDASSVC_ERROR_DEVICE_ENTRY_NOT_FOUND);
	}

	CNdasDevicePtr pDevice = itrId->second;
	
	if (pDevice->GetStatus() != NDAS_DEVICE_STATUS_DISABLED) 
	{
		::SetLastError(NDASSVC_ERROR_CANNOT_UNREGISTER_ENABLED_DEVICE);
		return FALSE;
	}

	DWORD SlotNo = pDevice->GetSlotNo();
	XTLASSERT(0 != SlotNo);

	DeviceSlotMap::iterator itrSlot = m_deviceSlotMap.find(SlotNo);

	m_deviceIdMap.erase(itrId);
	m_deviceSlotMap.erase(itrSlot);
	m_slotbit[SlotNo] = false;

	XTL::CStaticStringBuffer<30> containerName(_T("Devices\\%04d"), SlotNo);
	BOOL fSuccess = _NdasSystemCfg.DeleteContainer(containerName, TRUE);
	if (!fSuccess) 
	{
		XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_WARNING,
			"Deleting registration entry from the registry failed at %ls, error=0x%X\n", 
			containerName, GetLastError());
	}

	(void) m_service.GetEventPublisher().DeviceEntryChanged();

	return TRUE;
}
Example #2
0
CNdasDeviceRegistrar::CNdasDeviceRegistrar() :
    m_fBootstrapping(FALSE),
    m_slotbit(MAX_SLOT_NUMBER + 1)
{
    XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_INFORMATION,
              "CNdasDeviceRegistrar::ctor()\n");

    // Slot 0 is always occupied and reserved!
    m_slotbit[0] = true;
}
Example #3
0
HRESULT
pGetVolumeMountPointForPathW(
	__in LPCWSTR Path,
	__out LPWSTR* MountPoint)
{
	if (NULL == MountPoint)
	{
		return E_POINTER;
	}

	*MountPoint = NULL;

	// TODO: It is possible to be the path is more than MAX_PATH
	// in case of supporting unicode file names up to 65534
	DWORD mountPointLength = MAX_PATH;
	XTL::AutoProcessHeapPtr<TCHAR> mountPoint = 
		static_cast<TCHAR*>(
			::HeapAlloc(
				::GetProcessHeap(), 
				HEAP_ZERO_MEMORY,
				mountPointLength * sizeof(WCHAR)));

	if (mountPoint.IsInvalid())
	{
		return E_OUTOFMEMORY;
	}

	if (!GetVolumePathName(Path, mountPoint, mountPointLength))
	{
		HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
		XTLTRACE2(NdasVolTrace, TRACE_LEVEL_ERROR,
			"GetVolumePathName(%ls) failed, hr=0x%X\n",
			Path, hr);
		return hr;
	}

	XTLTRACE2(NdasVolTrace, TRACE_LEVEL_INFORMATION,
		"Path(%ls) is mounted from %s.\n", Path, mountPoint);

	*MountPoint = mountPoint.Detach();

	return S_OK;
}
CNdasUnitDevice*
CNdasUnitDeviceCreator::_CreateUnknownUnitDiskDevice(NDAS_UNITDEVICE_ERROR Error)
{
	CNdasUnitDevice* pUnitDevice = 
		new CNdasNullUnitDiskDevice(m_pDevice, m_dwUnitNo, m_udinfo, Error);
	if (NULL == pUnitDevice)
	{
		XTLTRACE2(TLError, TCUnitDevice, "OUTOFMEM for CNdasNullUnitDiskDevice\n");
	}
	return pUnitDevice;
}
Example #5
0
LRESULT 
CNdasServiceDeviceEventHandler::OnDeviceHandleQueryRemove(
	PDEV_BROADCAST_HANDLE pdbch)
{
	XTLTRACE2(NDASSVC_PNP, TRACE_LEVEL_INFORMATION, 
		"OnDeviceHandleQueryRemove: Device Handle %p, Notify Handle %p\n", 
		pdbch->dbch_handle,
		pdbch->dbch_hdevnotify);

	return TRUE;
}
CNdasUnitDevice*
CNdasUnitDeviceCreator::_CreateUnknownUnitDevice()
{
	CNdasUnitDevice* pUnitDevice = 
		new CNdasNullUnitDevice(m_pDevice, m_dwUnitNo);
	if (NULL == pUnitDevice)
	{
		XTLTRACE2(TLError, TCUnitDevice, "OUTOFMEM for CNdasNullUnitDevice\n");
	}
	return pUnitDevice;
}
Example #7
0
LRESULT 
CNdasServiceDeviceEventHandler::
OnDeviceHandleQueryRemove(
	PDEV_BROADCAST_HANDLE pdbch)
{
	XTLTRACE2(TCPnp, TLInfo, 
		"OnDeviceHandleQueryRemove: Device Handle %p, Notify Handle %p\n", 
		pdbch->dbch_handle,
		pdbch->dbch_hdevnotify);
	return TRUE;
}
Example #8
0
NDASVOL_LINKAGE
HRESULT
NDASVOL_CALL
NdasGetNdasLocationForVolume(
	IN HANDLE hVolume, 
	OUT PNDAS_LOCATION NdasLocation)
{
	XTLTRACE2(NdasVolTrace, TRACE_LEVEL_INFORMATION, 
		"NdasGetNdasScsiSlotNumber(%p)\n", hVolume);

	if (NULL == NdasLocation) 
	{
		return E_POINTER;
	}

	*NdasLocation = 0;

	NDAS_LOCATION location = 0;
	
	HRESULT hr = NdasEnumNdasLocationsForVolume(
		hVolume, 
		SimpleNdasLocationEnum, 
		&location);
	
	if (FAILED(hr))
	{
		XTLTRACE2(NdasVolTrace, TRACE_LEVEL_ERROR, 
			"NdasEnumNdasLocationsForVolume failed, hr=0x%X\n", hr);
		return hr;
	} 
	else if (0 == location) // means not found!
	{
		XTLTRACE2(NdasVolTrace, TRACE_LEVEL_ERROR, 
			"Slot No is zero.\n");
		return S_FALSE;
	}

	*NdasLocation = location;

	return S_OK;
}
Example #9
0
void 
CNdasServiceDeviceEventHandler::OnDeviceHandleRemovePending(
	PDEV_BROADCAST_HANDLE pdbch)
{
	//
	// RemoveComplete will handle the completion of the removal
	//
	XTLTRACE2(NDASSVC_PNP, TRACE_LEVEL_INFORMATION, 
		"OnDeviceHandleRemovePending: Device Handle %p, Notify Handle %p\n", 
		pdbch->dbch_handle,
		pdbch->dbch_hdevnotify);
}
Example #10
0
DWORD
CNdasIXBcast::ThreadStart(HANDLE hStopEvent)
{
	if (0 == m_NDFSVersion.wMajor && 0 == m_NDFSVersion.wMinor)
	{
		return 1;
	}

	HANDLE waitHandles[] = { 
		hStopEvent, 
		m_sockAddrChangeNotifier.GetChangeEvent()};
	const DWORD nWaitHandles = RTL_NUMBER_OF(waitHandles);

	// CTask::Initialized called?
	XTLASSERT(NULL != waitHandles[0]);
	// m_sockAddrChangeNotifier is initialized?
	XTLASSERT(NULL != waitHandles[1]);

	//
	// Initial bind
	//
	ResetBind(hStopEvent);

	//
	// initial LPX socket address list is attained
	//
	DWORD dwTimeout = 1000; // broadcast interval
	while (TRUE) 
	{
		DWORD waitResult = ::WaitForMultipleObjects(
			nWaitHandles, waitHandles, FALSE, dwTimeout);

		if (WAIT_OBJECT_0 == waitResult) 
		{
			return 0;
		}
		else if (WAIT_OBJECT_0 + 1 == waitResult) 
		{
			// reset bind
			ResetBind(hStopEvent);
		}
		else if (WAIT_TIMEOUT == waitResult) 
		{
			BroadcastStatus();
		}
		else 
		{
			XTLTRACE2(NDASSVC_IX, TRACE_LEVEL_ERROR,
				"WaitForMultipleObject failed, waitResult=%d.\n", waitResult);
			XTLASSERT(FALSE);
		}
	}
}
Example #11
0
CNdasUnitDevice*
CNdasUnitDeviceCreator::_CreateUnknownUnitDiskDevice(NDAS_UNITDEVICE_ERROR Error)
{
    CNdasUnitDevice* pUnitDevice =
        new CNdasNullUnitDiskDevice(m_pDevice, m_dwUnitNo, m_udinfo, Error);
    if (NULL == pUnitDevice)
    {
        XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR,
                  "new CNdasNullUnitDiskDevice failed\n");
    }
    return pUnitDevice;
}
Example #12
0
DWORD
CNdasDeviceHeartbeatListener::ThreadStart(HANDLE hStopEvent)
{
	CCoInitialize coinit(COINIT_MULTITHREADED);

	DWORD ret;

	XTLTRACE2(NDASSVC_HEARTBEAT, TRACE_LEVEL_INFORMATION, 
		"Starting NDAS Heartbeat Listener.\n");

	CLpxDatagramServer dgramServer;

	BOOL success = dgramServer.Initialize();
	if (!success) 
	{
		XTLTRACE2(NDASSVC_HEARTBEAT, TRACE_LEVEL_ERROR, 
			"CLpxDatagramServer init failed, error=0x%X\n",
			GetLastError());
		return ret = 254;
	}

	success = dgramServer.Receive(
		this, 
		m_ListenPort, 
		sizeof(HEARTBEAT_RAW_DATA),
		hStopEvent);

	if (!success) 
	{
		XTLTRACE2(NDASSVC_HEARTBEAT, TRACE_LEVEL_ERROR,
			"Listening Heartbeat at port %d failed, error=0x%X\n", 
			m_ListenPort, GetLastError());
		return ret = 255;
	}

	XTLTRACE2(NDASSVC_HEARTBEAT, TRACE_LEVEL_INFORMATION, 
		"NDAS Heartbeat Stopped.\n");

	return ret = 0;
}
Example #13
0
//
// Returns the symbolic link name of the disk.
//
// Caller should free the non-null returned pointer
// with HeapFree(GetProcessHeap(),...)
//
LPTSTR
pGetChildDevInstIdsForNdasScsiLocation(
    const NDAS_SCSI_LOCATION* NdasScsiLocation)
{
    DEVINST NdasScsiDevInst;
    if (!pFindNdasScsiDevInst(&NdasScsiDevInst, NdasScsiLocation->SlotNo))
    {
        XTLTRACE2(NdasVolTrace, TRACE_LEVEL_ERROR,
                  "FindNdasScsiDevInst failed, error=0x%X\n", GetLastError());
        return NULL;
    }

    TCHAR NdasScsiInstanceId[MAX_DEVICE_ID_LEN];
    CONFIGRET ret = ::CM_Get_Device_ID(
                        NdasScsiDevInst,
                        NdasScsiInstanceId,
                        RTL_NUMBER_OF(NdasScsiInstanceId),
                        0);
    if (CR_SUCCESS != ret)
    {
        XTLTRACE2(NdasVolTrace, TRACE_LEVEL_ERROR,
                  "CM_Get_Device_ID failed, cret=0x%X\n", ret);
        return NULL;
    }

    XTL::AutoProcessHeapPtr<TCHAR> ChildDevInstIdList;
    ret = pCMGetDeviceIDList(
              &ChildDevInstIdList,
              NdasScsiInstanceId,
              CM_GETIDLIST_FILTER_BUSRELATIONS);
    if (CR_SUCCESS != ret)
    {
        XTLTRACE2(NdasVolTrace, TRACE_LEVEL_ERROR,
                  "pCMGetDeviceIDList failed, cret=0x%X\n", ret);
        ::SetLastError(ConfigRetToWin32Error(ret));
        return NULL;
    }

    return ChildDevInstIdList.Detach();
}
Example #14
0
STDMETHODIMP 
CNdasDiskUnit::IsBitmapClean()
{
	CAutoInstanceLock autolock(this);

	CNdasDeviceComm devComm(m_pParentNdasDevice, m_unitDeviceId.UnitNo);

	HRESULT hr = devComm.Connect(FALSE);
	if (FAILED(hr)) 
	{
		return hr;
	}

	NDAS_UNITDEVICE_HARDWARE_INFO udinfo = {0};
	udinfo.Size = sizeof(NDAS_UNITDEVICE_HARDWARE_INFO);
	hr = devComm.GetNdasUnitInfo(&udinfo);
	if (FAILED(hr)) 
	{
		XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR,
			"GetUnitDeviceInformation of %s failed, error=0x%X\n", 
			CNdasUnitDeviceId(m_unitDeviceId).ToStringA(), hr);
		return hr;
	}

	BYTE BitmapData[128 * 512] = {0};

	// 1MB from NDAS_BLOCK_LOCATION_BITMAP
	for (INT i = 0; i < 16; i++)  
	{
		hr = devComm.ReadDiskBlock(
			BitmapData, 
			NDAS_BLOCK_LOCATION_BITMAP + (i * 128), 
			128);

		if (FAILED(hr)) 
		{
			return hr;
		}

		PULONG pBitmapData = (PULONG)BitmapData;
		for (INT j = 0; j < 128 * 512 / 4; ++j) 
		{
			if (*pBitmapData) 
			{
				return E_FAIL;
			}
			pBitmapData++;
		}
	}	

	return S_OK;
}
Example #15
0
STDMETHODIMP 
CNdasDiskUnit::FillBlockAcl(__in PVOID BlockAcl)
{
	PNDAS_BLOCK_ACL pNdasBlockAcl = (NDAS_BLOCK_ACL *)BlockAcl;
	PNDAS_BLOCK_ACE pNdasBlockAce = NULL;
	PBLOCK_ACCESS_CONTROL_LIST_ELEMENT pBACLE = NULL;

	if (!m_pBACL)
	{
		return S_FALSE;
	}

	if (!BlockAcl)
	{
		return S_FALSE;
	}

	UINT nBACLESkipped = 0;
	for (UINT i = 0; i < m_pBACL->ElementCount; i++)
	{
		ATLASSERT(FALSE);

		pBACLE = &m_pBACL->Elements[i];
		if (!(pBACLE->AccessMask & BACL_ACCESS_MASK_PC_SYSTEM))
		{
			nBACLESkipped++;
			continue;
		}
		pNdasBlockAce = &pNdasBlockAcl->BlockACEs[i - nBACLESkipped];
		pNdasBlockAce->AccessMode |= 
			(pBACLE->AccessMask & BACL_ACCESS_MASK_WRITE) ? NBACE_ACCESS_WRITE : 0;
		pNdasBlockAce->AccessMode |= 
			(pBACLE->AccessMask & BACL_ACCESS_MASK_READ) ? NBACE_ACCESS_READ : 0;
		
		pNdasBlockAce->StartingOffset = pBACLE->ui64StartSector * 512;
		pNdasBlockAce->Length = pBACLE->ui64SectorCount * 512;

		XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_INFORMATION,
			"FillBACL() pNdasBlockAce : %x %I64d ~ %I64d\n",
			pNdasBlockAce->AccessMode,
			pNdasBlockAce->StartingOffset,
			pNdasBlockAce->Length);
	}

	DWORD blockAclLength;
	COMVERIFY(get_BlockAclSize(nBACLESkipped, &blockAclLength));

	pNdasBlockAcl->Length = blockAclLength;
	pNdasBlockAcl->BlockACECnt = m_pBACL->ElementCount - nBACLESkipped;

	return S_OK;
}
HRESULT
CNdasDeviceComm::Disconnect()
{
	BOOL success = ::NdasCommDisconnect(m_hNdas);
	if (!success)
	{
		HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
		XTLTRACE2(NDASSVC_NDASCOMM, TRACE_LEVEL_ERROR,
			"NdasCommDisconnect failed, hr=0x%X\n", hr);
		return hr;
	}
	return S_OK;
}
Example #17
0
HRESULT 
CNdasServiceDeviceEventHandler::RegisterDeviceInterfaceNotification(
	__in LPCGUID InterfaceGuid,
	__in LPCSTR TypeName)
{
	HDEVNOTIFY devNotifyHandle;

	HRESULT hr = pRegisterDeviceInterfaceNotification(
		m_hRecipient, 
		m_dwReceptionFlags,
		InterfaceGuid,
		&devNotifyHandle);

	if (FAILED(hr))
	{
		XTLTRACE2(NDASSVC_PNP, TRACE_LEVEL_ERROR,
			"RegisterDeviceInterfaceNotification failed, type=%hs, hr=0x%X\n",
			TypeName, hr);
		return hr;
	}

	try
	{
		m_DeviceInterfaceNotifyHandles.push_back(devNotifyHandle);
	}
	catch (...)
	{
		XTLTRACE2(NDASSVC_PNP, TRACE_LEVEL_ERROR,
			"RegisterDeviceInterfaceNotification failed, "
			"C++ exception, type=%hs\n",
			TypeName);			

		XTLVERIFY(UnregisterDeviceNotification(devNotifyHandle));

		return E_FAIL;
	}

	return S_OK;
}
Example #18
0
DWORD
CNdasService::Impl::OnServiceShutdown()
{
	XTLTRACE2(NDASSVC_INIT, TRACE_LEVEL_INFORMATION, 
		"System is shutting down...\n");

	m_cLogDeviceManager.OnShutdown();
	m_cDeviceEventHandler.OnShutdown();

	XTLVERIFY( ::LfsFiltCtlShutdown() );
	
	return NO_ERROR;
}
Example #19
0
VOID
CNdasIXServer::OnIXPrimaryUpdate(
	CLpxDatagramSocket& sock,
	CONST SOCKADDR_LPX* pRemoteAddr,
	CONST LSINFOX_PRIMARY_UPDATE* pData)
{
	NDAS_UNITDEVICE_ID unitDeviceId = { 
		{ 
			pData->NetDiskNode[0], pData->NetDiskNode[1],
			pData->NetDiskNode[2], pData->NetDiskNode[3],
			pData->NetDiskNode[4], pData->NetDiskNode[5]
		}, 
		pData->UnitDiskNo
	};

	CNdasUnitDevicePtr pUnitDevice = pGetNdasUnitDevice(unitDeviceId);
	if (0 == pUnitDevice.get()) {
		//
		// Discard non-discovered unit device
		//
		return;
	}

	NDAS_UNITDEVICE_PRIMARY_HOST_INFO hostinfo;

	::CopyMemory(
		hostinfo.Host.Node, 
		pData->PrimaryNode,
		sizeof(hostinfo.Host.Node));

	hostinfo.Host.Port = NTOHS(pData->PrimaryPort);
	hostinfo.SWMajorVersion = pData->SWMajorVersion;
	hostinfo.SWMinorVersion = pData->SWMinorVersion;
	hostinfo.SWBuildNumber = pData->SWBuildNumber;
	hostinfo.NDFSCompatVersion = pData->NDFSCompatVersion;
	hostinfo.NDFSVersion = pData->NDFSVersion;

	XTLTRACE2(NDASSVC_IX, TRACE_LEVEL_RESERVED6,
		"LSINFOX_PRIMATE_UPDATE_MESSAGE: %02X:%02X:%02X:%02X:%02X:%02X@%d\n",
		pData->NetDiskNode[0],
		pData->NetDiskNode[1],
		pData->NetDiskNode[2],
		pData->NetDiskNode[3],
		pData->NetDiskNode[4],
		pData->NetDiskNode[5],
		pData->UnitDiskNo);

	pUnitDevice->UpdatePrimaryHostInfo(hostinfo);

	return;
}
Example #20
0
BOOL
CNdasUnitDeviceCreator::ReadDIBv1AndConvert(PNDAS_DIB_V2 pDIBv2)
{
    BOOL fSuccess = FALSE;
    NDAS_DIB DIBv1 = {0};
    PNDAS_DIB pDIBv1 = &DIBv1;

    fSuccess = m_devComm.ReadDiskBlock(
                   reinterpret_cast<PBYTE>(pDIBv1),
                   NDAS_BLOCK_LOCATION_DIB_V1);

    if (!fSuccess)
    {
        XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR,
                  "ReadDiskBlock(DIBv1) failed, error=0x%X\n",
                  GetLastError());
        return FALSE;
    }

    //
    // If there is no DIB in the disk,
    // create a pseudo DIBv2
    //
    if (NDAS_DIB_SIGNATURE != pDIBv1->Signature ||
            IS_NDAS_DIBV1_WRONG_VERSION(*pDIBv1))
    {
        //
        // Create a pseudo DIBv2
        //
        InitializeDIBv2AsSingle(pDIBv2);
        return TRUE;
    }

    //
    // Convert V1 to V2
    //
    fSuccess = ConvertDIBv1toDIBv2(
                   pDIBv1,
                   pDIBv2,
                   m_udinfo.SectorCount.QuadPart);

    if (!fSuccess) {
        //
        // Create a pseudo DIBv2 again!
        //
        InitializeDIBv2AsSingle(pDIBv2);
        return TRUE;
    }

    return TRUE;
}
Example #21
0
BOOL
CNdasUnitDiskDevice::IsBitmapClean()
{
	InstanceAutoLock autolock(this);

	CNdasDevicePtr pParentDevice(m_pParentDevice);
	CNdasDeviceComm devComm(pParentDevice, m_unitDeviceId.UnitNo);

	BOOL fSuccess = devComm.Connect(FALSE);
	if(!fSuccess) 
	{
		return FALSE;
	}

	NDAS_UNITDEVICE_HARDWARE_INFO udinfo = {0};
	udinfo.Size = sizeof(NDAS_UNITDEVICE_HARDWARE_INFO);
	fSuccess = devComm.GetUnitDeviceInformation(&udinfo);
	if (!fSuccess) 
	{
		XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_ERROR,
			"GetUnitDeviceInformation of %s failed, error=0x%X\n", 
			this->ToStringA(), GetLastError());
		return FALSE;
	}

	BYTE BitmapData[128 * 512] = {0};

	// 1MB from NDAS_BLOCK_LOCATION_BITMAP
	for(INT i = 0; i < 16; i++)  
	{
		fSuccess = devComm.ReadDiskBlock(BitmapData, 
			NDAS_BLOCK_LOCATION_BITMAP + (i * 128), 128);

		if(!fSuccess) 
		{
			return FALSE;
		}

		PULONG pBitmapData = (PULONG)BitmapData;
		for (INT j = 0; j < 128 * 512 / 4; ++j) 
		{
			if(*pBitmapData) 
			{
				return FALSE;
			}
			pBitmapData++;
		}
	}	

	return TRUE;
}
Example #22
0
HRESULT 
CNdasDiskUnit::UnitInitialize(
	__in INdasDevice* pNdasDevice, 
	__in DWORD UnitNo, 
	__in NDAS_DISK_UNIT_TYPE DiskType, 
	__in const NDAS_UNITDEVICE_HARDWARE_INFO& HardwareInfo, 
	__in const NDAS_LOGICALUNIT_DEFINITION& NdasLogicalUnitDefinition,
	__in DWORD LuSequence,
	__in UINT64 UserBlocks,
	__in PVOID pRaidInfo,
	__in const NDAS_CONTENT_ENCRYPT& Encryption,
	__in NDAS_DIB_V2* pDIBv2,
	__in BLOCK_ACCESS_CONTROL_LIST *pBlockAcl)
{
	HRESULT hr = CNdasUnitImpl::ImplInitialize(
		pNdasDevice, UnitNo, NDAS_UNITDEVICE_TYPE_DISK, 
		CreateSubType(DiskType),
		HardwareInfo,
		NdasLogicalUnitDefinition,
		LuSequence);

	if (FAILED(hr))
	{
		ATLASSERT(FALSE);
		return hr;
	}

	ATLASSERT(NULL != pDIBv2);

	m_ulUserBlocks = UserBlocks;
	m_pNdasLogicalUnitRaidInfo.Attach(pRaidInfo);
	m_contentEncrypt = Encryption;
	m_pDIBv2.Attach(pDIBv2);
	m_pBACL.Attach(pBlockAcl);
	m_diskType = DiskType;

	//
	// m_pDIBv2 and m_pAddTargetInfo will be deleted 
	// by this class on destruction
	//
	XTLASSERT(
	(NDAS_CONTENT_ENCRYPT_METHOD_NONE == m_contentEncrypt.Method &&
	m_contentEncrypt.KeyLength == 0) ||
	(NDAS_CONTENT_ENCRYPT_METHOD_NONE != m_contentEncrypt.Method &&
	m_contentEncrypt.KeyLength > 0));

	XTLTRACE2(NDASSVC_NDASUNITDEVICE, TRACE_LEVEL_VERBOSE, 
		"%s\n", CNdasUnitDeviceId(m_unitDeviceId).ToStringA());

	return S_OK;
}
Example #23
0
BOOL
pFindNdasScsiDevInst(
    DEVINST* TargetDevInst,
    DWORD UINumber)
{
    // Get devices under Enum\NDAS
    XTL::AutoDeviceInfoSet devInfoSet = ::SetupDiGetClassDevs(
                                            NULL,
                                            _T("NDAS"),
                                            NULL,
                                            DIGCF_ALLCLASSES | DIGCF_PRESENT);
    if (devInfoSet.IsInvalid())
    {
        XTLTRACE2(NdasVolTrace, TRACE_LEVEL_ERROR,
                  "SetupDiGetClassDevs failed, error=0x%X\n", GetLastError());
        return FALSE;
    }
    for (DWORD i = 0; ; ++i)
    {
        SP_DEVINFO_DATA devInfoData = {0};
        devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
        BOOL fSuccess = ::SetupDiEnumDeviceInfo(devInfoSet, i, &devInfoData);
        if (!fSuccess)
        {
            XTLTRACE2(NdasVolTrace, TRACE_LEVEL_ERROR,
                      "SetupDiEnumDeviceInfo failed, error=0x%X\n", GetLastError());
            break;
        }
        DWORD uiNumber = pGetDeviceUINumber(devInfoSet, &devInfoData);
        if (UINumber == uiNumber)
        {
            *TargetDevInst = devInfoData.DevInst;
            return TRUE;
        }
    }
    return FALSE;
}
Example #24
0
HRESULT
CNdasLogicalUnitManager::Unregister(INdasUnit* pNdasUnit)
{
	XTLTRACE2(NDASSVC_NDASLOGDEVMANAGER, TRACE_LEVEL_INFORMATION, 
		"Unregistering NdasUnit=%p from LDM\n", pNdasUnit);

	if (NULL == pNdasUnit)
	{
		return E_POINTER;
	}

	CComPtr<INdasLogicalUnit> pNdasLogicalUnit;
	COMVERIFY(pNdasUnit->get_NdasLogicalUnit(&pNdasLogicalUnit));

	DWORD luseq;
	COMVERIFY(pNdasUnit->get_LogicalUnitSequence(&luseq));

	COMVERIFY(pNdasLogicalUnit->RemoveNdasUnitInstance(pNdasUnit));

	DWORD instanceCount;
	COMVERIFY(pNdasLogicalUnit->get_NdasUnitInstanceCount(&instanceCount));

	if (0 == instanceCount) 
	{
		NDAS_LOGICALDEVICE_ID logicalUnitId;
		COMVERIFY(pNdasLogicalUnit->get_Id(&logicalUnitId));

		NDAS_LOGICALDEVICE_GROUP logicalUnitDefinition;
		COMVERIFY(pNdasLogicalUnit->get_LogicalUnitDefinition(&logicalUnitDefinition));

		LockInstance();
		XTLVERIFY(1 == m_LogicalUnitDefinitionMap.erase(logicalUnitDefinition));
		XTLVERIFY(1 == m_LogicalUnitIdMap.erase(logicalUnitId));
		size_t count = m_NdasLogicalUnits.GetCount();
		for (size_t i = 0; i < count; ++i)
		{
			INdasLogicalUnit* p = m_NdasLogicalUnits.GetAt(i);
			if (p == pNdasLogicalUnit)
			{
				m_NdasLogicalUnits.RemoveAt(i);
				break;
			}
		}
		XTLVERIFY(pDeallocateID(logicalUnitId));
		UnlockInstance();
	}

	return S_OK;
}
void
CNdasEventMonitor::Attach(INdasDevice* pNdasDevice)
{
	DWORD slotNo;
	COMVERIFY(pNdasDevice->get_SlotNo(&slotNo));
	XTLTRACE2(NDASSVC_EVENTMON, TRACE_LEVEL_INFORMATION,
		"Attaching ndas device %d to the monitor\n", slotNo);

	// DEVICE WRITE LOCK REGION
	{
		XTL::CWriterLockHolder holder(m_NdasDeviceDataLock);
		m_NdasDevices.Add(pNdasDevice);
	}
	// DEVICE WRITE LOCK REGION
}
Example #26
0
CNdasDeviceRegistrar::
CNdasDeviceRegistrar(
	CNdasService& service,
	DWORD MaxSlotNo) :
	m_service(service),
	m_fBootstrapping(FALSE),
	m_dwMaxSlotNo(MaxSlotNo),
	m_slotbit(MaxSlotNo + 1)
{
	XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_INFORMATION,
		"CNdasDeviceRegistrar::ctor()\n");

	// Slot 0 is always occupied and reserved!
	m_slotbit[0] = true;
}
Example #27
0
BOOL
DisableDiskWriteCache(LPCTSTR szDiskPath)
{
	XTLTRACE2(NDASSVC_SYSTEMUTIL, TRACE_LEVEL_INFORMATION, 
		"CreateFile(%ls).\n", szDiskPath);

	XTL::AutoFileHandle hDisk = ::CreateFile(
		szDiskPath, 
		GENERIC_READ | GENERIC_WRITE,
		0,
		NULL,
		OPEN_EXISTING,
		0,
		NULL);

	if (hDisk.IsInvalid()) 
	{
		XTLTRACE2(NDASSVC_SYSTEMUTIL, TRACE_LEVEL_INFORMATION, 
			"CreateFile(%ls) failed, error=0x%X\n", szDiskPath, GetLastError());
		return FALSE;
	}

	return DisableDiskWriteCache(hDisk);
}
Example #28
0
HRESULT
pGetNdasSlotNumberFromDiskNumber(
	__in DWORD DiskNumber,
	__out LPDWORD NdasSlotNumber)
{
	WCHAR diskName[MAX_PATH];

	XTLVERIFY(SUCCEEDED(
		StringCchPrintfW(
			diskName, MAX_PATH,
			L"\\\\.\\PhysicalDrive%d", DiskNumber)));

	XTLTRACE2(NdasVolTrace, 2, "Disk Name: %ls\n", diskName);

	return pGetNdasSlotNumberFromDeviceNameW(diskName, NdasSlotNumber);
}
void
CNdasEventMonitor::Attach(INdasLogicalUnit* pNdasLogicalUnit)
{
	XTLTRACE2(NDASSVC_EVENTMON, TRACE_LEVEL_INFORMATION,
		"Attaching logical unit %p to the monitor\n",
		pNdasLogicalUnit);

	// LOGICAL DEVICE WRITE LOCK REGION
	{
		XTL::CWriterLockHolder holder(m_NdasLogicalUnitDataLock);
		m_NdasLogicalUnits.Add(pNdasLogicalUnit);
	}
	// LOGICAL DEVICE WRITE LOCK REGION

	XTLVERIFY( ::SetEvent(m_NdasLogicalUnitSetChanged) );
}
Example #30
0
BOOL
CNdasDeviceRegistrar::Unregister(DWORD SlotNo)
{
	InstanceAutoLock autolock(this);

	DeviceSlotMap::iterator slot_itr = m_deviceSlotMap.find(SlotNo);

	if (m_deviceSlotMap.end() == slot_itr) 
	{
		// TODO: Make more specific error code
		::SetLastError(NDASSVC_ERROR_DEVICE_ENTRY_NOT_FOUND);
		return FALSE;
	}

	CNdasDevicePtr pDevice = slot_itr->second;

	if (NDAS_DEVICE_STATUS_DISABLED != pDevice->GetStatus()) 
	{
		// TODO: ::SetLastError(NDAS_ERROR_CANNOT_UNREGISTER_ENABLED_DEVICE);
		// TODO: Make more specific error code
		::SetLastError(NDASSVC_ERROR_CANNOT_UNREGISTER_ENABLED_DEVICE);
		return FALSE;
	}

	DeviceIdMap::iterator id_itr = m_deviceIdMap.find(pDevice->GetDeviceId());

	XTLASSERT(m_deviceIdMap.end() != id_itr);

	m_deviceIdMap.erase(id_itr);
	m_deviceSlotMap.erase(slot_itr);
	m_slotbit[SlotNo] = FALSE;

	XTL::CStaticStringBuffer<30> containerName(_T("Devices\\%04d"), SlotNo);
	BOOL fSuccess = _NdasSystemCfg.DeleteContainer(containerName, FALSE);
	
	if (!fSuccess) 
	{
		XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_WARNING,
			"Deleting registration entry from the registry failed at %ls, error=0x%X\n", 
			containerName, GetLastError());
	}

	(void) m_service.GetEventPublisher().DeviceEntryChanged();

	return TRUE;

}