WarFsys.cpp
资源名称:warftpd.zip [点击查看]
上传用户:surprise9
上传日期:2007-01-04
资源大小:426k
文件大小:7k
源码类别:
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 : Memory optimized file system for 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.
- //
- // This implementation use a UNIX file system only. That is, all paths are '/'
- // Each user has his own 'virtual' environment with one or more root path's.
- // If one root path is used, the root will be the physical entry point for that
- // path. If the root is /, a list with all disk drives will be created as
- // a maps.
- // If a user has a map as root directory, a 'virtual' directory is created for
- // that user, He will then not have write access to the root dir.
- // Listed directories are cached, and used as the primary file system until
- // the cache expire. Changes in the file system will be reflected in the cache.
- // This should speed things up a bit...
- //
- // 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 "WarDaemon.h"
- #include "WarSMemory.h"
- #include "WarFsys.h"
- #include "WarFsysDll.h"
- #include <afxdllx.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define LogMsg FsysLogMsg
- static AFX_EXTENSION_MODULE WarFsysDLL = { NULL, NULL };
- int Initialize();
- WAR_FSYS_HDR *GetFsysHdr(CSharedMemSegment *pSharedMem);
- WAR_FSYS_HDR *pFsysHdr = NULL;
- CSharedMemSegment *pSharedMem;
- extern "C" int APIENTRY
- DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
- {
- if (dwReason == DLL_PROCESS_ATTACH)
- {
- LogMsg(LOGF_SYSTEM,"WARFSYS.DLL Initializing! Basic, memory optimized file system.");
- // Extension DLL one-time initialization
- AfxInitExtensionModule(WarFsysDLL, hInstance);
- // Insert this DLL into the resource chain
- new CDynLinkLibrary(WarFsysDLL);
- }
- else if (dwReason == DLL_PROCESS_DETACH)
- {
- LogMsg(LOGF_DEBUG,"WARFSYS.DLL Terminating!");
- if (pSharedMem)
- delete pSharedMem;
- }
- return Initialize();
- }
- // Initialize global memory
- int Initialize()
- {
- if (!pSharedMem)
- {
- pSharedMem = new CSharedMemSegment;
- if (pSharedMem->Create("WarFsysShared", sizeof(WAR_FSYS_HDR), FALSE) == NULL)
- {
- delete pSharedMem;
- return 0;
- }
- // See if we have to initialize
- pFsysHdr = GetFsysHdr(pSharedMem);
- }
- return pFsysHdr != NULL;
- }
- WAR_FSYS_HDR *GetFsysHdr(CSharedMemSegment *pSharedMem)
- {
- WAR_FSYS_HDR *pHdr = NULL;
- CGlobalLock Lock(WAR_FSYS_SHARED_LOCK);
- pHdr = (WAR_FSYS_HDR *)pSharedMem->GetDataPtr();
- if (!pHdr->IsInitialized)
- {
- // Initialize
- CString Path = GetStartupPath(), cBuf;
- LPSTR p = Path.GetBuffer(1);
- p = strrchr(p, '\');
- if (!p)
- return NULL;
- *p = 0;
- Path.ReleaseBuffer();
- cBuf = Path;
- cBuf += "\Daemons\.Index\";
- strcpy(PrivateIndexPath, cBuf);
- cBuf = Path;
- cBuf += "\Daemons\WarFsys.ini";
- strcpy(PrivateIniPath, cBuf);
- pHdr->IsInitialized = TRUE;
- }
- return pHdr;
- }
- void FsysLogMsg(int flag, LPCSTR Format, ...)
- {
- if (!ShouldLog(CLog::GetLog(), flag))
- return;
- {
- CString cBuf;
- ASSERT(AfxIsValidString(Format, FALSE));
- cBuf.Format("WARFSYS.DLL: %s", Format);
- va_list argList;
- va_start(argList, Format);
- CLog::GetLog()->LogMsgV(flag, cBuf, argList);
- va_end(argList);
- }
- }
- ///////////////////////////////////////////////////////////////////////////////////
- // API entry point functions
- HANDLE fsys_OpenFsys(
- LPCSTR RootPath,
- LPCSTR Maps,
- LPCSTR HomeDir,
- USER User,
- USER Class,
- BOOL IsAdmin,
- HANDLE hNTsec
- )
- {
- return INVALID_HANDLE_VALUE;
- }
- void fsys_CloseFsys(HANDLE hFsys)
- {
- }
- BOOL fsys_ChDir(HANDLE hFsys, LPCSTR Path)
- {
- return TRUE;
- }
- BOOL fsys_CanAccess(HANDLE hFsys, LPCSTR Path, int AccessMode)
- {
- return TRUE;
- }
- HANDLE fsys_CreateFile(
- HANDLE hFsys,
- 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
- )
- {
- return INVALID_HANDLE_VALUE;
- }
- BOOL fsys_CreateDirectory(HANDLE hFsys, LPCSTR Path)
- {
- return TRUE;
- }
- BOOL fsys_DeleteFile(HANDLE hFsys, LPCSTR Path)
- {
- return TRUE;
- }
- FLEN fsys_GetDiskFreeSpace(HANDLE hFsys, LPCSTR Path)
- {
- return TRUE;
- }
- BOOL fsys_MoveFile(HANDLE hFsys, LPCTSTR ExistingFileName, LPCTSTR NewFileName)
- {
- return TRUE;
- }
- HANDLE fsys_GetOSHandle(HANDLE hFile)
- {
- return INVALID_HANDLE_VALUE;
- }
- void fsys_CloseHandle(HANDLE hFsys)
- {
- }
- HANDLE fsys_FindFirstFile(HANDLE hFsys, LPCTSTR lpFileName, CFileInfo& FileInfo)
- {
- return INVALID_HANDLE_VALUE;
- }
- BOOL fsys_FindNextFile(HANDLE hFindFile, CFileInfo& FileInfo)
- {
- return TRUE;
- }
- void fsys_FindClose(HANDLE hFindFile)
- {
- }
- CString fsys_GetCWD(HANDLE hFsys)
- {
- return "";
- }
- ///////////////////////////////////////////////////////////////////////////////////
- // CWarFsysHandle
- CSharedBlksMem *CWarFsysHandle::m_pSM = NULL;
- int CWarFsysHandle::m_NumObjects = 0;
- CWarFsysHandle::CWarFsysHandle()
- {
- ++m_NumObjects;
- }
- CWarFsysHandle::~CWarFsysHandle()
- {
- if (!--m_NumObjects && m_pSM)
- delete m_pSM; // Last one out clean's up
- }
- HANDLE CWarFsysHandle::OpenFsys(
- LPCSTR RootPath,
- LPCSTR Maps,
- LPCSTR HomeDir,
- USER User,
- USER Class,
- BOOL IsAdmin,
- HANDLE hNTsec);
- {
- if (!m_pSM)
- {
- // Create shared memory for file system cache
- int CacheBlkSize = GetPrivateProfileInt("Shared memory", "seglen", (1024 * 1024), pFsysHdr->PrivateIniPath);
- CString cBuf;
- cBuf.Format("%d", CacheBlkSize);
- WritePrivateProfileString("Shared memory", "seglen", cBuf, pFsysHdr->PrivateIniPath);
- m_pSM = new CSharedBlksMem;
- if (!m_pSM->Create("warfsys", CacheBlkSize))
- {
- delete m_pSM;
- m_pSM = NULL;
- FsysLogMsg(LOGF_ERROR,"CWarFsysHandle::OpenFsys() - Failed to create shared memory. (seglen=%d)", CacheBlkSize);
- return INVALID_HANDLE_VALUE;
- }
- // Create root node
- }