trying to open a directory

In my fs filter, I’m trying to figure out if a directory exists. Say c:\A\B\C. If it does I’m going to create a file in it. If it does not I’m going to create the Dir, and then write the file.

So I start out asking if c:\ exists, and if not create it. Then I’ll go on and create c:\A, etc.

I keep getting access violation 0xc0000005 returns. Here is my code:

I’ve tried setting Path = “C:\” and also to
“C:\A” , and finally to “\Device\HarddiskVolume2\” .
InitializeObjectAttributes(&ObjAttrs,&Path, OBJ_KERNEL_HANDLE,NULL,NULL);

Status = IoCreateFile(&FileHandle,
FILE_WRITE_ATTRIBUTES|FILE_WRITE_DATA,
&ObjAttrs,
&StatusBlock,
0, //allocation size
FILE_ATTRIBUTE_DIRECTORY,
FILE_SHARE_WRITE, //share access
FILE_OPEN_IF, // disposition
FILE_DIRECTORY_FILE, // CreateOptions,
0, // EaBuffer OPTIONAL,
0 , // EaLength
CreateFileTypeNone, // CreateFileType
NULL, // extra params
IO_FORCE_ACCESS_CHECK // Options
);

What am I missing?

Thanks

Larry

FWIW, I do something very similar with no problems, although I’m using
IoCreateFileSpecifyDeviceObjectHint:

InitializeObjectAttributes(
&objAttributes,
&GenName,
OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE,
0,
NULL );

status = IoCreateFileSpecifyDeviceObjectHint(
&hFKFile, // File handle
STANDARD_RIGHTS_WRITE, // Desired access
&objAttributes, // Attributes
&IoSb, // IO Status Block
NULL, // Allocation size
FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM, // File attributes
FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_OPEN_IF, // Create disposition (create if it doesn’t
exist)
FILE_DIRECTORY_FILE, // Create options
NULL, // EA buffer
0, // EA size
CreateFileTypeNone, // CreateFileType
NULL, // Extra create parameters
0, // Options
devExt->AttachedToDeviceObject ); // Device object to use for open

Ken


Ken Cross

Network Storage Corp.
Phone 865.675.4070 ext 31
xxxxx@nssolutions.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Larry Dick
Sent: Tuesday, June 01, 2004 9:55 PM
To: Windows File Systems Devs Interest List
Subject: [ntfsd] trying to open a directory

In my fs filter, I’m trying to figure out if a directory exists. Say
c:\A\B\C. If it does I’m going to create a file in it. If it does not I’m
going to create the Dir, and then write the file.

So I start out asking if c:\ exists, and if not create it. Then I’ll go on
and create c:\A, etc.

I keep getting access violation 0xc0000005 returns. Here is my code:

I’ve tried setting Path = “C:\” and also to
“C:\A” , and finally to “\Device\HarddiskVolume2\” .
InitializeObjectAttributes(&ObjAttrs,&Path, OBJ_KERNEL_HANDLE,NULL,NULL);
Status = IoCreateFile(&FileHandle,
FILE_WRITE_ATTRIBUTES|FILE_WRITE_DATA,
&ObjAttrs,
&StatusBlock,
0, //allocation size
FILE_ATTRIBUTE_DIRECTORY,
FILE_SHARE_WRITE, //share access
FILE_OPEN_IF, // disposition
FILE_DIRECTORY_FILE, // CreateOptions,
0, // EaBuffer OPTIONAL,
0 , // EaLength
CreateFileTypeNone, // CreateFileType
NULL, // extra params
IO_FORCE_ACCESS_CHECK // Options
);
What am I missing?
Thanks
Larry

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

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

I think this is because IoCreateFile expects an user-mode
pointers. Try to use ZwCreateFile. IoCreateFileSpecifyDeviceObjectHint
is designed to be used in filters, so it expects kernel-mode
buffers.

L.

Don’t use IO_FORCE_ACCESS_CHECK in the last parameter of IoCreateFile. You need to use IO_NO_PARAMETER_CHECKING for that parameter.

YF
“Larry Dick” wrote in message news:xxxxx@ntfsd…
In my fs filter, I’m trying to figure out if a directory exists. Say c:\A\B\C. If it does I’m going to create a file in it. If it does not I’m going to create the Dir, and then write the file.

So I start out asking if c:\ exists, and if not create it. Then I’ll go on and create c:\A, etc.

I keep getting access violation 0xc0000005 returns. Here is my code:

I’ve tried setting Path = “C:\” and also to
“C:\A” , and finally to “\Device\HarddiskVolume2\” .
InitializeObjectAttributes(&ObjAttrs,&Path, OBJ_KERNEL_HANDLE,NULL,NULL);

Status = IoCreateFile(&FileHandle,
FILE_WRITE_ATTRIBUTES|FILE_WRITE_DATA,
&ObjAttrs,
&StatusBlock,
0, //allocation size
FILE_ATTRIBUTE_DIRECTORY,
FILE_SHARE_WRITE, //share access
FILE_OPEN_IF, // disposition
FILE_DIRECTORY_FILE, // CreateOptions,
0, // EaBuffer OPTIONAL,
0 , // EaLength
CreateFileTypeNone, // CreateFileType
NULL, // extra params
IO_FORCE_ACCESS_CHECK // Options
);

What am I missing?

Thanks

Larry