⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shareinfo.cpp

📁 Windows CE 6.0 Server 源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    ce::smart_ptr<SMBFileStream> pStream = NULL;

    //
    // Search out the SMBFileStream
    if(FAILED(hr = FindFileStream(usFID, pStream)) || !pStream) {
        TRACEMSG(ZONE_ERROR, (L"SMB-SRV: TIDState(TID:0x%x) cant find (FID:0x%x) on Open()", this->usTid, usFID));
        goto Done;
    }

    //
    // Perform our operation
    if(FAILED(hr = pStream->Open(pFileName, dwAccess, dwDisposition, dwAttributes, dwShareMode))) {
        TRACEMSG(ZONE_ERROR, (L"SMB-SRV: TIDState(TID:0x%x) (FID:0x%x) operation Open() failed", this->usTid, usFID));
        goto Done;
    }

    //
    // Success
    hr = S_OK;
    Done:
        return hr;
}

HRESULT
TIDState::IsLocked(USHORT usFID,
                  SMB_LARGELOCK_RANGE *pRangeLock,
                  BOOL *pfLocked)
{
    HRESULT hr = E_FAIL;
    ce::smart_ptr<SMBFileStream> pStream = NULL;

    //
    // Search out the SMBFileStream
    if(FAILED(hr = FindFileStream(usFID, pStream)) || !pStream) {
        TRACEMSG(ZONE_ERROR, (L"SMB-SRV: IsLocked(TID:0x%x) cant find (FID:0x%x) on IsLocked()", this->usTid, usFID));
        goto Done;
    }

    //
    // Perform our operation
    if(FAILED(hr = pStream->IsLocked(pRangeLock, pfLocked))) {
        TRACEMSG(ZONE_ERROR, (L"SMB-SRV: IsLocked(TID:0x%x) (FID:0x%x) operation IsLocked() failed", this->usTid, usFID));
        goto Done;
    }

    //
    // Success
    hr = S_OK;

    Done:
        return hr;
}

HRESULT
TIDState::Lock(USHORT usFID,
               SMB_LARGELOCK_RANGE *pRangeLock)
{
    HRESULT hr = E_FAIL;
    ce::smart_ptr<SMBFileStream> pStream = NULL;

    //
    // Search out the SMBFileStream
    if(FAILED(hr = FindFileStream(usFID, pStream)) || !pStream) {
        TRACEMSG(ZONE_ERROR, (L"SMB-SRV: Lock(TID:0x%x) cant find (FID:0x%x) on Lock()", this->usTid, usFID));
        goto Done;
    }

    //
    // Perform our operation
    if(FAILED(hr = pStream->Lock(pRangeLock))) {
        TRACEMSG(ZONE_ERROR, (L"SMB-SRV: Lock(TID:0x%x) (FID:0x%x) operation Lock() failed", this->usTid, usFID));
        goto Done;
    }

    //
    // Success
    hr = S_OK;

    Done:
        return hr;
}

HRESULT
TIDState::UnLock(USHORT usFID,
                    SMB_LARGELOCK_RANGE *pRangeLock)
{
    HRESULT hr = E_FAIL;
    ce::smart_ptr<SMBFileStream> pStream = NULL;

    //
    // Search out the SMBFileStream
    if(FAILED(hr = FindFileStream(usFID, pStream)) || !pStream) {
        TRACEMSG(ZONE_ERROR, (L"SMB-SRV: UnLock(TID:0x%x) cant find (FID:0x%x) on UnLock()", this->usTid, usFID));
        goto Done;
    }

    //
    // Perform our operation
    if(FAILED(hr = pStream->UnLock(pRangeLock))) {
        TRACEMSG(ZONE_ERROR, (L"SMB-SRV: UnLock(TID:0x%x) (FID:0x%x) operation UnLock() failed", this->usTid, usFID));
        goto Done;
    }

    //
    // Success
    hr = S_OK;
    Done:
        return hr;
}


HRESULT
TIDState::BreakOpLock(USHORT usFID)
{
    HRESULT hr = E_FAIL;
    ce::smart_ptr<SMBFileStream> pStream = NULL;

    //
    // Search out the SMBFileStream
    if(FAILED(hr = FindFileStream(usFID, pStream)) || !pStream) {
        TRACEMSG(ZONE_ERROR, (L"SMB-SRV: BreakOpLock(TID:0x%x) cant find (FID:0x%x) on UnLock()", this->usTid, usFID));
        goto Done;
    }

    //
    // Perform our operation
    if(FAILED(hr = pStream->BreakOpLock())) {
        TRACEMSG(ZONE_ERROR, (L"SMB-SRV: UnLock(TID:0x%x) (FID:0x%x) operation UnLock() failed", this->usTid, usFID));
        goto Done;
    }

    //
    // Success
    hr = S_OK;
    Done:
        return hr;

}


