Developing a File System filter Driver

N

noe

Hello all devs!!

I’m a student and I’m developing my Final Project in the University. I
have to develop a driver for Windows XP that work so:
I have a file in the HD (NTFS file system) of my PC and I want to copy it
to the floppy disk (FAT16 file system). But I need that the file data in
the floppy disk is modified (added 1 respect to the original value).
For example:

I have-> HD file data: ‘hello’
I need to obtain -> Floppy file data: ‘ifmmp’

I know I have to write a File System Filter Driver.
I’m working about the sample code ‘sfilter.c’ of IFS Kit.
I think that one of the routines which will be modified is this:

BOOLEAN
SfFastIoRead (IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset,
IN ULONG Length, IN BOOLEAN Wait, IN ULONG LockKey, OUT PVOID Buffer,
OUT PIO_STATUS_BLOCK IoStatus, IN PDEVICE_OBJECT DeviceObject)

{
PDEVICE_OBJECT nextDeviceObject;
PFAST_IO_DISPATCH fastIoDispatch;

PAGED_CODE();
VALIDATE_IRQL(Irp);

if (DeviceObject->DeviceExtension) {

ASSERT(IS_MY_DEVICE_OBJECT( DeviceObject ));

//
// Pass through logic for this type of Fast I/O
//

nextDeviceObject = ((PSFILTER_DEVICE_EXTENSION)
DeviceObject->DeviceExtension)->AttachedToDeviceObject;
ASSERT(nextDeviceObject);

fastIoDispatch = nextDeviceObject->DriverObject->FastIoDispatch;

if (VALID_FAST_IO_DISPATCH_HANDLER( fastIoDispatch, FastIoRead ))
{

return (fastIoDispatch->FastIoRead)(
FileObject,
FileOffset,
Length,
Wait,
LockKey,
Buffer,
IoStatus,
nextDeviceObject );
}
}
return FALSE;
}

I suppose what I have to modify is the parameter “buffer” but I’m not sure
and I don’t know how I have to do.

It’s the first time I face a problem so serious because I have never
worked with drivers.
Please, could you help me?
Thanks a lot
 
D

Dan Pop

In said:
BOOLEAN
SfFastIoRead (IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset,
IN ULONG Length, IN BOOLEAN Wait, IN ULONG LockKey, OUT PVOID Buffer,
OUT PIO_STATUS_BLOCK IoStatus, IN PDEVICE_OBJECT DeviceObject)

{
PDEVICE_OBJECT nextDeviceObject;
PFAST_IO_DISPATCH fastIoDispatch;

PAGED_CODE();
VALIDATE_IRQL(Irp);

if (DeviceObject->DeviceExtension) {

ASSERT(IS_MY_DEVICE_OBJECT( DeviceObject ));

//
// Pass through logic for this type of Fast I/O
//

nextDeviceObject = ((PSFILTER_DEVICE_EXTENSION)
DeviceObject->DeviceExtension)->AttachedToDeviceObject;
ASSERT(nextDeviceObject);

fastIoDispatch = nextDeviceObject->DriverObject->FastIoDispatch;

if (VALID_FAST_IO_DISPATCH_HANDLER( fastIoDispatch, FastIoRead ))
{

return (fastIoDispatch->FastIoRead)(
FileObject,
FileOffset,
Length,
Wait,
LockKey,
Buffer,
IoStatus,
nextDeviceObject );
}
}
return FALSE;
}

Please do not post garbage to this newsgroup. If I try to compile your
code, this is what I get:

