Everhart,Glenn
From:	Raynor, Brian [raynor@xgate.ColumbiaSC.NCR.COM]
Sent:	Monday, May 04, 1998 5:16 PM
To:	'Samuel DELPLACE'; 'ntdev@atria.com'; 'ntfsd@atria.com'
Subject:	[ntdev] RE: [ntfsd] Drive Size question

Hmm..  Funny you should ask...

The last few days I have been working on almost exactly the same type of
stuff...  Dunno what your issue with using ZwQueryInformationFile() is
though...  

I'm actually using IoQueryVolumeInformation() which is defined in the
NTIFS.H if you have the NT IFS kit (structures and such are documented
on pages 557-561 of the "Windows NT File System Internals: A Developer's
Guide" by Rajeev Nagar).  

I'm using IoQueryVolumeInformation() because I have a few other routines
that need to get information not available from ZwQueryInformationFile()
(at least to my knowledge...).  

Anyways, assuming you have an already open HANDLE to the device, the
following should do the trick:

NTSTATUS    DrvVolGetSize(  IN  HANDLE          hHandle,
                            OUT PLARGE_INTEGER  pliTotalNumberOfBytes,
                            OUT PLARGE_INTEGER
pliTotalNumberOfFreeBytes )
{
    NTSTATUS                    status              = STATUS_SUCCESS;
    PFILE_OBJECT                pFileObj            = NULL;
    ULONG                       ulReturnedLength    = 0;
    FILE_FS_SIZE_INFORMATION    SizeInfo;
    LARGE_INTEGER               liBytesPerAllocationUnit;
	
    status = ObReferenceObjectByHandle( hHandle, 0, NULL, KernelMode,
&pFileObj, NULL );

    if ( STATUS_SUCCESS == status )
    {
        status = IoQueryVolumeInformation(  pFileObj,
                                            FileFsSizeInformation,
                                            sizeof( SizeInfo ),
                                            (PVOID) &SizeInfo,
                                            &ulReturnedLength );
        if ( STATUS_SUCCESS == status )
        {   // Success
            ASSERT( sizeof( SizeInfo ) == ulReturnedLength );

            liBytesPerAllocationUnit.QuadPart 
                = SizeInfo.BytesPerSector 
                * SizeInfo.SectorsPerAllocationUnit;

            if ( ARGUMENT_PRESENT( pliTotalNumberOfBytes ) )
            {
                pliTotalNumberOfBytes->QuadPart
                    = liBytesPerAllocationUnit.QuadPart 
                    * SizeInfo.TotalAllocationUnits.QuadPart;
            }

            if ( ARGUMENT_PRESENT( pliTotalNumberOfFreeBytes ) )
            {
                pliTotalNumberOfFreeBytes->QuadPart 
                    = liBytesPerAllocationUnit.QuadPart 
                    * SizeInfo.AvailableAllocationUnits.QuadPart;
            }
        } 
    }
    else pFileObj = NULL;

    if ( NULL != pFileObj )     ObDereferenceObject( pFileObj );

    return status;
} // DrvVolGetSize()

Most likely you should be able to easily change this function to use
ZwQueryInformationFile() todo the same thing if you would like.  

BTW - This returns the "file system size" of the drive...  ie: the
number of bytes that a file system would see... (ie: different from
partition length if you are looking at a disk drive).  You can also use
the IoQueryVolumeInformation() to get things such as the file system,
serial number, characteristics, device type, etc if you like.  Consult
the book I referenced for more information (it is an INVALUABLE
help!)...

Hope this helps,Brian


>-----Original Message-----
>From:	Samuel DELPLACE [SMTP:S.DELPLACE@archimed.fr]
>Sent:	Monday, May 04, 1998 1:14 PM
>To:	'ntdev@atria.com'; 'ntfsd@atria.com'
>Subject:	[ntfsd] Drive Size question
>
>Hello,
>
>I want to get the size of a drive (\Device\CdRom0).
>I've tried to create a file and use ZwQueryInformationFile.
>But it returns STATUS_INVALID_PARAMETER.
>
>Any idea ?
>
>Samuel,
>
>----------------------------------------------------------------
>                   Samuel DELPLACE
>       Software and Computer Graphics Engineer      
> Archimed - 2 place du concert - 59800 Lille - France
>Tel : (33) 03 20 13 10 60 - FAX : (33) 03 20 13 10 70
>            Url : http://www.archimed.fr
>           E-Mail : S.Delplace@archimed.fr
>----------------------------------------------------------------
>
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>[ To unsubscribe, send email to ntfsd-request@atria.com with body
>UNSUBSCRIBE (the subject is ignored). ]
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[ To unsubscribe, send email to ntdev-request@atria.com with body
UNSUBSCRIBE (the subject is ignored). ]