📄 fatdata.c
字号:
// Extract the data and fill in the non zero fields of the output
// buffer
//
Buffer->LastWriteTime = Fcb->LastWriteTime;
Buffer->CreationTime = Fcb->CreationTime;
Buffer->LastAccessTime = Fcb->LastAccessTime;
//
// Zero out the field we don't support.
//
Buffer->ChangeTime.QuadPart = 0;
Buffer->FileAttributes = Fcb->DirentFatFlags;
} else {
Buffer->LastWriteTime.QuadPart = 0;
Buffer->CreationTime.QuadPart = 0;
Buffer->LastAccessTime.QuadPart = 0;
Buffer->ChangeTime.QuadPart = 0;
Buffer->FileAttributes = FILE_ATTRIBUTE_DIRECTORY;
}
//
// If the temporary flag is set, then set it in the buffer.
//
if (FlagOn( Fcb->FcbState, FCB_STATE_TEMPORARY )) {
SetFlag( Buffer->FileAttributes, FILE_ATTRIBUTE_TEMPORARY );
}
//
// If no attributes were set, set the normal bit.
//
if (Buffer->FileAttributes == 0) {
Buffer->FileAttributes = FILE_ATTRIBUTE_NORMAL;
}
IoStatus->Status = STATUS_SUCCESS;
IoStatus->Information = sizeof(FILE_BASIC_INFORMATION);
Results = TRUE;
try_exit: NOTHING;
} finally {
if (FcbAcquired) { ExReleaseResourceLite( Fcb->Header.Resource ); }
FsRtlExitFileSystem();
}
//
// And return to our caller
//
return Results;
}
BOOLEAN
FatFastQueryStdInfo (
IN PFILE_OBJECT FileObject,
IN BOOLEAN Wait,
IN OUT PFILE_STANDARD_INFORMATION Buffer,
OUT PIO_STATUS_BLOCK IoStatus,
IN PDEVICE_OBJECT DeviceObject
)
/*++
Routine Description:
This routine is for the fast query call for standard file information.
Arguments:
FileObject - Supplies the file object used in this operation
Wait - Indicates if we are allowed to wait for the information
Buffer - Supplies the output buffer to receive the basic information
IoStatus - Receives the final status of the operation
Return Value:
BOOLEAN - TRUE if the operation succeeded and FALSE if the caller
needs to take the long route.
--*/
{
BOOLEAN Results = FALSE;
IRP_CONTEXT IrpContext;
TYPE_OF_OPEN TypeOfOpen;
PVCB Vcb;
PFCB Fcb;
PCCB Ccb;
BOOLEAN FcbAcquired = FALSE;
//
// Prepare the dummy irp context
//
RtlZeroMemory( &IrpContext, sizeof(IRP_CONTEXT) );
IrpContext.NodeTypeCode = FAT_NTC_IRP_CONTEXT;
IrpContext.NodeByteSize = sizeof(IRP_CONTEXT);
if (Wait) {
SetFlag(IrpContext.Flags, IRP_CONTEXT_FLAG_WAIT);
} else {
ClearFlag(IrpContext.Flags, IRP_CONTEXT_FLAG_WAIT);
}
//
// Determine the type of open for the input file object and only accept
// the user file or directory open
//
TypeOfOpen = FatDecodeFileObject( FileObject, &Vcb, &Fcb, &Ccb );
if ((TypeOfOpen != UserFileOpen) && (TypeOfOpen != UserDirectoryOpen)) {
return Results;
}
//
// Get access to the Fcb but only if it is not the paging file
//
FsRtlEnterFileSystem();
if (!FlagOn( Fcb->FcbState, FCB_STATE_PAGING_FILE )) {
if (!ExAcquireResourceSharedLite( Fcb->Header.Resource, Wait )) {
FsRtlExitFileSystem();
return Results;
}
FcbAcquired = TRUE;
}
try {
//
// If the Fcb is not in a good state, return FALSE.
//
if (Fcb->FcbCondition != FcbGood) {
try_return( Results );
}
Buffer->NumberOfLinks = 1;
Buffer->DeletePending = BooleanFlagOn( Fcb->FcbState, FCB_STATE_DELETE_ON_CLOSE );
//
// Case on whether this is a file or a directory, and extract
// the information and fill in the fcb/dcb specific parts
// of the output buffer.
//
if (NodeType(Fcb) == FAT_NTC_FCB) {
//
// If we don't alread know the allocation size, we cannot look
// it up in the fast path.
//
if (Fcb->Header.AllocationSize.QuadPart == FCB_LOOKUP_ALLOCATIONSIZE_HINT) {
try_return( Results );
}
Buffer->AllocationSize = Fcb->Header.AllocationSize;
Buffer->EndOfFile = Fcb->Header.FileSize;
Buffer->Directory = FALSE;
} else {
Buffer->AllocationSize = FatLargeZero;
Buffer->EndOfFile = FatLargeZero;
Buffer->Directory = TRUE;
}
IoStatus->Status = STATUS_SUCCESS;
IoStatus->Information = sizeof(FILE_STANDARD_INFORMATION);
Results = TRUE;
try_exit: NOTHING;
} finally {
if (FcbAcquired) { ExReleaseResourceLite( Fcb->Header.Resource ); }
FsRtlExitFileSystem();
}
//
// And return to our caller
//
return Results;
}
BOOLEAN
FatFastQueryNetworkOpenInfo (
IN PFILE_OBJECT FileObject,
IN BOOLEAN Wait,
IN OUT PFILE_NETWORK_OPEN_INFORMATION Buffer,
OUT PIO_STATUS_BLOCK IoStatus,
IN PDEVICE_OBJECT DeviceObject
)
/*++
Routine Description:
This routine is for the fast query call for network open information.
Arguments:
FileObject - Supplies the file object used in this operation
Wait - Indicates if we are allowed to wait for the information
Buffer - Supplies the output buffer to receive the information
IoStatus - Receives the final status of the operation
Return Value:
BOOLEAN - TRUE if the operation succeeded and FALSE if the caller
needs to take the long route.
--*/
{
BOOLEAN Results = FALSE;
IRP_CONTEXT IrpContext;
TYPE_OF_OPEN TypeOfOpen;
PVCB Vcb;
PFCB Fcb;
PCCB Ccb;
BOOLEAN FcbAcquired = FALSE;
//
// Prepare the dummy irp context
//
RtlZeroMemory( &IrpContext, sizeof(IRP_CONTEXT) );
IrpContext.NodeTypeCode = FAT_NTC_IRP_CONTEXT;
IrpContext.NodeByteSize = sizeof(IRP_CONTEXT);
if (Wait) {
SetFlag(IrpContext.Flags, IRP_CONTEXT_FLAG_WAIT);
} else {
ClearFlag(IrpContext.Flags, IRP_CONTEXT_FLAG_WAIT);
}
//
// Determine the type of open for the input file object and only accept
// the user file or directory open
//
TypeOfOpen = FatDecodeFileObject( FileObject, &Vcb, &Fcb, &Ccb );
if ((TypeOfOpen != UserFileOpen) && (TypeOfOpen != UserDirectoryOpen)) {
return Results;
}
FsRtlEnterFileSystem();
//
// Get access to the Fcb but only if it is not the paging file
//
if (!FlagOn( Fcb->FcbState, FCB_STATE_PAGING_FILE )) {
if (!ExAcquireResourceSharedLite( Fcb->Header.Resource, Wait )) {
FsRtlExitFileSystem();
return Results;
}
FcbAcquired = TRUE;
}
try {
//
// If the Fcb is not in a good state, return FALSE.
//
if (Fcb->FcbCondition != FcbGood) {
try_return( Results );
}
//
// Extract the data and fill in the non zero fields of the output
// buffer
//
//
// Default the field we don't support to a reasonable value.
//
ExLocalTimeToSystemTime( &FatJanOne1980,
&Buffer->ChangeTime );
if (Fcb->Header.NodeTypeCode == FAT_NTC_ROOT_DCB) {
//
// Reuse the default for the root dir.
//
Buffer->CreationTime =
Buffer->LastAccessTime =
Buffer->LastWriteTime = Buffer->ChangeTime;
} else {
Buffer->LastWriteTime = Fcb->LastWriteTime;
Buffer->CreationTime = Fcb->CreationTime;
Buffer->LastAccessTime = Fcb->LastAccessTime;
}
Buffer->FileAttributes = Fcb->DirentFatFlags;
//
// If the temporary flag is set, then set it in the buffer.
//
if (FlagOn( Fcb->FcbState, FCB_STATE_TEMPORARY )) {
SetFlag( Buffer->FileAttributes, FILE_ATTRIBUTE_TEMPORARY );
}
//
// If no attributes were set, set the normal bit.
//
if (Buffer->FileAttributes == 0) {
Buffer->FileAttributes = FILE_ATTRIBUTE_NORMAL;
}
if (NodeType(Fcb) == FAT_NTC_FCB) {
//
// If we don't already know the allocation size, we cannot
// lock it up in the fast path.
//
if (Fcb->Header.AllocationSize.QuadPart == FCB_LOOKUP_ALLOCATIONSIZE_HINT) {
try_return( Results );
}
Buffer->AllocationSize = Fcb->Header.AllocationSize;
Buffer->EndOfFile = Fcb->Header.FileSize;
} else {
Buffer->AllocationSize = FatLargeZero;
Buffer->EndOfFile = FatLargeZero;
}
IoStatus->Status = STATUS_SUCCESS;
IoStatus->Information = sizeof(FILE_NETWORK_OPEN_INFORMATION);
Results = TRUE;
try_exit: NOTHING;
} finally {
if (FcbAcquired) { ExReleaseResourceLite( Fcb->Header.Resource ); }
FsRtlExitFileSystem();
}
//
// And return to our caller
//
return Results;
}
VOID
FatPopUpFileCorrupt (
IN PIRP_CONTEXT IrpContext,
IN PFCB Fcb
)
/*++
Routine Description:
The Following routine makes an informational popup that the file
is corrupt.
Arguments:
Fcb - The file that is corrupt.
Return Value:
None.
--*/
{
PKTHREAD Thread;
//
// Disable the popup on the root directory. It is important not
// to generate them on objects which are part of the mount process.
//
if (NodeType(Fcb) == FAT_NTC_ROOT_DCB) {
return;
}
//
// Got to grab the full filename now.
//
if (Fcb->FullFileName.Buffer == NULL) {
FatSetFullFileNameInFcb( IrpContext, Fcb );
}
//
// We never want to block a system thread waiting for the user to
// press OK.
//
if (IoIsSystemThread(IrpContext->OriginatingIrp->Tail.Overlay.Thread)) {
Thread = NULL;
} else {
Thread = IrpContext->OriginatingIrp->Tail.Overlay.Thread;
}
IoRaiseInformationalHardError( STATUS_FILE_CORRUPT_ERROR,
&Fcb->FullFileName,
Thread);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -