How to read some config data from file in my filter?

I just want to read some config infomation from my config file.
I put the code into driverentry and some place else,but the return value
from
ZwReadFile is always not success, what shoud I do?

Are there any easy way to get info from file in filter driver?
//

RtlInitUnicodeString(&filename,L"\DosDevices\C:\config.dat");
InitializeObjectAttributes( &attributes,&filename,
OBJ_CASE_INSENSITIVE,NULL,NULL);
status =
ZwOpenFile(&hFile,FILE_READ_DATA,&attributes,&sb,FILE_SHARE_READ,FILE_NON_DI
RECTORY_FILE);
if (!NT_SUCCESS(status)) {
ret = 0;
goto OUTWAY;
}

buffer = ExAllocatePoolWithTag( NonPagedPool, buflen,
FILESPY_POOL_TAG );
if (NULL == buffer){
ret = 0;
goto OUTWAY;
}

status = ZwReadFile(hFile,NULL,NULL,NULL,&sb,buffer,buflen,NULL,NULL);
if (!NT_SUCCESS(status)) {
ret = 0; //always go here, why? how can I correct
it?
goto OUTWAY;
}

Maybe you can give us some clues - like what status code are you seeing?
STATUS_OBJECT_PATH_NOT_FOUND? STATUS_OBJECT_NAME_NOT_FOUND?
STATUS_ACCESS_DENIED?

When are you loading your driver? It is possible you’ve done it before
the drive letters have been created.

Regards,

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

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Holk Leng
Sent: Tuesday, May 18, 2004 6:40 AM
To: ntfsd redirect
Subject: [ntfsd] How to read some config data from file in my filter?

I just want to read some config infomation from my config file.
I put the code into driverentry and some place else,but the return value
from
ZwReadFile is always not success, what shoud I do?

Are there any easy way to get info from file in filter driver?
//

RtlInitUnicodeString(&filename,L"\DosDevices\C:\config.dat");
InitializeObjectAttributes( &attributes,&filename,
OBJ_CASE_INSENSITIVE,NULL,NULL);
status =
ZwOpenFile(&hFile,FILE_READ_DATA,&attributes,&sb,FILE_SHARE_READ,FILE_NO
N_DI
RECTORY_FILE);
if (!NT_SUCCESS(status)) {
ret = 0;
goto OUTWAY;
}

buffer = ExAllocatePoolWithTag( NonPagedPool, buflen,
FILESPY_POOL_TAG );
if (NULL == buffer){
ret = 0;
goto OUTWAY;
}

status =
ZwReadFile(hFile,NULL,NULL,NULL,&sb,buffer,buflen,NULL,NULL);
if (!NT_SUCCESS(status)) {
ret = 0; //always go here, why? how can I
correct
it?
goto OUTWAY;
}


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

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

You still haven’t told us what the error code is. Without that, there’s
not much I can suggest. I still think the problem is in your ZwCreate
call, however. But without that status code, there’s not much anyone
can really do but guess. The status code helps narrow down the actual
cause of the problem and focus attention in the right place.

How about trying GENERIC_READ instead of FILE_READ_DATA? That way
you’ll have other rights as well - I don’t think that’s the problem, but
since you won’t give us the status code, it is a matter of guessing
(“gee, how does this differ from what I’ve done…”)

Also, how do you expect to find out when the operation is done? You
didn’t specify that you wanted synchronous I/O, but you neither provided
an event nor an APC. So maybe you are getting back
STATUS_INVALID_PARAMETER?

We try to be helpful in this group, but you really need to give us
something to go by, rather than just your code - I always find trying to
decipher an error from a code snippet to be difficult, and often the
problem isn’t in the code snippet, it is elsewhere…

Regards,

Tony

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

-----Original Message-----
From: Holk Leng [mailto:xxxxx@baidu.com]
Sent: Tuesday, May 18, 2004 7:21 AM
To: Tony Mason
Subject: Re: How to read some config data from file in my filter?

but zwopenfile return valid handle, so I think the file is opened ok,
only can’t read.
if can’t find the file, zwopenfile must return wrong

----- Original Message -----
From: “Tony Mason”
Newsgroups: ntfsd
To: “ntfsd redirect”
Sent: Tuesday, May 18, 2004 7:05 PM
Subject: RE: How to read some config data from file in my filter?

Maybe you can give us some clues - like what status code are you seeing?
STATUS_OBJECT_PATH_NOT_FOUND? STATUS_OBJECT_NAME_NOT_FOUND?
STATUS_ACCESS_DENIED?

When are you loading your driver? It is possible you’ve done it before
the drive letters have been created.

Regards,

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

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Holk Leng
Sent: Tuesday, May 18, 2004 6:40 AM
To: ntfsd redirect
Subject: [ntfsd] How to read some config data from file in my filter?

I just want to read some config infomation from my config file.
I put the code into driverentry and some place else,but the return value
from
ZwReadFile is always not success, what shoud I do?

Are there any easy way to get info from file in filter driver?
//

RtlInitUnicodeString(&filename,L"\DosDevices\C:\config.dat");
InitializeObjectAttributes( &attributes,&filename,
OBJ_CASE_INSENSITIVE,NULL,NULL);
status =
ZwOpenFile(&hFile,FILE_READ_DATA,&attributes,&sb,FILE_SHARE_READ,FILE_NO
N_DI
RECTORY_FILE);
if (!NT_SUCCESS(status)) {
ret = 0;
goto OUTWAY;
}

buffer = ExAllocatePoolWithTag( NonPagedPool, buflen,
FILESPY_POOL_TAG );
if (NULL == buffer){
ret = 0;
goto OUTWAY;
}

status =
ZwReadFile(hFile,NULL,NULL,NULL,&sb,buffer,buflen,NULL,NULL);
if (!NT_SUCCESS(status)) {
ret = 0; //always go here, why? how can I
correct
it?
goto OUTWAY;
}


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

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

  • use ZwCreateFile

  • status = ZwReadFile(hFile,
    NULL,
    NULL,
    NULL,
    &sb,
    buffer,
    buflen,
    NULL, <=== set the offset of file to
    read
    NULL);

From: “Holk Leng”
>Reply-To: “Windows File Systems Devs Interest List”
>To: “Windows File Systems Devs Interest List”
>Subject: [ntfsd] How to read some config data from file in my filter?
>Date: Tue, 18 May 2004 18:40:06 +0800
>
>I just want to read some config infomation from my config file.
>I put the code into driverentry and some place else,but the return value
>from
>ZwReadFile is always not success, what shoud I do?
>
>Are there any easy way to get info from file in filter driver?
>//
>
>RtlInitUnicodeString(&filename,L"\DosDevices\C:\config.dat");
> InitializeObjectAttributes( &attributes,&filename,
> OBJ_CASE_INSENSITIVE,NULL,NULL);
> status =
>ZwOpenFile(&hFile,FILE_READ_DATA,&attributes,&sb,FILE_SHARE_READ,FILE_NON_DI

>RECTORY_FILE);
> if (!NT_SUCCESS(status)) {
> ret = 0;
> goto OUTWAY;
> }
>
> buffer = ExAllocatePoolWithTag( NonPagedPool, buflen,
>FILESPY_POOL_TAG );
> if (NULL == buffer){
> ret = 0;
> goto OUTWAY;
> }
>
> status =
ZwReadFile(hFile,NULL,NULL,NULL,&sb,buffer,buflen,NULL,NULL);
> if (!NT_SUCCESS(status)) {
> ret = 0; //always go here, why? how can I correct
>it?
> goto OUTWAY;
> }
>
>
>
>—
>Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17
>
>You are currently subscribed to ntfsd as: xxxxx@hotmail.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com

_________________________________________________________________
Áõ±Ç Á¤º¸ °¡Àå ºü¸£°í ÆíÇÏ°Ô º¸½Ç ¼ö ÀÖ½À´Ï´Ù. MSN Áõ±Ç/ÅõÀÚ
http://www.msn.co.kr/stock/