Symbolic link problems...

Hi,

I am really desperate about this. I am creating a function driver that should communicate with user mode, to enable communication I create a Symbolic link for the driver and try to access it from user mode by calling CreateFile, of some reason CreateFile fails and GetLastError returns 0x00000001 (Incorrect function.)

When using Compuwares ‘Symbolic Link Viewer’ I can see the link ( e.g. “\Device\SETSDriver” ).

Following are code snaps of the link creation code in the driver and the link association code on user-mode:

DriverEntry:

//L"\Device\SETSDriver"

PUNICODE_STRING pDevName = &Names::FullDeviceName;

//L"\DosDevices\SETSDriver"

UNICODE_STRING pLinkName= &Names::DosDeviceName;

status = IoCreateDevice( DriverObject, 0, pDevName, EXEC_GAURD,

FILE_DEVICE_SECURE_OPEN, FALSE, &m_pControlDevice);

if(!NT_SUCCESS(status))

return status;

status = IoCreateSymbolicLink(pLinkName, pDevName);

if (!NT_SUCCESS(status))

{

IoDeleteSymbolicLink(pLinkName);

status = IoCreateSymbolicLink(pLinkName, pDevName);

if(!NT_SUCCESS(status))

goto ErrExit;

}

User mode app:

*pDriver = ::CreateService(m_hSCM, pDriverName, pDriverName, SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER,

SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, pFullDriverPath, NULL, NULL, NULL, NULL, NULL);

if(0 == *pDriver &&

(::GetLastError() == ERROR_SERVICE_EXISTS ||

::GetLastError() == ERROR_SERVICE_MARKED_FOR_DELETE) &&

(0 == (*pDriver = ::OpenService(m_hSCM, pDriverName, SERVICE_ALL_ACCESS))))

{

return 0;

}

SERVICE_STATUS serviceStatus = { 0 };

BOOL bResult = ::StartService(*pDriver, 0, NULL);

if(bResult)

bResult = WaitForState(*pDriver, SERVICE_RUNNING, &serviceStatus);

else

bResult = (::GetLastError() == ERROR_SERVICE_ALREADY_RUNNING);

if (!bResult)

return HRESULT_FROM_WIN32(GetLastError());

m_hSymLink = CreateFileW(L”\.\SETSDriver”, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);

if(INVALID_HANDLE_VALUE == m_hSymLink)

{

m_hSymLink = CreateFileW(L”\.\Global\SETSDriver”, GENERIC_READ |

GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL |

FILE_FLAG_OVERLAPPED, NULL);

if(INVALID_HANDLE_VALUE == m_hSymLink)

return E_INVALID_HANDLE; // always gets here ( with GetLastError of 1 (Incorrect function)…

}

Thanks in advance,

Nadav.


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

Nadav wrote:

Hi,

I am really desperate about this. I am creating a function driver that
should communicate with user mode, to enable communication I create a
Symbolic link for the driver and try to access it from user mode by
calling CreateFile, of some reason CreateFile fails and GetLastError
returns 0x00000001 (Incorrect function.)

I assume you set the callbacks in the driver object for IRP_MJ_CREATE,
IRP_MJ_CLEANUP, and IRP_MJ_CLOSE.
The create function should return status success for the create file
call to succeed.

When using Compuwares ‘Symbolic Link Viewer’ I can see the link ( e.g.
“\Device\SETSDriver” ).

Following are code snaps of the link creation code in the driver and
the link association code on user-mode:

*DriverEntry:*

//L"\Device\SETSDriver"

PUNICODE_STRING pDevName = &Names::FullDeviceName;

//L"\DosDevices\SETSDriver"

UNICODE_STRING pLinkName= &Names::DosDeviceName;

status = IoCreateDevice( DriverObject, 0, pDevName, EXEC_GAURD,

FILE_DEVICE_SECURE_OPEN, FALSE, &m_pControlDevice);

if(!NT_SUCCESS(status))

return status;

status = IoCreateSymbolicLink(pLinkName, pDevName);

if (!NT_SUCCESS(status))

{

IoDeleteSymbolicLink(pLinkName);

You should delete the link in you DriverUnload routine.

status = IoCreateSymbolicLink(pLinkName, pDevName);

if(!NT_SUCCESS(status))

goto ErrExit;

}

*User mode app:*

*pDriver = ::CreateService(m_hSCM, pDriverName, pDriverName,
SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER,

SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, pFullDriverPath, NULL,
NULL, NULL, NULL, NULL);

