WarFsys.cpp
资源名称:warftpd.zip [点击查看]
上传用户:surprise9
上传日期:2007-01-04
资源大小:426k
文件大小:21k
源码类别:
Ftp客户端
开发平台:
Visual C++
- // This is part of the WAR SOFTWARE SERIES initiated by Jarle Aase
- // Copyright 1996 by Jarle Aase. All rights reserved.
- // See the "War Software Series Licende Agreement" for details concerning
- // use and distribution.
- // ---
- // This source code, executables and programs containing source code or
- // binaries or proprietetary technology from the War Software Series are
- // NOT alloed used, viewed or tested by any governmental agencies in
- // any countries. This includes the government, departments, police,
- // military etc.
- // ---
- // This file is intended for use with Tab space = 2
- // Created and maintained in MSVC Developer Studio
- // ---
- // NAME : WarFsys.cpp
- // PURPOSE : Header file for all file systems used by the War daemons
- // PROGRAM :
- // DATE : March 11 1997
- // AUTHOR : Jarle Aase
- // ---
- //
- // Overview:
- // This dll provides the higher levels in the server with file system calls.
- // The file system support UNIX/VFsys file attributes, VFsys and Win95/NT 4
- // soft-links and true multithread/multiprocess access.
- //
- // Only one file system dll might be running at one time pr. machine. All
- // daemons will share the same file system.
- //
- // Exports are done in the .def file.
- //
- // REVISION HISTORY
- //
- #include "stdafx.h"
- #include "WarSoftware.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- ////////////////////////////////////////////////////////////////////////////////////
- // File system.
- CLinkedList CUserFsys::m_ObjectList;
- HINSTANCE CUserFsys::m_hFsys;
- HWND CUserFsys::m_Fsys_hWnd;
- CUserFsys::CUserFsys(LPVOID *pRef)
- {
- m_IsAdmin = 0;
- m_IsSystem = 0;
- m_CallbackPending = 0;
- m_IsZombie = 0;
- m_User = INVALID_USER_VALUE;
- m_Class = INVALID_USER_VALUE;
- m_hNTsec = NULL;
- m_pRef = pRef;
- m_CWD = "";
- }
- CUserFsys::~CUserFsys()
- {
- CWarFile *pFile;
- while(pFile = (CWarFile *)m_OpenFiles.FirstPtr())
- pFile->Destroy();
- if (m_pRef && (*m_pRef == this))
- *m_pRef = NULL;
- }
- BOOL CUserFsys::StartFileSystem(LPCSTR IniPath)
- {
- CString IniPathBuf;
- if (IniPath == NULL)
- {
- IniPathBuf = GetStartupPath();
- LPSTR p = IniPathBuf.GetBuffer(1);
- p = strrchr(p, '\');
- if (*p)
- *p = 0;
- IniPathBuf.ReleaseBuffer();
- IniPathBuf += "\Fsys\Fsys.ini";
- IniPath = IniPathBuf;
- }
- // Load the file system dll
- CString FsysName;
- GetPrivateProfileString("fsys", "driver", "VfSys.dll", FsysName.GetBuffer(MAX_PATH), MAX_PATH, IniPath);
- FsysName.ReleaseBuffer();
- CLog::GetLog()->LogMsg(LOGF_SYSTEM,"CUserFsys::StartFileSystem() - Starting file system '%s'", FsysName);
- m_hFsys = LoadLibrary(FsysName);
- if (m_hFsys == NULL)
- {
- CLog::GetLog()->LogMsg(LOGF_ERROR,"CUserFsys::StartFileSystem() - Failed to load file system '%s'. %s",
- FsysName, GetLastErrorText());
- return FALSE;
- }
- BOOL (*OpenFsys)(HWND *phWnd, LPCSTR IniFilePath);
- if ((OpenFsys = (BOOL (*)(HWND *, LPCSTR))GetProcAddress(m_hFsys, "?OpenFsys@@YAHPAPAUHWND__@@PBD@Z")) == NULL)
- {
- FreeLibrary(m_hFsys);
- m_hFsys = NULL;
- CLog::GetLog()->LogMsg(LOGF_ERROR,"CUserFsys::StartFileSystem() - Failed to resolve OpenFsys() in dll '%s'. %s",
- FsysName, GetLastErrorText());
- return FALSE;
- }
- if (!OpenFsys(&m_Fsys_hWnd, IniPath))
- {
- CLog::GetLog()->LogMsg(LOGF_ERROR,"CUserFsys::StartFileSystem() - OpenFsys() in dll '%s' failed. %s",
- FsysName, GetLastErrorText());
- FreeLibrary(m_hFsys);
- m_hFsys = NULL;
- }
- return TRUE;
- }
- void CUserFsys::CloseFileSystem()
- {
- if (m_hFsys)
- {
- SendMessage(m_Fsys_hWnd,FSM_QUIT,0,0);
- FreeLibrary((HMODULE)m_hFsys);
- m_hFsys = NULL;
- }
- }
- void CUserFsys::LogMsg(int flag, LPCSTR Format, ...)
- {
- if (!ShouldLog(CLog::GetLog(), flag))
- return;
- {
- CString cBuf;
- ASSERT(AfxIsValidString(Format, FALSE));
- cBuf.Format("%s: %s", "CUserFsys", Format);
- va_list argList;
- va_start(argList, Format);
- CLog::GetLog()->LogMsgV(flag, cBuf, argList);
- va_end(argList);
- }
- }
- BOOL CUserFsys::ProcessRequest(int Type, WPARAM wParam, LPARAM lParam)
- {
- if (m_CallbackPending)
- {
- LogMsg(LOGF_ERROR,"ProcessRequest() - There is alredy a request pending. Call aborted.");
- return FALSE;
- }
- if (!IsWindow(m_Fsys_hWnd))
- {
- LogMsg(LOGF_ERROR,"ProcessRequest() - Fsys_hWnd is invalid. Call aborted.");
- return FALSE;
- }
- if (!SetOnHold())
- {
- LogMsg(LOGF_WARNINGS,"ProcessRequest() - SetOnHold() returned FALSE. Call aborted.");
- return FALSE;
- }
- m_Output.Empty();
- if (!SendMessage(m_Fsys_hWnd, Type, wParam, lParam))
- {
- CheckForZombie();
- ReleaseHold();
- return FALSE;
- }
- m_CallbackPending = TRUE;
- m_LastReqType = Type;
- return TRUE;
- }
- void CUserFsys::CheckForZombie()
- {
- if (m_IsZombie)
- throw this;
- }
- BOOL CUserFsys::SetOnHold()
- {
- ASSERT(FALSE); // Must be overridden
- return FALSE;
- }
- void CUserFsys::ReleaseHold()
- {
- ASSERT(FALSE); // Must be overridden
- }
- // Entry point for results
- void CUserFsys::OnCallback(LPARAM lParam)
- {
- ASSERT(m_CallbackPending);
- m_CallbackPending = 0;
- if (m_IsZombie)
- {
- delete this;
- return;
- }
- ReleaseHold();
- if (m_FsysErrno)
- {
- int lastError = ERROR_GEN_FAILURE;
- switch(m_FsysErrno)
- {
- case FSE_PERMISSION_DENIED: lastError = ERROR_ACCESS_DENIED; break;
- case FSE_UNKNOWN_CALL: lastError = ERROR_INVALID_FUNCTION; break;
- case FSE_NO_ROOTPATH: lastError = ERROR_INVALID_DRIVE; break;
- case FSE_BAD_ROOTPATH: lastError = ERROR_INVALID_DRIVE; break;
- case FSE_BAD_PATH: lastError = ERROR_INVALID_DATA; break;
- case FSE_PATH_NOT_FOUND: lastError = ERROR_ACCESS_DENIED; break;
- }
- SetLastError(lastError);
- }
- switch(m_LastReqType)
- {
- case FSM_CREATEUSER:
- OnCreate(m_FsysErrno);
- break;
- case FSM_CREATEFILE:
- OnCreateFile(m_FsysErrno);
- break;
- case FSM_CHDIR:
- OnChdir(m_FsysErrno);
- break;
- case FSM_PRPCMDLINE:
- OnPrpCmdLine(m_FsysErrno);
- break;
- case FSM_LIST:
- OnList(m_FsysErrno);
- break;
- case FSM_WLST:
- OnWlist(m_FsysErrno);
- break;
- case FSM_CHMOD:
- OnChmod(m_FsysErrno);
- break;
- case FSM_FSYSSTAT:
- OnFsysStat(m_FsysErrno);
- break;
- case FSM_CREATEDIR:
- OnCreateDirectory(m_FsysErrno);
- break;
- case FSM_DELEDIR:
- OnDeleteDirectory(m_FsysErrno);
- break;
- case FSM_DELEFILE:
- OnDeleteFile(m_FsysErrno);
- break;
- case FSM_DELE:
- OnDeleteGeneric(m_FsysErrno);
- break;
- case FSM_LINK:
- OnLinkFile(m_FsysErrno);
- break;
- case FSM_MOVE:
- OnMoveFile(m_FsysErrno);
- break;
- case FSM_STAT:
- OnStat(m_FsysErrno);
- break;
- }
- }
- // Try to log a user on to the file system
- // Roots in the format <VfSysPath>,<UserPath>
- BOOL CUserFsys::Create(
- LPCSTR Roots,
- LPCSTR Home,
- USER User,
- USER Class,
- LPCSTR Name,
- DWORD Umask,
- USER AssignTo)
- {
- m_Name = Name ? Name : "uninitialized-name";
- m_User = User;
- m_Class = Class;
- m_Home = Home;
- m_FsysPath1 = Roots;
- m_AssignTo = AssignTo;
- m_Umask = Umask;
- return ProcessRequest(FSM_CREATEUSER, (WPARAM)this, 0);
- }
- // Log a user out from the file system. Called by the user.
- void CUserFsys::Logout()
- {
- if (m_CallbackPending)
- {
- m_IsZombie = TRUE;
- return;
- }
- delete this;
- }
- BOOL CUserFsys::OnCreate(int nErrorCode)
- {
- return TRUE;
- }
- BOOL CUserFsys::OnChdir(int nErrorCode)
- {
- return TRUE;
- }
- BOOL CUserFsys::OnPrpCmdLine(int nErrorCode)
- {
- return TRUE;
- }
- BOOL CUserFsys::OnList(int nErrorCode)
- {
- return TRUE;
- }
- BOOL CUserFsys::OnWlist(int nErrorCode)
- {
- return TRUE;
- }
- BOOL CUserFsys::OnChmod(int nErrorCode)
- {
- return TRUE;
- }
- BOOL CUserFsys::OnCreateFile(int nErrorCode)
- {
- if (m_CreateHdr.pFile->m_IsZombie || nErrorCode)
- {
- m_CreateHdr.pFile->m_ProtectFromDelete++; // Prevent callback to destroy object
- try
- {
- if (!m_CreateHdr.pFile->m_IsZombie)
- m_CreateHdr.Callback(m_CreateHdr.pFile ,FALSE , m_CreateHdr.lParam);
- }
- catch(...)
- {
- CLog::GetLog()->LogMsg(LOGF_WARNINGS,"CUserFsys::OnCreateFile(%d) - Caught unknown exception.", nErrorCode);
- return FALSE;
- }
- m_CreateHdr.pFile->m_ProtectFromDelete--;
- m_CreateHdr.pFile->Destroy();
- return FALSE;
- }
- m_CreateHdr.Callback(m_CreateHdr.pFile ,TRUE , m_CreateHdr.lParam);
- return TRUE;
- }
- BOOL CUserFsys::OnFsysStat(int nErrorCode)
- {
- return TRUE;
- }
- BOOL CUserFsys::OnCreateDirectory(int nErrorCode)
- {
- return TRUE;
- }
- BOOL CUserFsys::OnDeleteDirectory(int nErrorCode)
- {
- return TRUE;
- }
- BOOL CUserFsys::OnDeleteFile(int nErrorCode)
- {
- return TRUE;
- }
- BOOL CUserFsys::OnDeleteGeneric(int nErrorCode)
- {
- return TRUE;
- }
- BOOL CUserFsys::OnLinkFile(int nErrorCode)
- {
- return TRUE;
- }
- BOOL CUserFsys::OnMoveFile(int nErrorCode)
- {
- return TRUE;
- }
- BOOL CUserFsys::OnStat(int nErrorCode)
- {
- return TRUE;
- }
- BOOL CUserFsys::BldFileInfoList(CFileInfoList& FileList, LPCSTR Path, BOOL ListDir)
- {
- return FALSE;
- }
- BOOL CUserFsys::ChDir(LPCSTR Path)
- {
- m_FsysPath1 = Path;
- return ProcessRequest(FSM_CHDIR, (WPARAM)this, 0);
- }
- BOOL CUserFsys::ChMod(CCmdArgs& Args)
- {
- m_Args = Args;
- return ProcessRequest(FSM_CHMOD, (WPARAM)this, 0);
- }
- BOOL CUserFsys::CreateFile(LPCSTR Path, CREATE_HDR *pHdr)
- {
- if (pHdr->HdrLen != sizeof(CREATE_HDR))
- {
- LogMsg(LOGF_ERROR,"CUserFsys::CreateFile() - CREATE_HDR length mismatch");
- ASSERT(FALSE);
- return FALSE;
- }
- m_FsysPath1 = Path;
- m_CreateHdr = *pHdr;
- return ProcessRequest(FSM_CREATEFILE, (WPARAM)this, 0);
- }
- BOOL CUserFsys::FsysStat()
- {
- return ProcessRequest(FSM_FSYSSTAT, (WPARAM)this, 0);
- }
- BOOL CUserFsys::CreateDirectory(LPCSTR FsysPath)
- {
- m_FsysPath1 = FsysPath;
- return ProcessRequest(FSM_CREATEDIR, (WPARAM)this, 0);
- }
- BOOL CUserFsys::DeleteDirectory(LPCSTR FsysPath)
- {
- m_FsysPath1 = FsysPath;
- return ProcessRequest(FSM_DELEDIR, (WPARAM)this, 0);
- }
- BOOL CUserFsys::DeleteFile(LPCSTR FsysPath)
- {
- m_FsysPath1 = FsysPath;
- return ProcessRequest(FSM_DELEFILE, (WPARAM)this, 0);
- }
- BOOL CUserFsys::DeleteGeneric(LPCSTR FsysPath)
- {
- m_FsysPath1 = FsysPath;
- return ProcessRequest(FSM_DELE, (WPARAM)this, 0);
- }
- BOOL CUserFsys::LinkFile(LPCSTR FromPath, LPCSTR ToPath)
- {
- m_FsysPath1 = FromPath;
- m_FsysPath2 = ToPath;
- return ProcessRequest(FSM_LINK, (WPARAM)this, 0);
- }
- // Move and rename
- BOOL CUserFsys::MoveFile(LPCSTR FromPath, LPCSTR ToPath)
- {
- m_FsysPath1 = FromPath;
- m_FsysPath2 = ToPath;
- return ProcessRequest(FSM_MOVE, (WPARAM)this, 0);
- }
- BOOL CUserFsys::Stat(LPCSTR FsysPath)
- {
- m_FsysPath1 = FsysPath;
- return ProcessRequest(FSM_STAT, (WPARAM)this, 0);
- }
- ///////////////////////////////////////////////////////////////////////////
- // CFileInfo - support class for Find*File()
- CFileInfo::CFileInfo()
- {
- m_Comment.Empty();
- m_Hide = FALSE;
- m_pMoreUsers = NULL;
- m_SpecialNewFilePerms = 0;
- }
- CFileInfo::~CFileInfo()
- {
- if (m_pMoreUsers)
- delete m_pMoreUsers;
- }
- CString CFileInfo::MakeFileNameASCII()
- {
- CString cBuf = FileName();
- LPSTR p = cBuf.GetBuffer(1);
- while(*p)
- {
- if (!isprint(*p))
- *p = '?';
- }
- cBuf.ReleaseBuffer();
- return cBuf;
- }
- BOOL CFileInfo::Hide(int State)
- {
- if ((State == FALSE) || (State == TRUE))
- m_Hide = State;
- return m_Hide;
- }
- int CFileInfo::GetInode()
- {
- return (int)this;
- }
- int CFileInfo::GetLinks()
- {
- return m_Links;
- }
- ///////////////////////////////////////////////////////////////////////////
- // CFileInfoList - Representation of files, typically in one directory.
- CFileInfoList::CFileInfoList()
- {
- m_MaxCols = 0;
- m_Prev = NULL;
- }
- CFileInfoList::~CFileInfoList()
- {
- // Delete the nodes
- CFileInfo *Info;
- while(Info = (CFileInfo *)m_List.GetAndDeleteFirst())
- {
- ASSERT(AfxIsValidAddress(Info, sizeof(CFileInfo)));
- delete Info;
- }
- }
- void CFileInfoList::Add(CFileInfo *Node)
- {
- ASSERT(AfxIsValidAddress(Node,sizeof(CFileInfo)));
- int Len = strlen(Node->FileName());
- m_MaxCols = max(Len, m_MaxCols);
- m_List.AddLast((LPVOID)Node);
- }
- CFileInfo *CFileInfoList::GetNext(CFileInfo *Current)
- {
- if (Current)
- {
- ASSERT(AfxIsValidAddress(Current,sizeof(CFileInfo)));
- if (m_Prev && (m_List.Ptr(m_Prev) == Current))
- m_Prev = m_List.Next(m_Prev);
- else
- {
- if (m_Prev = m_List.FindPtr(Current))
- m_Prev = m_List.Next(m_Prev);
- }
- }
- else
- m_Prev = m_List.First();
- return m_Prev ? (CFileInfo *)m_List.Ptr(m_Prev) : NULL;
- }
- void CFileInfoList::Sort(int (*SortFunc)(const void *, const void *))
- {
- m_List.Sort(SortFunc);
- }
- // List in War's own listing format.
- // "Filename" size date flags owner class "comment"
- // Date is a 64 bit hex number, giving the precision of FILETIME
- // Size is a 64 bit hex number.
- // Flags is a 32 bit hex number
- // " characters in the string is preceeded with and \ represents
- // a single backslash.
- BOOL CFileInfoList::ListRaw(CString& cReturnBuf, DWORD Flags)
- {
- CFileInfo *Info;
- CString cBuf;
- FILETIME *ft;
- LPCSTR FileName;
- cReturnBuf.Empty();
- __int64 MyDate;
- __int64 MySize;
- for(Info = NULL; Info = GetNext(Info);)
- {
- cBuf.Empty();
- char buf[64];
- FileName = Info->FileName();
- ASSERT(AfxIsValidString(FileName));
- ft = Info->GetModifyTime();
- MyDate = ft->dwHighDateTime;
- MyDate = MyDate << 32;
- MyDate |= ft->dwLowDateTime;
- MySize = Info->GetFileLength();
- cBuf += '"';
- cBuf += FileName;
- cBuf += "" ";
- *buf = 0;
- sprintf(buf, "%I64d ", MySize);
- cBuf += buf;
- *buf = 0;
- sprintf(buf, "%I64x ", MyDate);
- cBuf += buf;
- *buf = 0;
- sprintf(buf, "%X ", Info->m_Flags);
- cBuf += buf;
- *buf = 0;
- sprintf(buf, "%X ", Info->m_User);
- cBuf += buf;
- *buf = 0;
- sprintf(buf, "%X ", Info->m_Group);
- cBuf += buf;
- cBuf += '"';
- cBuf += Info->m_Comment;
- cBuf += ""rn";
- // CString does not support __I64
- //cBuf.Format(""%s" %I64x %I64x %X %X %X "%s"n",
- // FileName, MySize, MyDate, Info->m_Flags, Info->m_User, Info->m_Group,
- // Info->m_Comment);
- cReturnBuf += cBuf;
- }
- return TRUE;
- }
- ////////////////////////////////////////////////////////////////////////////////
- // CWarFile
- CWarFile::CWarFile(CUserFsys *pFsys)
- {
- m_hFile = INVALID_HANDLE_VALUE;
- m_DEV = NULL;
- m_Path = "";
- m_pFsys = pFsys;
- m_CallbackPending = FALSE;
- m_IsZombie = FALSE;
- m_ProtectFromDelete = FALSE;
- }
- CWarFile::~CWarFile()
- {
- if (m_hFile != INVALID_HANDLE_VALUE)
- Close();
- CLog::GetLog()->LogMsg(LOGF_DEBUG,"CWarFile::~CWarFile() - %x killed.", (int)this);
- }
- void CWarFile::Close()
- {
- CLog::GetLog()->LogMsg(LOGF_DEBUG,"CWarFile::Close() - Closing file");
- if (IsOpen())
- {
- if (m_pFsys)
- {
- // Tell the file system that we are trough..
- // This call has no callback.
- SendMessage(m_pFsys->GetFsys_hWnd(), FSM_CLOSEFILE, NULL,*(WPARAM *)&m_smNode);
- }
- if (m_DEV)
- m_DEV->CloseHandle(m_hFile);
- else
- CloseHandle(m_hFile);
- }
- m_hFile = INVALID_HANDLE_VALUE;
- if (m_pFsys)
- {
- CLog::GetLog()->LogMsg(LOGF_DEBUG,"CWarFile::Close() - Removed %x from m_OpenFiles.", (int)this);
- m_pFsys->m_OpenFiles.DeletePtr((LPVOID)this);
- }
- }
- void CWarFile::Destroy()
- {
- try
- {
- Close();
- ASSERT(m_CallbackPending == FALSE);
- if (m_ProtectFromDelete || (m_pFsys && m_pFsys->m_CallbackPending))
- m_IsZombie = TRUE;
- else
- delete this;
- }
- catch(...)
- {
- CLog::GetLog()->LogMsg(LOGF_WARNINGS,"CWarFile::Destroy() - caught unknown exception.");
- return;
- }
- }
- DWORD CWarFile::GetFileAttributes()
- {
- ASSERT(FALSE);
- return 0;
- }
- UINT CWarFile::GetDriveType()
- {
- ASSERT(FALSE);
- return 0;
- };
- FLEN CWarFile::GetFileSize()
- {
- FLEN Rval = 0;
- int err = 0;
- if (m_DEV)
- Rval = m_DEV->GetFileSize(m_hFile);
- else
- {
- DWORD LoDWord, HiDWord;
- LoDWord = ::GetFileSize(m_hFile, &HiDWord);
- if ((LoDWord == 0xFFFFFFFF) && ((err = GetLastError()) != NO_ERROR))
- {
- Rval = INVALID_FLEN_VALUE;
- SetLastError(err);
- }
- Rval = (FLEN)((FLEN)HiDWord * (FLEN)MAXDWORD) + (FLEN)LoDWord;
- }
- return Rval;
- }
- FLEN CWarFile::Seek(FLEN lsOfs, UINT nFrom )
- {
- FLEN Rval;
- if (m_DEV)
- Rval = m_DEV->Seek(m_hFile, lsOfs, nFrom);
- else
- {
- DWORD LoDWord, HiDWord;
- LoDWord = LODWORD(lsOfs);
- HiDWord = HIDWORD(lsOfs);
- LoDWord = SetFilePointer(m_hFile, LoDWord, (PLONG)&HiDWord, nFrom);
- if ((LoDWord == 0xFFFFFFFF) && (GetLastError() != NO_ERROR))
- return INVALID_FLEN_VALUE;
- Rval = (FLEN)((FLEN)HiDWord * (FLEN)MAXDWORD) + (FLEN)LoDWord;
- }
- return Rval;
- }
- BOOL CWarFile::Create(
- LPCTSTR lpFileName, // pointer to name of the file
- DWORD dwDesiredAccess, // access (read-write) mode
- DWORD dwShareMode, // share mode
- LPSECURITY_ATTRIBUTES lpSecurityAttributes, // pointer to security descriptor
- DWORD dwCreationDistribution, // how to create
- DWORD dwFlagsAndAttributes, // file attributes
- HANDLE hTemplateFile, // handle to file with attributes to copy
- DWORD Flags,
- LPARAM lParam, // Callback data
- void (*Callback)(CWarFile *, BOOL, LPARAM) // Callback function
- )
- {
- BOOL Rval = FALSE;
- if (m_hFile != INVALID_HANDLE_VALUE)
- {
- ASSERT(FALSE); // File is open!
- SetLastError(ERROR_ALREADY_ASSIGNED);
- return FALSE;
- }
- // If this is a DOS style file, use the native IO calls
- if (lpFileName && isalpha(lpFileName[0]) && (lpFileName[1] == ':'))
- m_pFsys = NULL;
- m_DEV = NULL;
- m_Path = lpFileName;
- if (m_pFsys)
- {
- CREATE_HDR CreateHdr;
- CreateHdr.HdrLen = sizeof(CREATE_HDR);
- CreateHdr.dwDesiredAccess = dwDesiredAccess;
- CreateHdr.dwShareMode = dwShareMode;
- CreateHdr.lpSecurityAttributes = lpSecurityAttributes;
- CreateHdr.dwCreationDistribution = dwCreationDistribution;
- CreateHdr.dwFlagsAndAttributes = dwFlagsAndAttributes;
- CreateHdr.hTemplateFile = hTemplateFile;
- CreateHdr.Flags = Flags;
- CreateHdr.lParam = lParam;
- CreateHdr.Callback = Callback;
- CreateHdr.pFile = this;
- m_hFile = (HANDLE) HANDLE_PENDING;
- m_pFsys->CreateFile(lpFileName, &CreateHdr);
- }
- else
- {
- // Look for special flags...
- if (!ProcessFlagsLocal(Flags))
- return FALSE;
- m_hFile = ::CreateFile(
- lpFileName,
- dwDesiredAccess,
- dwShareMode,
- lpSecurityAttributes,
- dwCreationDistribution,
- dwFlagsAndAttributes,
- hTemplateFile);
- }
- if (m_pFsys && (m_hFile != INVALID_HANDLE_VALUE))
- {
- CLog::GetLog()->LogMsg(LOGF_DEBUG,"CWarFile::Create() - Added %x to m_OpenFiles.", (int)this);
- m_pFsys->m_OpenFiles.AddFirst((LPVOID)this);
- }
- return m_hFile != INVALID_HANDLE_VALUE;
- }
- BOOL CWarFile::ProcessFlagsLocal(DWORD Flags)
- {
- if (Flags & UNIQUE_NAME)
- {
- // Unique file name
- CLog::GetLog()->LogMsg(LOGF_ERROR,"CWarFile::ProcessFlagsLocal(%s) - UNIQUE_NAME is illegal without fsys",
- m_Path);
- return FALSE;
- }
- return TRUE;
- }
- BOOL CWarFile::Read(
- LPVOID lpBuffer, // address of buffer that receives data
- DWORD nNumberOfBytesToRead, // number of bytes to read
- LPDWORD lpNumberOfBytesRead, // address of number of bytes read
- LPOVERLAPPED lpOverlapped // address of structure for data
- )
- {
- if (m_DEV)
- return m_DEV->ReadFile(m_hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, lpOverlapped);
- return ::ReadFile(m_hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, lpOverlapped);
- }
- BOOL CWarFile::ReadEx(
- LPVOID lpBuffer, // address of buffer
- DWORD nNumberOfBytesToRead, // number of bytes to read
- LPOVERLAPPED lpOverlapped, // address of offset
- LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine // address of completion routine
- )
- {
- if (m_DEV)
- return m_DEV->ReadFileEx(m_hFile, lpBuffer, nNumberOfBytesToRead, lpOverlapped, lpCompletionRoutine);
- return ::ReadFileEx(m_hFile, lpBuffer, nNumberOfBytesToRead, lpOverlapped, lpCompletionRoutine);
- }
- BOOL CWarFile::Write(
- LPCVOID lpBuffer, // pointer to data to write to file
- DWORD nNumberOfBytesToWrite, // number of bytes to write
- LPDWORD lpNumberOfBytesWritten, // pointer to number of bytes written
- LPOVERLAPPED lpOverlapped // pointer to structure needed for overlapped I/O
- )
- {
- if (m_DEV)
- return m_DEV->WriteFile(m_hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, lpOverlapped);
- return ::WriteFile(m_hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, lpOverlapped);
- }
- BOOL CWarFile::WriteEx(
- LPCVOID lpBuffer, // pointer to input buffer
- DWORD nNumberOfBytesToWrite, // number of bytes to write
- LPOVERLAPPED lpOverlapped, // pointer to async. i/o data
- LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine // ptr. to completion routine
- )
- {
- if (m_DEV)
- return m_DEV->WriteFileEx(m_hFile, lpBuffer, nNumberOfBytesToWrite, lpOverlapped, lpCompletionRoutine);
- return ::WriteFileEx(m_hFile, lpBuffer, nNumberOfBytesToWrite, lpOverlapped, lpCompletionRoutine);
- }