Software & Application Miscellaneous: ZwReadFile failed on Vista with files on udf formated DVD

  • anonymous / 205 / Mon, 25 Jan 2010 20:47:00 GMT / Comments (3)
  • The following snippet shows some calls to ZwCreateFile and ZwReadFile which work fine on 2000,2003, XP. But on Vista ZwReadFile will fail with STATUS_INVALID_PARAMETER. It only fails, if the file is located on an UDF formated DVD. If file is located on a physical disk, USB device or CD, everything is ok.

    ntStatus = ZwCreateFile (&hDeviceFile,
    GENERIC_READ | SYNCHRONIZE,
    &oaFileAttributes,
    &IoStatusBlock,
    NULL,
    FILE_ATTRIBUTE_NORMAL |
    FILE_ATTRIBUTE_SYSTEM,
    FILE_SHARE_READ,
    FILE_OPEN,
    FILE_NO_INTERMEDIATE_BUFFERING |
    FILE_SYNCHRONOUS_IO_NONALERT,
    NULL,
    0);

    if (!NT_SUCCESS (ntStatus))
    {
    goto error;
    }

    ntStatus = ZwReadFile (hDeviceFile,
    NULL,
    NULL,
    NULL,
    &IoStatusBlock,
    ReadBuffer,
    FIRST_READ_SIZE, // means 512 * 11 = 5632
    &BaseOffset, //it's 0
    NULL);

    -->> here ntStatus == STATUS_INVALID_PARAMETER

    I checked the Alignment Requirement with
    #if DBG
    //Alignment Requirement
    ntStatus = ZwQueryInformationFile(hDeviceFile, &IoStatusBlock, &FileAlignmentInfo, sizeof (FileAlignmentInfo),
    FileAlignmentInformation);
    #endif

    FileAlignmentInfo shows 1, which means Word Boundary required. I also changed GENERIC_READ to FILE_READ_DATA|FILE_READ_ATTRIBUTES|FILE_READ_EA but this also changed nothing.

    Any ideas?

    Thanks in advance
  • Keywords:

    zwreadfile, failed, vista, files, udf, formated, dvd, software, application

  • http://software.itags.org/software-application/240750/«« Last Thread - Next Thread »»
    1. "Horst" <Horst...discussions.microsoft.com> wrote in message
      news:187D17EB-9634-44B2-BF15-4A106370CA37...microsoft.com...
      > The following snippet shows some calls to ZwCreateFile and ZwReadFile
      > which
      > work fine on
      > 2000,2003, XP. But on Vista ZwReadFile will fail with
      > STATUS_INVALID_PARAMETER. It only fails, if
      > the file is located on an UDF formated DVD. If file is located on a
      > physical
      > disk, USB device or CD, everything is ok.
      > ntStatus = ZwCreateFile (&hDeviceFile,
      > GENERIC_READ | SYNCHRONIZE,
      > &oaFileAttributes,
      > &IoStatusBlock,
      > NULL,
      > FILE_ATTRIBUTE_NORMAL |
      > FILE_ATTRIBUTE_SYSTEM,
      > FILE_SHARE_READ,
      > FILE_OPEN,
      > FILE_NO_INTERMEDIATE_BUFFERING |
      > FILE_SYNCHRONOUS_IO_NONALERT,
      > NULL,
      > 0);
      > if (!NT_SUCCESS (ntStatus))
      > {
      > goto error;
      > }
      >
      > ntStatus = ZwReadFile (hDeviceFile,
      > NULL,
      > NULL,
      > NULL,
      > &IoStatusBlock,
      > ReadBuffer,
      > FIRST_READ_SIZE, // means 512 * 11 = 5632
      > &BaseOffset, //it's 0
      > NULL);
      > -->> here ntStatus == STATUS_INVALID_PARAMETER
      > I checked the Alignment Requirement with
      > #if DBG
      > //Alignment Requirement
      > ntStatus = ZwQueryInformationFile(hDeviceFile,
      > &IoStatusBlock,
      > &FileAlignmentInfo,
      > sizeof (FileAlignmentInfo),
      > FileAlignmentInformation);
      > #endif
      > FileAlignmentInfo shows 1, which means Word Boundary required. I also
      > changed GENERIC_READ to
      > FILE_READ_DATA|FILE_READ_ATTRIBUTES|FILE_READ_EA but this also changed
      > nothing.
      > Any ideas?
      > Thanks in advance
      > Horst
      >

      matthew | Tues, 20 May 2008 07:39:00 GMT |

    2. It says this in the ZwReadFile documentation:

      If the preceding call to ZwCreateFile set the FILE_NO_INTERMEDIATE_BUFFERING
      flag in the CreateOptions parameter to ZwCreateFile, the Length and
      ByteOffset parameters to ZwReadFile must be multiples of the sector size.
      For more information, see ZwCreateFile.

      Perhaps the sector size is the issue. I have no idea why the sector size
      would change in Vista, but trying a sector size that is a multiple of 2048
      should rule this out as the source of the problem. Data sectors on CDs hold
      2048 bytes of data.

      "Horst" <Horst...discussions.microsoft.com> wrote in message
      news:187D17EB-9634-44B2-BF15-4A106370CA37...microsoft.com...
      > The following snippet shows some calls to ZwCreateFile and ZwReadFile
      > which
      > work fine on
      > 2000,2003, XP. But on Vista ZwReadFile will fail with
      > STATUS_INVALID_PARAMETER. It only fails, if
      > the file is located on an UDF formated DVD. If file is located on a
      > physical
      > disk, USB device or CD, everything is ok.
      > ntStatus = ZwCreateFile (&hDeviceFile,
      > GENERIC_READ | SYNCHRONIZE,
      > &oaFileAttributes,
      > &IoStatusBlock,
      > NULL,
      > FILE_ATTRIBUTE_NORMAL |
      > FILE_ATTRIBUTE_SYSTEM,
      > FILE_SHARE_READ,
      > FILE_OPEN,
      > FILE_NO_INTERMEDIATE_BUFFERING |
      > FILE_SYNCHRONOUS_IO_NONALERT,
      > NULL,
      > 0);
      > if (!NT_SUCCESS (ntStatus))
      > {
      > goto error;
      > }
      >
      > ntStatus = ZwReadFile (hDeviceFile,
      > NULL,
      > NULL,
      > NULL,
      > &IoStatusBlock,
      > ReadBuffer,
      > FIRST_READ_SIZE, // means 512 * 11 = 5632
      > &BaseOffset, //it's 0
      > NULL);
      > -->> here ntStatus == STATUS_INVALID_PARAMETER
      > I checked the Alignment Requirement with
      > #if DBG
      > //Alignment Requirement
      > ntStatus = ZwQueryInformationFile(hDeviceFile,
      > &IoStatusBlock,
      > &FileAlignmentInfo,
      > sizeof (FileAlignmentInfo),
      > FileAlignmentInformation);
      > #endif
      > FileAlignmentInfo shows 1, which means Word Boundary required. I also
      > changed GENERIC_READ to
      > FILE_READ_DATA|FILE_READ_ATTRIBUTES|FILE_READ_EA but this also changed
      > nothing.
      > Any ideas?
      > Thanks in advance
      > Horst
      >

      matthew | Tues, 20 May 2008 07:40:00 GMT |

    3. Hello Matthew,

      Thanks, it realy works with buffersizes dividable by 2048. But it's only
      necessary on UDF formated DVDs on vista.
      On a CD the Physical Device Object also says Sector Size 0x800, but you can
      use any offset and any buffersize, even on vista. I'm not quite sure, if this
      vista udf behaviour is a bug/inconsistancy or a new requirement/stricter use
      of that on the vista platform.

      "Matthew Carter" wrote:

      > It says this in the ZwReadFile documentation:
      > If the preceding call to ZwCreateFile set the FILE_NO_INTERMEDIATE_BUFFERING
      > flag in the CreateOptions parameter to ZwCreateFile, the Length and
      > ByteOffset parameters to ZwReadFile must be multiples of the sector size.
      > For more information, see ZwCreateFile.
      > Perhaps the sector size is the issue. I have no idea why the sector size
      > would change in Vista, but trying a sector size that is a multiple of 2048
      > should rule this out as the source of the problem. Data sectors on CDs hold
      > 2048 bytes of data.

      horst | Tues, 20 May 2008 07:41:00 GMT |