how to access the raw partition

Hi , this is mrunal from Pune Institute Of Computer Technology.
I m trying to access raw partition in windows2000 from my filter driver which lies below NTFS drivers and above disk drivers. I tried ZwCreateFile call but it is returning FILE_SUPERSEDED in IoStatus. Wht does it mean?
Help me as soon as possible I need it in my Under Graduate Project.

Regards
Mrunal Rege


Jiyo cricket on Yahoo! India cricket
Yahoo! Messenger Mobile Stay in touch with your buddies all the time.

yuvraj rege wrote:

Hi , this is mrunal from Pune Institute Of Computer Technology.
I m trying to access raw partition in windows2000 from my filter driver
which lies below NTFS drivers and above disk drivers. I tried
ZwCreateFile call but it is returning FILE_SUPERSEDED in IoStatus. Wht
does it mean?
Help me as soon as possible I need it in my Under Graduate Project.

Regards
Mrunal Rege


Jiyo cricket on Yahoo! India cricket
http:</http:>
Yahoo! Messenger Mobile
http:</http:>
Stay in touch with your buddies all the time.

What status code are you getting from ZwCreateFile though?

You would get FILE_SUPERSEDED if you supplied FILE_SUPERSEDE in your
flags… in this case, the information in the I/O Status Block is merely
informational.

It’s also possible that you’re getting a failure in your Status (are
you?) and that the I/O Status Block isn’t giving you any “valid”
information (sometimes the lower drivers won’t clean it up).

So again, what’s your NTSTATUS?

Best regards,
Alex Ionescu

FILE_SUPERSEDE = 0 = STATUS_SUCCESS?

“yuvraj rege” wrote in message news:xxxxx@ntdev…
Hi , this is mrunal from Pune Institute Of Computer Technology.
I m trying to access raw partition in windows2000 from my filter driver
which lies below NTFS drivers and above disk drivers. I tried ZwCreateFile
call but it is returning FILE_SUPERSEDED in IoStatus. Wht does it mean?
Help me as soon as possible I need it in my Under Graduate Project.

Regards
Mrunal Rege

Jiyo cricket on Yahoo! India cricket
Yahoo! Messenger Mobile Stay in touch with your buddies all the time.

Just for the record:

#define FILE_SUPERSEDE 0x00000000

So this might be a coincidence value.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

Looking forward to seeing you at the next OSR File Systems class in
Boston, MA April 18-21, 2006 (note new date - MS scheduled plugfest the
same week again.)

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Alex Ionescu
[397670]
Sent: Friday, March 03, 2006 4:22 PM
To: ntdev redirect
Subject: Re:[ntdev] how to access the raw partition

yuvraj rege wrote:

Hi , this is mrunal from Pune Institute Of Computer Technology.
I m trying to access raw partition in windows2000 from my filter
driver
which lies below NTFS drivers and above disk drivers. I tried
ZwCreateFile call but it is returning FILE_SUPERSEDED in IoStatus. Wht

does it mean?
Help me as soon as possible I need it in my Under Graduate Project.

Regards
Mrunal Rege


Jiyo cricket on Yahoo! India cricket

http:cricket/>
> Yahoo! Messenger Mobile
>
http:hoo.com/new/messenger/>
> Stay in touch with your buddies all the time.

What status code are you getting from ZwCreateFile though?

You would get FILE_SUPERSEDED if you supplied FILE_SUPERSEDE in your
flags… in this case, the information in the I/O Status Block is merely

informational.

It’s also possible that you’re getting a failure in your Status (are
you?) and that the I/O Status Block isn’t giving you any “valid”
information (sometimes the lower drivers won’t clean it up).

So again, what’s your NTSTATUS?

Best regards,
Alex Ionescu


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer</http:></http:>

Tony/Lyndon,

Actually the flag you get is FILE_SUPERSEDED. FILE_SUPERSEDE is what you
*send*.

But yes, they are both equal to 0, which is why I asked for his NTSTATUS
from ZwCreateFile.

Best regards,
Alex Ionescu

Tony Mason wrote:

Just for the record:

#define FILE_SUPERSEDE 0x00000000

So this might be a coincidence value.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

Looking forward to seeing you at the next OSR File Systems class in
Boston, MA April 18-21, 2006 (note new date - MS scheduled plugfest the
same week again.)

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Alex Ionescu
[397670]
Sent: Friday, March 03, 2006 4:22 PM
To: ntdev redirect
Subject: Re:[ntdev] how to access the raw partition

yuvraj rege wrote:

>Hi , this is mrunal from Pune Institute Of Computer Technology.
>I m trying to access raw partition in windows2000 from my filter

driver

>which lies below NTFS drivers and above disk drivers. I tried
>ZwCreateFile call but it is returning FILE_SUPERSEDED in IoStatus. Wht

>does it mean?
>Help me as soon as possible I need it in my Under Graduate Project.
>
>
>Regards
>Mrunal Rege
>
>


>Jiyo cricket on Yahoo! India cricket
>

http:> cricket/>
>
>>Yahoo! Messenger Mobile
>>
>
> http:> hoo.com/new/messenger/>
>
>>Stay in touch with your buddies all the time.
>
>
> What status code are you getting from ZwCreateFile though?
>
> You would get FILE_SUPERSEDED if you supplied FILE_SUPERSEDE in your
> flags… in this case, the information in the I/O Status Block is merely
>
> informational.
>
> It’s also possible that you’re getting a failure in your Status (are
> you?) and that the I/O Status Block isn’t giving you any “valid”
> information (sometimes the lower drivers won’t clean it up).
>
> So again, what’s your NTSTATUS?
>
> Best regards,
> Alex Ionescu
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
></http:></http:>

Hello Sir,
Thank you for response!
You have asked me about the return value of ZwCreateFile. Its STATUS_OBJECT_PATH_SYNTAX_BAD . Then how can I give the correct path? Give me some example ,please.

NOTE: I have changed the return type of osr function “OsrNTStatusToString”
from PUCHAR to char * .
Here is the source code:

