Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes

bea_DiskMedium Class Reference
[IVD Back-End Agent]

#include <bea_diskmedium.h>

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

List of all members.

Public Member Functions

 bea_DiskMedium (const string &a_barcode)
virtual void ChangeVolume (UInt32_t a_volNum, UInt32_t a_block=0)
virtual UInt32_t ReadCurrentVolume ()
virtual void Format (vector< UInt32_t > a_volSizes, bool a_duplAITMode)
virtual void AppendVolume (UInt32_t a_volSize)

Static Public Member Functions

static string VolDirName (UInt32_t a_volNum)
static cmn_Path GetDiskMediumPath (const string &a_barcode)
static bool IsDiskMediumOnUNC (const string &a_barcode)

Protected Member Functions

virtual ~bea_DiskMedium ()
virtual void Refresh ()

Private Attributes

cmn_Path m_dmBasePath
 log_CLASSID_m

Detailed Description

Definition at line 41 of file bea_diskmedium.h.


Constructor & Destructor Documentation

bea_DiskMedium::bea_DiskMedium ( const string &  a_barcode  ) 

Definition at line 64 of file bea_diskmedium.cpp.

References log_FUNC_m, Refresh(), and bea_Medium::SetBarcode().

Here is the call graph for this function:

bea_DiskMedium::~bea_DiskMedium (  )  [protected, virtual]

Definition at line 74 of file bea_diskmedium.cpp.

References log_FUNC_m.


Member Function Documentation

void bea_DiskMedium::AppendVolume ( UInt32_t  a_volSize  )  [virtual]

Implements bea_Medium.

Definition at line 160 of file bea_diskmedium.cpp.

References bea_Medium::AddVolume(), cmn_CreatePath(), dbg_NORM, bea_Medium::GetVolumeCount(), log_DBG_m, log_FUNC_A_m, m_dmBasePath, and VolDirName().

Referenced by Format().

                                                    {
    log_FUNC_A_m(AppendVolume, "size: " << a_volSize);
    
    // Create new directory
    cmn_Path volPath(m_dmBasePath + VolDirName(GetVolumeCount() + 1));
                        
    cmn_CreatePath(volPath);
    log_DBG_m(dbg_NORM, "Volume directory created: " << volPath);
    
    AddVolume(new bea_DiskVolume(this, GetVolumeCount() + 1, a_volSize));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void bea_DiskMedium::ChangeVolume ( UInt32_t  a_volNum,
UInt32_t  a_block = 0 
) [virtual]

Implements bea_Medium.

Definition at line 92 of file bea_diskmedium.cpp.

References bea_Medium::DoMediumLogging(), bea_Medium::GetCurrentVolume(), bea_Medium::GetJobID(), bea_Volume::GetVolumeNumber(), ie_INVALID_ARG, log_FUNC_A_m, log_WriteEvent(), bea_Medium::m_barcode, bea_Volume::SeekBlock(), bea_Medium::SetCurrentVolume(), and str.

                                                                     {
    log_FUNC_A_m(ChangeVolume,
        "volume: " << a_volNum <<
        " blk: " << a_block);

    if (a_volNum < 1) {
        throw ivd_InternalError(
            ie_INVALID_ARG, "Media volume number must be greater than 0.");
    };
    
    if (DoMediumLogging()) {
        ostringstream str;
        str << "Vol " << GetCurrentVolume()->GetVolumeNumber()
            << ": Changing to volume " << a_volNum << "...";

        log_WriteEvent(str.str(), "", GetJobID(), m_barcode);
    }
    
    SetCurrentVolume(a_volNum);
    GetCurrentVolume()->SeekBlock(a_block);
}

Here is the call graph for this function:

void bea_DiskMedium::Format ( vector< UInt32_t a_volSizes,
bool  a_duplAITMode 
) [virtual]

Implements bea_Medium.

Definition at line 116 of file bea_diskmedium.cpp.

References AppendVolume(), dbg_LOW, dbg_NORM, cmn_File::DeleteDir(), cmn_File::DeleteF(), dv_VOLINFO, bea_Volume::Erase(), ivd_BaseException::GetFriendly(), bea_Medium::GetSize(), bea_Medium::GetVolume(), bea_Medium::GetVolumeCount(), log_DBG_m, log_FUNC_A_m, m_dmBasePath, Refresh(), and VolDirName().

                                                                           {
    log_FUNC_A_m(Format, "# part:" << a_volSizes.size() );
    
    //create volume directories
    for (UInt32_t i(0); i < GetVolumeCount(); i++) {
        GetVolume(i+1)->Erase();
        
        try {
            // Delete vol.info file
            cmn_File volinfo( m_dmBasePath + VolDirName(i+1) + dv_VOLINFO );
            volinfo.DeleteF();
        }
        catch(const ivd_Exception& ie) {
            log_DBG_m(dbg_NORM,
                "Error deleting " << dv_VOLINFO << ": " << ie.GetFriendly());
        }
        
        // Delete volume directory
        cmn_File::DeleteDir(m_dmBasePath + VolDirName(i+1));
    };
    
    Refresh();
    
    UInt32_t leftOnMedium(GetSize());
    
    //create volume directories
    for (UInt32_t i(0); i < a_volSizes.size(); i++) {
        if ( leftOnMedium < a_volSizes[i]) {
            AppendVolume(leftOnMedium);
            log_DBG_m(dbg_LOW, "Last volume size: " << leftOnMedium);
            break;
        }
        else {
            AppendVolume(a_volSizes[i]);
        }
        leftOnMedium -= a_volSizes[i];
    };
    
    // Re-read object properties.
    Refresh();
}

Here is the call graph for this function:

cmn_Path bea_DiskMedium::GetDiskMediumPath ( const string &  a_barcode  )  [static]

Definition at line 184 of file bea_diskmedium.cpp.

References cmn_Global::dirs, ivd_Directories::dm, g_cmn, and IsDiskMediumOnUNC().

Referenced by Refresh().

                                                                  {
    if (IsDiskMediumOnUNC(a_barcode)) {
        // UNC name specified - remote CIFS file system
        return a_barcode;
    }
    else {
        return g_cmn.dirs.dm + a_barcode;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool bea_DiskMedium::IsDiskMediumOnUNC ( const string &  a_barcode  )  [static]

Definition at line 174 of file bea_diskmedium.cpp.

Referenced by GetDiskMediumPath(), and Refresh().

                                                              {
#if TGT_OS_windows
    return a_barcode.substr(0, 2) == string("\\\\");
#else
    return false; // UNC barcodes only supported on Windows
#endif
}

Here is the caller graph for this function:

UInt32_t bea_DiskMedium::ReadCurrentVolume (  )  [virtual]

Implements bea_Medium.

Definition at line 80 of file bea_diskmedium.cpp.

References bea_Medium::GetCurVolNumber(), log_FUNC_m, and bea_Medium::SetCurrentVolume().

Referenced by Refresh().

                                           {
    log_FUNC_m(ReadCurrentVolume);
    
    UInt32_t vol = GetCurVolNumber();
    if (vol == 0) {
        SetCurrentVolume(1);
    }
    return (vol > 0) ? vol : 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void bea_DiskMedium::Refresh (  )  [protected, virtual]

Implements bea_Medium.

Definition at line 207 of file bea_diskmedium.cpp.

References bea_Medium::AddVolume(), ivd_FileSystemSize_t::bytesTotal, cfg_MEGABYTE, cmn_IsSpecialName(), dbg_LOW, dbg_NORM, bea_Medium::DeleteVolumes(), cmn_Global::dirs, ivd_Directories::dm, g_cmn, GetDiskMediumPath(), cmn_File::GetFileSystemID(), cmn_File::GetFileSystemSize(), cmn_DirLst::GetNextName(), bea_Medium::GetSize(), ie_MEDIUM_MEDERR, ift_DIR, IsDiskMediumOnUNC(), ivd_Error, ivd_FS_SIZE_CORRECTION, log_DBG_m, log_FUNC_m, bea_Medium::m_barcode, m_dmBasePath, bea_Medium::m_mediumFamily, bea_Medium::m_mediumType, bea_Medium::m_serialNum, ReadCurrentVolume(), bea_Medium::SetSize(), bea_Medium::SetWORM(), cmn_File::StatF(), and VolDirName().

Referenced by bea_DiskMedium(), and Format().

                             {
    log_FUNC_m(Refresh);

    m_dmBasePath = GetDiskMediumPath(m_barcode);

    m_serialNum.clear();
    m_mediumFamily = bmf_DISK;
    m_mediumType = bmt_DISK;
    SetWORM(false);

    // Delete old volume information.
    DeleteVolumes();

    // Get names of files of volume chunks
    list<string> volNames;
    {
        cmn_DirLst volFiles(m_dmBasePath, "");
        string name;
        name = volFiles.GetNextName();
        while ( name.size() > 0 ) {
            cmn_Path fullName(m_dmBasePath + name);
            ivd_FileType_e type;
            {
                cmn_File entry(fullName);
                ivd_FileInfo_t stat;
                entry.StatF(stat);
                type = stat.type;
            }
  
            if (type != ift_DIR) {
                log_MARKLINE_m;
                ostringstream sstr;
                sstr << m_barcode << ": Found non-directory entry \'" << name << "\'";
                log_DBG_m(dbg_LOW, "Entry type: " << type);
                
                throw ivd_Error(ie_MEDIUM_MEDERR, sstr.str() );
            } 
            else 
            {
                log_DBG_m(dbg_NORM, "Found directory: " << name);
                if ( cmn_IsSpecialName(name) == false) {
                     volNames.push_back(name);
                }
            }
            name = volFiles.GetNextName();
        }
        volNames.sort();
    }
    
    log_DBG_m(dbg_LOW, "Number of volumes: " << volNames.size());
    
    list<string>::const_iterator name_i;
    UInt32_t volNum(0);
    for (name_i = volNames.begin(); name_i != volNames.end(); ++name_i) {
        ++volNum;
                
        if (VolDirName(volNum) != (*name_i)) {
            log_MARKLINE_m;
            ostringstream sstr;
            sstr
                << m_barcode << ": Unexpected volume name :"
                << (*name_i) << ", expected: " << VolDirName(volNum);
                
            throw ivd_Error(ie_MEDIUM_MEDERR, sstr.str());
        };
        AddVolume(new bea_DiskVolume(this, volNum, 0));

    };
    if (volNum == 0) {
        log_DBG_m(dbg_LOW, "This medium doesn't have any volumes yet.");
    }
    
    ReadCurrentVolume();

    cmn_File info(m_dmBasePath);
    ivd_FileSystemSize_t fsSize;
    info.GetFileSystemSize(fsSize);
    log_DBG_m(dbg_LOW, "fsSize.bytesTotal: " << fsSize.bytesTotal );
    SetSize(UInt32_t(fsSize.bytesTotal/cfg_MEGABYTE * ivd_FS_SIZE_CORRECTION));
    
    log_DBG_m(dbg_LOW, "Disk medium size: " << GetSize() );
    
//#warning Try to get UUID if possible.
    m_serialNum = info.GetFileSystemID();

    if (!IsDiskMediumOnUNC(m_barcode)) {
        // Verify that the disk medium is mounted
        // Note: change the comparison if we will use UUID as medium serial number.
        cmn_File info(g_cmn.dirs.dm);
        if (m_serialNum == info.GetFileSystemID()) {
            throw ivd_Error(ie_MEDIUM_MEDERR, "Disk medium is not mounted.");
        }
    }    
    
    log_DBG_m(dbg_LOW, "Disk medium \"serial number\": " << m_serialNum );
}

Here is the call graph for this function:

Here is the caller graph for this function:

string bea_DiskMedium::VolDirName ( UInt32_t  a_volNum  )  [static]

Definition at line 196 of file bea_diskmedium.cpp.

Referenced by AppendVolume(), Format(), and Refresh().

                                                   {
    ostringstream sstr;
    sstr
        << std::setw(8) 
        << std::setfill('0')
        << a_volNum;
    return sstr.str();
}

Here is the caller graph for this function:


Member Data Documentation

Reimplemented from bea_Medium.

Definition at line 65 of file bea_diskmedium.h.

Definition at line 63 of file bea_diskmedium.h.

Referenced by AppendVolume(), Format(), and Refresh().


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