if(0 == *pDriver &&

(::GetLastError() == ERROR_SERVICE_EXISTS ||

::GetLastError() == ERROR_SERVICE_MARKED_FOR_DELETE) &&

(0 == (*pDriver = ::OpenService(m_hSCM, pDriverName,
SERVICE_ALL_ACCESS))))

{

return 0;

}

SERVICE_STATUS serviceStatus = { 0 };

BOOL bResult = ::StartService(*pDriver, 0, NULL);

if(bResult)

bResult = WaitForState(*pDriver, SERVICE_RUNNING, &serviceStatus);

else

bResult = (::GetLastError() == ERROR_SERVICE_ALREADY_RUNNING);

if (!bResult)

return HRESULT_FROM_WIN32(GetLastError());

m_hSymLink = CreateFileW(L”\.\SETSDriver”, GENERIC_READ |
GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL |
FILE_FLAG_OVERLAPPED, NULL);

if(INVALID_HANDLE_VALUE == m_hSymLink)

{

m_hSymLink = CreateFileW(L”\.\Global\SETSDriver”, GENERIC_READ |

GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL |

FILE_FLAG_OVERLAPPED, NULL);

if(INVALID_HANDLE_VALUE == m_hSymLink)

return E_INVALID_HANDLE; *// always gets here ( with GetLastError of 1
(Incorrect function)…*

}

Thanks in advance,

Nadav.


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com — Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17 You are currently
subscribed to ntfsd as: xxxxx@bitdefender.com To unsubscribe send a
blank email to xxxxx@lists.osr.com



Ignorance more frequently begets confidence than does knowledge.
— Charles Darwin


This message was scanned for spam and viruses by BitDefender.
For more information please visit http://linux.bitdefender.com/

Hi Andrei,
Thanks for your help, it resolved my problem.

Andrei Zlate-Podani wrote:Nadav wrote:

> Hi,
>
> I am really desperate about this. I am creating a function driver that
> should communicate with user mode, to enable communication I create a
> Symbolic link for the driver and try to access it from user mode by
> calling CreateFile, of some reason CreateFile fails and GetLastError
> returns 0x00000001 (Incorrect function.)
>
I assume you set the callbacks in the driver object for IRP_MJ_CREATE,
IRP_MJ_CLEANUP, and IRP_MJ_CLOSE.
The create function should return status success for the create file
call to succeed.

> When using Compuwares ‘Symbolic Link Viewer’ I can see the link ( e.g.
> “\Device\SETSDriver” ).
>
> Following are code snaps of the link creation code in the driver and
> the link association code on user-mode:
>
> DriverEntry:
>
> //L"\Device\SETSDriver"
>
> PUNICODE_STRING pDevName = &Names::FullDeviceName;
>
> //L"\DosDevices\SETSDriver"
>
> UNICODE_STRING pLinkName= &Names::DosDeviceName;
>
> status = IoCreateDevice( DriverObject, 0, pDevName, EXEC_GAURD,
>
> FILE_DEVICE_SECURE_OPEN, FALSE, &m_pControlDevice);
>
> if(!NT_SUCCESS(status))
>
> return status;
>
> status = IoCreateSymbolicLink(pLinkName, pDevName);
>
> if (!NT_SUCCESS(status))
>
> {
>
> IoDeleteSymbolicLink(pLinkName);
>
You should delete the link in you DriverUnload routine.

> status = IoCreateSymbolicLink(pLinkName, pDevName);
>
> if(!NT_SUCCESS(status))
>
> goto ErrExit;
>
> }
>
> User mode app:
>
> *pDriver = ::CreateService(m_hSCM, pDriverName, pDriverName,
> SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER,
>
> SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, pFullDriverPath, NULL,
> NULL, NULL, NULL, NULL);
>
> if(0 == *pDriver &&
>
> (::GetLastError() == ERROR_SERVICE_EXISTS ||
>
> ::GetLastError() == ERROR_SERVICE_MARKED_FOR_DELETE) &&
>
> (0 == (*pDriver = ::OpenService(m_hSCM, pDriverName,
> SERVICE_ALL_ACCESS))))
>
> {
>
> return 0;
>
> }
>
> SERVICE_STATUS serviceStatus = { 0 };
>
> BOOL bResult = ::StartService(*pDriver, 0, NULL);
>
> if(bResult)
>
> bResult = WaitForState(*pDriver, SERVICE_RUNNING, &serviceStatus);
>
> else
>
> bResult = (::GetLastError() == ERROR_SERVICE_ALREADY_RUNNING);
>
> if (!bResult)
>
> return HRESULT_FROM_WIN32(GetLastError());
>
> m_hSymLink = CreateFileW(L”\.\SETSDriver”, GENERIC_READ |
> GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL |
> FILE_FLAG_OVERLAPPED, NULL);
>
> if(INVALID_HANDLE_VALUE == m_hSymLink)
>
> {
>
> m_hSymLink = CreateFileW(L”\.\Global\SETSDriver”, GENERIC_READ |
>
> GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL |
>
> FILE_FLAG_OVERLAPPED, NULL);
>
> if(INVALID_HANDLE_VALUE == m_hSymLink)
>
> return E_INVALID_HANDLE; // always gets here ( with GetLastError of 1
> (Incorrect function)…

>
> }
>
> Thanks in advance,
>
> Nadav.
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com — Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17 You are currently
> subscribed to ntfsd as: xxxxx@bitdefender.com To unsubscribe send a
> blank email to xxxxx@lists.osr.com
>
>------------------------------------------------------------------------
>
>
>
>