fangorn:~/tmp 177> gcc -c test.c
test.c:2: error: parse error before "SfFastIoRead"
test.c:2: error: parse error before "PFILE_OBJECT"
test.c: In function `SfFastIoRead':
test.c:7: error: `PDEVICE_OBJECT' undeclared (first use in this function)
test.c:7: error: (Each undeclared identifier is reported only once
test.c:7: error: for each function it appears in.)
test.c:7: error: parse error before "nextDeviceObject"
test.c:8: error: `PFAST_IO_DISPATCH' undeclared (first use in this function)
test.c:11: error: `Irp' undeclared (first use in this function)
test.c:13: error: `DeviceObject' undeclared (first use in this function)
test.c:21: error: `nextDeviceObject' undeclared (first use in this function)
test.c:21: error: `PSFILTER_DEVICE_EXTENSION' undeclared (first use in this function)
test.c:22: error: parse error before "DeviceObject"
test.c:25: error: `fastIoDispatch' undeclared (first use in this function)
test.c:27: error: `FastIoRead' undeclared (first use in this function)
test.c:31: error: `FileObject' undeclared (first use in this function)
test.c:32: error: `FileOffset' undeclared (first use in this function)
test.c:33: error: `Length' undeclared (first use in this function)
test.c:34: error: `Wait' undeclared (first use in this function)
test.c:35: error: `LockKey' undeclared (first use in this function)
test.c:36: error: `Buffer' undeclared (first use in this function)
test.c:37: error: `IoStatus' undeclared (first use in this function)
test.c:41: error: `FALSE' undeclared (first use in this function)

Furthermore, none of these diagnostics could be fixed by the inclusion of
any standard header, so your code is beyond any hope in this newsgroup.

Dan
 
N

noe

Obviously it's only a part of the sample code. If you want to see the
complete code you have to check "sfilter.c" from the samples of IFS Kit.
 
M

Mark A. Odell

Obviously it's only a part of the sample code. If you want to see the
complete code you have to check "sfilter.c" from the samples of IFS Kit.

So what? This is system specific stuff - off-topic here.
 
J

Jack Klein

Hello all devs!!

I’m a student and I’m developing my Final Project in the University. I
have to develop a driver for Windows XP that work so:
I have a file in the HD (NTFS file system) of my PC and I want to copy it
to the floppy disk (FAT16 file system). But I need that the file data in
the floppy disk is modified (added 1 respect to the original value).
For example:

I have-> HD file data: ‘hello’
I need to obtain -> Floppy file data: ‘ifmmp’

[snip vast amounts of off-topic code that look more like Visual Basic
than C]

There is no need whatsoever for this to be a driver program. Plain
old ordinary C FILE * streams will do this quite nicely.

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
FILE *fin, *fout;
int ch;

fin = fopen("source_file_name", "r");
fout = fopen("destination_file_name", "w");

if (!fin || !fout)
{
puts("error opening files!");
return EXIT_FAILURE;
}

while ((ch = fgetc(fin)) != EOF)
{
fputc(ch + 1, fout);
}
fclose(fin);
fclose(fout);
return EXIT_SUCCESS;
}
 
D

Dan Pop

In said:
Obviously it's only a part of the sample code. If you want to see the
complete code you have to check "sfilter.c" from the samples of IFS Kit.

1. How can you expect any advice without posting the complete code?

2. My point was that the code is not written in portable C, so you have
posted it in the wrong newsgroup.

Dan
 
D

Dan Pop

In said:
Hello all devs!!

I’m a student and I’m developing my Final Project in the University. I
have to develop a driver for Windows XP that work so:
I have a file in the HD (NTFS file system) of my PC and I want to copy it
to the floppy disk (FAT16 file system). But I need that the file data in
the floppy disk is modified (added 1 respect to the original value).
For example:

I have-> HD file data: ‘hello’
I need to obtain -> Floppy file data: ‘ifmmp’

[snip vast amounts of off-topic code that look more like Visual Basic
than C]

There is no need whatsoever for this to be a driver program. Plain
old ordinary C FILE * streams will do this quite nicely.

Not if you want the filtering to happen *transparently*. If the filter
must be hooked into the OS, it must fit into the hooks provided for this
purpose. This is what makes the post off topic here. Once the OS
interfacing issues are understood, the actual filtering is one of the
most trivial things one can imagine.

Dan
 
R

RoSsIaCrIiLoIA

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
FILE *fin, *fout;
int ch;

fin = fopen("source_file_name", "r");
fout = fopen("destination_file_name", "w");

if (!fin || !fout)
{
puts("error opening files!");
return EXIT_FAILURE;
}

if fin==NULL and fout!=NULL and no exit()
does it mean that "fout" is open afther the end of
the programme?
 
M

Michael Fyles

RoSsIaCrIiLoIA said:
if fin==NULL and fout!=NULL and no exit()
does it mean that "fout" is open afther the end of
the programme?

No, returning from main does the same thing as calling exit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top