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.


Detailed Description

Definition at line 27 of file bea_diskmedium.h.


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

Constructor & Destructor Documentation

bea_DiskMedium::bea_DiskMedium ( const string &  a_barcode  ) 

Definition at line 50 of file bea_diskmedium.cpp.

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

00050                                                       {
00051     
00052     log_FUNC_m(bea_DiskMedium);
00053     SetBarcode(a_barcode);
00054     
00055     Refresh();
00056 }

Here is the call graph for this function:

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

Definition at line 60 of file bea_diskmedium.cpp.

References log_FUNC_m.

00060                                 {
00061     log_FUNC_m(~bea_DiskMedium);
00062 }


Member Function Documentation

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

Implements bea_Medium.

Definition at line 78 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.

00078                                                                      {
00079     log_FUNC_A_m(ChangeVolume,
00080         "volume: " << a_volNum <<
00081         " blk: " << a_block);
00082 
00083     if (a_volNum < 1) {
00084         throw ivd_InternalError(
00085             ie_INVALID_ARG, "Media volume number must be greater than 0.");
00086     };
00087     
00088     if (DoMediumLogging()) {
00089         ostringstream str;
00090         str << "Vol " << GetCurrentVolume()->GetVolumeNumber()
00091             << ": Changing to volume " << a_volNum << "...";
00092 
00093         log_WriteEvent(str.str(), "", GetJobID(), m_barcode);
00094     }
00095     
00096     SetCurrentVolume(a_volNum);
00097     GetCurrentVolume()->SeekBlock(a_block);
00098 }

Here is the call graph for this function:

UInt32_t bea_DiskMedium::ReadCurrentVolume (  )  [virtual]

Implements bea_Medium.

Definition at line 66 of file bea_diskmedium.cpp.

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

Referenced by Refresh().