Ignorance more frequently begets confidence than does knowledge.
— Charles Darwin


This message was scanned for spam and viruses by BitDefender.
For more information please visit http://linux.bitdefender.com/


Questions? First check the IFS FAQ at https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@yahoo.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

---------------------------------
Do you Yahoo!?
Yahoo! Mail - Find what you need with new enhanced search. Learn more.

Note that C and C++ languages require the backslash to be duplicated inside the literal constants. Un duplicated backslash is treated as escape.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com
----- Original Message -----
From: Nadav
To: Windows File Systems Devs Interest List
Sent: Thursday, May 19, 2005 12:37 PM
Subject: [ntfsd] Symbolic link problems…

Hi,

I am really desperate about this. I am creating a function driver that should communicate with user mode, to enable communication I create a Symbolic link for the driver and try to access it from user mode by calling CreateFile, of some reason CreateFile fails and GetLastError returns 0x00000001 (Incorrect function.)

When using Compuwares ‘Symbolic Link Viewer’ I can see the link ( e.g. “\Device\SETSDriver” ).

Following are code snaps of the link creation code in the driver and the link association code on user-mode:

DriverEntry:

//L"\Device\SETSDriver"

PUNICODE_STRING pDevName = &Names::FullDeviceName;

//L"\DosDevices\SETSDriver"

UNICODE_STRING pLinkName= &Names::DosDeviceName;

status = IoCreateDevice( DriverObject, 0, pDevName, EXEC_GAURD,

FILE_DEVICE_SECURE_OPEN, FALSE, &m_pControlDevice);

if(!NT_SUCCESS(status))

return status;

status = IoCreateSymbolicLink(pLinkName, pDevName);

if (!NT_SUCCESS(status))

{

IoDeleteSymbolicLink(pLinkName);

status = IoCreateSymbolicLink(pLinkName, pDevName);

if(!NT_SUCCESS(status))

goto ErrExit;

}

User mode app:

*pDriver = ::CreateService(m_hSCM, pDriverName, pDriverName, SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER,

SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, pFullDriverPath, NULL, NULL, NULL, NULL, NULL);

if(0 == *pDriver &&

(::GetLastError() == ERROR_SERVICE_EXISTS ||

::GetLastError() == ERROR_SERVICE_MARKED_FOR_DELETE) &&

(0 == (*pDriver = ::OpenService(m_hSCM, pDriverName, SERVICE_ALL_ACCESS))))

{

return 0;

}

SERVICE_STATUS serviceStatus = { 0 };

BOOL bResult = ::StartService(*pDriver, 0, NULL);

if(bResult)

bResult = WaitForState(*pDriver, SERVICE_RUNNING, &serviceStatus);

else

bResult = (::GetLastError() == ERROR_SERVICE_ALREADY_RUNNING);

if (!bResult)

return HRESULT_FROM_WIN32(GetLastError());

m_hSymLink = CreateFileW(L"\.\SETSDriver", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);

if(INVALID_HANDLE_VALUE == m_hSymLink)

{

m_hSymLink = CreateFileW(L"\.\Global\SETSDriver", GENERIC_READ |

GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL |

FILE_FLAG_OVERLAPPED, NULL);

if(INVALID_HANDLE_VALUE == m_hSymLink)

return E_INVALID_HANDLE; // always gets here ( with GetLastError of 1 (Incorrect function)…

}

Thanks in advance,

Nadav.


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com — Questions? First check the IFS FAQ at https://www.osronline.com/article.cfm?id=17 You are currently subscribed to ntfsd as: xxxxx@storagecraft.com To unsubscribe send a blank email to xxxxx@lists.osr.com