NTSTATUS
WcdCreate(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
{

UNICODE_STRING FileName;
NTSTATUS ntStatus;
HANDLE FileHandle;
OBJECT_ATTRIBUTES ObjectAttributes;
WCHAR PathPrefix = L"\Device\Harddisk0\Dp(2)0xfe730c00-0x1780800+2";
ULONG FileNameLength;
IO_STATUS_BLOCK IoStatus;
char *result;

UNREFERENCED_PARAMETER(DeviceObject);
Irp->IoStatus.Status = STATUS_SUCCESS;

FileNameLength = sizeof(PathPrefix);
FileName.Buffer = ExAllocatePool(NonPagedPool,
FileNameLength);
FileName.MaximumLength = (USHORT)FileNameLength;
RtlMoveMemory (FileName.Buffer, PathPrefix, sizeof(PathPrefix));

InitializeObjectAttributes ( &ObjectAttributes,
&FileName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL );

ntStatus= ZwCreateFile(
&FileHandle,
FILE_READ_DATA | FILE_WRITE_DATA,
&ObjectAttributes,
&IoStatus,
NULL,
FILE_ATTRIBUTE_NORMAL,
0,
FILE_OPEN_IF,
FILE_NON_DIRECTORY_FILE,
NULL,
0
);

result=OsrNTStatusToString(ntStatus);

DbgPrint(“\n\n%s”,result);

ZwClose( FileHandle );

DbgPrint(“\n\nWCD : WCD_Create called”);
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
} // end WcdCreate()

“Alex Ionescu [397670]” wrote:
yuvraj rege wrote:
> Hi , this is mrunal from Pune Institute Of Computer Technology.
> I m trying to access raw partition in windows2000 from my filter driver
> which lies below NTFS drivers and above disk drivers. I tried
> ZwCreateFile call but it is returning FILE_SUPERSEDED in IoStatus. Wht
> does it mean?
> Help me as soon as possible I need it in my Under Graduate Project.
>
>
> Regards
> Mrunal Rege
>
> ------------------------------------------------------------------------
> Jiyo cricket on Yahoo! India cricket
>
> Yahoo! Messenger Mobile
>
> Stay in touch with your buddies all the time.

What status code are you getting from ZwCreateFile though?

You would get FILE_SUPERSEDED if you supplied FILE_SUPERSEDE in your
flags… in this case, the information in the I/O Status Block is merely
informational.

It’s also possible that you’re getting a failure in your Status (are
you?) and that the I/O Status Block isn’t giving you any “valid”
information (sometimes the lower drivers won’t clean it up).

So again, what’s your NTSTATUS?

Best regards,
Alex Ionescu


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

---------------------------------
Jiyo cricket on Yahoo! India cricket
Yahoo! Messenger Mobile Stay in touch with your buddies all the time.

Alex - Okay I missed a ‘D’ when I typed :slight_smile:

“Alex Ionescu [397670]” wrote in message
news:xxxxx@ntdev…
> Tony/Lyndon,
>
> Actually the flag you get is FILE_SUPERSEDED. FILE_SUPERSEDE is what you
> send.
>
> But yes, they are both equal to 0, which is why I asked for his NTSTATUS
> from ZwCreateFile.
>
> Best regards,
> Alex Ionescu
>
> Tony Mason wrote:
>> Just for the record:
>>
>> #define FILE_SUPERSEDE 0x00000000
>>
>> So this might be a coincidence value.
>>
>> Regards,
>>
>> Tony
>>
>> Tony Mason
>> Consulting Partner
>> OSR Open Systems Resources, Inc.
>> http://www.osr.com
>> Looking forward to seeing you at the next OSR File Systems class in
>> Boston, MA April 18-21, 2006 (note new date - MS scheduled plugfest the
>> same week again.)
>>
>> -----Original Message-----
>> From: xxxxx@lists.osr.com
>> [mailto:xxxxx@lists.osr.com] On Behalf Of Alex Ionescu
>> [397670]
>> Sent: Friday, March 03, 2006 4:22 PM
>> To: ntdev redirect
>> Subject: Re:[ntdev] how to access the raw partition
>>
>> yuvraj rege wrote:
>>
>>>Hi , this is mrunal from Pune Institute Of Computer Technology.
>>>I m trying to access raw partition in windows2000 from my filter
>>
>> driver
>>>which lies below NTFS drivers and above disk drivers. I tried
>>>ZwCreateFile call but it is returning FILE_SUPERSEDED in IoStatus. Wht
>>
>>
>>>does it mean?
>>>Help me as soon as possible I need it in my Under Graduate Project.
>>>
>>> Regards
>>>Mrunal Rege
>>>
>>
>> ------------------------------------------------------------------------
>>
>>>Jiyo cricket on Yahoo! India cricket
>>
>> http:>> cricket/>
>>
>>>Yahoo! Messenger Mobile
>>
>> http:>> hoo.com/new/messenger/>
>>>Stay in touch with your buddies all the time.
>>
>>
>> What status code are you getting from ZwCreateFile though?
>>
>> You would get FILE_SUPERSEDED if you supplied FILE_SUPERSEDE in your
>> flags… in this case, the information in the I/O Status Block is merely
>>
>> informational.
>>
>> It’s also possible that you’re getting a failure in your Status (are
>> you?) and that the I/O Status Block isn’t giving you any “valid”
>> information (sometimes the lower drivers won’t clean it up).
>>
>> So again, what’s your NTSTATUS?
>>
>> Best regards,
>> Alex Ionescu
>>
>> —
>> Questions? First check the Kernel Driver FAQ at
>> http://www.osronline.com/article.cfm?id=256
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>>
></http:></http:>

Without going any further:

FileNameLength = sizeof(PathPrefix);

This sets FileNameLength to 4, which is NOT what you want.
It’s all stupid C/C++: WCHAR PathPrefix is treated by the compiler as a pointer (to WCHAR, but this does not matter here).
On a 32-bit box all ptrs are 4 bytes.

To find the buffer length, either count WCHARs manually, or, for testing purposes,
do like that:

#define Elts(array) (sizeof(array) / sizeof(array[0])) // Elts(L"ab") is 3, Elts(“ab”) is also 3

#define MY_W_STRING L"\Device\Harddisk0\Dp(2)0xfe730c00-0x1780800+2"

WCHAR* PathPrefix = MY_W_STRING;
ULONG FileNameLength = Elts(MY_W_STRING); // length in WCHARs, includes ending zero

etc.

You may want to re-read about arrays in C, they are - do not laugh! - tricky.
I’d say there are NO arrays in C at all, only pointers:-)

