📄 cddata.c
字号:
/*++
Copyright (c) 1989-2000 Microsoft Corporation
Module Name:
CdData.c
Abstract:
This module declares the global data used by the Cdfs file system.
This module also handles the dispath routines in the Fsd threads as well as
handling the IrpContext and Irp through the exception path.
--*/
#include "CdProcs.h"
#ifdef CD_SANITY
BOOLEAN CdTestTopLevel = TRUE;
BOOLEAN CdTestRaisedStatus = TRUE;
BOOLEAN CdBreakOnAnyRaise = FALSE;
BOOLEAN CdTraceRaises = FALSE;
NTSTATUS CdInterestingExceptionCodes[] = { STATUS_DISK_CORRUPT_ERROR,
STATUS_FILE_CORRUPT_ERROR,
0, 0, 0, 0, 0, 0, 0, 0 };
#endif
//
// The Bug check file id for this module
//
#define BugCheckFileId (CDFS_BUG_CHECK_CDDATA)
//
// Global data structures
//
CD_DATA CdData;
FAST_IO_DISPATCH CdFastIoDispatch;
//
// Reserved directory strings.
//
WCHAR CdUnicodeSelfArray[] = { L'.' };
WCHAR CdUnicodeParentArray[] = { L'.', L'.' };
UNICODE_STRING CdUnicodeDirectoryNames[] = {
{ 2, 2, CdUnicodeSelfArray},
{ 4, 4, CdUnicodeParentArray}
};
//
// Volume descriptor identifier strings.
//
CHAR CdHsgId[] = { 'C', 'D', 'R', 'O', 'M' };
CHAR CdIsoId[] = { 'C', 'D', '0', '0', '1' };
CHAR CdXaId[] = { 'C', 'D', '-', 'X', 'A', '0', '0', '1' };
//
// Volume label for audio disks.
//
WCHAR CdAudioLabel[] = { L'A', L'u', L'd', L'i', L'o', L' ', L'C', L'D' };
USHORT CdAudioLabelLength = sizeof( CdAudioLabel );
//
// Pseudo file names for audio disks.
//
CHAR CdAudioFileName[] = { 'T', 'r', 'a', 'c', 'k', '0', '0', '.', 'c', 'd', 'a' };
UCHAR CdAudioFileNameLength = sizeof( CdAudioFileName );
ULONG CdAudioDirentSize = FIELD_OFFSET( RAW_DIRENT, FileId ) + sizeof( CdAudioFileName ) + sizeof( SYSTEM_USE_XA );
ULONG CdAudioDirentsPerSector = SECTOR_SIZE / (FIELD_OFFSET( RAW_DIRENT, FileId ) + sizeof( CdAudioFileName ) + sizeof( SYSTEM_USE_XA ));
ULONG CdAudioSystemUseOffset = FIELD_OFFSET( RAW_DIRENT, FileId ) + sizeof( CdAudioFileName );
//
// Escape sequences for mounting Unicode volumes.
//
PCHAR CdJolietEscape[] = { "%/@", "%/C", "%/E" };
//
// Audio Play Files consist completely of this header block. These
// files are readable in the root of any audio disc regardless of
// the capabilities of the drive.
//
// The "Unique Disk ID Number" is a calculated value consisting of
// a combination of parameters, including the number of tracks and
// the starting locations of those tracks.
//
// Applications interpreting CDDA RIFF files should be advised that
// additional RIFF file chunks may be added to this header in the
// future in order to add information, such as the disk and song title.
//
LONG CdAudioPlayHeader[] = {
0x46464952, // Chunk ID = 'RIFF'
4 * 11 - 8, // Chunk Size = (file size - 8)
0x41444443, // 'CDDA'
0x20746d66, // 'fmt '
24, // Chunk Size (of 'fmt ' subchunk) = 24
0x00000001, // WORD Format Tag, WORD Track Number
0x00000000, // DWORD Unique Disk ID Number
0x00000000, // DWORD Track Starting Sector (LBN)
0x00000000, // DWORD Track Length (LBN count)
0x00000000, // DWORD Track Starting Sector (MSF)
0x00000000 // DWORD Track Length (MSF)
};
// Audio Philes begin with this header block to identify the data as a
// PCM waveform. AudioPhileHeader is coded as if it has no data included
// in the waveform. Data must be added in 2352-byte multiples.
//
// Fields marked 'ADJUST' need to be adjusted based on the size of the
// data: Add (nSectors*2352) to the DWORDs at offsets 1*4 and 10*4.
//
// File Size of TRACK??.WAV = nSectors*2352 + sizeof(AudioPhileHeader)
// RIFF('WAVE' fmt(1, 2, 44100, 176400, 16, 4) data( <CD Audio Raw Data> )
//
// The number of sectors in a CD-XA CD-DA file is (DataLen/2048).
// CDFS will expose these files to applications as if they were just
// 'WAVE' files, adjusting the file size so that the RIFF file is valid.
//
// NT NOTE: We do not do any fidelity adjustment. These are presented as raw
// 2352 byte sectors - 95 has the glimmer of an idea to allow CDFS to expose
// the CDXA CDDA data at different sampling rates in a virtual directory
// structure, but we will never do that.
//
LONG CdXAAudioPhileHeader[] = {
0x46464952, // Chunk ID = 'RIFF'
-8, // Chunk Size = (file size - 8) ADJUST1
0x45564157, // 'WAVE'
0x20746d66, // 'fmt '
16, // Chunk Size (of 'fmt ' subchunk) = 16
0x00020001, // WORD Format Tag WORD nChannels
44100, // DWORD nSamplesPerSecond
2352 * 75, // DWORD nAvgBytesPerSec
0x00100004, // WORD nBlockAlign WORD nBitsPerSample
0x61746164, // 'data'
-44 // <CD Audio Raw Data> ADJUST2
};
//
// XA Files begin with this RIFF header block to identify the data as
// raw CD-XA sectors. Data must be added in 2352-byte multiples.
//
// This header is added to all CD-XA files which are marked as having
// mode2form2 sectors.
//
// Fields marked 'ADJUST' need to be adjusted based on the size of the
// data: Add file size to the marked DWORDS.
//
// File Size of TRACK??.WAV = nSectors*2352 + sizeof(XAFileHeader)
//
// RIFF('CDXA' FMT(Owner, Attr, 'X', 'A', FileNum, 0) data ( <CDXA Raw Data> )
//
LONG CdXAFileHeader[] = {
0x46464952, // Chunk ID = 'RIFF'
-8, // Chunk Size = (file size - 8) ADJUST
0x41584443, // 'CDXA'
0x20746d66, // 'fmt '
16, // Chunk Size (of CDXA chunk) = 16
0, // DWORD Owner ID
0x41580000, // WORD Attributes
// BYTE Signature byte 1 'X'
// BYTE Signature byte 2 'A'
0, // BYTE File Number
0, // BYTE Reserved[7]
0x61746164, // 'data'
-44 // <CD-XA Raw Sectors> ADJUST
};
#ifdef ALLOC_PRAGMA
#pragma alloc_text(PAGE, CdFastIoCheckIfPossible)
#pragma alloc_text(PAGE, CdSerial32)
#endif
NTSTATUS
CdFsdDispatch (
IN PVOLUME_DEVICE_OBJECT VolumeDeviceObject,
IN PIRP Irp
)
/*++
Routine Description:
This is the driver entry to all of the Fsd dispatch points.
Conceptually the Io routine will call this routine on all requests
to the file system. We case on the type of request and invoke the
correct handler for this type of request. There is an exception filter
to catch any exceptions in the CDFS code as well as the CDFS process
exception routine.
This routine allocates and initializes the IrpContext for this request as
well as updating the top-level thread context as necessary. We may loop
in this routine if we need to retry the request for any reason. The
status code STATUS_CANT_WAIT is used to indicate this. Suppose the disk
in the drive has changed. An Fsd request will proceed normally until it
recognizes this condition. STATUS_VERIFY_REQUIRED is raised at that point
and the exception code will handle the verify and either return
STATUS_CANT_WAIT or STATUS_PENDING depending on whether the request was
posted.
Arguments:
VolumeDeviceObject - Supplies the volume device object for this request
Irp - Supplies the Irp being processed
Return Value:
NTSTATUS - The FSD status for the IRP
--*/
{
THREAD_CONTEXT ThreadContext;
PIRP_CONTEXT IrpContext = NULL;
BOOLEAN Wait;
#ifdef CD_SANITY
PVOID PreviousTopLevel;
#endif
NTSTATUS Status;
#if DBG
KIRQL SaveIrql = KeGetCurrentIrql();
#endif
ASSERT_OPTIONAL_IRP( Irp );
FsRtlEnterFileSystem();
#ifdef CD_SANITY
PreviousTopLevel = IoGetTopLevelIrp();
#endif
//
// Loop until this request has been completed or posted.
//
do {
//
// Use a try-except to handle the exception cases.
//
try {
//
// If the IrpContext is NULL then this is the first pass through
// this loop.
//
if (IrpContext == NULL) {
//
// Decide if this request is waitable an allocate the IrpContext.
// If the file object in the stack location is NULL then this
// is a mount which is always waitable. Otherwise we look at
// the file object flags.
//
if (IoGetCurrentIrpStackLocation( Irp )->FileObject == NULL) {
Wait = TRUE;
} else {
Wait = CanFsdWait( Irp );
}
IrpContext = CdCreateIrpContext( Irp, Wait );
//
// Update the thread context information.
//
CdSetThreadContext( IrpContext, &ThreadContext );
#ifdef CD_SANITY
ASSERT( !CdTestTopLevel ||
SafeNodeType( IrpContext->TopLevel ) == CDFS_NTC_IRP_CONTEXT );
#endif
//
// Otherwise cleanup the IrpContext for the retry.
//
} else {
//
// Set the MORE_PROCESSING flag to make sure the IrpContext
// isn't inadvertently deleted here. Then cleanup the
// IrpContext to perform the retry.
//
SetFlag( IrpContext->Flags, IRP_CONTEXT_FLAG_MORE_PROCESSING );
CdCleanupIrpContext( IrpContext, FALSE );
}
//
// Case on the major irp code.
//
switch (IrpContext->MajorFunction) {
case IRP_MJ_CREATE :
Status = CdCommonCreate( IrpContext, Irp );
break;
case IRP_MJ_CLOSE :
Status = CdCommonClose( IrpContext, Irp );
break;
case IRP_MJ_READ :
//
// If this is an Mdl complete request, don't go through
// common read.
//
if (FlagOn( IrpContext->MinorFunction, IRP_MN_COMPLETE )) {
Status = CdCompleteMdl( IrpContext, Irp );
} else {
Status = CdCommonRead( IrpContext, Irp );
}
break;
case IRP_MJ_QUERY_INFORMATION :
Status = CdCommonQueryInfo( IrpContext, Irp );
break;
case IRP_MJ_SET_INFORMATION :
Status = CdCommonSetInfo( IrpContext, Irp );
break;
case IRP_MJ_QUERY_VOLUME_INFORMATION :
Status = CdCommonQueryVolInfo( IrpContext, Irp );
break;
case IRP_MJ_DIRECTORY_CONTROL :
Status = CdCommonDirControl( IrpContext, Irp );
break;
case IRP_MJ_FILE_SYSTEM_CONTROL :
Status = CdCommonFsControl( IrpContext, Irp );
break;
case IRP_MJ_DEVICE_CONTROL :
Status = CdCommonDevControl( IrpContext, Irp );
break;
case IRP_MJ_LOCK_CONTROL :
Status = CdCommonLockControl( IrpContext, Irp );
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -