From 81d8eda2419e7a23088a98cdfc52a305c9ceac0d Mon Sep 17 00:00:00 2001 From: Martin Ebourne Date: Wed, 7 Dec 2005 16:34:47 +0000 Subject: Merged martin/autoconf at r35 to trunk --- lib/raidfile/RaidFileRead.cpp | 26 +++++++++----------------- lib/raidfile/RaidFileUtil.cpp | 8 ++++---- lib/raidfile/RaidFileWrite.cpp | 22 +++++++++++----------- 3 files changed, 24 insertions(+), 32 deletions(-) (limited to 'lib/raidfile') diff --git a/lib/raidfile/RaidFileRead.cpp b/lib/raidfile/RaidFileRead.cpp index 6314ba90..d60936fc 100755 --- a/lib/raidfile/RaidFileRead.cpp +++ b/lib/raidfile/RaidFileRead.cpp @@ -29,10 +29,6 @@ #include "RaidFileController.h" #include "RaidFileUtil.h" -#ifdef PLATFORM_LINUX - #include "LinuxWorkaround.h" -#endif - #include "MemLeakFindOn.h" #define READ_NUMBER_DISCS_REQUIRED 3 @@ -715,7 +711,7 @@ int RaidFileRead_Raid::ReadRecovered(void *pBuffer, int NBytes) if(mLastBlockHasSize) { int sizeXorOffset = (mBlockSize - sizeof(FileSizeType)) + ((mStripe1Handle != -1)?mBlockSize:0); - *((FileSizeType*)(mRecoveryBuffer + sizeXorOffset)) ^= ntoh64(mFileSize); + *((FileSizeType*)(mRecoveryBuffer + sizeXorOffset)) ^= box_ntoh64(mFileSize); } } else @@ -1233,7 +1229,7 @@ std::auto_ptr RaidFileRead::Open(int SetNumber, const std::string if(parityIntegralPlusOffT) { // Wonderful! Have the value - length = ntoh64(parityLastData); + length = box_ntoh64(parityLastData); } else { @@ -1298,7 +1294,7 @@ std::auto_ptr RaidFileRead::Open(int SetNumber, const std::string // Lovely! length = stripe1LastData ^ parityLastData; // Convert to host byte order - length = ntoh64(length); + length = box_ntoh64(length); ASSERT(length <= (paritySize + stripe1Size)); // Mark is as having this to aid code later lastBlockHasSize = true; @@ -1531,10 +1527,6 @@ bool RaidFileRead::ReadDirectoryContents(int SetNumber, const std::string &rDirN struct dirent *en = 0; while((en = ::readdir(dirHandle)) != 0) { -#ifdef PLATFORM_LINUX - LinuxWorkaround_FinishDirentStruct(en, dn.c_str()); -#endif - if(en->d_name[0] == '.' && (en->d_name[1] == '\0' || (en->d_name[1] == '.' && en->d_name[2] == '\0'))) { @@ -1547,7 +1539,9 @@ bool RaidFileRead::ReadDirectoryContents(int SetNumber, const std::string &rDirN unsigned int countToAdd = 1; // stat the file to find out what type it is -#ifdef PLATFORM_SUNOS +#ifdef HAVE_VALID_DIRENT_D_TYPE + if(DirReadType == DirReadType_FilesOnly && en->d_type == DT_REG) +#else struct stat st; std::string fullName(dn + DIRECTORY_SEPARATOR + en->d_name); if(::lstat(fullName.c_str(), &st) != 0) @@ -1555,8 +1549,6 @@ bool RaidFileRead::ReadDirectoryContents(int SetNumber, const std::string &rDirN THROW_EXCEPTION(RaidFileException, OSError) } if(DirReadType == DirReadType_FilesOnly && (st.st_mode & S_IFDIR) == 0) -#else - if(DirReadType == DirReadType_FilesOnly && en->d_type == DT_REG) #endif { // File. Complex, need to check the extension @@ -1585,10 +1577,10 @@ bool RaidFileRead::ReadDirectoryContents(int SetNumber, const std::string &rDirN } } } -#ifdef PLATFORM_SUNOS - if(DirReadType == DirReadType_DirsOnly && (st.st_mode & S_IFDIR)) -#else +#ifdef HAVE_VALID_DIRENT_D_TYPE if(DirReadType == DirReadType_DirsOnly && en->d_type == DT_DIR) +#else + if(DirReadType == DirReadType_DirsOnly && (st.st_mode & S_IFDIR)) #endif { // Directory, and we want directories diff --git a/lib/raidfile/RaidFileUtil.cpp b/lib/raidfile/RaidFileUtil.cpp index c71bb2df..da23cef5 100755 --- a/lib/raidfile/RaidFileUtil.cpp +++ b/lib/raidfile/RaidFileUtil.cpp @@ -54,7 +54,7 @@ RaidFileUtil::ExistType RaidFileUtil::RaidFileExists(RaidFileDiscSet &rDiscSet, if(pRevisionID != 0) { (*pRevisionID) = FileModificationTime(st); -#ifdef PLATFORM_stat_SHORT_mtime +#ifndef HAVE_STRUCT_STAT_ST_MTIMESPEC // On linux, the time resolution is very low for modification times. // So add the size to it to give a bit more chance of it changing. // TODO: Make this better. @@ -71,7 +71,7 @@ RaidFileUtil::ExistType RaidFileUtil::RaidFileExists(RaidFileDiscSet &rDiscSet, int64_t revisionID = 0; int setSize = rDiscSet.size(); int rfCount = 0; -#ifdef PLATFORM_stat_SHORT_mtime +#ifndef HAVE_STRUCT_STAT_ST_MTIMESPEC // TODO: replace this with better linux revision ID detection int64_t revisionIDplus = 0; #endif @@ -92,7 +92,7 @@ RaidFileUtil::ExistType RaidFileUtil::RaidFileExists(RaidFileDiscSet &rDiscSet, { int64_t rid = FileModificationTime(st); if(rid > revisionID) revisionID = rid; -#ifdef PLATFORM_stat_SHORT_mtime +#ifndef HAVE_STRUCT_STAT_ST_MTIMESPEC revisionIDplus += st.st_size; #endif } @@ -101,7 +101,7 @@ RaidFileUtil::ExistType RaidFileUtil::RaidFileExists(RaidFileDiscSet &rDiscSet, if(pRevisionID != 0) { (*pRevisionID) = revisionID; -#ifdef PLATFORM_stat_SHORT_mtime +#ifndef HAVE_STRUCT_STAT_ST_MTIMESPEC (*pRevisionID) += revisionIDplus; #endif } diff --git a/lib/raidfile/RaidFileWrite.cpp b/lib/raidfile/RaidFileWrite.cpp index 987aa22c..8341943d 100755 --- a/lib/raidfile/RaidFileWrite.cpp +++ b/lib/raidfile/RaidFileWrite.cpp @@ -112,7 +112,10 @@ void RaidFileWrite::Open(bool AllowOverwrite) } // Get a lock on the write file -#ifdef PLATFORM_open_USE_fcntl +#ifdef HAVE_FLOCK + int errnoBlock = EWOULDBLOCK; + if(::flock(mOSFileHandle, LOCK_EX | LOCK_NB) != 0) +#else int errnoBlock = EAGAIN; struct flock desc; desc.l_type = F_WRLCK; @@ -120,9 +123,6 @@ void RaidFileWrite::Open(bool AllowOverwrite) desc.l_start = 0; desc.l_len = 0; if(::fcntl(mOSFileHandle, F_SETLK, &desc) != 0) -#else - int errnoBlock = EWOULDBLOCK; - if(::flock(mOSFileHandle, LOCK_EX | LOCK_NB) != 0) #endif { // Lock was not obtained. @@ -387,14 +387,14 @@ void RaidFileWrite::TransformToRaidStorage() // Then open them all for writing (in strict order) try { -#if defined(PLATFORM_open_USE_flock) || defined(PLATFORM_open_USE_fcntl) - FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL)> stripe1(stripe1FilenameW.c_str()); - FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL)> stripe2(stripe2FilenameW.c_str()); - FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL)> parity(parityFilenameW.c_str()); -#else +#if HAVE_DECL_O_EXLOCK FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL | O_EXLOCK)> stripe1(stripe1FilenameW.c_str()); FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL | O_EXLOCK)> stripe2(stripe2FilenameW.c_str()); FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL | O_EXLOCK)> parity(parityFilenameW.c_str()); +#else + FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL)> stripe1(stripe1FilenameW.c_str()); + FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL)> stripe2(stripe2FilenameW.c_str()); + FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL)> parity(parityFilenameW.c_str()); #endif // Then... read in data... @@ -461,7 +461,7 @@ void RaidFileWrite::TransformToRaidStorage() ASSERT(sizeof(RaidFileRead::FileSizeType) == (2*sizeof(unsigned int))); ASSERT(sizeof(RaidFileRead::FileSizeType) >= sizeof(off_t)); int sizePos = (blockSize/sizeof(unsigned int)) - 2; - RaidFileRead::FileSizeType sw = hton64(writeFileStat.st_size); + RaidFileRead::FileSizeType sw = box_hton64(writeFileStat.st_size); unsigned int *psize = (unsigned int *)(&sw); pparity[sizePos+0] = pstripe1[sizePos+0] ^ psize[0]; pparity[sizePos+1] = pstripe1[sizePos+1] ^ psize[1]; @@ -517,7 +517,7 @@ void RaidFileWrite::TransformToRaidStorage() if(sizeRecordRequired) { ASSERT(sizeof(writeFileStat.st_size) <= sizeof(RaidFileRead::FileSizeType)); - RaidFileRead::FileSizeType sw = hton64(writeFileStat.st_size); + RaidFileRead::FileSizeType sw = box_hton64(writeFileStat.st_size); ASSERT((::lseek(parity, 0, SEEK_CUR) % blockSize) == 0); if(::write(parity, &sw, sizeof(sw)) != sizeof(sw)) { -- cgit v1.2.3