Developing a File System filter Driver

Discussion in 'C Programming' started by noe, May 26, 2004.

  1. noe

    noe Guest

    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
    noe, May 26, 2004
    #1
    1. Advertising

  2. noe

    Dan Pop Guest

    In <> "noe" <> writes:

    >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
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
    Dan Pop, May 26, 2004
    #2
    1. Advertising

  3. noe

    noe Guest

    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.
    noe, May 26, 2004
    #3
  4. "noe" <> wrote in
    news::

    > 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.

    --
    - Mark ->
    --
    Mark A. Odell, May 26, 2004
    #4
  5. noe

    Jack Klein Guest

    On Wed, 26 May 2004 11:54:02 -0400, "noe" <> wrote
    in comp.lang.c:

    > 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;
    }

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
    Jack Klein, May 27, 2004
    #5
  6. noe

    Dan Pop Guest

    In <> "noe" <> writes:

    >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
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
    Dan Pop, May 27, 2004
    #6
  7. noe

    Dan Pop Guest

    In <> Jack Klein <> writes:

    >On Wed, 26 May 2004 11:54:02 -0400, "noe" <> wrote
    >in comp.lang.c:
    >
    >> 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
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
    Dan Pop, May 27, 2004
    #7
  8. On Wed, 26 May 2004 -0500, Jack Klein <> wrote:
    >#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?
    RoSsIaCrIiLoIA, May 30, 2004
    #8
  9. RoSsIaCrIiLoIA <> wrote:
    > On Wed, 26 May 2004 -0500, Jack Klein <> wrote:
    > >#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?


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

    --
    Michael
    Michael Fyles, May 30, 2004
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SamIAm
    Replies:
    0
    Views:
    511
    SamIAm
    Oct 22, 2003
  2. yogesh

    about system call in driver

    yogesh, Feb 6, 2006, in forum: C Programming
    Replies:
    1
    Views:
    316
    Artie Gold
    Feb 6, 2006
  3. zax75
    Replies:
    1
    Views:
    1,094
  4. bienwell
    Replies:
    1
    Views:
    3,402
    Gregory A. Beamer
    Dec 10, 2009
  5. kazaam
    Replies:
    6
    Views:
    216
    kazaam
    Aug 27, 2007
Loading...

Share This Page