----- Original Message -----
From: yuvraj rege
To: Windows System Software Devs Interest List
Sent: Saturday, March 04, 2006 6:05 AM
Subject: Re:[ntdev] how to access the raw partition

Hello Sir,
Thank you for response!
You have asked me about the return value of ZwCreateFile. Its STATUS_OBJECT_PATH_SYNTAX_BAD . Then how can I give the correct path? Give me some example ,please.

NOTE: I have changed the return type of osr function “OsrNTStatusToString”
from PUCHAR to char * .
Here is the source code:

NTSTATUS
WcdCreate(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
{

UNICODE_STRING FileName;
NTSTATUS ntStatus;
HANDLE FileHandle;
OBJECT_ATTRIBUTES ObjectAttributes;
WCHAR PathPrefix = L"\Device\Harddisk0\Dp(2)0xfe730c00-0x1780800+2";
ULONG FileNameLength;
IO_STATUS_BLOCK IoStatus;
char *result;

UNREFERENCED_PARAMETER(DeviceObject);
Irp->IoStatus.Status = STATUS_SUCCESS;

FileNameLength = sizeof(PathPrefix);
FileName.Buffer = ExAllocatePool(NonPagedPool,
FileNameLength);
FileName.MaximumLength = (USHORT)FileNameLength;
RtlMoveMemory (FileName.Buffer, PathPrefix, sizeof(PathPrefix));

InitializeObjectAttributes ( &ObjectAttributes,
&FileName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL );

ntStatus= ZwCreateFile(
&FileHandle,
FILE_READ_DATA | FILE_WRITE_DATA,
&ObjectAttributes,
&IoStatus,
NULL,
FILE_ATTRIBUTE_NORMAL,
0,
FILE_OPEN_IF,
FILE_NON_DIRECTORY_FILE,
NULL,
0
);

result=OsrNTStatusToString(ntStatus);

DbgPrint(“\n\n%s”,result);

ZwClose( FileHandle );

DbgPrint(“\n\nWCD : WCD_Create called”);
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
} // end WcdCreate()

“Alex Ionescu [397670]” wrote:
yuvraj rege wrote:
> Hi , this is mrunal from Pune Institute Of Computer Technology.
> I m trying to access raw partition in windows2000 from my filter driver
> which lies below NTFS drivers and above disk drivers. I tried
> ZwCreateFile call but it is returning FILE_SUPERSEDED in IoStatus. Wht
> does it mean?
> Help me as soon as possible I need it in my Under Graduate Project.
>
>
> Regards
> Mrunal Rege
>
> ------------------------------------------------------------------------
> Jiyo cricket on Yahoo! India cricket
>
> Yahoo! Messenger Mobile
>
> Stay in touch with your buddies all the time.

What status code are you getting from ZwCreateFile though?

You would get FILE_SUPERSEDED if you supplied FILE_SUPERSEDE in your
flags… in this case, the information in the I/O Status Block is merely
informational.

It’s also possible that you’re getting a failure in your Status (are
you?) and that the I/O Status Block isn’t giving you any “valid”
information (sometimes the lower drivers won’t clean it up).

So again, what’s your NTSTATUS?

Best regards,
Alex Ionescu


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

------------------------------------------------------------------------------
Jiyo cricket on Yahoo! India cricket
Yahoo! Messenger Mobile Stay in touch with your buddies all the time. — Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Replace this junk …

FileNameLength = sizeof(PathPrefix);
FileName.Buffer = ExAllocatePool(NonPagedPool,
FileNameLength);
FileName.MaximumLength = (USHORT)FileNameLength;
RtlMoveMemory (FileName.Buffer, PathPrefix, sizeof(PathPrefix));

… with this junk …

RtlInitUnicodeString(&FileName, PathPrefix);

… ?

“yuvraj rege” wrote in message news:xxxxx@ntdev…
Hello Sir,
Thank you for response!
You have asked me about the return value of ZwCreateFile. Its
STATUS_OBJECT_PATH_SYNTAX_BAD . Then how can I give the correct path? Give
me some example ,please.

NOTE: I have changed the return type of osr function “OsrNTStatusToString”
from PUCHAR to char * .
Here is the source code:

NTSTATUS
WcdCreate(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
{

UNICODE_STRING FileName;
NTSTATUS ntStatus;
HANDLE FileHandle;
OBJECT_ATTRIBUTES ObjectAttributes;
WCHAR PathPrefix =
L"\Device\Harddisk0\Dp(2)0xfe730c00-0x1780800+2";
ULONG FileNameLength;
IO_STATUS_BLOCK IoStatus;
char *result;

UNREFERENCED_PARAMETER(DeviceObject);
Irp->IoStatus.Status = STATUS_SUCCESS;

FileNameLength = sizeof(PathPrefix);
FileName.Buffer = ExAllocatePool(NonPagedPool,
FileNameLength);
FileName.MaximumLength = (USHORT)FileNameLength;
RtlMoveMemory (FileName.Buffer, PathPrefix, sizeof(PathPrefix));

InitializeObjectAttributes ( &ObjectAttributes,
&FileName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL );

ntStatus= ZwCreateFile(
&FileHandle,
FILE_READ_DATA | FILE_WRITE_DATA,
&ObjectAttributes,
&IoStatus,
NULL,
FILE_ATTRIBUTE_NORMAL,
0,
FILE_OPEN_IF,
FILE_NON_DIRECTORY_FILE,
NULL,
0
);

result=OsrNTStatusToString(ntStatus);

DbgPrint(“\n\n%s”,result);

ZwClose( FileHandle );

DbgPrint(“\n\nWCD : WCD_Create called”);
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
} // end WcdCreate()

“Alex Ionescu [397670]” wrote:
yuvraj rege wrote:
> Hi , this is mrunal from Pune Institute Of Computer Technology.
> I m trying to access raw partition in windows2000 from my filter driver
> which lies below NTFS drivers and above disk drivers. I tried
> ZwCreateFile call but it is returning FILE_SUPERSEDED in IoStatus. Wht
> does it mean?
> Help me as soon as possible I need it in my Under Graduate Project.
>
>
> Regards
> Mrunal Rege
>
> ------------------------------------------------------------------------
> Jiyo cricket on Yahoo! India cricket
>
> Yahoo! Messenger Mobile
>
> Stay in touch with your buddies all the time.

What status code are you getting from ZwCreateFile though?

You would get FILE_SUPERSEDED if you supplied FILE_SUPERSEDE in your
flags… in this case, the information in the I/O Status Block is merely
informational.

It’s also possible that you’re getting a failure in your Status (are
you?) and that the I/O Status Block isn’t giving you any “valid”
information (sometimes the lower drivers won’t clean it up).

So again, what’s your NTSTATUS?

Best regards,
Alex Ionescu


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Jiyo cricket on Yahoo! India cricket
Yahoo! Messenger Mobile Stay in touch with your buddies all the time.

Hello Sir!
Yes ,I have made a silly mistake by not using RtlInitUnicodeString. Now I have used "RtlInitUnicodeString(&FileName, PathPrefix); " in my code.
But what about “\Device\Harddisk0\ Dp(2)0xfe730c00-0x1780800+2” path for device ? Is it wrong?
Because it is giving STATUS_OBJECT_PATH_SYNTAX_BAD as return value of ZwCreateFile. What would be the correct path so that I can receive the handle of the device object of that unformatted partition?
I am planing to convert the handle into pointer so that I can write the data structures to that unformatted partition.

Regards
Yuvraj Rege


Jiyo cricket on Yahoo! India cricket
Yahoo! Messenger Mobile Stay in touch with your buddies all the time.

lol … ok how do you get along with \Device\HardDisk0\Partition1 for
example?

“yuvraj rege” wrote in message news:xxxxx@ntdev…
Hello Sir!
Yes ,I have made a silly mistake by not using RtlInitUnicodeString. Now I
have used "RtlInitUnicodeString(&FileName, PathPrefix); " in my code.
But what about “\Device\Harddisk0\ Dp(2)0xfe730c00-0x1780800+2” path
for device ? Is it wrong?
Because it is giving STATUS_OBJECT_PATH_SYNTAX_BAD as return value of
ZwCreateFile. What would be the correct path so that I can receive the
handle of the device object of that unformatted partition?
I am planing to convert the handle into pointer so that I can write the
data structures to that unformatted partition.

Regards
Yuvraj Rege

Jiyo cricket on Yahoo! India cricket
Yahoo! Messenger Mobile Stay in touch with your buddies all the time.

STATUS_INVALID_PARAMETER is the result of ZwCreateFile .Is there any problem with double slash “\” ? or somthing else. Or tell how to interprete WinObj utility.
Help me please!

NTSTATUS
WcdCreate(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
{

UNICODE_STRING FileName;

NTSTATUS ntStatus;
HANDLE FileHandle;
OBJECT_ATTRIBUTES ObjectAttributes;
WCHAR PathPrefix = L"\Device\Harddisk0\Partition2";
ULONG FileNameLength;
IO_STATUS_BLOCK IoStatus;
char *result;

UNREFERENCED_PARAMETER(DeviceObject);
Irp->IoStatus.Status = STATUS_SUCCESS;

RtlInitUnicodeString(&FileName, PathPrefix);

InitializeObjectAttributes ( &ObjectAttributes,
&FileName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL );

ntStatus= ZwCreateFile(
&FileHandle,
FILE_READ_DATA | FILE_WRITE_DATA,
&ObjectAttributes,
&IoStatus,
NULL,
FILE_ATTRIBUTE_NORMAL,
0,
FILE_OPEN_IF,
FILE_NON_DIRECTORY_FILE,
NULL,
0
);

result=OsrNTStatusToString(ntStatus);

DbgPrint(“\n\n%s”,result);

ZwClose( FileHandle );

DbgPrint(“\n\nWCD : WCD_Create called”);
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
} // end WcdCreate()


Jiyo cricket on Yahoo! India cricket
Yahoo! Messenger Mobile Stay in touch with your buddies all the time.

The init of FileNamelegnth is still wrong b/c it includes the terminating NULL. When creating a UNICODE_STRING, the Length field should not include the NULL,otherwise the NULL itself will be a part of the name and not a terminating character.

d


From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@Home
Sent: Saturday, March 04, 2006 5:28 AM
To: Windows System Software Devs Interest List
Subject: Re: Re:[ntdev] how to access the raw partition

Without going any further:
?

FileNameLength = sizeof(PathPrefix);
?
This sets FileNameLength to 4, which is NOT what you want.
It’s all stupid C/C++: WCHAR PathPrefix is treated by the compiler as a pointer (to WCHAR, but this does not matter here).
On a 32-bit box all ptrs are 4 bytes.
?
To find the buffer length, either count WCHARs manually, or, for testing purposes,
do like that:
?
#define Elts(array)??? (sizeof(array) / sizeof(array[0]))??? ??? ??? // Elts(L"ab") is 3, Elts(“ab”) is also 3
?
#define MY_W_STRING??? L"\Device\Harddisk0\Dp(2)0xfe730c00-0x1780800+2"
?
???WCHAR* PathPrefix = MY_W_STRING;
???ULONG FileNameLength = Elts(MY_W_STRING);??? // length in WCHARs, includes ending zero
etc.
?
You may want to re-read about arrays in C, they are - do not laugh! - tricky.
I’d say there are NO arrays in C at all, only pointers:-)
?
?
----- Original Message -----
From: yuvraj rege
To: Windows System Software Devs Interest List
Sent: Saturday, March 04, 2006 6:05 AM
Subject: Re:[ntdev] how to access the raw partition

Hello Sir,
?Thank you for response!?
You have asked me about the return value of ZwCreateFile. Its ?STATUS_OBJECT_PATH_SYNTAX_BAD . Then how can I give the correct path?? Give me some example ,please.
?
NOTE: I have changed the return type of osr function “OsrNTStatusToString”
??? from PUCHAR to? char * .
Here is the source code:
?
NTSTATUS
WcdCreate(
??? IN PDEVICE_OBJECT DeviceObject,
??? IN PIRP Irp
??? )
{
???
?? UNICODE_STRING??FileName;
???NTSTATUS??? ntStatus;
???HANDLE??? FileHandle;
?? OBJECT_ATTRIBUTES?? ObjectAttributes;
???WCHAR??? PathPrefix = L"\Device\Harddisk0\Dp(2)0xfe730c00-0x1780800+2";
???ULONG??? FileNameLength;
???IO_STATUS_BLOCK??? IoStatus;
???char??? *result;
?
?
?UNREFERENCED_PARAMETER(DeviceObject);
??? Irp->IoStatus.Status = STATUS_SUCCESS;
?
??? FileNameLength = sizeof(PathPrefix);
??? FileName.Buffer = ExAllocatePool(NonPagedPool,
??? FileNameLength);
??? FileName.MaximumLength = (USHORT)FileNameLength;
?? RtlMoveMemory (FileName.Buffer, PathPrefix, sizeof(PathPrefix));
???
?
?InitializeObjectAttributes ( &ObjectAttributes,
??? &FileName,
??? OBJ_CASE_INSENSITIVE,
??? NULL,
??? NULL );
???
??
??? ntStatus= ZwCreateFile(
??? &FileHandle,
??? FILE_READ_DATA | FILE_WRITE_DATA,
??? &ObjectAttributes,
??? &IoStatus,
??? NULL,
??? FILE_ATTRIBUTE_NORMAL,
??? 0,
??? FILE_OPEN_IF,
??? FILE_NON_DIRECTORY_FILE,
??? NULL,
??? 0
??? );
?
?
?
?result=OsrNTStatusToString(ntStatus);
?
??
?DbgPrint(“\n\n%s”,result);
???
?
??? ZwClose( FileHandle );

?DbgPrint(“\n\nWCD : WCD_Create called”);
??? IoCompleteRequest(Irp, IO_NO_INCREMENT);
??? return STATUS_SUCCESS;
} // end WcdCreate()
?
?
?
?
?
?

“Alex Ionescu [397670]” wrote:
yuvraj rege wrote:
> Hi , this is mrunal from Pune Institute Of Computer Technology.
> I m trying to access raw partition in windows2000 from my filter driver
> which lies below NTFS drivers and above disk drivers. I tried
> ZwCreateFile call but it is returning FILE_SUPERSEDED in IoStatus. Wht
> does it mean?
> Help me as soon as possible I need it in my Under Graduate Project.
>
>
> Regards
> Mrunal Rege
>
> ------------------------------------------------------------------------
> Jiyo cricket on Yahoo! India cricket
>
> Yahoo! Messenger Mobile
>
> Stay in touch with your buddies all the time.

What status code are you getting from ZwCreateFile though?

You would get FILE_SUPERSEDED if you supplied FILE_SUPERSEDE in your
flags… in this case, the information in the I/O Status Block is merely
informational.

It’s also possible that you’re getting a failure in your Status (are
you?) and that the I/O Status Block isn’t giving you any “valid”
information (sometimes the lower drivers won’t clean it up).

So again, what’s your NTSTATUS?

Best regards,
Alex Ionescu


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

________________________________________
Jiyo cricket on Yahoo! India cricket
Yahoo! Messenger Mobile Stay in touch with your buddies all the time. — Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

> Length field should not include the NULL
True.
I said “Without going any further”…

----- Original Message -----
From: “Doron Holan”
To: “Windows System Software Devs Interest List”
Sent: Saturday, March 04, 2006 5:07 PM
Subject: RE: Re:[ntdev] how to access the raw partition

The init of FileNamelegnth is still wrong b/c it includes the terminating
NULL. When creating a UNICODE_STRING, the Length field should not include
the NULL,otherwise the NULL itself will be a part of the name and not a
terminating character.

d


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@Home
Sent: Saturday, March 04, 2006 5:28 AM
To: Windows System Software Devs Interest List
Subject: Re: Re:[ntdev] how to access the raw partition

Without going any further:

> FileNameLength = sizeof(PathPrefix);

This sets FileNameLength to 4, which is NOT what you want.
It’s all stupid C/C++: WCHAR PathPrefix[] is treated by the compiler as a
pointer (to WCHAR, but this does not matter here).
On a 32-bit box all ptrs are 4 bytes.

To find the buffer length, either count WCHARs manually, or, for testing
purposes,
do like that:

#define Elts(array) (sizeof(array) / sizeof(array[0])) // Elts(L"ab") is 3,
Elts(“ab”) is also 3

#define MY_W_STRING L"\Device\Harddisk0\Dp(2)0xfe730c00-0x1780800+2"

WCHAR* PathPrefix = MY_W_STRING;
ULONG FileNameLength = Elts(MY_W_STRING); // length in WCHARs, includes
ending zero
etc.

You may want to re-read about arrays in C, they are - do not laugh! -
tricky.
I’d say there are NO arrays in C at all, only pointers:-)

----- Original Message -----
From: yuvraj rege
To: Windows System Software Devs Interest List
Sent: Saturday, March 04, 2006 6:05 AM
Subject: Re:[ntdev] how to access the raw partition

Hello Sir,
Thank you for response!
You have asked me about the return value of ZwCreateFile. Its
STATUS_OBJECT_PATH_SYNTAX_BAD . Then how can I give the correct path? Give
me some example ,please.

NOTE: I have changed the return type of osr function “OsrNTStatusToString”
from PUCHAR to char * .
Here is the source code:

NTSTATUS
WcdCreate(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
{

UNICODE_STRING FileName;
NTSTATUS ntStatus;
HANDLE FileHandle;
OBJECT_ATTRIBUTES ObjectAttributes;
WCHAR PathPrefix[] = L"\Device\Harddisk0\Dp(2)0xfe730c00-0x1780800+2";
ULONG FileNameLength;
IO_STATUS_BLOCK IoStatus;
char *result;

UNREFERENCED_PARAMETER(DeviceObject);
Irp->IoStatus.Status = STATUS_SUCCESS;

FileNameLength = sizeof(PathPrefix);
FileName.Buffer = ExAllocatePool(NonPagedPool,
FileNameLength);
FileName.MaximumLength = (USHORT)FileNameLength;
RtlMoveMemory (FileName.Buffer, PathPrefix, sizeof(PathPrefix));

InitializeObjectAttributes ( &ObjectAttributes,
&FileName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL );

ntStatus= ZwCreateFile(
&FileHandle,
FILE_READ_DATA | FILE_WRITE_DATA,
&ObjectAttributes,
&IoStatus,
NULL,
FILE_ATTRIBUTE_NORMAL,
0,
FILE_OPEN_IF,
FILE_NON_DIRECTORY_FILE,
NULL,
0
);

result=OsrNTStatusToString(ntStatus);

DbgPrint(“\n\n%s”,result);

ZwClose( FileHandle );

DbgPrint(“\n\nWCD : WCD_Create called”);
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
} // end WcdCreate()

“Alex Ionescu [397670]” wrote:
yuvraj rege wrote:
> Hi , this is mrunal from Pune Institute Of Computer Technology.
> I m trying to access raw partition in windows2000 from my filter driver
> which lies below NTFS drivers and above disk drivers. I tried
> ZwCreateFile call but it is returning FILE_SUPERSEDED in IoStatus. Wht
> does it mean?
> Help me as soon as possible I need it in my Under Graduate Project.
>
>
> Regards
> Mrunal Rege
>
> ------------------------------------------------------------------------
> Jiyo cricket on Yahoo! India cricket
>
> Yahoo! Messenger Mobile
>
> Stay in touch with your buddies all the time.

What status code are you getting from ZwCreateFile though?

You would get FILE_SUPERSEDED if you supplied FILE_SUPERSEDE in your
flags… in this case, the information in the I/O Status Block is merely
informational.

It’s also possible that you’re getting a failure in your Status (are
you?) and that the I/O Status Block isn’t giving you any “valid”
information (sometimes the lower drivers won’t clean it up).

So again, what’s your NTSTATUS?

Best regards,
Alex Ionescu


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


Jiyo cricket on Yahoo! India cricket
Yahoo! Messenger Mobile Stay in touch with your buddies all the time. —
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit the List
Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Everyone here should read Doron’s blog. This week it has been about Unicode
and all the mistakes and false starts that he has seen.

“Doron Holan” wrote in message
news:xxxxx@ntdev…
The init of FileNamelegnth is still wrong b/c it includes the terminating
NULL. When creating a UNICODE_STRING, the Length field should not include
the NULL,otherwise the NULL itself will be a part of the name and not a
terminating character.

d


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@Home
Sent: Saturday, March 04, 2006 5:28 AM
To: Windows System Software Devs Interest List
Subject: Re: Re:[ntdev] how to access the raw partition

Without going any further:

> FileNameLength = sizeof(PathPrefix);

This sets FileNameLength to 4, which is NOT what you want.
It’s all stupid C/C++: WCHAR PathPrefix[] is treated by the compiler as a
pointer (to WCHAR, but this does not matter here).
On a 32-bit box all ptrs are 4 bytes.

To find the buffer length, either count WCHARs manually, or, for testing
purposes,
do like that:

#define Elts(array) (sizeof(array) / sizeof(array[0])) // Elts(L"ab") is 3,
Elts(“ab”) is also 3

#define MY_W_STRING L"\Device\Harddisk0\Dp(2)0xfe730c00-0x1780800+2"

WCHAR* PathPrefix = MY_W_STRING;
ULONG FileNameLength = Elts(MY_W_STRING); // length in WCHARs, includes
ending zero
etc.

You may want to re-read about arrays in C, they are - do not laugh! -
tricky.
I’d say there are NO arrays in C at all, only pointers:-)

----- Original Message -----
From: yuvraj rege
To: Windows System Software Devs Interest List
Sent: Saturday, March 04, 2006 6:05 AM
Subject: Re:[ntdev] how to access the raw partition

Hello Sir,
Thank you for response!
You have asked me about the return value of ZwCreateFile. Its
STATUS_OBJECT_PATH_SYNTAX_BAD . Then how can I give the correct path? Give
me some example ,please.

NOTE: I have changed the return type of osr function “OsrNTStatusToString”
from PUCHAR to char * .
Here is the source code:

NTSTATUS
WcdCreate(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
{

UNICODE_STRING FileName;
NTSTATUS ntStatus;
HANDLE FileHandle;
OBJECT_ATTRIBUTES ObjectAttributes;
WCHAR PathPrefix[] = L"\Device\Harddisk0\Dp(2)0xfe730c00-0x1780800+2";
ULONG FileNameLength;
IO_STATUS_BLOCK IoStatus;
char *result;

UNREFERENCED_PARAMETER(DeviceObject);
Irp->IoStatus.Status = STATUS_SUCCESS;

FileNameLength = sizeof(PathPrefix);
FileName.Buffer = ExAllocatePool(NonPagedPool,
FileNameLength);
FileName.MaximumLength = (USHORT)FileNameLength;
RtlMoveMemory (FileName.Buffer, PathPrefix, sizeof(PathPrefix));

InitializeObjectAttributes ( &ObjectAttributes,
&FileName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL );

ntStatus= ZwCreateFile(
&FileHandle,
FILE_READ_DATA | FILE_WRITE_DATA,
&ObjectAttributes,
&IoStatus,
NULL,
FILE_ATTRIBUTE_NORMAL,
0,
FILE_OPEN_IF,
FILE_NON_DIRECTORY_FILE,
NULL,
0
);

result=OsrNTStatusToString(ntStatus);

DbgPrint(“\n\n%s”,result);

ZwClose( FileHandle );

DbgPrint(“\n\nWCD : WCD_Create called”);
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
} // end WcdCreate()

“Alex Ionescu [397670]” wrote:
yuvraj rege wrote:
> Hi , this is mrunal from Pune Institute Of Computer Technology.
> I m trying to access raw partition in windows2000 from my filter driver
> which lies below NTFS drivers and above disk drivers. I tried
> ZwCreateFile call but it is returning FILE_SUPERSEDED in IoStatus. Wht
> does it mean?
> Help me as soon as possible I need it in my Under Graduate Project.
>
>
> Regards
> Mrunal Rege
>
> ------------------------------------------------------------------------
> Jiyo cricket on Yahoo! India cricket
>
> Yahoo! Messenger Mobile
>
> Stay in touch with your buddies all the time.

What status code are you getting from ZwCreateFile though?

You would get FILE_SUPERSEDED if you supplied FILE_SUPERSEDE in your
flags… in this case, the information in the I/O Status Block is merely
informational.

It’s also possible that you’re getting a failure in your Status (are
you?) and that the I/O Status Block isn’t giving you any “valid”
information (sometimes the lower drivers won’t clean it up).

So again, what’s your NTSTATUS?

Best regards,
Alex Ionescu


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


Jiyo cricket on Yahoo! India cricket
Yahoo! Messenger Mobile Stay in touch with your buddies all the time. —
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit the List
Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

yuvraj rege wrote:

STATUS_INVALID_PARAMETER is the result of ZwCreateFile .Is there any
problem with double slash “\” ? or somthing else. Or tell how to
interprete WinObj utility.
Help me please!

NTSTATUS
WcdCreate(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
{

UNICODE_STRING FileName;

NTSTATUS ntStatus;
HANDLE FileHandle;
OBJECT_ATTRIBUTES ObjectAttributes;
WCHAR PathPrefix = L"\Device\Harddisk0\Partition2";
ULONG FileNameLength;
IO_STATUS_BLOCK IoStatus;
char *result;

UNREFERENCED_PARAMETER(DeviceObject);
Irp->IoStatus.Status = STATUS_SUCCESS;

RtlInitUnicodeString(&FileName, PathPrefix);

InitializeObjectAttributes ( &ObjectAttributes,
&FileName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL );

ntStatus= ZwCreateFile(
&FileHandle,
FILE_READ_DATA | FILE_WRITE_DATA,
&ObjectAttributes,
&IoStatus,
NULL,
FILE_ATTRIBUTE_NORMAL,
0,
FILE_OPEN_IF,
FILE_NON_DIRECTORY_FILE,
NULL,
0
);

result=OsrNTStatusToString(ntStatus);

DbgPrint(“\n\n%s”,result);

ZwClose( FileHandle );

DbgPrint(“\n\nWCD : WCD_Create called”);
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
} // end WcdCreate()

Note that this won’t fix your problem but it’s even cleaner if you do this:

UNICODE_STRING FileName =
RTL_CONSTANT_STRING(L"\Device\Harddisk0\Partition2");

And get rid of the RtlInitUnicodeString call.

Best regards,
Alex Ionescu

Hello Sir ,
I have tried the pathname “\Device\Harddisk0\Partition2”. Now the syntax problem is solved because I have used
FileName.Length= FileName.Length - sizeof(WCHAR);
to ommit the NULL from my path.
But this time the new result encountered is STATUS_OBJECT_NOT_FOUND.
I am using Device Tree for finding right object .How can I find the right object?
Can I use the sysmbolic link? I am doubtfull about that.

Regards
Yuvraj Rege

NTSTATUS
WcdCreate(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
{

UNICODE_STRING FileName;

NTSTATUS ntStatus;
HANDLE FileHandle;
OBJECT_ATTRIBUTES ObjectAttributes;
WCHAR PathPrefix = L"\Device\Harddisk0\Partition2";
ULONG FileNameLength;
IO_STATUS_BLOCK IoStatus;
char *result;

UNREFERENCED_PARAMETER(DeviceObject);
Irp->IoStatus.Status = STATUS_SUCCESS;
file://ZwCreateFile stuff
RtlInitUnicodeString(&FileName, PathPrefix);
FileName.Length= FileName.Length - sizeof(WCHAR);

InitializeObjectAttributes ( &ObjectAttributes,
&FileName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL );

ntStatus= ZwCreateFile(
&FileHandle,
FILE_READ_DATA | FILE_WRITE_DATA,
&ObjectAttributes,
&IoStatus,
NULL,
FILE_ATTRIBUTE_NORMAL,
0,
FILE_OPEN_IF,
FILE_NON_DIRECTORY_FILE,
NULL,
0
);

result=OsrNTStatusToString(ntStatus);

DbgPrint(“\n\n%s”,result);

ZwClose( FileHandle );

DbgPrint(“\n\nWCD : WCD_Create called”);
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
} // end WcdCreate()


Jiyo cricket on Yahoo! India cricket
Yahoo! Messenger Mobile Stay in touch with your buddies all the time.

yuvraj,

Bless your heart… Do as others have told you and eliminate this
WCHAR PathPrefix = L"\Device\Harddisk0\Partition2" crap.

What is this? FileName.Length= FileName.Length - sizeof(WCHAR);

The length is already set when you call RtlInitUnicodeString or when you
do

UNICODE_STRING FileName = L"\Device\Harddisk0\Partition2"

Listen when people give you advice on inproving your code.

m

yuvraj rege wrote:

Hello Sir ,
I have tried the pathname “\Device\Harddisk0\Partition2”
<file:>. Now the
> syntax problem is solved because I have used
> FileName.Length= FileName.Length - sizeof(WCHAR);
> to ommit the NULL from my path.
> But this time the new result encountered is STATUS_OBJECT_NOT_FOUND.
> I am using Device Tree for finding right object .How can I find the
> right object?
> Can I use the sysmbolic link? I am doubtfull about that.
>
> Regards
> Yuvraj Rege
>
> NTSTATUS
> WcdCreate(
> IN PDEVICE_OBJECT DeviceObject,
> IN PIRP Irp
> )
> {
>
> UNICODE_STRING FileName;
>
> NTSTATUS ntStatus;
> HANDLE FileHandle;
> OBJECT_ATTRIBUTES ObjectAttributes;
> WCHAR PathPrefix = L"\Device\Harddisk0\Partition2";
> ULONG FileNameLength;
> IO_STATUS_BLOCK IoStatus;
> char *result;
>
> UNREFERENCED_PARAMETER(DeviceObject);
> Irp->IoStatus.Status = STATUS_SUCCESS;
> file://ZwCreateFile stuff
> RtlInitUnicodeString(&FileName, PathPrefix);
> FileName.Length= FileName.Length - sizeof(WCHAR);
>
>
> InitializeObjectAttributes ( &ObjectAttributes,
> &FileName,
> OBJ_CASE_INSENSITIVE,
> NULL,
> NULL );
>
> ntStatus= ZwCreateFile(
> &FileHandle,
> FILE_READ_DATA | FILE_WRITE_DATA,
> &ObjectAttributes,
> &IoStatus,
> NULL,
> FILE_ATTRIBUTE_NORMAL,
> 0,
> FILE_OPEN_IF,
> FILE_NON_DIRECTORY_FILE,
> NULL,
> 0
> );
>
>
>
> result=OsrNTStatusToString(ntStatus);
>
> DbgPrint(“\n\n%s”,result);
>
> ZwClose( FileHandle );
>
> DbgPrint(“\n\nWCD : WCD_Create called”);
> IoCompleteRequest(Irp, IO_NO_INCREMENT);
> return STATUS_SUCCESS;
> } // end WcdCreate()
>
> ------------------------------------------------------------------------
> Jiyo cricket on Yahoo! India cricket
> http:</http:>
> Yahoo! Messenger Mobile
> http:</http:>
> Stay in touch with your buddies all the time. — Questions? First
> check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit the
> List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer</file:>

Correction in that, use UNICODE_STRING FileName =
RTL_CONSTANT_STRING(L"\Device\Harddisk0\Partition2");

left out RTL_CONSTAN…

MM wrote:

yuvraj,

Bless your heart… Do as others have told you and eliminate this
WCHAR PathPrefix = L"\Device\Harddisk0\Partition2" crap.

What is this? FileName.Length= FileName.Length - sizeof(WCHAR);

The length is already set when you call RtlInitUnicodeString or when you
do

UNICODE_STRING FileName = L"\Device\Harddisk0\Partition2"

Listen when people give you advice on inproving your code.

m

yuvraj rege wrote:

> Hello Sir ,
> I have tried the pathname “\Device\Harddisk0\Partition2”
> <file:>. Now the
>> syntax problem is solved because I have used
>> FileName.Length= FileName.Length - sizeof(WCHAR);
>> to ommit the NULL from my path.
>> But this time the new result encountered is STATUS_OBJECT_NOT_FOUND.
>> I am using Device Tree for finding right object .How can I find the
>> right object?
>> Can I use the sysmbolic link? I am doubtfull about that.
>>
>> Regards
>> Yuvraj Rege
>>
>> NTSTATUS
>> WcdCreate(
>> IN PDEVICE_OBJECT DeviceObject,
>> IN PIRP Irp
>> )
>> {
>> UNICODE_STRING FileName;
>> NTSTATUS ntStatus;
>> HANDLE FileHandle;
>> OBJECT_ATTRIBUTES ObjectAttributes;
>> WCHAR PathPrefix =
>> L"\Device\Harddisk0\Partition2";
>> ULONG FileNameLength;
>> IO_STATUS_BLOCK IoStatus;
>> char *result;
>>
>> UNREFERENCED_PARAMETER(DeviceObject);
>> Irp->IoStatus.Status = STATUS_SUCCESS;
>> file://ZwCreateFile stuff
>> RtlInitUnicodeString(&FileName, PathPrefix);
>> FileName.Length= FileName.Length - sizeof(WCHAR);
>>
>> InitializeObjectAttributes ( &ObjectAttributes,
>> &FileName,
>> OBJ_CASE_INSENSITIVE,
>> NULL,
>> NULL );
>> ntStatus= ZwCreateFile(
>> &FileHandle,
>> FILE_READ_DATA | FILE_WRITE_DATA,
>> &ObjectAttributes,
>> &IoStatus,
>> NULL,
>> FILE_ATTRIBUTE_NORMAL,
>> 0,
>> FILE_OPEN_IF,
>> FILE_NON_DIRECTORY_FILE,
>> NULL,
>> 0
>> );
>>
>>
>>
>> result=OsrNTStatusToString(ntStatus);
>>
>> DbgPrint(“\n\n%s”,result);
>> ZwClose( FileHandle );
>>
>> DbgPrint(“\n\nWCD : WCD_Create called”);
>> IoCompleteRequest(Irp, IO_NO_INCREMENT);
>> return STATUS_SUCCESS;
>> } // end WcdCreate()
>>
>> ------------------------------------------------------------------------
>> Jiyo cricket on Yahoo! India cricket
>> http:</http:>
>>
>> Yahoo! Messenger Mobile
>> http:</http:>
>> Stay in touch with your buddies all the time. — Questions? First
>> check the Kernel Driver FAQ at
>> http://www.osronline.com/article.cfm?id=256 To unsubscribe, visit the
>> List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
></file:>

> Everyone here should read Doron’s blog. This week it has been about Unicode

Can you name us the URL?

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com