cfilesystemwatcher.cpp
来自「PGP8.0源码 请认真阅读您的文件包然后写出其具体功能」· C++ 代码 · 共 191 行
CPP
191 行
/*____________________________________________________________________________
Copyright (C) 2002 PGP Corporation
All rights reserved.
$Id: CFilesystemWatcher.cpp,v 1.6 2002/08/06 20:09:30 dallen Exp $
____________________________________________________________________________*/
#include "pgpClassesConfig.h"
#include "CFilesystemWatcher.h"
_USING_PGP
// Types
struct CFilesystemWatcher::WatchedBufInfo :
public CListableObject<CFilesystemWatcher::WatchedBufInfo>
{
void *buf;
};
// Class CFilesystemWatcher static variables
CFilesystemWatcher *CFilesystemWatcher::mHookInstance;
// Class CFilesystemWatcher member functions
CFilesystemWatcher::CFilesystemWatcher()
{
mHookInstance = this;
Status() = mWBIAllocator.Status();
}
CComboError
CFilesystemWatcher::WatchForBuffer(void *buf)
{
CComboError error;
WatchedBufInfo *pWBI;
error = mWBIAllocator.Allocate(pWBI);
if (error.IsntError())
{
pWBI->buf = buf;
mWBIList.AddHead(pWBI);
}
return error;
}
CComboError
CFilesystemWatcher::StopWatchingForBuffer(void *buf)
{
CComboError error;
PGPBoolean foundBufInfo = FALSE;
WatchedBufInfo *pWBI = mWBIList.Head();
// Find the info structure for this buffer.
while (IsntNull(pWBI))
{
if (pWBI->buf == buf)
{
foundBufInfo = TRUE;
break;
}
else
{
pWBI = mWBIList.Next(pWBI);
}
}
if (!foundBufInfo)
error.pgpErr = kPGPError_BadParams;
// Free the list entry.
mWBIList.Remove(pWBI);
mWBIAllocator.Free(pWBI);
return error;
}
CComboError
CFilesystemWatcher::Startup()
{
CComboError error;
mPreviousHook = IFSMgr_InstallFileSystemApiHook(FilesystemHook);
if (IsNull(mPreviousHook))
error.pgpErr = kPGPError_VolumeOpFailed;
return error;
}
void
CFilesystemWatcher::Shutdown()
{
if (IsntNull(mPreviousHook))
{
IFSMgr_RemoveFileSystemApiHook(FilesystemHook);
mPreviousHook = NULL;
}
}
int
CFilesystemWatcher::FilesystemHookAux(
pIFSFunc pfn,
int func,
int drive,
int resType,
int codePage,
pioreq pir)
{
// fix not being able to open > 2GB files
switch (func)
{
case IFSFN_OPEN:
if (pir->ir_options & R0_NO_CACHE)
pir->ir_attr |= OPEN_FLAGS_EXTENDED_SIZE;
// fix for bug in ID: Q183173
if ((pir->ir_options & OPEN_FLAGS_REOPEN) &&
(pir->ir_pid == -1))
{
switch (pir->ir_flags)
{
case ACCESS_WRITEONLY:
pir->ir_flags = ACCESS_READWRITE;
break;
}
}
break;
// fix access flags on our read/write requests
case IFSFN_READ:
case IFSFN_WRITE:
{
PGPBoolean foundBuffer = FALSE;
void *buf = static_cast<void *>(pir->ir_data);
WatchedBufInfo *pWBI = mWBIList.Head();
while (IsntNull(pWBI))
{
if (pWBI->buf == buf)
{
foundBuffer = TRUE;
break;
}
else
{
pWBI = mWBIList.Next(pWBI);
}
}
if (foundBuffer)
{
// OK, this is one of our virtual volume requests. Restore the
// memory-mapped flag.
PGPUInt32 oldOptions = pir->ir_options;
pir->ir_options |= R0_MM_READ_WRITE;
int ret = (*mPreviousHook)(pfn, func, drive, resType, codePage,
pir);
pir->ir_options = oldOptions;
return ret;
}
break;
}
}
return (*mPreviousHook)(pfn, func, drive, resType, codePage, pir);
}
int
_cdecl
CFilesystemWatcher::FilesystemHook(
pIFSFunc pfn,
int func,
int drive,
int resType,
int codePage,
pioreq pir)
{
return mHookInstance->FilesystemHookAux(pfn, func, drive, resType,
codePage, pir);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?