HRESULT
TIDState::SetEndOfStream(USHORT usFID,
                       DWORD dwOffset)
{
    HRESULT hr = E_FAIL;
    ce::smart_ptr<SMBFileStream> pStream = NULL;

    //
    // Search out the SMBFileStream
    if(FAILED(hr = FindFileStream(usFID, pStream)) || !pStream) {
        TRACEMSG(ZONE_ERROR, (L"SMB-SRV: TIDState(TID:0x%x) cant find (FID:0x%x) on SetEndOfStream()", this->usTid, usFID));
        goto Done;
    }

    //
    // Perform our operation
    if(FAILED(hr = pStream->SetEndOfStream(dwOffset))) {
        TRACEMSG(ZONE_ERROR, (L"SMB-SRV: TIDState(TID:0x%x) (FID:0x%x) operation SetEndOfStream() failed", this->usTid, usFID));
        goto Done;
    }

    //
    // Success
    hr = S_OK;
    Done:
        return hr;
}

HRESULT
TIDState::Close(USHORT usFID)
{
    HRESULT hr = E_FAIL;
    ce::smart_ptr<SMBFileStream> pStream = NULL;

    //
    // Search out the SMBFileStream
    if(FAILED(hr = FindFileStream(usFID, pStream)) || !pStream) {
        TRACEMSG(ZONE_ERROR, (L"SMB-SRV: TIDState(TID:0x%x) cant find (FID:0x%x) on Close()", this->usTid, usFID));
        hr = E_FAIL;
        goto Done;
    }

    //
    // Perform our operation
    if(FAILED(hr = pStream->Close())) {
        TRACEMSG(ZONE_ERROR, (L"SMB-SRV: TIDState(TID:0x%x) (FID:0x%x) operation Close() failed", this->usTid, usFID));
        goto Done;
    }

    //
    // Success
    hr = S_OK;
    Done:
        return hr;
}

HRESULT
TIDState::GetFileSize(USHORT usFID,
                   DWORD *pdwSize)
{
    HRESULT hr = E_FAIL;
    ce::smart_ptr<SMBFileStream> pStream = NULL;

    //
    // Search out the SMBFileStream
    if(FAILED(hr = FindFileStream(usFID, pStream)) || !pStream) {
        TRACEMSG(ZONE_ERROR, (L"SMB-SRV: TIDState(TID:0x%x) cant find (FID:0x%x) on GetFileSize()", this->usTid, usFID));
        goto Done;
    }

    //
    // Perform our operation
    if(FAILED(hr = pStream->GetFileSize(pdwSize))) {
        TRACEMSG(ZONE_ERROR, (L"SMB-SRV: TIDState(TID:0x%x) (FID:0x%x) operation GetFileSize() failed", this->usTid, usFID));
        goto Done;
    }

    //
    // Success
    hr = S_OK;
    Done:
        return hr;
}

HRESULT
TIDState::Delete(USHORT usFID)
{
    HRESULT hr = E_FAIL;
    ce::smart_ptr<SMBFileStream> pStream = NULL;

    //
    // Search out the SMBFileStream
    if(FAILED(hr = FindFileStream(usFID, pStream)) || !pStream) {
       TRACEMSG(ZONE_ERROR, (L"SMB-SRV: TIDState(TID:0x%x) cant find (FID:0x%x) on Delete()", this->usTid, usFID));
       goto Done;
    }

    //
    // Perform our operation
    if(FAILED(hr = pStream->Delete())) {
       TRACEMSG(ZONE_ERROR, (L"SMB-SRV: TIDState(TID:0x%x) (FID:0x%x) operation Delete() failed", this->usTid, usFID));
       goto Done;
    }

    //
    // Success
    hr = S_OK;
    Done:
       return hr;

}


HRESULT
TIDState::SetFileTime(USHORT usFID,
                    FILETIME *pCreation,
                    FILETIME *pAccess,
                    FILETIME *pWrite)
{
    HRESULT hr = E_FAIL;
    ce::smart_ptr<SMBFileStream> pStream = NULL;

    //
    // If they arent setting anything, return okay
    if(!pCreation && !pAccess && !pWrite) {
        hr = S_OK;
        goto Done;
    }

    //
    // Search out the SMBFileStream
    if(FAILED(hr = FindFileStream(usFID, pStream)) || !pStream) {
        TRACEMSG(ZONE_ERROR, (L"SMB-SRV: TIDState(TID:0x%x) cant find (FID:0x%x) on SetFileTime()", this->usTid, usFID));
        goto Done;
    }

    //
    // Perform our operation
    if(FAILED(hr = pStream->SetFileTime(pCreation, pAccess, pWrite))) {
        TRACEMSG(ZONE_ERROR, (L"SMB-SRV: TIDState(TID:0x%x) (FID:0x%x) operation SetFileTime() failed", this->usTid, usFID));
        goto Done;
    }

    //
    // Success
    hr = S_OK;
    Done:
        return hr;
}


