Hi all !
I must Open a file in my Driver , The fragment code as below . But it always
can not be opened .. Pls tell me why ??
Thanks in advance !

HANDLE fileOpen;
OBJECT_ATTRIBUTES objAttr;
UNICODE_STRING sLinkName;
#define FILE_NAME L"C:\\test.out"
RtlInitUnicodeString( &sLinkName, FILE_NAME);

KIRQL oldIrql,
newIrql = PASSIVE_LEVEL;
KeRaiseIrql(newIrql,&oldIrql);
InitializeObjectAttributes(
&objAttr,
&sLinkName,
OBJ_KERNEL_HANDLE,
NULL,
NULL);

LARGE_INTEGER nSize;
IO_STATUS_BLOCK ioStat;

NTSTATUS statusOpen = ZwOpenFile(
OUT &fileOpen,
IN FILE_READ_DATA | FILE_WRITE_DATA,
IN &objAttr,
OUT &ioStat,
IN FILE_SHARE_READ,
IN FILE_NON_DIRECTORY_FILE
);

RE: ZwOpenFile helppppppppp by anonymous

anonymous
Mon May 31 04:51:04 CDT 2004

Alex
You did not specify how exactly did the ZwOpenFile failed, more details could be useful..
You cannot access files with this path, try \\??\\C:\\test.out
Also, why do you use KeRaiseIrql? PASSIVE_LEVEL is the lowest and if you aren't already ther
you should not try to use the ZwOpenFile

G


Re: ZwOpenFile helppppppppp by Alex

Alex
Mon May 31 16:29:38 CDT 2004

Thank you so much ! Gram !
In fact , I must Open COM port in my driver , but I tried to open a normal
file first, and have not openned it . So I do not understand why .
I have deleted the lines KeRaiseIrdl . And tried with path
\\??\\C:\\test.out . and always get errors. Maybe in
InitializeObjectAttrbutes??
If you have any idea about openning COM port , pls help me directly with COM
. I am now very confuse .
Waiting for help from you !
Thank you so much !

HANDLE fileOpen;
OBJECT_ATTRIBUTES objAttr;
UNICODE_STRING sLinkName;
#define COM_NAME L"\\??\\C:\\test.out"
RtlInitUnicodeString( &sLinkName, COM_NAME);

InitializeObjectAttributes(
&objAttr,
&sLinkName,
OBJ_EXCLUSIVE,
NULL,
NULL);

LARGE_INTEGER nSize;
IO_STATUS_BLOCK ioStat;


NTSTATUS statusOpen = ZwOpenFile(
OUT &fileOpen,
IN FILE_READ_DATA | FILE_WRITE_DATA,
IN &objAttr,
OUT &ioStat,
IN FILE_SHARE_READ,
IN FILE_NON_DIRECTORY_FILE
);


DbgPrint("statusOpen= %X.", statusOpen); // return statusOpen=
C000000D.






"Gram" <anonymous@discussions.microsoft.com> wrote in message
news:FF8EF646-4089-4998-B330-E7F53392341E@microsoft.com...
> Alex,
> You did not specify how exactly did the ZwOpenFile failed, more details
could be useful...
> You cannot access files with this path, try \\??\\C:\\test.out.
> Also, why do you use KeRaiseIrql? PASSIVE_LEVEL is the lowest and if you
aren't already there
> you should not try to use the ZwOpenFile?
>
> G.
>



Re: ZwOpenFile helppppppppp by Alex

Alex
Mon May 31 09:37:56 CDT 2004

NTSTATUS 0x0C000000D is "STATUS_INVALID_PARAMETER"

So, double check your parameters, re-read the ddk documentation for
ZwOpenFile, and, don' use something you don't understand or didn't check out
in the DDK first, example, why did you used "OBJ_EXCLUSIVE"?

Did you looked in DDK what OBJ_EXCLUSIVE is used for?



"Alex" <Chipheo2k@hotmail.com> wrote in message
news:ujGwCnvREHA.3660@tk2msftngp13.phx.gbl...

> Thank you so much ! Gram !
> In fact , I must Open COM port in my driver , but I tried to open a
normal
> file first, and have not openned it . So I do not understand why .
> I have deleted the lines KeRaiseIrdl . And tried with path
> \\??\\C:\\test.out . and always get errors. Maybe in
> InitializeObjectAttrbutes??
> If you have any idea about openning COM port , pls help me directly with
COM
> . I am now very confuse .
> Waiting for help from you !
> Thank you so much !
>
> HANDLE fileOpen;
> OBJECT_ATTRIBUTES objAttr;
> UNICODE_STRING sLinkName;
> #define COM_NAME L"\\??\\C:\\test.out"
> RtlInitUnicodeString( &sLinkName, COM_NAME);
>
> InitializeObjectAttributes(
> &objAttr,
> &sLinkName,
> OBJ_EXCLUSIVE,
> NULL,
> NULL);
>
> LARGE_INTEGER nSize;
> IO_STATUS_BLOCK ioStat;
>
>
> NTSTATUS statusOpen = ZwOpenFile(
> OUT &fileOpen,
> IN FILE_READ_DATA | FILE_WRITE_DATA,
> IN &objAttr,
> OUT &ioStat,
> IN FILE_SHARE_READ,
> IN FILE_NON_DIRECTORY_FILE
> );
>
>
> DbgPrint("statusOpen= %X.", statusOpen); // return statusOpen=
> C000000D.
>
>
>
>
>
>
> "Gram" <anonymous@discussions.microsoft.com> wrote in message
> news:FF8EF646-4089-4998-B330-E7F53392341E@microsoft.com...
> > Alex,
> > You did not specify how exactly did the ZwOpenFile failed, more details
> could be useful...
> > You cannot access files with this path, try \\??\\C:\\test.out.
> > Also, why do you use KeRaiseIrql? PASSIVE_LEVEL is the lowest and if you
> aren't already there
> > you should not try to use the ZwOpenFile?
> >
> > G.
> >
>
>



Re: ZwOpenFile helppppppppp by Alex

Alex
Mon May 31 21:36:32 CDT 2004

Thank Alex!
So which value must be used for it ?
For a normal file ( text file ) , and for a Device ( Comm Port ) . I only
tried to pass different values to get true result . In DDK wrote nothing
about it !
damm ..

"Alex the 1'ts" <AlX@a> wrote in message
news:OrgLnzxREHA.2496@TK2MSFTNGP11.phx.gbl...
> NTSTATUS 0x0C000000D is "STATUS_INVALID_PARAMETER"
>
> So, double check your parameters, re-read the ddk documentation for
> ZwOpenFile, and, don' use something you don't understand or didn't check
out
> in the DDK first, example, why did you used "OBJ_EXCLUSIVE"?
>
> Did you looked in DDK what OBJ_EXCLUSIVE is used for?
>
>
>
> "Alex" <Chipheo2k@hotmail.com> wrote in message
> news:ujGwCnvREHA.3660@tk2msftngp13.phx.gbl...
>
> > Thank you so much ! Gram !
> > In fact , I must Open COM port in my driver , but I tried to open a
> normal
> > file first, and have not openned it . So I do not understand why .
> > I have deleted the lines KeRaiseIrdl . And tried with path
> > \\??\\C:\\test.out . and always get errors. Maybe in
> > InitializeObjectAttrbutes??
> > If you have any idea about openning COM port , pls help me directly with
> COM
> > . I am now very confuse .
> > Waiting for help from you !
> > Thank you so much !
> >
> > HANDLE fileOpen;
> > OBJECT_ATTRIBUTES objAttr;
> > UNICODE_STRING sLinkName;
> > #define COM_NAME L"\\??\\C:\\test.out"
> > RtlInitUnicodeString( &sLinkName, COM_NAME);
> >
> > InitializeObjectAttributes(
> > &objAttr,
> > &sLinkName,
> > OBJ_EXCLUSIVE,
> > NULL,
> > NULL);
> >
> > LARGE_INTEGER nSize;
> > IO_STATUS_BLOCK ioStat;
> >
> >
> > NTSTATUS statusOpen = ZwOpenFile(
> > OUT &fileOpen,
> > IN FILE_READ_DATA | FILE_WRITE_DATA,
> > IN &objAttr,
> > OUT &ioStat,
> > IN FILE_SHARE_READ,
> > IN FILE_NON_DIRECTORY_FILE
> > );
> >
> >
> > DbgPrint("statusOpen= %X.", statusOpen); // return statusOpen=
> > C000000D.
> >
> >
> >
> >
> >
> >
> > "Gram" <anonymous@discussions.microsoft.com> wrote in message
> > news:FF8EF646-4089-4998-B330-E7F53392341E@microsoft.com...
> > > Alex,
> > > You did not specify how exactly did the ZwOpenFile failed, more
details
> > could be useful...
> > > You cannot access files with this path, try \\??\\C:\\test.out.
> > > Also, why do you use KeRaiseIrql? PASSIVE_LEVEL is the lowest and if
you
> > aren't already there
> > > you should not try to use the ZwOpenFile?
> > >
> > > G.
> > >
> >
> >
>
>



Re: ZwOpenFile helppppppppp by Alex

Alex
Mon May 31 20:55:18 CDT 2004

> > > InitializeObjectAttributes(
> > > &objAttr,
> > > &sLinkName,
> > > OBJ_EXCLUSIVE,
> > > NULL,
> > > NULL);

Why do you use OBJ_EXCLUSIVE? This flas IS documented in the DDK, did you
look at it?

> > >
> > > LARGE_INTEGER nSize;
> > > IO_STATUS_BLOCK ioStat;
> > >
> > >
> > > NTSTATUS statusOpen = ZwOpenFile(
> > > OUT &fileOpen,
> > > IN FILE_READ_DATA | FILE_WRITE_DATA,
> > > IN &objAttr,
> > > OUT &ioStat,
> > > IN FILE_SHARE_READ,
> > > IN FILE_NON_DIRECTORY_FILE
> > > );


ZwOpenFile IS well documented in the DDK, did you read the documentation
carefully? Even at a glance I can see a wrong parameter.
If the OS tells you, you used same invalid parameters, you better belive it.
Now, why don't you look in the DDK and see for yourself?

> > >
> > >
> > > DbgPrint("statusOpen= %X.", statusOpen); // return statusOpen=
> > > C000000D.
> > >
> > >
> > >
> > >
> > >
> > >
> > > "Gram" <anonymous@discussions.microsoft.com> wrote in message
> > > news:FF8EF646-4089-4998-B330-E7F53392341E@microsoft.com...
> > > > Alex,
> > > > You did not specify how exactly did the ZwOpenFile failed, more
> details
> > > could be useful...
> > > > You cannot access files with this path, try \\??\\C:\\test.out.
> > > > Also, why do you use KeRaiseIrql? PASSIVE_LEVEL is the lowest and if
> you
> > > aren't already there
> > > > you should not try to use the ZwOpenFile?
> > > >
> > > > G.
> > > >
> > >
> > >
> >
> >
>
>