Windows Programming/드라이버

Device Object naming

좋은향기 2008. 5. 30. 17:45
반응형

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 );

 

...          

 

 

 

 

반응형