00066                                            {
00067     log_FUNC_m(ReadCurrentVolume);
00068     
00069     UInt32_t vol = GetCurVolNumber();
00070     if (vol == 0) {
00071         SetCurrentVolume(1);
00072     }
00073     return (vol > 0) ? vol : 1;
00074 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Implements bea_Medium.

Definition at line 102 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().

00102                                                                            {
00103     log_FUNC_A_m(Format, "# part:" << a_volSizes.size() );
00104     
00105     //create volume directories
00106     for (UInt32_t i(0); i < GetVolumeCount(); i++) {
00107         GetVolume(i+1)->Erase();
00108         
00109         try {
00110             // Delete vol.info file
00111             cmn_File volinfo( m_dmBasePath + VolDirName(i+1) + dv_VOLINFO );
00112             volinfo.DeleteF();
00113         }
00114         catch(const ivd_Exception& ie) {
00115             log_DBG_m(dbg_NORM,
00116                 "Error deleting " << dv_VOLINFO << ": " << ie.GetFriendly());
00117         }
00118         
00119         // Delete volume directory
00120         cmn_File::DeleteDir(m_dmBasePath + VolDirName(i+1));
00121     };
00122     
00123     Refresh();
00124     
00125     UInt32_t leftOnMedium(GetSize());
00126     
00127     //create volume directories
00128     for (UInt32_t i(0); i < a_volSizes.size(); i++) {
00129         if ( leftOnMedium < a_volSizes[i]) {
00130             AppendVolume(leftOnMedium);
00131             log_DBG_m(dbg_LOW, "Last volume size: " << leftOnMedium);
00132             break;
00133         }
00134         else {
00135             AppendVolume(a_volSizes[i]);
00136         }
00137         leftOnMedium -= a_volSizes[i];
00138     };
00139     
00140     // Re-read object properties.
00141     Refresh();
00142 }

Here is the call graph for this function:

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

Implements bea_Medium.

Definition at line 146 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().

00146                                                     {
00147     log_FUNC_A_m(AppendVolume, "size: " << a_volSize);
00148     
00149     // Create new directory
00150     cmn_Path volPath(m_dmBasePath + VolDirName(GetVolumeCount() + 1));
00151                         
00152     cmn_CreatePath(volPath);
00153     log_DBG_m(dbg_NORM, "Volume directory created: " << volPath);
00154     
00155     AddVolume(new bea_DiskVolume(this, GetVolumeCount() + 1, a_volSize));
00156 }

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 182 of file bea_diskmedium.cpp.

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

00182                                                    {
00183     ostringstream sstr;
00184     sstr
00185         << std::setw(8) 
00186         << std::setfill('0')
00187         << a_volNum;
00188     return sstr.str();
00189 }

Here is the caller graph for this function:

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

Definition at line 170 of file bea_diskmedium.cpp.

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

Referenced by Refresh().

00170                                                                   {
00171     if (IsDiskMediumOnUNC(a_barcode)) {
00172         // UNC name specified - remote CIFS file system
00173         return a_barcode;
00174     }
00175     else {
00176         return g_cmn.dirs.dm + a_barcode;
00177     }
00178 }

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 160 of file bea_diskmedium.cpp.

Referenced by GetDiskMediumPath(), and Refresh().

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

Here is the caller graph for this function:

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

Implements bea_Medium.

Definition at line 193 of file bea_diskmedium.cpp.

References bea_Medium::AddVolume(), bmf_DISK, bmt_DISK, 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, log_MARKLINE_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(), stat(), cmn_File::StatF(), and VolDirName().

Referenced by bea_DiskMedium(), and Format().

00193                              {
00194     log_FUNC_m(Refresh);
00195 
00196     m_dmBasePath = GetDiskMediumPath(m_barcode);
00197 
00198     m_serialNum.clear();
00199     m_mediumFamily = bmf_DISK;
00200     m_mediumType = bmt_DISK;
00201     SetWORM(false);
00202 
00203     // Delete old volume information.
00204     DeleteVolumes();
00205 
00206     // Get names of files of volume chunks
00207     list<string> volNames;
00208     {
00209         cmn_DirLst volFiles(m_dmBasePath, "");
00210         string name;
00211         name = volFiles.GetNextName();
00212         while ( name.size() > 0 ) {
00213             cmn_Path fullName(m_dmBasePath + name);
00214             ivd_FileType_e type;
00215             {
00216                 cmn_File entry(fullName);
00217                 ivd_FileInfo_t stat;
00218                 entry.StatF(stat);
00219                 type = stat.type;
00220             }
00221   
00222             if (type != ift_DIR) {
00223                 log_MARKLINE_m;
00224                 ostringstream sstr;
00225                 sstr << m_barcode << ": Found non-directory entry \'" << name << "\'";
00226                 log_DBG_m(dbg_LOW, "Entry type: " << type);
00227                 
00228                 throw ivd_Error(ie_MEDIUM_MEDERR, sstr.str() );
00229             } 
00230             else 
00231             {
00232                 log_DBG_m(dbg_NORM, "Found directory: " << name);
00233                 if ( cmn_IsSpecialName(name) == false) {
00234                      volNames.push_back(name);
00235                 }
00236             }
00237             name = volFiles.GetNextName();
00238         }
00239         volNames.sort();
00240     }
00241     
00242     log_DBG_m(dbg_LOW, "Number of volumes: " << volNames.size());
00243     
00244     list<string>::const_iterator name_i;
00245     UInt32_t volNum(0);
00246     for (name_i = volNames.begin(); name_i != volNames.end(); ++name_i) {
00247         ++volNum;
00248                 
00249         if (VolDirName(volNum) != (*name_i)) {
00250             log_MARKLINE_m;
00251             ostringstream sstr;
00252             sstr
00253                 << m_barcode << ": Unexpected volume name :"
00254                 << (*name_i) << ", expected: " << VolDirName(volNum);
00255                 
00256             throw ivd_Error(ie_MEDIUM_MEDERR, sstr.str());
00257         };
00258         AddVolume(new bea_DiskVolume(this, volNum, 0));
00259 
00260     };
00261     if (volNum == 0) {
00262         log_DBG_m(dbg_LOW, "This medium doesn't have any volumes yet.");
00263     }
00264     
00265     ReadCurrentVolume();
00266 
00267     cmn_File info(m_dmBasePath);
00268     ivd_FileSystemSize_t fsSize;
00269     info.GetFileSystemSize(fsSize);
00270     log_DBG_m(dbg_LOW, "fsSize.bytesTotal: " << fsSize.bytesTotal );
00271     SetSize(UInt32_t(fsSize.bytesTotal/cfg_MEGABYTE * ivd_FS_SIZE_CORRECTION));
00272     
00273     log_DBG_m(dbg_LOW, "Disk medium size: " << GetSize() );
00274     
00275 //#warning Try to get UUID if possible.
00276     m_serialNum = info.GetFileSystemID();
00277 
00278     if (!IsDiskMediumOnUNC(m_barcode)) {
00279         // Verify that the disk medium is mounted
00280         // Note: change the comparison if we will use UUID as medium serial number.
00281         cmn_File info(g_cmn.dirs.dm);
00282         if (m_serialNum == info.GetFileSystemID()) {
00283             throw ivd_Error(ie_MEDIUM_MEDERR, "Disk medium is not mounted.");
00284         }
00285     }    
00286     
00287     log_DBG_m(dbg_LOW, "Disk medium \"serial number\": " << m_serialNum );
00288 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 49 of file bea_diskmedium.h.

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

Reimplemented from bea_Medium.

Definition at line 51 of file bea_diskmedium.h.


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

Generated on Mon Feb 27 18:58:02 2012 for OPENARCHIVE by  doxygen 1.5.6