반응형

Device Object naming

 

1. Device Object naming이 필요한 이유

(1) 다른 커널모드 컴포넌트들이 IoGetDeviceObjectPointer()같은 서비스함수 호출을 통해 디바이스를 찾을 수 있게한다.

(2) User-Mode 프로그램이 해당 Device 핸들를 Open할 수 있게 한다

 

2. Device naming 방법

(1) Symbolic Link 생성

PDEVICE_OBJECT  pDeviceObject = NULL;

NTSTATUS                        status = STATUS_SUCCESS;

UNICODE_STRING strNtDeviceName;

UNICODE_STRING strDosDeviceName;

...

 

// Init NtDeviceName

RtlInitUnicodeString( &strNtDeviceName, NT_DEVICE_NAME );

 

// Create Device

status = IoCreateDevice( DriverObject,

                                       0,

                                       &strNtDeviceName,

                                       FILE_DEVICE_UNKNOWN,

                                       0,

                                       FALSE,

                                       &pDeviceObject

                                       );

if ( !NT_SUCCESS( status ) )

{

             return STATUS_SUCCESS;

}

 

// Init SymbolicLink Name

RtlInitUnicodeString( &strDosDeviceName, DOS_DEVICE_NAME );

 

// Create SymbolicLink

status = IoCreateSymbolicLink( &strDosDeviceName, &strNtDeviceName );

if ( !NT_SUCCESS( status ) )

{

            IoDeleteSymbolicLink(&strDosDeviceName);

            IoDeleteDevice(g_pDeviceObject);

 

            return status;

}

 

(2) Device Interface 생성

NTSTATUS                          status;

PDEVICE_OBJECT    fdo;

 

// Create out Functional Device Object in fdo

status = IoCreateDevice( DriverObject

                                        , sizeof( MYWDM_DEVICE_EXTENSION )

                                        , NULL // No Name

                                        , FILE_DEVICE_UNKNOWN

                                        , 0

                                        , FALSE //Not exclusive

                                        , &fdo

                                        );

 

if ( !NT_SUCCESS( status ) )

{

             return status;

}

 

// Register and enable our device interface

status = IoRegisterDeviceInterface( pdo, &GUID_DEVINTERFACE, NULL, & ifSymLinkName );

if( !NT_SUCCESS( status ) )

{

             IoDeleteDevice( fdo );

 

             return status;

}

 

IoSetDeviceInterfaceState( &dx->ifSymLinkName, TRUE );

 

...          

 

 

 

 

반응형

'Windows Programming > 드라이버' 카테고리의 다른 글

WDK는 VC6.0에서 빌드되지 않는다.  (0) 2008.07.24
Filter-Hook Driver  (0) 2008.07.21
Network Driver의 종류  (0) 2008.07.21
DeviceObject 삭제  (1) 2008.06.20
데이타 버퍼 어드레싱  (0) 2008.06.11

+ Recent posts