HRESULT
TIDState::Flush(USHORT usFID)
{
    HRESULT hr = E_FAIL;
    ce::smart_ptr<SMBFileStream> pStream = NULL;
    CCritSection csLock(&csTIDLock);
    csLock.Lock();

    //
    // if the FID is 0xFFFF flush everyone (per smbhlp.zip spec)
    if(0xFFFF == usFID)  {
        ce::list<ce::smart_ptr<SMBFileStream>, TIDSTATE_FID_STREAM_ALLOC >::iterator it;
        ce::list<ce::smart_ptr<SMBFileStream>, TIDSTATE_FID_STREAM_ALLOC >::iterator itEnd = FIDList.end();

        for(it = FIDList.begin(); it != itEnd; ++it) {
            ce::smart_ptr<SMBFileStream> pFound = *it;
            if(FAILED(hr = pFound->Flush())) {
                TRACEMSG(ZONE_ERROR, (L"SMB-SRV: TIDState(TID:0x%x) cant find (FID:0x%x) on batch Flush()", this->usTid, pFound->FID()));
                goto Done;
            }
        }
    } else {

        //
        // Search out the SMBFileStream
        if(FAILED(hr = FindFileStream(usFID, pStream)) || !pStream) {
            TRACEMSG(ZONE_ERROR, (L"SMB-SRV: TIDState(TID:0x%x) cant find (FID:0x%x) on Flush()", this->usTid, usFID));
            goto Done;
        }

        //
        // Perform our operation
        if(FAILED(hr = pStream->Flush())) {
            TRACEMSG(ZONE_ERROR, (L"SMB-SRV: TIDState(TID:0x%x) (FID:0x%x) operation Flush() failed", this->usTid, usFID));
            goto Done;
        }
    }

    //
    // Success
    hr = S_OK;
    Done:
        return hr;
}


HRESULT
TIDState::QueryFileInformation(USHORT usFID, WIN32_FIND_DATA *fd, DWORD *pdwNumberOfLinks)
{
    HANDLE hFileHand = INVALID_HANDLE_VALUE; // = FindFirstFile(pObject->FileName(), &fd);
    ce::smart_ptr<SMBFileStream> pStream = NULL;
    HRESULT hr = E_FAIL;

    //
    // Search out the SMBFileStream
    if(FAILED(hr = FindFileStream(usFID, pStream)) || !pStream) {
        TRACEMSG(ZONE_ERROR, (L"SMB-SRV: TIDState(TID:0x%x) cant find (FID:0x%x) on QueryFileInformation()", this->usTid, usFID));
        goto Done;
    }

    //
    // Make the query
    hr = pStream->QueryFileInformation(fd, pdwNumberOfLinks);

    Done:
        return hr;
}


HRESULT
TIDState::SetFilePointer(USHORT usFID,
                    LONG lDistance,
                    DWORD dwMoveMethod,
                    ULONG *pOffset)
{
    HRESULT hr = E_FAIL;
    ce::smart_ptr<SMBFileStream> pStream = NULL;

    //
    // Search out the SMBFileStream
    if(FAILED(hr = FindFileStream(usFID, pStream)) || !pStream) {
        TRACEMSG(ZONE_ERROR, (L"SMB-SRV: TIDState(TID:0x%x) cant find (FID:0x%x) on SetFilePointer()", this->usTid, usFID));
        goto Done;
    }

    //
    // Perform our operation
    if(FAILED(hr = pStream->SetFilePointer(lDistance, dwMoveMethod, pOffset))) {
        TRACEMSG(ZONE_ERROR, (L"SMB-SRV: TIDState(TID:0x%x) (FID:0x%x) operation SetFilePointer() failed", this->usTid, usFID));
        goto Done;
    }

    //
    // Success
    hr = S_OK;
    Done:
        return hr;
}


HRESULT
TIDState::FindFileStream(USHORT usFID, ce::smart_ptr<SMBFileStream> &pStream)
{
    HRESULT hr = E_FAIL;
    CCritSection csLock(&csTIDLock);
    csLock.Lock();

    pStream = NULL;
    ce::list<ce::smart_ptr<SMBFileStream>, TIDSTATE_FID_STREAM_ALLOC >::iterator it;
    ce::list<ce::smart_ptr<SMBFileStream>, TIDSTATE_FID_STREAM_ALLOC >::iterator itEnd = FIDList.end();

    for(it = FIDList.begin(); it != itEnd; ++it) {
        ce::smart_ptr<SMBFileStream> pFound = *it;
        ASSERT(pFound);
        if(pFound && usFID == pFound->FID()) {
            pStream = pFound;
            hr = S_OK;
            break;
        }
    }
    return hr;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -