Public Member Functions | Private Member Functions | Private Attributes

hsm_IVDFSRecoverer Class Reference
[G_new_group]

#include <hsm_IVDFSRecoverer.h>

Inheritance diagram for hsm_IVDFSRecoverer:
Inheritance graph
[legend]
Collaboration diagram for hsm_IVDFSRecoverer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 hsm_IVDFSRecoverer (UInt32_t a_blkSize)
 ~hsm_IVDFSRecoverer (void)

Private Member Functions

virtual void ProcRecFileHdr (const df_RecCmn_t *a_recCmn_p)
void CreateParentDir (cmn_Path &a_fileName, ivd_RecordIDX_t &a_fileID)
void CreateFile (cmn_Path &a_fileName, ivd_RecordIDX_t &a_fileID)
virtual void ProcRecFileEnd (const df_RecCmn_t *a_recCmn_p)
virtual void ProcRecBSStart (const df_RecCmn_t *a_recCmn_p)
virtual void ProcRecEmbData (const df_RecCmn_t *a_recCmn_p)
virtual void ProcRecRawData (const UInt8_t *a_block_p)
virtual void ProcRecBSEnd (const df_RecCmn_t *a_recCmn_p)

Private Attributes

 log_CLASSID_m
 Macro to add class name member s_className.
ivd_FS_Filem_recovFile_p
ivd_FileInfo_t m_fileInfo
ivd_RecordIDX_t m_fileID

Detailed Description

Definition at line 47 of file hsm_IVDFSRecoverer.h.


Constructor & Destructor Documentation

hsm_IVDFSRecoverer::hsm_IVDFSRecoverer ( UInt32_t  a_blkSize  ) 
hsm_IVDFSRecoverer::~hsm_IVDFSRecoverer ( void   ) 

Definition at line 61 of file hsm_IVDFSRecoverer.cpp.

References m_recovFile_p.

{
    if (m_recovFile_p) {
        delete m_recovFile_p;
        m_recovFile_p = NULL;
    }
}


Member Function Documentation

void hsm_IVDFSRecoverer::CreateFile ( cmn_Path a_fileName,
ivd_RecordIDX_t a_fileID 
) [private]

Definition at line 278 of file hsm_IVDFSRecoverer.cpp.

References ivd_FS_File::Close(), dbg_DETAIL, ivd_FS_File::e_Recovery, ivd_BaseException::GetError(), ivd_BaseException::GetFriendly(), ivd_FS_File::GetProperties(), IVD_PRINT_ID_FS, log_DBG_m, log_FUNC_m, log_WRN_m, ivd_FS_FileProperty_t::m_chgTime, ivd_FS_FileProperty_t::m_dirtyFlag, m_fileInfo, ivd_FS_FileProperty_t::m_offlineFlag, m_recovFile_p, ivd_FS_File::Open(), ivd_FS_File::SetInode(), and ivd_FS_File::StatF().

Referenced by ProcRecFileHdr().

                                                                                  {
    log_FUNC_m(CreateFile);

    try {
        m_recovFile_p->Open(ivd_FS_File::e_Recovery);
    }
    catch (ivd_SysError &ie) { //
        log_DBG_m(dbg_DETAIL, " Can't open file to recover " << a_fileName
            << " error " << ie.GetError());
        log_WRN_m("Can't open file to recover"
            << " error "  << ie.GetFriendly()
            << " FileID " << a_fileID
            << " Name "   << a_fileName );

        delete m_recovFile_p;
        m_recovFile_p = NULL;
        return;
    }

    log_DBG_m(dbg_DETAIL, " Get its stat." );
    m_recovFile_p->StatF(m_fileInfo);

    ivd_FS_FileProperty_t fileProp;
    log_DBG_m(dbg_DETAIL, " Get properties. inode = " << IVD_PRINT_ID_FS(m_fileInfo.idOnFS));

    // setting inode for GetProperties()
    m_recovFile_p->SetInode(m_fileInfo.idOnFS);

    try {
        m_recovFile_p->GetProperties(fileProp); // just to set proper general inode (FSid)
    }
    catch (const ivd_SysError &ie) { // Catch failures from file system.

        log_DBG_m(dbg_DETAIL,  " GetProperties failed. FileName = " << a_fileName
            << " error = " << ie.GetError());

        log_WRN_m("GetProperties failed."
            << " error "  << ie.GetError()
            << " FileID " << a_fileID
            << " Name "   << a_fileName );

        m_recovFile_p->Close();

        delete m_recovFile_p;
        m_recovFile_p = NULL;

        return;
    };

    log_DBG_m(dbg_DETAIL,  " m_dirtyFlag = " << fileProp.m_dirtyFlag
        << " m_offlineFlag = " << fileProp.m_offlineFlag
        << " m_chg_time = " << fileProp.m_chgTime);

}//Createfile

