#include <cmn_File.h>


It supports 64-bit seek, but it does not support reading or writing blocks larger than 2 GB!
Definition at line 95 of file cmn_File.h.
Public Member Functions | |
| cmn_File () | |
| cmn_File (const cmn_File &a_file) | |
| cmn_File (const cmn_Path &a_fullPathUTF8, const ivd_FileSize_t a_fileSize=0) | |
| cmn_File & | operator= (const cmn_File &a_file) |
| virtual | ~cmn_File () |
| cmn_Path & | GetFullPathRef () |
| Pathname set/get. | |
| void | SetFullPath (const cmn_Path &a_fullPathUTF8) |
| string | GetFileSystemID () |
| Get file system ID (where file is located). | |
| void | GetFileSystemSize (ivd_FileSystemSize_t &a_fsSize) |
| Get file system sizes (FS where file is located) . | |
| void | StatF (ivd_FileInfo_t &a_info) |
| Get file information (stat()-like). | |
| ivd_FileType_e | GetFileType () |
| Get IVD internal file type. | |
| void | CreatePipe () |
| Creates named pipe/fifo. | |
| void | OpenF (const UInt32_t a_mode=fom_DEFAULT_MODE_d) |
| Opens file with specific flags and permissions. | |
| bool | IsOpen () const |
| bool | Exists () |
| void | CloseF () |
| Close the file. | |
| ivd_FileRetSize_t | ReadF (void *a_buf, ivd_FileBufSize_t a_size) |
| Reads a_size number of bytes to buffer a_buf from file and return the number of bytes read. | |
| ivd_FileRetSize_t | WriteF (const void *a_buf, ivd_FileBufSize_t a_size) const |
| Writes a_size number of bytes from buffer a_buf to file and return the number of bytes written. | |
| ivd_FilePosition_t | SeekF (ivd_FilePosition_t a_offset) const |
| Set the file position for next read or write operation. | |
| ivd_FilePosition_t | SeekRelF (ivd_FilePosition_t a_offset) const |
| Set the file position for next read or write operation using offset from current position. | |
| ivd_FilePosition_t | SeekEndF () |
| Set the file position to the end of file for next read or write operation. | |
| ivd_FilePosition_t | GetCurrentPosF () const |
| Return current position in file. | |
| void | SyncF () |
| Commit all changes to disk. | |
| void | DataSyncF () |
| In Posix commit only data changes to disk. | |
| void | TruncF (ivd_FilePosition_t a_size=0) |
| Truncation of file. | |
| void | SparseF (ivd_FilePosition_t a_size) |
| Create sparse file of specified size. | |
| void | DeleteF () |
| Delete the file. | |
| void | SymLink (const cmn_Path &a_linkNameUTF8) |
| Create symbolic link (shell link on Windows platform) to file. | |
| UInt32_t | GetStreamHeader (string &a_streamName, ivd_FilePosition_t &a_streamSize) |
| Get stream header of next stream. | |
| ivd_FilePosition_t | GetStreamLeft () |
| ivd_FileRetSize_t | ReadStream (void *a_buf, ivd_FileBufSize_t a_size) |
| Reads a_size number of bytes to buffer a_buf from current stream and return the number of bytes read. | |
| void | SetStreamHeader (UInt32_t a_streamType, const string &a_streamName, ivd_FilePosition_t a_streamSize) |
| Set stream header of next stream. | |
| ivd_FileRetSize_t | WriteStream (const void *a_buf, ivd_FileBufSize_t a_size) |
| Writes a_size number of bytes from a_buf to current stream and return the number of bytes written. | |
| bool | CleanupWriteStream () |
| Releases memory and sets m_context to NULL after each restore operation. | |
| void | SetFileHandle (const ivd_FileHandle_t, const UInt32_t) |
| void | GetFileHandle (ivd_FileHandle_t &a_fileHandle, UInt32_t &a_openMode) |
Static Public Member Functions | |
| static void | DeleteFile (const cmn_Path &a_fileUTF8, int *a_errno=NULL) |
| static void | DeleteDir (const cmn_Path &a_dirUTF8, int *a_errno=NULL) |
| static cmn_Path | ReadLink (const cmn_Path &a_linkNameUTF8) |
| Reads where the symbolic link (shell link on Windows platform) points to. | |
| static ivd_FileType_e | FileTypeFromMode (const UInt32_t a_mode) |
| Get file type from attributes/mode. | |
Private Member Functions | |
| void | DuplicateFrom (const cmn_File &a_file) |
Private Attributes | |
| log_CLASSID_m | |
| cmn_Path | m_fullPath |
| string | m_localeFullPath |
| ivd_FileHandle_t | m_fileHandle |
| bool | m_opened |
| bool | m_createdPipe |
| UInt32_t | m_openMode |
| int | m_lastError |
| bool | m_dataStream |
| ivd_FilePosition_t | m_streamLeft |
| ivd_FileSize_t | m_fileSize |
| cmn_File::cmn_File | ( | ) |
Definition at line 44 of file cmn_File_LNX.cpp.
References log_FUNC_m.
Referenced by cmn_File().
00045 : m_fileHandle(-1), 00046 m_opened(false), 00047 m_createdPipe(false), 00048 m_lastError(0), 00049 m_dataStream(false), 00050 m_streamLeft(0), 00051 m_fileSize(0) { 00052 log_FUNC_m(cmn_File()); 00053 }

| cmn_File::cmn_File | ( | const cmn_File & | a_file | ) |
Definition at line 106 of file cmn_File_LNX.cpp.
References DuplicateFrom().
00106 { 00107 DuplicateFrom(a_file); 00108 }

| cmn_File::cmn_File | ( | const cmn_Path & | a_fullPathUTF8, | |
| const ivd_FileSize_t | a_fileSize = 0 | |||
| ) |
Definition at line 55 of file cmn_File_LNX.cpp.
References cmn_File(), log_FUNC_m, and SetFullPath().
00057 : m_fileHandle(-1), 00058 m_opened(false), 00059 m_createdPipe(false), 00060 m_lastError(0), 00061 m_dataStream(false), 00062 m_streamLeft(0), 00063 m_fileSize(a_fileSize) { 00064 // m_fileSize is not used in linux environment yet. 00065 // implementation needs to be done once we have the evidence 00066 // that enlarging the file does also help here. 00067 00068 log_FUNC_m(cmn_File(cmn_Path)); 00069 00070 SetFullPath(a_fullPathUTF8); 00071 }

| cmn_File::~cmn_File | ( | ) | [virtual] |
Definition at line 76 of file cmn_File_LNX.cpp.
References CloseF(), dbg_NORM, errno, log_DBG_m, log_FUNC_m, m_createdPipe, m_fullPath, m_lastError, m_localeFullPath, and m_opened.
00076 { 00077 log_FUNC_m(~cmn_File); 00078 00079 // if file was not closed yet -> close it 00080 try { 00081 if (m_opened) { 00082 CloseF(); 00083 } 00084 } 00085 catch (...) { 00086 // Ignore all exceptions in destructors 00087 } 00088 00089 // if FIFO was created, we will remove it to not load /var/opt/ivd/tmp 00090 if (m_createdPipe) { 00091 if (unlink(m_localeFullPath.c_str()) == -1) { 00092 m_lastError = errno; 00093 log_DBG_m(dbg_NORM, 00094 "Can't unlink() fifo=" << m_fullPath 00095 << ": errno=" << m_lastError 00096 << " IGNORED IN DTOR!" ); 00097 } 00098 m_createdPipe = false; 00099 } 00100 }

Definition at line 114 of file cmn_File_LNX.cpp.
References DuplicateFrom().
00114 { 00115 DuplicateFrom(a_file); 00116 return *this; 00117 }

| void cmn_File::DeleteFile | ( | const cmn_Path & | a_fileUTF8, | |
| int * | a_errno = NULL | |||
| ) | [static] |
Definition at line 725 of file cmn_File_LNX.cpp.
References cmn_UTF8ToLocale(), dbg_DETAIL, dbg_NORM, errno, log_DBG_m, log_FUNC_m, and NULL.
Referenced by _tmain(), cmn_CleanDir(), cmn_MoveFile(), DeleteF(), fsc_FLSPerVolume::fsc_FLSPerVolume(), fsc_RawMedVolPathCollector::fsc_RawMedVolPathCollector(), bea_Volume::Init(), bea_FRI::MoveFromWorkToFRI(), nsc_ScanForIVDFSRecovery(), RecRemove::ProcessEntry(), ReadRefFromFile(), fio_JourMgr::RemoveArhivedJourFile(), RemoveJournalFiles(), RevertUpdate(), bea_FRI::SaveFRIOnError(), SimulateMediumError(), SimulateUVStructureError(), cmn_TreeWalk::Start(), and Update().
00725 { 00726 log_FUNC_m(DeleteFile); 00727 00728 if (a_fileUTF8.empty()) { 00729 return; 00730 } 00731 00732 string csName(cmn_UTF8ToLocale(a_fileUTF8)); 00733 00734 log_DBG_m(dbg_DETAIL, 00735 "delete file \'" << a_fileUTF8 << "\'."); 00736 if (unlink(csName.c_str()) == -1) { 00737 if (a_errno != NULL) { 00738 *a_errno = errno; 00739 } 00740 log_DBG_m(dbg_NORM, 00741 "Can't delete file \'" << a_fileUTF8 << "\'." << 00742 ": errno=" << errno ); 00743 00744 ostringstream sstr; 00745 sstr << "unlink(" << csName << ")"; 00746 00747 throw ivd_SysError(errno, sstr.str()); 00748 } 00749 }


| void cmn_File::DeleteDir | ( | const cmn_Path & | a_dirUTF8, | |
| int * | a_errno = NULL | |||
| ) | [static] |
Definition at line 754 of file cmn_File_LNX.cpp.
References cmn_UTF8ToLocale(), dbg_DETAIL, dbg_NORM, errno, log_DBG_m, log_FUNC_m, and NULL.
Referenced by cmn_CleanDir(), i_HSM_i::DoDeletion(), i_Service_i::Execute(), bea_DiskMedium::Format(), i_HSM_i::IVDFSPrepareRecovery(), RecRemove::ProcessEntry(), mif_CfgRep::RemoveCfg(), i_ManagementInterface_i::RemovePartition(), and fsc_MedVolReader::~fsc_MedVolReader().
00754 { 00755 log_FUNC_m(DeleteDir); 00756 00757 if (a_dirUTF8.empty()) { 00758 return; 00759 } 00760 00761 string csDir(cmn_UTF8ToLocale(a_dirUTF8)); 00762 00763 log_DBG_m(dbg_DETAIL, 00764 "delete dir \'" << a_dirUTF8 << "\'."); 00765 00766 if (rmdir(csDir.c_str()) == -1) { 00767 if (a_errno != NULL) { 00768 *a_errno = errno; 00769 } 00770 log_DBG_m(dbg_NORM, 00771 "Can't delete directory \'" << a_dirUTF8 << "\'." << 00772 ": errno=" << errno ); 00773 00774 ostringstream sstr; 00775 sstr << "rmdir(" << csDir << ")"; 00776 00777 throw ivd_SysError(errno, sstr.str(), true); 00778 } 00779 }


| cmn_Path& cmn_File::GetFullPathRef | ( | ) | [inline] |
Pathname set/get.
Definition at line 112 of file cmn_File.h.
Referenced by blk_DiskFRIReader::blk_DiskFRIReader(), fsc_DataCollectorStorage::CheckHeader(), ClearPDBI(), cmn_CopyFile(), cmn_IsMounted(), fsc_DataCollectorStorage::CreateFile(), bea_DiskVolume::CreateNewFile(), fio_JourFile::DecRefCount(), fio_Vector::Dump(), DumpEmbData(), hdb_Tables::DumpReleaseCand(), fsc_MedVolWriter::Flush(), fsc_DataCollectorStorage::Flush(), ui_MsgWriter::GetStreamPath(), i_BackupAgent_i::i_BackupAgent_i(), i_RestoreAgent_i::i_RestoreAgent_i(), fsc_MedVolume::InitBuffer(), fsc_DataCollectorStorage::InitBuffer(), ivd_FS_File::IsOfflineProlonged(), fio_RelFile::ReadListOfUnusedVector(), fio_RelFile::ReadNextUnusedVectorIDX(), bea_DiskVolume::ReadVolInfo(), RenameToBadFile(), hsm_FHrelc::Run(), ivd_FS_File::SetStatAttr(), fsc_MedVolReader::SortData(), ivd_FS_File::TriggerEvent(), ui_MsgWriter::TruncFile(), UnpackFile(), blk_DiskFRIWriter::Write(), blk_DiskBufferWriter::Write(), cmn_FileTest::WriteContents(), bea_DiskVolume::WriteRaw(), bea_DiskVolume::WriteVolInfo(), and blk_DiskFRIWriter::~blk_DiskFRIWriter().
00112 { return m_fullPath; };

| void cmn_File::SetFullPath | ( | const cmn_Path & | a_fullPathUTF8 | ) |
Definition at line 150 of file cmn_File_LNX.cpp.
References cmn_HexDump(), cmn_UTF8ToLocale(), dbg_DETAIL, log_DBG_m, log_FUNC_m, m_fullPath, and m_localeFullPath.
Referenced by blk_DiskFRIReader::blk_DiskFRIReader(), cmn_File(), bea_DiskVolume::CreateNewFile(), CreatePipe(), DumpBSStart(), DumpFile(), fsc_MedVolWriter::fsc_MedVolWriter(), fsc_RedunCopyDataVolStorage::fsc_RedunCopyDataVolStorage(), fsc_ReorgScanContentVolStorage::fsc_ReorgScanContentVolStorage(), fsc_ReorgScanReorgVolStorage::fsc_ReorgScanReorgVolStorage(), fsc_MedVolReader::GetFSCdata(), i_DownloadAgent_i::i_DownloadAgent_i(), i_UploadAgent_i::i_UploadAgent_i(), hsm_FHrelc::Init(), main(), hsm_FileHeader::MakeStat(), ivd_FS_File::Open(), ui_MsgWriter::OpenFile(), blk_DiskFRIWriter::OpenFRIFile(), hsm_FHrelc::Reconfigure(), ui_MsgWriter::SetStreamPath(), and UnpackFile().
00150 { 00151 log_FUNC_m(SetFullPath); 00152 00153 m_fullPath = a_fullPathUTF8; 00154 00155 m_localeFullPath = cmn_UTF8ToLocale(m_fullPath); 00156 00157 log_DBG_m(dbg_DETAIL, 00158 endl << 00159 "UTF-8 path: \'" << a_fullPathUTF8 << "\' " << endl << 00160 "Locale path: " << endl << 00161 cmn_HexDump( 00162 m_localeFullPath.c_str(), m_localeFullPath.length(), 16, true) ); 00163 }


| string cmn_File::GetFileSystemID | ( | ) |
Get file system ID (where file is located).
This ID is used by IVD for identification of IVD FS. Note: Can be called, even if file is not opened.
Definition at line 207 of file cmn_File_LNX.cpp.
References cmn_Num2Str(), errno, log_FUNC_m, lstat, m_fileHandle, m_fullPath, m_lastError, m_localeFullPath, m_opened, major, minor, and stat().
Referenced by cmn_IsMounted(), FileName2IPCFileList(), FileName2IPCStringList(), InputFile2IPCFileList(), and bea_DiskMedium::Refresh().
00207 { 00208 log_FUNC_m(GetFileSystemID); 00209 00210 struct stat statdata; 00211 00212 int ret(0); 00213 if (m_opened) { 00214 // use fstat() on open file descriptor 00215 ret = fstat(m_fileHandle, &statdata); 00216 } 00217 else { 00218 // use lstat() in order to work with symlinks 00219 ret = lstat(m_localeFullPath.c_str(), &statdata); 00220 } 00221 00222 if (ret == -1) { 00223 m_lastError = errno; 00224 ostringstream sstr; 00225 sstr << (m_opened ? "fstat(" : "lstat('") << m_fullPath << "')"; 00226 throw ivd_SysError(m_lastError, sstr.str() ); 00227 } 00228 00229 return cmn_Num2Str(major(statdata.st_dev)) + ":" + 00230 cmn_Num2Str(minor(statdata.st_dev)); 00231 }


| void cmn_File::GetFileSystemSize | ( | ivd_FileSystemSize_t & | a_fsSize | ) |
Get file system sizes (FS where file is located) .
Note: Can be called, even if file is not opened.
Definition at line 168 of file cmn_File_LNX.cpp.
References ivd_FileSystemSize_t::bytesAvail, ivd_FileSystemSize_t::bytesFree, ivd_FileSystemSize_t::bytesTotal, dbg_DETAIL, errno, ivd_FileSystemSize_t::inodeFree, ivd_FileSystemSize_t::inodeTotal, log_DBG_m, log_FUNC_m, m_fileHandle, m_fullPath, m_lastError, m_localeFullPath, and m_opened.
Referenced by bea_DiskVolume::ReadEstimSizes(), bea_DiskMedium::Refresh(), rm_DiskBuffer::rm_DiskBuffer(), hsm_FHrelc::SetAvailBytes(), hsm_FHrelc::SpaceCheck(), and hsm_FHrelc::TruncationCheck().
00168 { 00169 log_FUNC_m(GetFileSystemSize); 00170 00171 struct statfs statfsdata; 00172 00173 int ret(0); 00174 if (m_opened) { 00175 // use fstatfs() on open file descriptor 00176 ret = fstatfs(m_fileHandle, &statfsdata); 00177 } 00178 else { 00179 ret = statfs(m_localeFullPath.c_str(), &statfsdata); 00180 int timeout = 30; 00181 while((ret == -1) && (timeout != 0)) { 00182 log_DBG_m(dbg_DETAIL, "Mount retry!"); 00183 sleep(1); 00184 timeout--; 00185 ret = statfs(m_localeFullPath.c_str(), &statfsdata); 00186 } 00187 00188 } 00189 00190 if (ret == -1) { 00191 m_lastError = errno; 00192 ostringstream sstr; 00193 sstr << (m_opened ? "fstatfs(" : "statfs(") << m_fullPath << ")"; 00194 throw ivd_SysError(m_lastError, sstr.str()); 00195 } 00196 00197 a_info.bytesTotal = UInt64_t(statfsdata.f_bsize) * UInt64_t(statfsdata.f_blocks); 00198 a_info.bytesFree = UInt64_t(statfsdata.f_bsize) * UInt64_t(statfsdata.f_bfree); 00199 a_info.bytesAvail = UInt64_t(statfsdata.f_bsize) * UInt64_t(statfsdata.f_bavail); 00200 00201 a_info.inodeTotal = statfsdata.f_files; 00202 a_info.inodeFree = statfsdata.f_ffree; 00203 }

| void cmn_File::StatF | ( | ivd_FileInfo_t & | a_info | ) |
Get file information (stat()-like).
Can be also used on non-file objects (directories, special files). Note: Can be called, even if file is not opened.
Definition at line 463 of file cmn_File_LNX.cpp.
References errno, FileTypeFromMode(), log_FUNC_m, lstat, m_fileHandle, m_fullPath, m_lastError, m_localeFullPath, m_opened, and stat().
Referenced by Backup(), blk_DiskFRIReader::blk_DiskFRIReader(), TreeWalkBackup::CheckDir(), FileName2IPCFileList(), FileName2IPCStringList(), mif_CfgRep::GetCfg(), fsc_MedVolReader::GetFSCdata(), cmn_FastDirLst::GetNextName(), InputFile2IPCFileList(), ipc_ReadFromFile(), Collocation::IsReplicated(), ivd_AccessFsAttr(), ivd_FS_File::ivd_FS_File(), ivd_GetMountPoint(), main(), hsm_FileHeader::MakeStat(), bea_Volume::MustDumpFRI(), PackFile(), ParseMedium(), fsc_DataCollectorStorage::ReadContent(), pf_File::ReadFile(), hsm_FHADPRecall::RecallFileFromADP(), bea_DiskMedium::Refresh(), bea_DiskVolume::ReparseFiles(), and Restore().
00463 { 00464 log_FUNC_m(StatF); 00465 00466 struct stat statdata; 00467 00468 int ret(0); 00469 if (m_opened) { 00470 // use fstat() on open file descriptor 00471 ret = fstat(m_fileHandle, &statdata); 00472 } 00473 else { 00474 // use lstat() in order to work with symlinks 00475 ret = lstat(m_localeFullPath.c_str(), &statdata); 00476 } 00477 00478 if (ret == -1) { 00479 m_lastError = errno; 00480 ostringstream sstr; 00481 sstr 00482 << (m_opened ? "fstat(" : "lstat(") 00483 << m_fullPath << ")"; 00484 00485 throw ivd_SysError(m_lastError, sstr.str()); 00486 } 00487 00488 00489 a_info.idOnFS = statdata.st_ino; 00490 a_info.fsID = statdata.st_dev; 00491 a_info.type = FileTypeFromMode(statdata.st_mode); 00492 a_info.size = statdata.st_size; 00493 // Block size of Unix file systems is 512 bytes. See "man 2 stat" 00494 a_info.allocated = statdata.st_blocks * 512; 00495 00496 a_info.attr = statdata.st_rdev; 00497 a_info.attr = (a_info.attr << 32) + statdata.st_mode; 00498 00499 a_info.owner = statdata.st_uid; 00500 a_info.group = statdata.st_gid; 00501 a_info.numLinks = statdata.st_nlink; 00502 a_info.timeCreate = 0; 00503 a_info.timeAccess = statdata.st_atime; 00504 a_info.timeModify = statdata.st_mtime; 00505 a_info.timeChange = statdata.st_ctime; 00506 }


| ivd_FileType_e cmn_File::GetFileType | ( | void | ) | [inline] |
Get IVD internal file type.
Definition at line 140 of file cmn_File.h.
Referenced by api_Partition::GetFileLocations(), api_Partition::GetFileStatus(), and hsm_Recall::ProcRecBSStart().
00140 { 00141 ivd_FileInfo_t fileInfo; 00142 StatF(fileInfo); 00143 return fileInfo.type; 00144 };

| void cmn_File::CreatePipe | ( | ) |
Creates named pipe/fifo.
Caller needs to call OpenF() to wait the other side to connect to/open pipe.
Definition at line 235 of file cmn_File_LNX.cpp.
References dbg_NORM, cmn_Global::dirs, errno, g_cmn, log_DBG_m, log_FUNC_A_m, m_createdPipe, m_fullPath, m_lastError, m_localeFullPath, SetFullPath(), and ivd_Directories::tmp.
Referenced by DuplicateFrom(), i_DownloadAgent_i::i_DownloadAgent_i(), and i_UploadAgent_i::i_UploadAgent_i().
00235 { 00236 log_FUNC_A_m(CreatePipe, "name=" << m_fullPath); 00237 00238 // FIFO is always created on /var/opt/ivd/tmp (relative path) 00239 m_fullPath = g_cmn.dirs.tmp + m_fullPath; 00240 SetFullPath(m_fullPath); 00241 00242 log_DBG_m(dbg_NORM, "mkfifo(): path=" << m_fullPath); 00243 if (mkfifo(m_localeFullPath.c_str(), S_IRUSR | S_IWUSR) == -1) { // 0600 00244 m_lastError = errno; 00245 ostringstream sstr; 00246 sstr << "mkfifo(" << m_fullPath << ")"; 00247 throw ivd_SysError(m_lastError, sstr.str(), true); 00248 } 00249 00250 m_createdPipe = true; 00251 }


| void cmn_File::OpenF | ( | const UInt32_t | a_mode = fom_DEFAULT_MODE_d |
) |
Opens file with specific flags and permissions.
fom_LINK is used to open link file instead of it's target
Definition at line 256 of file cmn_File_LNX.cpp.
References errno, fom_CREATE_ALWAYS, fom_CREATE_NEW, fom_OPEN_ALWAYS, fom_READ, fom_READWRITE, fom_WRITE, log_ERR_m, log_FUNC_A_m, m_fileHandle, m_fullPath, m_lastError, m_localeFullPath, m_opened, and m_openMode.
Referenced by blk_DiskBufferReader::blk_DiskBufferReader(), blk_DiskBufferWriter::blk_DiskBufferWriter(), blk_DiskFRIReader::blk_DiskFRIReader(), fsc_DataCollectorStorage::CheckHeader(), ClearPDBI(), cmn_CopyFile(), fsc_DataCollectorStorage::CreateFile(), bea_DiskVolume::CreateNewFile(), df_FileBlockReader::df_FileBlockReader(), DumpBSStart(), DumpFile(), DuplicateFrom(), bea_DiskVolume::Erase(), fio_File::fio_File(), fsc_MedVolWriter::Flush(), fsc_DataCollectorStorage::Flush(), fsc_RawMediumContentCollector::fsc_RawMediumContentCollector(), fsc_MedVolReader::GetFSCdata(), fsc_DataCollectorStorage::GetNextRecord(), GetPDBI(), i_BackupAgent_i::i_BackupAgent_i(), i_DownloadAgent_i::i_DownloadAgent_i(), i_RestoreAgent_i::i_RestoreAgent_i(), i_UploadAgent_i::i_UploadAgent_i(), ipc_ReadFromFile(), Collocation::IsReplicated(), ivd_AccessFsAttr(), main(), ivd_FS_File::Open(), cmn_FileTest::OpenContents(), ui_MsgWriter::OpenFile(), blk_DiskFRIWriter::OpenFRIFile(), PackFile(), ParseDiskMedium(), ParseDiskMediumVolume(), ParseFile(), RecOpen::ProcessEntry(), fsc_DataCollectorStorage::ReadContent(), cmn_FileTest::ReadContents(), pf_File::ReadFile(), bea_DupReadThread::ReadMedVolume(), ReadOneBackupFromMedium(), bea_DiskVolume::ReadRaw(), bea_DiskVolume::ReadVolInfo(), hsm_FHADPRecall::RecallFileFromADP(), bea_DiskVolume::SeekBlock(), bea_DiskVolume::SeekEOD(), bea_DiskVolume::SeekFileMark(), UnpackFile(), cmn_FileTest::WriteContents(), pf_File::WriteFile(), bea_DupWriteThread::WriteMedVolume(), bea_DiskVolume::WriteRaw(), WriteToMedium(), and bea_DiskVolume::WriteVolInfo().
00256 { 00257 log_FUNC_A_m(OpenF, 00258 "path=" << m_fullPath << 00259 ", mode=0x" << hex << a_mode); 00260 00261 if (m_opened) { 00262 log_ERR_m("Open called twice for " << m_fullPath); 00263 return; 00264 } 00265 00266 int flags(0); 00267 00268 if ((a_mode & fom_READWRITE) == fom_READWRITE) { 00269 flags |= O_RDWR; 00270 } 00271 else { 00272 if (a_mode & fom_READ) flags |= O_RDONLY; 00273 if (a_mode & fom_WRITE) flags |= O_WRONLY; 00274 } 00275 00276 if (a_mode & fom_CREATE_ALWAYS) flags |= O_CREAT | O_TRUNC; 00277 else if (a_mode & fom_CREATE_NEW) flags |= O_CREAT | O_EXCL; 00278 else if (a_mode & fom_OPEN_ALWAYS) flags |= O_CREAT; 00279 00280 m_fileHandle = open(m_localeFullPath.c_str(), flags, S_IRUSR | S_IWUSR); // 0600 00281 00282 if (m_fileHandle == -1) { 00283 m_lastError = errno; 00284 ostringstream sstr; 00285 sstr 00286 << "open(" << m_fullPath 00287 << ", mode=0x" << hex << a_mode 00288 << ", flags=0x" << hex << flags << ")"; 00289 throw ivd_SysError(m_lastError, sstr.str()); 00290 } 00291 00292 m_opened = true; 00293 m_openMode = a_mode; 00294 }
| bool cmn_File::IsOpen | ( | ) | const [inline] |
Definition at line 157 of file cmn_File.h.
Referenced by CheckForOpenedFile(), DumpBSEnd(), DumpEmbData(), bea_DiskVolume::Erase(), bea_DiskVolume::Flush(), fsc_DataCollectorStorage::GetNextRecord(), bea_DiskVolume::GetPosition(), ParseBlock(), bea_DiskVolume::ReadRaw(), RenameToBadFile(), ui_MsgWriter::TruncFile(), bea_DiskVolume::WriteRaw(), fsc_MedVolReader::~fsc_MedVolReader(), and i_UploadAgent_i::~i_UploadAgent_i().
00157 { return m_opened; };

| bool cmn_File::Exists | ( | ) |
Definition at line 299 of file cmn_File_LNX.cpp.
References errno, log_FUNC_m, m_fullPath, m_localeFullPath, and m_opened.
Referenced by CheckForOpenedFile(), i_MaintFriJob_i::CheckReadFri(), cmn_CleanDir(), api_Partition::GetFileLocations(), api_Partition::GetFileStatus(), main(), i_HSM_i::MigrateByAPI(), i_MaintFriJob_i::PrepareVolumes(), hsm_IVDFSRecoverer::ProcRecFileHdr(), cmn_FileTest::WriteContents(), and fsc_MedVolReader::~fsc_MedVolReader().
00299 { 00300 log_FUNC_m(Exists); 00301 00302 if (m_opened) { 00303 return true; 00304 } 00305 00306 // File is not open. Try to open and close it. 00307 00308 ivd_FileHandle_t h = open(m_localeFullPath.c_str(), O_RDONLY, S_IRUSR | S_IWUSR); // 0600 00309 if (h != -1) { 00310 close(h); 00311 return true; 00312 } 00313 int err(errno); 00314 if (err == ENOENT || err == ENXIO) { 00315 return false; 00316 } 00317 else { 00318 ostringstream sstr; 00319 sstr 00320 << "open(" << m_fullPath 00321 << ", mode=0x" << hex << O_RDONLY << ") to check existence."; 00322 throw ivd_SysError(err, sstr.str()); 00323 } 00324 return false; 00325 }

| void cmn_File::CloseF | ( | ) |
Close the file.
Definition at line 330 of file cmn_File_LNX.cpp.
References errno, log_FUNC_A_m, m_fileHandle, m_fullPath, m_lastError, and m_opened.
Referenced by _tmain(), fsc_DataCollectorStorage::CheckHeader(), ivd_FS_File::Close(), i_DownloadAgent_i::Close(), i_UploadAgent_i::Close(), ui_MsgWriter::CloseFile(), fsc_DataCollectorStorage::CreateFile(), bea_DiskVolume::CreateNewFile(), DeleteF(), DumpBSEnd(), DumpFile(), fsc_MedVolWriter::Flush(), fsc_DataCollectorStorage::Flush(), fsc_MedVolReader::GetNextBuff(), fsc_DataCollectorStorage::GetNextRecord(), ipc_ReadFromFile(), Collocation::IsReplicated(), ivd_AccessFsAttr(), main(), PackFile(), ParseDiskMedium(), ParseDiskMediumVolume(), ParseFile(), RecOpen::ProcessEntry(), RecAccess::ProcessEntry(), fsc_DataCollectorStorage::ReadContent(), pf_File::ReadFile(), bea_DupReadThread::ReadMedVolume(), ReadOneBackupFromMedium(), bea_DiskVolume::ReadRaw(), bea_DiskVolume::ReadVolInfo(), RenameToBadFile(), bea_DiskVolume::SeekBlock(), bea_DiskVolume::SeekEOD(), bea_DiskVolume::SeekFileMark(), SetFileHandle(), UnpackFile(), pf_File::WriteFile(), bea_DupWriteThread::WriteMedVolume(), WriteToMedium(), bea_DiskVolume::WriteVolInfo(), ~cmn_File(), fsc_MedVolReader::~fsc_MedVolReader(), and fsc_RawMediumContentCollector::~fsc_RawMediumContentCollector().
00330 { 00331 log_FUNC_A_m(CloseF, "path=" << m_fullPath); 00332 00333 if (m_opened) { 00334 m_opened = false; 00335 if (close(m_fileHandle) == -1) { 00336 m_lastError = errno; 00337 ostringstream sstr; 00338 sstr << "close(" << m_fullPath << ")"; 00339 throw ivd_SysError(m_lastError, sstr.str(), true); 00340 } 00341 } 00342 }

| ivd_FileRetSize_t cmn_File::ReadF | ( | void * | a_buf, | |
| ivd_FileBufSize_t | a_size | |||
| ) |
Reads a_size number of bytes to buffer a_buf from file and return the number of bytes read.
Definition at line 533 of file cmn_File_LNX.cpp.
References errno, log_FUNC_m, m_fileHandle, m_fullPath, and m_lastError.
Referenced by fsc_DataCollectorStorage::CheckHeader(), cmn_CopyFile(), cmn_FastFileSearch::Find(), fio_RelFileHeader_t::fio_RelFileHeader_t(), fsc_MedVolReader::GetFSCdata(), df_FileBlockReader::GetNextBlock(), fsc_DataCollectorStorage::GetNextRecord(), GetPDBI(), df_FileBlockReader::GetRawNextBlock(), ipc_ReadFromFile(), Collocation::IsReplicated(), ivd_AccessFsAttr(), main(), ParseDiskMedium(), ParseDiskMediumVolume(), ParseFile(), fio_File::PosRead(), i_DownloadAgent_i::Read(), blk_DiskFRIReader::Read(), blk_DiskBufferReader::Read(), fsc_DataCollectorStorage::ReadContent(), cmn_FileTest::ReadContents(), pf_File::ReadFile(), fio_PermDBinfoMgr::ReadInfo(), bea_DiskVolume::ReadRaw(), ReadStream(), bea_DiskVolume::ReadVolInfo(), hsm_FHADPRecall::RecallFileFromADP(), bea_DupWriteThread::WriteMedVolume(), and WriteToMedium().
00533 { 00534 00535 ivd_FileRetSize_t ret = read(m_fileHandle, a_buf, a_size); 00536 if (ret == -1) { 00537 log_FUNC_m(ReadF); 00538 m_lastError = errno; 00539 ostringstream sstr; 00540 sstr << "read(" << m_fullPath << ", buf, " << a_size << ")"; 00541 throw ivd_SysError(m_lastError, sstr.str()); 00542 } 00543 return ret; 00544 }

| ivd_FileRetSize_t cmn_File::WriteF | ( | const void * | a_buf, | |
| ivd_FileBufSize_t | a_size | |||
| ) | const |
Writes a_size number of bytes from buffer a_buf to file and return the number of bytes written.
Definition at line 510 of file cmn_File_LNX.cpp.
References errno, log_FUNC_m, log_WRN_m, m_fileHandle, m_fullPath, and m_lastError.
Referenced by ClearPDBI(), cmn_CopyFile(), fsc_DataCollectorStorage::CreateFile(), fio_RelFile::CreateFile(), ui_MsgWriter::DisplayError(), ui_MsgWriter::DisplayMessage(), ui_MsgWriter::DisplayWarning(), DumpEmbData(), DumpFile(), fsc_MedVolWriter::Flush(), fsc_DataCollectorStorage::Flush(), ivd_AccessFsAttr(), ParseBlock(), fio_File::PosWrite(), fsc_RawMediumContentCollector::ProcRecMedPosMgr(), bea_DupReadThread::ReadMedVolume(), ReadOneBackupFromMedium(), i_UploadAgent_i::Write(), blk_DiskFRIWriter::Write(), blk_DiskBufferWriter::Write(), cmn_FileTest::WriteContents(), ivd_FS_File::WriteF(), pf_File::WriteFile(), fio_PermDBinfoMgr::WriteInfo(), bea_DiskVolume::WriteRaw(), WriteStream(), and bea_DiskVolume::WriteVolInfo().
00511 { 00512 00513 ivd_FileRetSize_t ret = write(m_fileHandle, a_buf, a_size); 00514 if (ret == -1) { 00515 log_FUNC_m(WriteF); 00516 m_lastError = errno; 00517 ostringstream sstr; 00518 sstr << "Write to " << m_fullPath << ", size " << a_size; 00519 throw ivd_SysError(m_lastError, sstr.str()); 00520 } 00521 if (ret < static_cast<ivd_FileRetSize_t>(a_size) ) { 00522 log_FUNC_m(WriteF); 00523 log_WRN_m( 00524 "Write request to " << m_fullPath << ", size " << a_size << 00525 " wrote only " << ret); 00526 } 00527 00528 return ret; 00529 }

| ivd_FilePosition_t cmn_File::SeekF | ( | ivd_FilePosition_t | a_offset | ) | const |
Set the file position for next read or write operation.
Returns actual position after seek.
Definition at line 548 of file cmn_File_LNX.cpp.
References errno, log_FUNC_m, m_fileHandle, m_fullPath, and m_lastError.
Referenced by blk_DiskBufferWriter::blk_DiskBufferWriter(), ClearPDBI(), fio_RelFile::CreateFile(), DuplicateFrom(), cmn_FastFileSearch::Find(), fio_RelFileHeader_t::fio_RelFileHeader_t(), fsc_DataCollectorStorage::GetNextRecord(), GetPDBI(), ivd_AccessFsAttr(), main(), fio_File::PosRead(), fio_File::PosWrite(), fsc_DataCollectorStorage::ReadContent(), fio_PermDBinfoMgr::ReadInfo(), bea_DiskVolume::SeekBlock(), ivd_FS_File::SeekF(), and fio_PermDBinfoMgr::WriteInfo().
00548 { 00549 00550 ivd_FilePosition_t pos = lseek(m_fileHandle, a_offset , SEEK_SET); 00551 if (pos == -1) { 00552 log_FUNC_m(SeekF); 00553 m_lastError = errno; 00554 ostringstream sstr; 00555 sstr << "lseek(" << m_fullPath << ", " << a_offset << ", SEEK_SET)"; 00556 throw ivd_SysError(m_lastError, sstr.str(), true); 00557 } 00558 return pos; 00559 }

| ivd_FilePosition_t cmn_File::SeekRelF | ( | ivd_FilePosition_t | a_offset | ) | const |
Set the file position for next read or write operation using offset from current position.
Returns actual position after seek.
Definition at line 592 of file cmn_File_LNX.cpp.
References errno, log_FUNC_m, m_fileHandle, m_fullPath, and m_lastError.
Referenced by fio_JourHandle::JourSkip(), blk_DiskBufferWriter::Seek(), and i_UploadAgent_i::Write().
00592 { 00593 00594 ivd_FilePosition_t pos = lseek(m_fileHandle, a_offset , SEEK_CUR); 00595 if (pos == -1) { 00596 log_FUNC_m(SeekRelF); 00597 m_lastError = errno; 00598 00599 ostringstream sstr; 00600 sstr << "lseek(" << m_fullPath << ", " << a_offset << ", SEEK_CUR)"; 00601 00602 throw ivd_SysError(m_lastError, sstr.str(), true); 00603 } 00604 return pos; 00605 }

| ivd_FilePosition_t cmn_File::SeekEndF | ( | ) |
Set the file position to the end of file for next read or write operation.
Returns actual position after seek.
Definition at line 563 of file cmn_File_LNX.cpp.
References errno, log_FUNC_m, m_fileHandle, m_fullPath, and m_lastError.
Referenced by blk_DiskBufferWriter::blk_DiskBufferWriter(), bea_DiskVolume::Erase(), fio_StartTransaction_t::FindStart(), fio_JourFile::fio_JourFile(), fio_PermDBinfoMgr::fio_PermDBinfoMgr(), fio_RelFile::fio_RelFile(), fio_RelFile::FirstNewIDX(), fsc_MedVolWriter::Flush(), fsc_DataCollectorStorage::Flush(), ui_MsgWriter::OpenFile(), blk_DiskFRIWriter::OpenFRIFile(), bea_DiskVolume::SeekEOD(), and bea_DiskVolume::SeekFileMark().
00563 { 00564 ivd_FilePosition_t pos = lseek(m_fileHandle, 0, SEEK_END); 00565 if (pos == -1) { 00566 log_FUNC_m(SeekEndF); 00567 m_lastError = errno; 00568 ostringstream sstr; 00569 sstr << "lseek(" << m_fullPath << ", 0, SEEK_END)"; 00570 throw ivd_SysError(m_lastError, sstr.str(), true); 00571 } 00572 return pos; 00573 }

| ivd_FilePosition_t cmn_File::GetCurrentPosF | ( | ) | const |
Return current position in file.
Definition at line 577 of file cmn_File_LNX.cpp.
References errno, log_FUNC_m, m_fileHandle, m_fullPath, and m_lastError.
Referenced by i_UploadAgent_i::Close(), DuplicateFrom(), bea_DiskVolume::Erase(), bea_DiskVolume::GetPosition(), bea_DiskVolume::ReadRaw(), blk_DiskFRIWriter::Write(), blk_DiskBufferWriter::Write(), and bea_DiskVolume::WriteRaw().
00577 { 00578 00579 ivd_FilePosition_t pos = lseek(m_fileHandle, 0, SEEK_CUR); 00580 if (pos == -1) { 00581 log_FUNC_m(SeekCurrentF); 00582 m_lastError = errno; 00583 ostringstream sstr; 00584 sstr << "lseek(" << m_fullPath << ", 0, SEEK_CUR)"; 00585 throw ivd_SysError(m_lastError, sstr.str(), true); 00586 } 00587 return pos; 00588 }

| void cmn_File::SyncF | ( | ) |
Commit all changes to disk.
Data and meta data (attributes).
Definition at line 609 of file cmn_File_LNX.cpp.
References errno, log_FUNC_m, m_fileHandle, m_fullPath, and m_lastError.
Referenced by bea_DiskVolume::Flush(), fio_JourHandle::JourSync(), bea_DupReadThread::ReadMedVolume(), and blk_DiskFRIWriter::~blk_DiskFRIWriter().
00609 { 00610 log_FUNC_m(SyncF); 00611 00612 if (fsync(m_fileHandle) == -1) { 00613 m_lastError = errno; 00614 00615 ostringstream sstr; 00616 sstr << "fsync(" << m_fullPath << ")"; 00617 00618 throw ivd_SysError(m_lastError, sstr.str(), true); 00619 } 00620 }

| void cmn_File::DataSyncF | ( | ) |
In Posix commit only data changes to disk.
Attributes stay as is. In Windows work the same as SyncF method.
Definition at line 624 of file cmn_File_LNX.cpp.
References errno, log_FUNC_m, m_fileHandle, m_fullPath, and m_lastError.
00624 { 00625 log_FUNC_m(DataSyncF); 00626 00627 if (fdatasync(m_fileHandle) == -1) { 00628 m_lastError = errno; 00629 00630 ostringstream sstr; 00631 sstr << "fdatasync(" << m_fullPath << ")"; 00632 00633 throw ivd_SysError(m_lastError, sstr.str(), true); 00634 } 00635 }
| void cmn_File::TruncF | ( | ivd_FilePosition_t | a_size = 0 |
) |
Truncation of file.
Definition at line 639 of file cmn_File_LNX.cpp.
References errno, log_FUNC_A_m, m_fileHandle, m_fullPath, and m_lastError.
Referenced by blk_DiskBufferWriter::blk_DiskBufferWriter(), i_UploadAgent_i::Close(), bea_DiskVolume::Erase(), bea_DiskVolume::ExtendToFullBlock(), SparseF(), ui_MsgWriter::TruncFile(), blk_DiskFRIWriter::Write(), blk_DiskBufferWriter::Write(), and bea_DiskVolume::WriteRaw().
00639 { 00640 log_FUNC_A_m(TruncF, "path=" << m_fullPath << ", size=" << a_size); 00641 00642 if (ftruncate(m_fileHandle, a_size) == -1) { 00643 m_lastError = errno; 00644 00645 ostringstream sstr; 00646 sstr << "ftruncate(" << m_fullPath << ")"; 00647 00648 throw ivd_SysError(m_lastError, sstr.str(), true); 00649 } 00650 }

| void cmn_File::SparseF | ( | ivd_FilePosition_t | a_size | ) |
Create sparse file of specified size.
Note: this function removes existing contents of the file!
Definition at line 654 of file cmn_File_LNX.cpp.
References log_FUNC_A_m, m_fullPath, and TruncF().
Referenced by main(), and ivd_FS_File::Release().
00654 { 00655 log_FUNC_A_m(SparseF, "path=" << m_fullPath << ", size=" << a_size); 00656 00657 // first remove existing contents 00658 TruncF(0); 00659 00660 // now extend the file to new size 00661 TruncF(a_size); 00662 }


| void cmn_File::DeleteF | ( | ) |
Delete the file.
Note: if file is opened, it will be closed before delete!
Definition at line 666 of file cmn_File_LNX.cpp.
References CloseF(), DeleteFile(), log_FUNC_A_m, m_fullPath, m_lastError, and m_opened.
Referenced by i_Service_i::DeleteFile(), bea_DiskVolume::Erase(), bea_DiskMedium::Format(), fsc_RedunCopyDataVolStorageWriter::fsc_RedunCopyDataVolStorageWriter(), i_ReorgJob_i::InitializeVolumes(), df_FRI::MediumVolumeClosed(), i_RecoveryJob_i::ProcessFRI(), i_MediumCheckJob_i::ProcessFRI(), i_ManagementInterface_i::RemovePartition(), mif_CfgRep::Upload(), bea_DupWriteThread::WriteMedVolume(), i_MediumDupl_i::~i_MediumDupl_i(), and i_RedundantCopyJob_i::~i_RedundantCopyJob_i().
00666 { 00667 log_FUNC_A_m(DeleteF, "path=" << m_fullPath); 00668 00669 if (m_opened) { 00670 CloseF(); 00671 }; 00672 00673 DeleteFile(m_fullPath, &m_lastError); 00674 }


| void cmn_File::SymLink | ( | const cmn_Path & | a_linkNameUTF8 | ) |
Create symbolic link (shell link on Windows platform) to file.
Definition at line 678 of file cmn_File_LNX.cpp.
References cmn_UTF8ToLocale(), errno, log_FUNC_m, m_fullPath, m_lastError, and m_localeFullPath.
00678 { 00679 log_FUNC_m(SymLink); 00680 00681 string csLink(cmn_UTF8ToLocale(a_linkNameUTF8)); 00682 if (symlink(m_localeFullPath.c_str(), csLink.c_str()) == -1) { 00683 m_lastError = errno; 00684 00685 ostringstream sstr; 00686 sstr << "symlink(" << m_fullPath << "," << a_linkNameUTF8 << ")"; 00687 00688 throw ivd_SysError(m_lastError, sstr.str()); 00689 } 00690 }

Reads where the symbolic link (shell link on Windows platform) points to.
Definition at line 696 of file cmn_File_LNX.cpp.
References cmn_LocaleToUTF8(), cmn_UTF8ToLocale(), dbg_NORM, errno, ivd_MAX_PATHNAME, log_DBG_m, log_FUNC_m, and size.
Referenced by mif_CfgRep::SetLastRevNum().
00696 { 00697 log_FUNC_m(ReadLink); 00698 00699 string csLink(cmn_UTF8ToLocale(a_linkUTF8)); 00700 char buffer[ivd_MAX_PATHNAME]; 00701 Int32_t size = readlink(csLink.c_str(), buffer, ivd_MAX_PATHNAME); 00702 00703 if (size == -1) { 00704 log_DBG_m(dbg_NORM, 00705 "Can't read symlink: " << a_linkUTF8 << 00706 ": errno=" << errno ); 00707 00708 ostringstream sstr; 00709 sstr << "readlink(" << csLink << ")"; 00710 00711 throw ivd_SysError(errno, sstr.str()); 00712 }; 00713 buffer[size] = '\0'; 00714 00715 // Convert read symlink to UTF-8 00716 string ut8String = cmn_LocaleToUTF8(string(buffer)); 00717 00718 return cmn_Path(ut8String); 00719 }


| static ivd_FileType_e cmn_File::FileTypeFromMode | ( | const UInt32_t | a_mode | ) | [inline, static] |
Get file type from attributes/mode.
Definition at line 249 of file cmn_File.h.
References ift_BLK_DEV, ift_CHR_DEV, ift_DIR, ift_FIFO, ift_FILE, ift_SOCKET, ift_SYMLINK, ift_UNKNOWN, S_ISBLK, S_ISCHR, S_ISDIR, and S_ISREG.
Referenced by ivd_FS_File::GetProperties(), and StatF().
00249 { 00250 if (S_ISREG(a_mode)) 00251 return ift_FILE; 00252 else if (S_ISDIR(a_mode)) 00253 return ift_DIR; 00254 else if (S_ISCHR(a_mode)) 00255 return ift_CHR_DEV; 00256 else if (S_ISBLK(a_mode)) 00257 return ift_BLK_DEV; 00258 else if (S_ISFIFO(a_mode)) 00259 return ift_FIFO; 00260 else if (S_ISLNK(a_mode)) 00261 return ift_SYMLINK; 00262 else if (S_ISSOCK(a_mode)) 00263 return ift_SOCKET; 00264 00265 return ift_UNKNOWN; 00266 }

| UInt32_t cmn_File::GetStreamHeader | ( | string & | a_streamName, | |
| ivd_FilePosition_t & | a_streamSize | |||
| ) |
Get stream header of next stream.
Returns stream type (return value), name and size of stream. Returns stt_NONE if there is no stream; Note: Should be called only on begining of the stream
Definition at line 346 of file cmn_File_LNX.cpp.
References errno, fom_STREAM, fom_STREAM_NO_DATA, ie_IMPOSSIBLE, ie_PRECONDITION, ivd_Error, log_ERR_m, log_FUNC_m, m_dataStream, m_fileHandle, m_fullPath, m_lastError, m_opened, m_openMode, m_streamLeft, stat(), stt_DATA, and stt_NONE.
Referenced by ivd_FS_File::GetStreamHeader(), and PackFile().
00347 { 00348 log_FUNC_m(GetStreamHeader); 00349 00350 if (!m_opened || !(m_openMode & fom_STREAM)) { 00351 throw ivd_Error(ie_PRECONDITION, "File not opened for stream IO", true); 00352 } 00353 00354 if (m_streamLeft > 0) { 00355 ostringstream sstr; 00356 sstr << "GetStreamHeader called but still left: " << m_streamLeft; 00357 throw ivd_Error(ie_IMPOSSIBLE, sstr.str(), true); 00358 } 00359 00360 // if data stream not yet sent and not opened with NO DATA 00361 if ( !m_dataStream 00362 && !(m_openMode & fom_STREAM_NO_DATA)) { 00363 00364 struct stat statdata; 00365 if (fstat(m_fileHandle, &statdata) == -1) { 00366 m_lastError = errno; 00367 log_ERR_m( 00368 "Cannot get data stream size file=" << m_fullPath 00369 << ": errno=" << m_lastError ); 00370 00371 ostringstream sstr; 00372 sstr << "fstat(" << m_fullPath << ")"; 00373 throw ivd_SysError(m_lastError, sstr.str(), true); 00374 } 00375 00376 a_streamSize = m_streamLeft = statdata.st_size; 00377 a_streamName = ""; 00378 00379 m_dataStream = true; 00380 00381 return stt_DATA; 00382 } 00383 00384 return stt_NONE; 00385 }


| ivd_FilePosition_t cmn_File::GetStreamLeft | ( | ) | [inline] |
| ivd_FileRetSize_t cmn_File::ReadStream | ( | void * | a_buf, | |
| ivd_FileBufSize_t | a_size | |||
| ) |
Reads a_size number of bytes to buffer a_buf from current stream and return the number of bytes read.
Definition at line 389 of file cmn_File_LNX.cpp.
References m_streamLeft, and ReadF().
Referenced by PackFile(), and ivd_FS_File::ReadStream().
00389 { 00390 00391 if (m_streamLeft == 0) { 00392 return 0; 00393 } 00394 00395 // only data stream for now -> just read 00396 ivd_FileRetSize_t readBytes = ReadF(a_buf, a_size); 00397 m_streamLeft -= readBytes; 00398 return readBytes; 00399 }


| void cmn_File::SetStreamHeader | ( | UInt32_t | a_streamType, | |
| const string & | a_streamName, | |||
| ivd_FilePosition_t | a_streamSize | |||
| ) |
Set stream header of next stream.
Note: Should be called only on begining of the stream
Definition at line 403 of file cmn_File_LNX.cpp.
References fom_STREAM, ie_IMPOSSIBLE, ie_PRECONDITION, ivd_Error, log_FUNC_m, m_dataStream, m_opened, m_openMode, m_streamLeft, and stt_DATA.
Referenced by ivd_FS_File::SetStreamHeader(), and UnpackFile().
00405 { 00406 log_FUNC_m(SetStreamHeader); 00407 00408 if (!m_opened || !(m_openMode & fom_STREAM)) { 00409 throw ivd_Error(ie_PRECONDITION, "File not opened for stream IO", true); 00410 } 00411 00412 if (m_streamLeft > 0) { 00413 ostringstream sstr; 00414 sstr << "SetStreamHeader called but still left: " << m_streamLeft; 00415 throw ivd_Error(ie_IMPOSSIBLE, sstr.str(), true); 00416 } 00417 00418 switch (a_streamType) { 00419 case stt_DATA: 00420 m_dataStream = true; 00421 m_streamLeft = a_streamSize; 00422 break; 00423 00424 default: 00425 ostringstream sstr; 00426 sstr << "SetStreamHeader called with unsupported type: " << a_streamType; 00427 throw ivd_InternalError(ie_IMPOSSIBLE, sstr.str()); 00428 } 00429 }

| ivd_FileRetSize_t cmn_File::WriteStream | ( | const void * | a_buf, | |
| ivd_FileBufSize_t | a_size | |||
| ) |
Writes a_size number of bytes from a_buf to current stream and return the number of bytes written.
Definition at line 433 of file cmn_File_LNX.cpp.
References ie_PRECONDITION, ivd_Error, log_FUNC_m, m_streamLeft, and WriteF().
Referenced by UnpackFile(), and ivd_FS_File::WriteStream().
00433 { 00434 00435 if (m_streamLeft < a_size) { 00436 log_FUNC_m(WriteStream); 00437 ostringstream sstr; 00438 sstr 00439 << "Can't write more than stream size. Got: " 00440 << a_size << ", left: " << m_streamLeft; 00441 00442 throw ivd_Error(ie_PRECONDITION, sstr.str()); 00443 } 00444 00445 // only data stream for now -> just write 00446 ivd_FileRetSize_t writeBytes = WriteF(a_buf, a_size); 00447 m_streamLeft -= writeBytes; 00448 return writeBytes; 00449 }


| bool cmn_File::CleanupWriteStream | ( | ) |
Releases memory and sets m_context to NULL after each restore operation.
Must be when performing sequential restores from the same stream.
Definition at line 453 of file cmn_File_LNX.cpp.
References log_FUNC_m.
Referenced by UnpackFile().
00453 { 00454 log_FUNC_m(CleanupWriteStream); 00455 00456 // This function is dummy on Linux. It completes the stream 00457 // on Windows. 00458 return(true); 00459 }

| void cmn_File::SetFileHandle | ( | const ivd_FileHandle_t | a_FileHandle, | |
| const UInt32_t | a_mode | |||
| ) |
Definition at line 1274 of file cmn_File_WIN32.cpp.
References CloseF(), ie_INVALID_ARG, ivd_Error, log_FUNC_m, m_fileHandle, m_opened, and m_openMode.
01275 { 01276 log_FUNC_m(SetFileHandle); 01277 01278 if (m_opened) { 01279 CloseF(); 01280 }; 01281 01282 if ((NULL == a_FileHandle) || (INVALID_HANDLE_VALUE == a_FileHandle)) 01283 { 01284 ostringstream sstr; 01285 sstr << "Invalid file handle=" << hex << a_FileHandle; 01286 throw ivd_Error(ie_INVALID_ARG, sstr.str(), true); 01287 }; 01288 01289 m_fileHandle = a_FileHandle; 01290 m_opened = true; 01291 m_openMode = a_mode; 01292 }

| void cmn_File::GetFileHandle | ( | ivd_FileHandle_t & | a_fileHandle, | |
| UInt32_t & | a_openMode | |||
| ) |
Definition at line 1296 of file cmn_File_WIN32.cpp.
References ie_INVALID_ARG, ivd_Error, log_FUNC_m, m_fileHandle, m_opened, and m_openMode.
01297 { 01298 log_FUNC_m(GetFileHandle); 01299 01300 if ((NULL == m_fileHandle) || (INVALID_HANDLE_VALUE == m_fileHandle) || (false == m_opened)) 01301 { 01302 ostringstream sstr; 01303 sstr << "File not open or invalid file handle=" << hex << a_fileHandle; 01304 throw ivd_Error(ie_INVALID_ARG, sstr.str(), true); 01305 }; 01306 01307 a_fileHandle = m_fileHandle; 01308 a_openMode = m_openMode; 01309 }
| void cmn_File::DuplicateFrom | ( | const cmn_File & | a_file | ) | [private] |
Definition at line 123 of file cmn_File_LNX.cpp.
References CreatePipe(), GetCurrentPosF(), m_createdPipe, m_dataStream, m_fileHandle, m_fullPath, m_lastError, m_localeFullPath, m_opened, m_openMode, m_streamLeft, OpenF(), and SeekF().
Referenced by cmn_File(), and operator=().
00123 { 00124 m_fullPath = a_file.m_fullPath; 00125 m_localeFullPath = a_file.m_localeFullPath; 00126 m_fileHandle = -1; 00127 00128 m_opened = false; 00129 m_createdPipe = false; 00130 m_openMode = 0; 00131 00132 m_lastError = a_file.m_lastError; 00133 00134 m_dataStream = a_file.m_dataStream; 00135 m_streamLeft = a_file.m_streamLeft; 00136 00137 if (a_file.m_opened) { 00138 OpenF(a_file.m_openMode); 00139 SeekF(a_file.GetCurrentPosF()); 00140 } 00141 if (a_file.m_createdPipe) { 00142 CreatePipe(); 00143 } 00144 }


cmn_File::log_CLASSID_m [private] |
Reimplemented in fio_CirFileTrans, fio_File, fio_JourFile, fio_PermDBinfoMgr, fio_RelFile, fio_RelFileTrans, fio_VarLenRFT, fsc_DataCollectorStorage, fsc_DataCollectorStorageCacheEl, fsc_MedVolume, fsc_MedVolWriter, fsc_MedVolReader, fsc_RedunCopyDataVolStorage, fsc_RedunCopyDataVolStorageWriter, fsc_RedunCopyDataVolStorageReader, fsc_ReorgScanDataVolStorage, fsc_ReorgScanReorgVolStorage, fsc_ReorgScanContentVolStorage, and cmn_FileTest.
Definition at line 321 of file cmn_File.h.
cmn_Path cmn_File::m_fullPath [private] |
Definition at line 323 of file cmn_File.h.
Referenced by CloseF(), CreatePipe(), DataSyncF(), DeleteF(), DuplicateFrom(), Exists(), GetCurrentPosF(), GetFileSystemID(), GetFileSystemSize(), GetStreamHeader(), OpenF(), ReadF(), SeekEndF(), SeekF(), SeekRelF(), SetFullPath(), SparseF(), StatF(), SymLink(), SyncF(), TruncF(), WriteF(), and ~cmn_File().
string cmn_File::m_localeFullPath [private] |
Definition at line 327 of file cmn_File.h.
Referenced by CreatePipe(), DuplicateFrom(), Exists(), GetFileSystemID(), GetFileSystemSize(), OpenF(), SetFullPath(), StatF(), SymLink(), and ~cmn_File().
ivd_FileHandle_t cmn_File::m_fileHandle [private] |
Definition at line 330 of file cmn_File.h.
Referenced by CloseF(), DataSyncF(), DuplicateFrom(), GetCurrentPosF(), GetFileHandle(), GetFileSystemID(), GetFileSystemSize(), GetStreamHeader(), OpenF(), ReadF(), SeekEndF(), SeekF(), SeekRelF(), SetFileHandle(), StatF(), SyncF(), TruncF(), and WriteF().
bool cmn_File::m_opened [private] |
Definition at line 331 of file cmn_File.h.
Referenced by CloseF(), DeleteF(), DuplicateFrom(), Exists(), GetFileHandle(), GetFileSystemID(), GetFileSystemSize(), GetStreamHeader(), OpenF(), SetFileHandle(), SetStreamHeader(), StatF(), and ~cmn_File().
bool cmn_File::m_createdPipe [private] |
Definition at line 332 of file cmn_File.h.
Referenced by CreatePipe(), DuplicateFrom(), and ~cmn_File().
UInt32_t cmn_File::m_openMode [private] |
Definition at line 333 of file cmn_File.h.
Referenced by DuplicateFrom(), GetFileHandle(), GetStreamHeader(), OpenF(), SetFileHandle(), and SetStreamHeader().
int cmn_File::m_lastError [mutable, private] |
Definition at line 335 of file cmn_File.h.
Referenced by CloseF(), CreatePipe(), DataSyncF(), DeleteF(), DuplicateFrom(), GetCurrentPosF(), GetFileSystemID(), GetFileSystemSize(), GetStreamHeader(), OpenF(), ReadF(), SeekEndF(), SeekF(), SeekRelF(), StatF(), SymLink(), SyncF(), TruncF(), WriteF(), and ~cmn_File().
bool cmn_File::m_dataStream [private] |
Definition at line 340 of file cmn_File.h.
Referenced by DuplicateFrom(), GetStreamHeader(), and SetStreamHeader().
ivd_FilePosition_t cmn_File::m_streamLeft [private] |
Definition at line 342 of file cmn_File.h.
Referenced by DuplicateFrom(), GetStreamHeader(), ReadStream(), SetStreamHeader(), and WriteStream().
ivd_FileSize_t cmn_File::m_fileSize [private] |
Definition at line 343 of file cmn_File.h.
1.5.6