test: udfinit.c Source File

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# udfinit.c

Go to the documentation of this file.

    00001 /*++
    00002
    00003 Copyright (c) 1996  Microsoft Corporation
    00004
    00005 Module Name:
    00006
    00007     UdfInit.c
    00008
    00009 Abstract:
    00010
    00011     This module implements the DRIVER_INITIALIZATION routine for Udfs
    00012
    00013 Author:
    00014
    00015     Dan Lovinger    [DanLo]   24-May-1996
    00016
    00017 Revision History:
    00018
    00019 --*/
    00020
    00021 #include "UdfProcs.h"
    00022
    00023 //
    00024 //  The Bug check file id for this module
    00025 //
    00026
    00027 #define BugCheckFileId                   (UDFS_BUG_CHECK_UDFINIT)
    00028
    00029 //
    00030 //  The local debug trace level
    00031 //
    00032
    00033 #define Dbg                              (UDFS_DEBUG_LEVEL_UDFINIT)
    00034
    00035 NTSTATUS
    00036 DriverEntry(
    00037     IN PDRIVER_OBJECT DriverObject,
    00038     IN PUNICODE_STRING RegistryPath
    00039     );
    00040
    00041 VOID
    00042 UdfInitializeGlobalData (
    00043     IN PDRIVER_OBJECT DriverObject,
    00044     IN PDEVICE_OBJECT *FileSystemDeviceObjects
    00045     );
    00046
    00047 #ifdef ALLOC_PRAGMA
    00048 #pragma alloc_text(INIT, DriverEntry)
    00049 #pragma alloc_text(INIT, UdfInitializeGlobalData)
    00050 #endif
    00051
    00052
    00053 //
    00054 //  Local support routine
    00055 //
    00056
    00057 NTSTATUS
    00058 DriverEntry(
    00059     IN PDRIVER_OBJECT DriverObject,
    00060     IN PUNICODE_STRING RegistryPath
    00061     )
    00062
    00063 /*++
    00064
    00065 Routine Description:
    00066
    00067     This is the initialization routine for the UDF file system
    00068     device driver.  This routine creates the device object for the FileSystem
    00069     device and performs all other driver initialization.
    00070
    00071 Arguments:
    00072
    00073     DriverObject - Pointer to driver object created by the system.
    00074
    00075 Return Value:
    00076
    00077     NTSTATUS - The function value is the final status from the initialization
    00078         operation.
    00079
    00080 --*/
    00081
    00082 {
    00083     NTSTATUS Status;
    00084     UNICODE_STRING UnicodeString;
    00085     PDEVICE_OBJECT UdfsFileSystemDeviceObjects[NUMBER_OF_FS_OBJECTS];
    00086     PDEVICE_OBJECT UdfsDiskFileSystemDeviceObject;
    00087
    00088     //
    00089     //  Create the device objects for both device "types".  Since
    00090     //  UDF is a legitimate filesystem for media underlying device
    00091     //  drivers claiming both DVD/CDROMs and disks, we must register
    00092     //  this filesystem twice.
    00093     //
    00094
    00095     ASSERT( NUMBER_OF_FS_OBJECTS >= 2 );
    00096     RtlZeroMemory( &UdfsFileSystemDeviceObjects, sizeof(PDEVICE_OBJECT) * NUMBER_OF_FS_OBJECTS );
    00097
    00098     RtlInitUnicodeString( &UnicodeString, L"\\UdfsCdRom" );
    00099
    00100     Status = IoCreateDevice( DriverObject,
    00101                              0,
    00102                              &UnicodeString,
    00103                              FILE_DEVICE_CD_ROM_FILE_SYSTEM,
    00104                              0,
    00105                              FALSE,
    00106                              &UdfsFileSystemDeviceObjects[0] );
    00107
    00108     if (!NT_SUCCESS( Status )) {
    00109         return Status;
    00110     }
    00111
    00112     RtlInitUnicodeString( &UnicodeString, L"\\UdfsDisk" );
    00113
    00114     Status = IoCreateDevice( DriverObject,
    00115                              0,
    00116                              &UnicodeString,
    00117                              FILE_DEVICE_DISK_FILE_SYSTEM,
    00118                              0,
    00119                              FALSE,
    00120                              &UdfsFileSystemDeviceObjects[1] );
    00121
    00122     if (!NT_SUCCESS( Status )) {
    00123
    00124         ObDereferenceObject( UdfsFileSystemDeviceObjects[0] );
    00125         return Status;
    00126     }
    00127
    00128     //
    00129     //  Note that because of the way data caching is done, we set neither
    00130     //  the Direct I/O or Buffered I/O bit in DeviceObject->Flags.  If
    00131     //  data is not in the cache, or the request is not buffered, we may,
    00132     //  set up for Direct I/O by hand.
    00133     //
    00134
    00135     //
    00136     //  Initialize the driver object with this driver's entry points.
    00137     //
    00138     //  NOTE - Each entry in the dispatch table must have an entry in
    00139     //  the Fsp/Fsd dispatch switch statements.
    00140     //
    00141
    00142     DriverObject->MajorFunction[IRP_MJ_CREATE]                  =
    00143     DriverObject->MajorFunction[IRP_MJ_CLOSE]                   =
    00144     DriverObject->MajorFunction[IRP_MJ_READ]                    =
    00145     DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION]       =
    00146     DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION]         =
    00147     DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION]=
    00148     DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL]       =
    00149     DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL]     =
    00150     DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL]          =
    00151     DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL]            =
    00152     DriverObject->MajorFunction[IRP_MJ_CLEANUP]                 =
    00153     DriverObject->MajorFunction[IRP_MJ_PNP]                     = (PDRIVER_DISPATCH) UdfFsdDispatch;
    00154
    00155     DriverObject->FastIoDispatch = &UdfFastIoDispatch;
    00156
    00157     //
    00158     //  Initialize the global data structures
    00159     //
    00160
    00161     UdfInitializeGlobalData( DriverObject, UdfsFileSystemDeviceObjects );
    00162
    00163     //
    00164     //  Register the file system with the I/O system
    00165     //
    00166
    00167     IoRegisterFileSystem( UdfsFileSystemDeviceObjects[0] );
    00168     IoRegisterFileSystem( UdfsFileSystemDeviceObjects[1] );
    00169
    00170     //
    00171     //  And return to our caller
    00172     //
    00173
    00174     return( STATUS_SUCCESS );
    00175 }
    00176
    00177
    00178 //
    00179 //  Local support routine
    00180 //
    00181
    00182 VOID
    00183 UdfInitializeGlobalData (
    00184     IN PDRIVER_OBJECT DriverObject,
    00185     IN PDEVICE_OBJECT *UdfsFileSystemDeviceObjects
    00186     )
    00187
    00188 /*++
    00189
    00190 Routine Description:
    00191
    00192     This routine initializes the global Udfs data structures.
    00193
    00194 Arguments:
    00195
    00196     DriverObject - Supplies the driver object for UDFS.
    00197
    00198     FileSystemDeviceObjects - Supplies a vector of device objects for UDFS.
    00199
    00200 Return Value:
    00201
    00202     None.
    00203
    00204 --*/
    00205
    00206 {
    00207     USHORT CcbMaxDepth;
    00208     USHORT FcbDataMaxDepth;
    00209     USHORT FcbIndexMaxDepth;
    00210     USHORT FcbNonPagedMaxDepth;
    00211     USHORT IrpContextMaxDepth;
    00212     USHORT LcbMaxDepth;
    00213
    00214     //
    00215     //  Start by initializing the FastIoDispatch Table.
    00216     //
    00217
    00218     RtlZeroMemory( &UdfFastIoDispatch, sizeof( FAST_IO_DISPATCH ));
    00219
    00220     UdfFastIoDispatch.SizeOfFastIoDispatch =    sizeof(FAST_IO_DISPATCH);
    00221
    00222     UdfFastIoDispatch.AcquireFileForNtCreateSection =   UdfAcquireForCreateSection;
    00223     UdfFastIoDispatch.ReleaseFileForNtCreateSection =   UdfReleaseForCreateSection;
    00224     UdfFastIoDispatch.FastIoCheckIfPossible =           UdfFastIoCheckIfPossible;   //  CheckForFastIo
    00225     UdfFastIoDispatch.FastIoRead =                      FsRtlCopyRead;              //  Read
    00226
    00227     UdfFastIoDispatch.FastIoQueryBasicInfo =            NULL;                       //  QueryBasicInfo
    00228     UdfFastIoDispatch.FastIoQueryStandardInfo =         NULL;                       //  QueryStandardInfo
    00229     UdfFastIoDispatch.FastIoLock =                      NULL;                       //  Lock
    00230     UdfFastIoDispatch.FastIoUnlockSingle =              NULL;                       //  UnlockSingle
    00231     UdfFastIoDispatch.FastIoUnlockAll =                 NULL;                       //  UnlockAll
    00232     UdfFastIoDispatch.FastIoUnlockAllByKey =            NULL;                       //  UnlockAllByKey
    00233     UdfFastIoDispatch.FastIoQueryNetworkOpenInfo =      NULL;                       //  QueryNetworkInfo
    00234
    00235     //
    00236     //  Initialize the CRC table. Per UDF 1.01, we use the seed 10041 octal (4129 dec).
    00237     //
    00238
    00239     UdfInitializeCrc16( 4129 );
    00240
    00241     //
    00242     //  Initialize the UdfData structure.
    00243     //
    00244
    00245     RtlZeroMemory( &UdfData, sizeof( UDF_DATA ));
    00246
    00247     UdfData.NodeTypeCode = UDFS_NTC_DATA_HEADER;
    00248     UdfData.NodeByteSize = sizeof( UDF_DATA );
    00249
    00250     UdfData.DriverObject = DriverObject;
    00251     RtlCopyMemory( &UdfData.FileSystemDeviceObjects,
    00252                    UdfsFileSystemDeviceObjects,
    00253                    sizeof(PDEVICE_OBJECT) * NUMBER_OF_FS_OBJECTS );
    00254
    00255     InitializeListHead( &UdfData.VcbQueue );
    00256
    00257     ExInitializeResource( &UdfData.DataResource );
    00258
    00259     //
    00260     //  Initialize the cache manager callback routines
    00261     //
    00262
    00263     UdfData.CacheManagerCallbacks.AcquireForLazyWrite  = &UdfAcquireForCache;
    00264     UdfData.CacheManagerCallbacks.ReleaseFromLazyWrite = &UdfReleaseFromCache;
    00265     UdfData.CacheManagerCallbacks.AcquireForReadAhead  = &UdfAcquireForCache;
    00266     UdfData.CacheManagerCallbacks.ReleaseFromReadAhead = &UdfReleaseFromCache;
    00267
    00268     UdfData.CacheManagerVolumeCallbacks.AcquireForLazyWrite  = &UdfNoopAcquire;
    00269     UdfData.CacheManagerVolumeCallbacks.ReleaseFromLazyWrite = &UdfNoopRelease;
    00270     UdfData.CacheManagerVolumeCallbacks.AcquireForReadAhead  = &UdfNoopAcquire;
    00271     UdfData.CacheManagerVolumeCallbacks.ReleaseFromReadAhead = &UdfNoopRelease;
    00272
    00273     //
    00274     //  Initialize the lock mutex and the async and delay close queues.
    00275     //
    00276
    00277     ExInitializeFastMutex( &UdfData.UdfDataMutex );
    00278     InitializeListHead( &UdfData.AsyncCloseQueue );
    00279     InitializeListHead( &UdfData.DelayedCloseQueue );
    00280
    00281     ExInitializeWorkItem( &UdfData.CloseItem,
    00282                           (PWORKER_THREAD_ROUTINE) UdfFspClose,
    00283                           NULL );
    00284
    00285     //
    00286     //  Do the initialization based on the system size.
    00287     //
    00288
    00289     switch (MmQuerySystemSize()) {
    00290
    00291     case MmSmallSystem:
    00292
    00293         IrpContextMaxDepth = 4;
    00294         UdfData.MaxDelayedCloseCount = 10;
    00295         UdfData.MinDelayedCloseCount = 2;
    00296         break;
    00297
    00298     case MmLargeSystem:
    00299
    00300         IrpContextMaxDepth = 24;
    00301         UdfData.MaxDelayedCloseCount = 72;
    00302         UdfData.MinDelayedCloseCount = 18;
    00303         break;
    00304
    00305     default:
    00306     case MmMediumSystem:
    00307
    00308         IrpContextMaxDepth = 8;
    00309         UdfData.MaxDelayedCloseCount = 32;
    00310         UdfData.MinDelayedCloseCount = 8;
    00311         break;
    00312
    00313     }
    00314
    00315     //
    00316     //  Size lookasides to match what will commonly be dumped into them when we
    00317     //  run down the delayed close queues.
    00318     //
    00319
    00320     LcbMaxDepth =
    00321     CcbMaxDepth =
    00322     FcbDataMaxDepth =
    00323     FcbNonPagedMaxDepth = (USHORT) (UdfData.MaxDelayedCloseCount - UdfData.MinDelayedCloseCount);
    00324
    00325     //
    00326     //  We should tend to have fewer indices than files.
    00327     //
    00328
    00329     FcbIndexMaxDepth = FcbNonPagedMaxDepth / 2;
    00330
    00331 #define NPagedInit(L,S,T,D) { ExInitializeNPagedLookasideList( (L), NULL, NULL, POOL_RAISE_IF_ALLOCATION_FAILURE, S, T, D); }
    00332 #define PagedInit(L,S,T,D)  { ExInitializePagedLookasideList(  (L), NULL, NULL, POOL_RAISE_IF_ALLOCATION_FAILURE, S, T, D); }
    00333
    00334     NPagedInit( &UdfIrpContextLookasideList, sizeof( IRP_CONTEXT ), TAG_IRP_CONTEXT, IrpContextMaxDepth );
    00335     NPagedInit( &UdfFcbNonPagedLookasideList, sizeof( FCB_NONPAGED ), TAG_FCB_NONPAGED, FcbNonPagedMaxDepth );
    00336
    00337     PagedInit( &UdfCcbLookasideList, sizeof( CCB ), TAG_CCB, CcbMaxDepth );
    00338     PagedInit( &UdfFcbIndexLookasideList, SIZEOF_FCB_INDEX, TAG_FCB_INDEX, FcbIndexMaxDepth );
    00339     PagedInit( &UdfFcbDataLookasideList, SIZEOF_FCB_DATA, TAG_FCB_DATA, FcbDataMaxDepth );
    00340     PagedInit( &UdfLcbLookasideList, SIZEOF_LOOKASIDE_LCB, TAG_LCB, LcbMaxDepth );
    00341 }