Here is the call graph for this function:

Here is the caller graph for this function:

void hsm_IVDFSRecoverer::CreateParentDir ( cmn_Path a_fileName,
ivd_RecordIDX_t a_fileID 
) [private]

Definition at line 234 of file hsm_IVDFSRecoverer.cpp.

References cmn_CreatePathNoException(), cmn_MoveFile(), dbg_DETAIL, g_fs_api_p, ivd_FS_File::GetProperties(), log_DBG_m, log_FUNC_m, log_WRN_m, ivd_FS_FileProperty_t::m_fileID, and cmn_Path::UpPath().

Referenced by ProcRecFileHdr().

                                                                                        {
    log_FUNC_m(CreateParentDir);
    cmn_Path dirName(a_fileName.UpPath());
    cmn_File dir(dirName);
    bool parentExists(false);

    if (dir.Exists()) {
        if ( dir.GetFileType() == ift_DIR) {
            parentExists = true;
        }
        else {
            ivd_FS_File fsDirEntry(*g_fs_api_p, dirName);
            ivd_FS_FileProperty_t fileProp;
            fsDirEntry.GetProperties(fileProp);
            if ( fileProp.m_fileID != 0) {
                ostringstream newName;
                newName << dirName << "_HSM_RECOVERY_" << fileProp.m_fileID;
                log_WRN_m("Parent entry of"
                    << " FileID " << a_fileID
                    << " Name "   << a_fileName
                    << " is not a directory:"
                    << " Name " << dirName
                    << " renaming it to " << newName.str());
                cmn_MoveFile(dirName, newName.str());
            }
            else {
                // recently created directory
                parentExists = true;
            }
        }
    }

    if (!parentExists) {
        // Creating parent directories
        // FileID will follow and will be set later
        log_DBG_m(dbg_DETAIL,
            "Parent directory doesn't exist yet. Creating: " << dirName);

        cmn_CreatePathNoException(dirName);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void hsm_IVDFSRecoverer::ProcRecBSEnd ( const df_RecCmn_t a_recCmn_p  )  [private, virtual]

Reimplemented from df_RecReader.

Definition at line 473 of file hsm_IVDFSRecoverer.cpp.

References dbg_DETAIL, df_ST_ALTDATA, df_RecCmn_t::GetVarDataNet(), log_DBG_m, log_FUNC_m, df_RecReader::m_curStreamType, m_fileID, m_recovFile_p, NULL, and df_RecByteStreamEnd_t::streamName.

                                                                   {
    log_FUNC_m(ProcRecBSEnd);

    if (m_recovFile_p == NULL) {
        log_DBG_m(dbg_DETAIL, "No recovery in progress: " <<  m_fileID);
        return;
    }

    if (m_curStreamType == df_ST_ALTDATA) {
        return;
    }
    const df_RecByteStreamEnd_t *bse_p = df_GetSpecificRec<df_RecByteStreamEnd_t>(a_recCmn_p);
    string streamName = a_recCmn_p->GetVarDataNet(bse_p->streamName);
}

Here is the call graph for this function:

void hsm_IVDFSRecoverer::ProcRecBSStart ( const df_RecCmn_t a_recCmn_p  )  [private, virtual]

Reimplemented from df_RecReader.

Definition at line 415 of file hsm_IVDFSRecoverer.cpp.

References cmn_Num2Str(), dbg_DETAIL, df_ST_ALTDATA, df_ST_META, df_RecCmn_t::GetVarDataNet(), ie_IMPOSSIBLE, log_DBG_m, log_FUNC_m, df_RecReader::m_curStreamName, m_fileID, m_recovFile_p, ntoh(), NULL, ivd_FS_File::SetStreamHeader(), df_RecByteStreamStart_t::streamName, df_RecByteStreamStart_t::streamSize, df_RecByteStreamStart_t::streamType, and stt_META.

                                                                     {
    log_FUNC_m(ProcRecBSStart);

    if (m_recovFile_p == NULL) {
        log_DBG_m(dbg_DETAIL, "No recovery in progress: " <<  m_fileID);
        return;
    }

    const df_RecByteStreamStart_t *bss_p = df_GetSpecificRec<df_RecByteStreamStart_t>(a_recCmn_p);
    UInt32_t streamType = ntoh(bss_p->streamType);
    if (streamType == df_ST_META) {
        string streamName = a_recCmn_p->GetVarDataNet(bss_p->streamName);
//        if (m_lastStreamName == c_df_StreamNameMetaWinACL) {
        m_recovFile_p->SetStreamHeader(stt_META, streamName.c_str(), ntoh(bss_p->streamSize));
    }
    else if (streamType == df_ST_ALTDATA) {
        log_DBG_m(dbg_DETAIL, "ADS are not recovered. ADS name '" << m_curStreamName << "'" );
        // TODO set an offline flag for ADS
    }
    else {
        throw ivd_InternalError(ie_IMPOSSIBLE,
            "Invalid stream type from data format: " +
            cmn_Num2Str(streamType));
    }
}

Here is the call graph for this function:

void hsm_IVDFSRecoverer::ProcRecEmbData ( const df_RecCmn_t a_recCmn_p  )  [private, virtual]

Reimplemented from df_RecReader.

Definition at line 442 of file hsm_IVDFSRecoverer.cpp.

References df_RecEmbeddedData_t::data, dbg_DETAIL, df_RecCmn_t::GetVarDataNet(), log_DBG_m, log_FUNC_m, m_fileID, m_recovFile_p, ntoh(), NULL, ivd_VarData_t::size, size, and ivd_FS_File::WriteStream().

                                                                     {
    log_FUNC_m(ProcRecEmbData);

    if (m_recovFile_p == NULL) {
        log_DBG_m(dbg_DETAIL, "No recovery in progress: " <<  m_fileID);
        return;
    }

    const df_RecEmbeddedData_t *embData_p = df_GetSpecificRec<df_RecEmbeddedData_t>(a_recCmn_p);
    UInt32_t size = ntoh(embData_p->data.size);

    UInt32_t written;
    written = m_recovFile_p->WriteStream((void *)const_cast<char*>(a_recCmn_p->GetVarDataNet(embData_p->data)), size);

}

Here is the call graph for this function:

void hsm_IVDFSRecoverer::ProcRecFileEnd ( const df_RecCmn_t a_recCmn_p  )  [private, virtual]

Reimplemented from df_RecReader.

Definition at line 334 of file hsm_IVDFSRecoverer.cpp.

References ivd_FS_File::Close(), dbg_DETAIL, ivd_FS_File::e_Cache, ivd_BaseException::GetError(), ivd_FS_File::GetFullPathRef(), ivd_FS_File::GetProperties(), ift_DIR, log_DBG_m, log_FUNC_m, log_WRN_m, ivd_FS_FileProperty_t::m_chgTime, m_fileID, m_fileInfo, m_recovFile_p, NULL, ivd_FS_File::Open(), ivd_FS_File::Release(), ivd_FS_File::SetDataClean(), ivd_FS_File::SetDataOffline(), ivd_FS_File::SetFileID(), ivd_FS_File::SetFileSize(), and ivd_FS_File::SetStatAttr().

                                                                    {
    log_FUNC_m(ProcRecFileEnd);

    if (m_recovFile_p == NULL) {
        log_DBG_m(dbg_DETAIL, "No recovery in progress: " <<  m_fileID);
        return;
    }

    try {
        log_DBG_m(dbg_DETAIL, " Set fileID = " <<  m_fileID);
        m_recovFile_p->SetFileID(m_fileID, m_fileInfo.size);
    }
    catch (ivd_SysError) {
        log_WRN_m(
            "Setting file ID failed for entry: "
            << m_recovFile_p->GetFullPathRef()
            << " fileID: " << m_fileID );
    }

    if (m_fileInfo.type != ift_DIR) {
#ifdef TGT_OS_windows
        // File is dirty by default on NT. See also Bug#1275.
        ivd_FS_FileProperty_t fileProp;

        try {
            m_recovFile_p->GetProperties(fileProp); // Could also modify filter to accept 0 for chgTime.
        }
        catch (ivd_SysError &ie) { // Catch failures from file system.

            log_DBG_m(dbg_DETAIL,  " GetProperties failed. FileName = "
                << " error = " << ie.GetError());

            log_WRN_m("GetProperties failed."
                << " error "  << ie.GetError() );

            m_recovFile_p->Close();
            return;
        };

        m_recovFile_p->SetDataClean(fileProp.m_chgTime, 0, m_fileInfo.size);
#endif
        // Zero size files are recovered as online.
        if (m_fileInfo.size > 0) {
            try {
                log_DBG_m(dbg_DETAIL, " Set data offline of size " << m_fileInfo.size);
                m_recovFile_p->SetFileSize(m_fileInfo.size);
                m_recovFile_p->Release();
                m_recovFile_p->Close();
            }
            catch (ivd_SysError) { //
            }

            try {
                //HPUX - The file needs to be opened ( to be in the kernel cache ).
                m_recovFile_p->Open(ivd_FS_File::e_Cache);
                m_recovFile_p->SetDataOffline(0, m_fileInfo.size);
            }
            catch (ivd_SysError) { //
            }
            m_recovFile_p->Close();
        }
        else {
            m_recovFile_p->Close();
            log_DBG_m(dbg_DETAIL, " File is zero length. Leave online.");
        }
    }
#ifdef TGT_OS_windows
    else { // directory is opened for restoring streams.
        m_recovFile_p->Close();
    }
#endif

    try {
        log_DBG_m(dbg_DETAIL, " Set standard attributes." );
        m_recovFile_p->SetStatAttr(m_fileInfo);
    }
    catch (ivd_SysError) { //
    }
}

Here is the call graph for this function:

void hsm_IVDFSRecoverer::ProcRecFileHdr ( const df_RecCmn_t a_recCmn_p  )  [private, virtual]

Reimplemented from df_RecReader.

Definition at line 70 of file hsm_IVDFSRecoverer.cpp.

References df_StandardAttr_t::attr, cmn_CreatePath(), cmn_MoveFile(), cmn_UTF8ToLocale(), CreateFile(), CreateParentDir(), dbg_DETAIL, dbg_NORM, ivd_FS_File::e_Cache, ivd_FS_File::e_Recovery, cmn_File::Exists(), g_fs_api_p, ivd_BaseException::GetError(), ivd_FS_File::GetProperties(), ivd_FileSystemAPI::GetRootPath(), df_RecCmn_t::GetVarDataNet(), df_StandardAttr_t::group, df_RecFile_t::idFile, ift_DIR, log_DBG_m, log_FUNC_m, log_WRN_m, m_fileID, ivd_FS_FileProperty_t::m_fileID, m_fileInfo, m_recovFile_p, df_RecFile_t::name, df_StandardAttr_t::NetToHost(), ntoh(), NULL, ivd_FS_File::Open(), df_StandardAttr_t::owner, ivd_FS_File::SetInode(), df_StandardAttr_t::size, ivd_FS_File::StatF(), df_RecFile_t::stdAttr, df_StandardAttr_t::timeAccess, df_StandardAttr_t::timeChange, df_StandardAttr_t::timeCreate, df_StandardAttr_t::timeModify, and df_StandardAttr_t::type.

                                                                    {
    log_FUNC_m(ProcRecFileHdr);

    if (m_recovFile_p != NULL) {
        delete m_recovFile_p;
    }

    const df_RecFile_t *file_p = df_GetSpecificRec<df_RecFile_t>(a_recCmn_p);

    ivd_RecordIDX_t fileID = static_cast<ivd_RecordIDX_t>(ntoh(file_p->idFile));

    cmn_Path entryName(g_fs_api_p->GetRootPath() + a_recCmn_p->GetVarDataNet(file_p->name));
#if IVD_POSIX_OS
    cmn_Path localeName(cmn_UTF8ToLocale(entryName));
    entryName = localeName;
#endif

    df_StandardAttr_t attr = file_p->stdAttr;
    attr.NetToHost();

    ivd_FileType_e dfAttrType = static_cast<ivd_FileType_e>(attr.type);

    m_recovFile_p = new ivd_FS_File(*g_fs_api_p, entryName, 0, attr.size, dfAttrType);

    ivd_FS_FileProperty_t fileProp;
    bool entryExists(false);

    // Verify if the entry already exists

    cmn_File entry(entryName);
    entryExists = entry.Exists();

    if (!entryExists) {
        log_DBG_m(dbg_DETAIL, "Entry " << entryName << " doesn't exist yet.");
    }
    else {
        m_recovFile_p->StatF(m_fileInfo);
        m_recovFile_p->SetInode(m_fileInfo.idOnFS);
        m_recovFile_p->GetProperties(fileProp);

        if (dfAttrType != m_fileInfo.type) {
            log_WRN_m(
                "Existing entry " << entryName
                << " has different type than the one from FSC. "
                << "fs = " << m_fileInfo.type
                << ", FSC = " << dfAttrType);
        }

        if (fileProp.m_fileID == fileID) {
            if (m_fileInfo.size != attr.size) {
                log_DBG_m(dbg_NORM,
                    "Existing entry "<< entryName << " has appropriate fileID"
                    << " but different size: fs = " << m_fileInfo.size
                    << ", FSC = " << attr.size);
            }
            else {
                log_DBG_m(dbg_NORM,
                    "Existing entry "<< entryName << " has appropriate fileID and size.");
            }
            delete m_recovFile_p;
            m_recovFile_p = NULL;

            return;
        }
        else {
            // Rename existing directory or file
            log_DBG_m(dbg_NORM,
                "Existing item "<< entryName << " already has fileID "
                << fileProp.m_fileID << ".");

            ostringstream newName;
            newName << entryName << "_HSM_RECOVERY_" << fileProp.m_fileID;

            if (dfAttrType != ift_DIR || fileProp.m_fileID != 0) {
                log_DBG_m(dbg_DETAIL, "Renaming to " << newName.str());
                cmn_MoveFile(entryName, newName.str());
            }
            else {
                log_DBG_m(dbg_DETAIL, "Directories with fileID 0 are not renamed.");
            }

            // We have handled existing entry on the file system.
            entryExists = false;
        }
    }

    // Create directory or file
    if (dfAttrType == ift_DIR) {

        log_DBG_m(dbg_DETAIL,
            "Recovery of directory " << entryName << " fileID = " << fileID);

        if (!entryExists) {
            try {
                // create a dir
                CreateParentDir(entryName, fileID);
                cmn_CreatePath(entryName);
                m_recovFile_p->StatF(m_fileInfo);
                m_recovFile_p->SetInode(m_fileInfo.idOnFS);
                m_recovFile_p->GetProperties(fileProp);
            }
            catch (const ivd_Exception &ie) {
                log_WRN_m("Creating directory failed."
                    << " error "  << ie.GetError()
                    << " FileID " << fileID
                    << " Name "   << entryName );

                delete m_recovFile_p;
                m_recovFile_p = NULL;
            };
        }

#ifdef TGT_OS_windows
        // directory is opened for restoring streams.
        m_recovFile_p->Open(ivd_FS_File::e_Recovery);
#else
        //HPUX - Directory needs to be opened ( to be in the kernel cache ).
        m_recovFile_p->Open(ivd_FS_File::e_Cache, entryName);
#endif
    }
    else { // file
        log_DBG_m(dbg_DETAIL,
            "Recovery of file " << entryName << " fileID = " << fileID);

        if (!entryExists) {
            try {
                CreateParentDir(entryName, fileID);
                CreateFile(entryName, fileID);
            }
            catch (const ivd_Exception& ie) {
                log_WRN_m("Creating file failed."
                    << " error "  << ie.GetError()
                    << " FileID " << fileID
                    << " Name "   << entryName );

                delete m_recovFile_p;
                m_recovFile_p = NULL;
            }
        }
        else {
            log_DBG_m(dbg_NORM, "File already exists with file ID 0: " << entryName);
        }
    }

    // When we get to this point, the directory or file without file ID exists.
    // File ID will be set in ProcRecFileEnd.

    m_fileInfo.size         = attr.size;
    m_fileInfo.attr         = attr.attr;
    m_fileInfo.owner        = attr.owner;
    m_fileInfo.group        = attr.group;

    m_fileInfo.timeCreate   = attr.timeCreate;
    m_fileInfo.timeAccess   = attr.timeAccess;
    m_fileInfo.timeModify   = attr.timeModify;
    m_fileInfo.timeChange   = attr.timeChange;

    m_fileInfo.type         = dfAttrType;

    m_fileID = fileID;
}

Here is the call graph for this function:

void hsm_IVDFSRecoverer::ProcRecRawData ( const UInt8_t a_block_p  )  [private, virtual]

Reimplemented from df_RecReader.

Definition at line 459 of file hsm_IVDFSRecoverer.cpp.

References dbg_DETAIL, df_RecReader::GetBlkSize(), log_DBG_m, log_FUNC_m, m_fileID, m_recovFile_p, NULL, and ivd_FS_File::WriteStream().

                                                                {
    log_FUNC_m(ProcRecRawData);

    if (m_recovFile_p == NULL) {
        log_DBG_m(dbg_DETAIL, "No recovery in progress: " <<  m_fileID);
        return;
    }

    UInt32_t written;
    written = m_recovFile_p->WriteStream((void *)const_cast<UInt8_t*>(a_block_p), GetBlkSize());

}

Here is the call graph for this function:


Member Data Documentation

Macro to add class name member s_className.

Reimplemented from df_RecReader.

Definition at line 52 of file hsm_IVDFSRecoverer.h.

ivd_FileInfo_t hsm_IVDFSRecoverer::m_fileInfo [private]

Definition at line 55 of file hsm_IVDFSRecoverer.h.

Referenced by CreateFile(), ProcRecFileEnd(), and ProcRecFileHdr().


The documentation for this class was generated from the following files: