diff options
author | Chris Wilson <chris+github@qwirx.com> | 2009-03-21 18:48:19 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2009-03-21 18:48:19 +0000 |
commit | 4d33206efeeacf0a20d6daabb0f5bcfa6da78a39 (patch) | |
tree | 23283a52f7dead12a340f96a194582fc3974fb07 /lib | |
parent | a3d70474128afaab98bbd6fa343760eb61178302 (diff) |
Fix tests (hopefully) on Win32 for struct stat ino_t change from 16 to
64 bits.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/backupclient/BackupClientFileAttributes.cpp | 8 | ||||
-rw-r--r-- | lib/backupclient/BackupClientFileAttributes.h | 8 | ||||
-rw-r--r-- | lib/backupclient/BackupStoreFile.cpp | 8 | ||||
-rw-r--r-- | lib/backupclient/BackupStoreFileDiff.cpp | 4 | ||||
-rw-r--r-- | lib/backupstore/BackupStoreAccountDatabase.cpp | 4 | ||||
-rw-r--r-- | lib/common/BoxPlatform.h | 4 | ||||
-rw-r--r-- | lib/common/FileModificationTime.h | 6 | ||||
-rw-r--r-- | lib/common/FileStream.cpp | 4 | ||||
-rw-r--r-- | lib/common/Test.cpp | 16 | ||||
-rw-r--r-- | lib/common/Utils.cpp | 8 | ||||
-rw-r--r-- | lib/raidfile/RaidFileUtil.cpp | 14 | ||||
-rw-r--r-- | lib/server/Daemon.cpp | 4 | ||||
-rw-r--r-- | lib/win32/emu.cpp | 156 | ||||
-rw-r--r-- | lib/win32/emu.h | 66 |
14 files changed, 87 insertions, 223 deletions
diff --git a/lib/backupclient/BackupClientFileAttributes.cpp b/lib/backupclient/BackupClientFileAttributes.cpp index 446f132a..bb17d41f 100644 --- a/lib/backupclient/BackupClientFileAttributes.cpp +++ b/lib/backupclient/BackupClientFileAttributes.cpp @@ -302,8 +302,8 @@ void BackupClientFileAttributes::ReadAttributes(const char *Filename, bool ZeroM StreamableMemBlock *pnewAttr = 0; try { - struct stat st; - if(::lstat(Filename, &st) != 0) + EMU_STRUCT_STAT st; + if(EMU_LSTAT(Filename, &st) != 0) { BOX_LOG_SYS_ERROR("Failed to stat file: '" << Filename << "'"); @@ -395,7 +395,7 @@ void BackupClientFileAttributes::ReadAttributes(const char *Filename, bool ZeroM // Created: 2003/10/07 // // -------------------------------------------------------------------------- -void BackupClientFileAttributes::FillAttributes(StreamableMemBlock &outputBlock, const char *Filename, struct stat &st, bool ZeroModificationTimes) +void BackupClientFileAttributes::FillAttributes(StreamableMemBlock &outputBlock, const char *Filename, EMU_STRUCT_STAT &st, bool ZeroModificationTimes) { outputBlock.ResizeBlock(sizeof(attr_StreamFormat)); attr_StreamFormat *pattr = (attr_StreamFormat*)outputBlock.GetBuffer(); @@ -1037,7 +1037,7 @@ void BackupClientFileAttributes::SetAttributeHashSecret(const void *pSecret, int // Created: 25/4/04 // // -------------------------------------------------------------------------- -uint64_t BackupClientFileAttributes::GenerateAttributeHash(struct stat &st, const std::string &filename, const std::string &leafname) +uint64_t BackupClientFileAttributes::GenerateAttributeHash(EMU_STRUCT_STAT &st, const std::string &filename, const std::string &leafname) { if(sAttributeHashSecretLength == 0) { diff --git a/lib/backupclient/BackupClientFileAttributes.h b/lib/backupclient/BackupClientFileAttributes.h index fa56ff65..b32c14dd 100644 --- a/lib/backupclient/BackupClientFileAttributes.h +++ b/lib/backupclient/BackupClientFileAttributes.h @@ -15,7 +15,7 @@ #include "StreamableMemBlock.h" #include "BoxTime.h" -struct stat; +EMU_STRUCT_STAT; // declaration // -------------------------------------------------------------------------- // @@ -53,11 +53,13 @@ public: static void SetBlowfishKey(const void *pKey, int KeyLength); static void SetAttributeHashSecret(const void *pSecret, int SecretLength); - static uint64_t GenerateAttributeHash(struct stat &st, const std::string &filename, const std::string &leafname); + static uint64_t GenerateAttributeHash(EMU_STRUCT_STAT &st, const std::string &filename, const std::string &leafname); static void FillExtendedAttr(StreamableMemBlock &outputBlock, const char *Filename); private: - static void FillAttributes(StreamableMemBlock &outputBlock, const char *Filename, struct stat &st, bool ZeroModificationTimes); + static void FillAttributes(StreamableMemBlock &outputBlock, + const char *Filename, EMU_STRUCT_STAT &st, + bool ZeroModificationTimes); static void FillAttributesLink(StreamableMemBlock &outputBlock, const char *Filename, struct stat &st); void WriteExtendedAttr(const char *Filename, int xattrOffset) const; diff --git a/lib/backupclient/BackupStoreFile.cpp b/lib/backupclient/BackupStoreFile.cpp index 68040d29..27e12bc8 100644 --- a/lib/backupclient/BackupStoreFile.cpp +++ b/lib/backupclient/BackupStoreFile.cpp @@ -272,8 +272,8 @@ bool BackupStoreFile::VerifyEncodedFileFormat(IOStream &rFile, int64_t *pDiffFro void BackupStoreFile::DecodeFile(IOStream &rEncodedFile, const char *DecodedFilename, int Timeout, const BackupClientFileAttributes *pAlterativeAttr) { // Does file exist? - struct stat st; - if(::stat(DecodedFilename, &st) == 0) + EMU_STRUCT_STAT st; + if(EMU_STAT(DecodedFilename, &st) == 0) { THROW_EXCEPTION(BackupStoreException, OutputFileAlreadyExists) } @@ -1260,8 +1260,8 @@ bool BackupStoreFile::CompareFileContentsAgainstBlockIndex(const char *Filename, // is it a symlink? bool sourceIsSymlink = false; { - struct stat st; - if(::lstat(Filename, &st) == -1) + EMU_STRUCT_STAT st; + if(EMU_LSTAT(Filename, &st) == -1) { THROW_EXCEPTION(CommonException, OSFileError) } diff --git a/lib/backupclient/BackupStoreFileDiff.cpp b/lib/backupclient/BackupStoreFileDiff.cpp index 87cf7cff..e9da1ee7 100644 --- a/lib/backupclient/BackupStoreFileDiff.cpp +++ b/lib/backupclient/BackupStoreFileDiff.cpp @@ -130,8 +130,8 @@ std::auto_ptr<IOStream> BackupStoreFile::EncodeFileDiff { // Is it a symlink? { - struct stat st; - if(::lstat(Filename, &st) != 0) + EMU_STRUCT_STAT st; + if(EMU_LSTAT(Filename, &st) != 0) { THROW_EXCEPTION(CommonException, OSFileError) } diff --git a/lib/backupstore/BackupStoreAccountDatabase.cpp b/lib/backupstore/BackupStoreAccountDatabase.cpp index 91a6b758..46cab68f 100644 --- a/lib/backupstore/BackupStoreAccountDatabase.cpp +++ b/lib/backupstore/BackupStoreAccountDatabase.cpp @@ -208,8 +208,8 @@ void BackupStoreAccountDatabase::CheckUpToDate() const // -------------------------------------------------------------------------- box_time_t BackupStoreAccountDatabase::GetDBFileModificationTime() const { - struct stat st; - if(::stat(pImpl->mFilename.c_str(), &st) == -1) + EMU_STRUCT_STAT st; + if(EMU_STAT(pImpl->mFilename.c_str(), &st) == -1) { THROW_EXCEPTION(CommonException, OSFileError) } diff --git a/lib/common/BoxPlatform.h b/lib/common/BoxPlatform.h index 269ca85f..01bdbcf1 100644 --- a/lib/common/BoxPlatform.h +++ b/lib/common/BoxPlatform.h @@ -38,10 +38,6 @@ // must define this before importing <sys/types.h> #define __MSVCRT_VERSION__ 0x0601 #endif - - // stop sys/types.h from defining its own ino_t as short, - // because we want a bigger one :) - #define _INO_T_ #endif #ifdef HAVE_SYS_TYPES_H diff --git a/lib/common/FileModificationTime.h b/lib/common/FileModificationTime.h index c64ca848..5f13c015 100644 --- a/lib/common/FileModificationTime.h +++ b/lib/common/FileModificationTime.h @@ -14,7 +14,7 @@ #include "BoxTime.h" -inline box_time_t FileModificationTime(struct stat &st) +inline box_time_t FileModificationTime(EMU_STRUCT_STAT &st) { #ifndef HAVE_STRUCT_STAT_ST_MTIMESPEC box_time_t datamodified = ((int64_t)st.st_mtime) * (MICRO_SEC_IN_SEC_LL); @@ -26,7 +26,7 @@ inline box_time_t FileModificationTime(struct stat &st) return datamodified; } -inline box_time_t FileAttrModificationTime(struct stat &st) +inline box_time_t FileAttrModificationTime(EMU_STRUCT_STAT &st) { box_time_t statusmodified = #ifdef HAVE_STRUCT_STAT_ST_MTIMESPEC @@ -45,7 +45,7 @@ inline box_time_t FileAttrModificationTime(struct stat &st) return statusmodified; } -inline box_time_t FileModificationTimeMaxModAndAttr(struct stat &st) +inline box_time_t FileModificationTimeMaxModAndAttr(EMU_STRUCT_STAT &st) { #ifndef HAVE_STRUCT_STAT_ST_MTIMESPEC box_time_t datamodified = ((int64_t)st.st_mtime) * (MICRO_SEC_IN_SEC_LL); diff --git a/lib/common/FileStream.cpp b/lib/common/FileStream.cpp index 09296d79..d6a3c5da 100644 --- a/lib/common/FileStream.cpp +++ b/lib/common/FileStream.cpp @@ -224,8 +224,8 @@ int FileStream::Read(void *pBuffer, int NBytes, int Timeout) // -------------------------------------------------------------------------- IOStream::pos_type FileStream::BytesLeftToRead() { - struct stat st; - if(::fstat(mOSFileHandle, &st) != 0) + EMU_STRUCT_STAT st; + if(EMU_FSTAT(mOSFileHandle, &st) != 0) { THROW_EXCEPTION(CommonException, OSFileError) } diff --git a/lib/common/Test.cpp b/lib/common/Test.cpp index 7cf4859b..04d778c1 100644 --- a/lib/common/Test.cpp +++ b/lib/common/Test.cpp @@ -25,28 +25,28 @@ bool TestFileExists(const char *Filename) { - struct stat st; - return ::stat(Filename, &st) == 0 && (st.st_mode & S_IFDIR) == 0; + EMU_STRUCT_STAT st; + return EMU_STAT(Filename, &st) == 0 && (st.st_mode & S_IFDIR) == 0; } bool TestFileNotEmpty(const char *Filename) { - struct stat st; - return ::stat(Filename, &st) == 0 && (st.st_mode & S_IFDIR) == 0 && + EMU_STRUCT_STAT st; + return EMU_STAT(Filename, &st) == 0 && (st.st_mode & S_IFDIR) == 0 && st.st_size > 0; } bool TestDirExists(const char *Filename) { - struct stat st; - return ::stat(Filename, &st) == 0 && (st.st_mode & S_IFDIR) == S_IFDIR; + EMU_STRUCT_STAT st; + return EMU_STAT(Filename, &st) == 0 && (st.st_mode & S_IFDIR) == S_IFDIR; } // -1 if doesn't exist int TestGetFileSize(const char *Filename) { - struct stat st; - if(::stat(Filename, &st) == 0) + EMU_STRUCT_STAT st; + if(EMU_STAT(Filename, &st) == 0) { return st.st_size; } diff --git a/lib/common/Utils.cpp b/lib/common/Utils.cpp index 408eaa57..f45ed26b 100644 --- a/lib/common/Utils.cpp +++ b/lib/common/Utils.cpp @@ -163,8 +163,8 @@ void DumpStackBacktrace() // -------------------------------------------------------------------------- bool FileExists(const char *Filename, int64_t *pFileSize, bool TreatLinksAsNotExisting) { - struct stat st; - if(::lstat(Filename, &st) != 0) + EMU_STRUCT_STAT st; + if(EMU_LSTAT(Filename, &st) != 0) { if(errno == ENOENT) { @@ -208,8 +208,8 @@ bool FileExists(const char *Filename, int64_t *pFileSize, bool TreatLinksAsNotEx // -------------------------------------------------------------------------- int ObjectExists(const std::string& rFilename) { - struct stat st; - if(::stat(rFilename.c_str(), &st) != 0) + EMU_STRUCT_STAT st; + if(EMU_STAT(rFilename.c_str(), &st) != 0) { if(errno == ENOENT) { diff --git a/lib/raidfile/RaidFileUtil.cpp b/lib/raidfile/RaidFileUtil.cpp index 079d14d0..7c6299ec 100644 --- a/lib/raidfile/RaidFileUtil.cpp +++ b/lib/raidfile/RaidFileUtil.cpp @@ -57,7 +57,12 @@ RaidFileUtil::ExistType RaidFileUtil::RaidFileExists(RaidFileDiscSet &rDiscSet, // Get unique ID if(pRevisionID != 0) { - (*pRevisionID) = FileModificationTime(st); + #ifdef WIN32 + *pRevisionID = st.st_mtime; + #else + *pRevisionID = FileModificationTime(st); + #endif + #ifdef BOX_RELEASE_BUILD // The resolution of timestamps may be very // low, e.g. 1 second. So add the size to it @@ -98,7 +103,12 @@ RaidFileUtil::ExistType RaidFileUtil::RaidFileExists(RaidFileDiscSet &rDiscSet, // Revision ID if(pRevisionID != 0) { - int64_t rid = FileModificationTime(st); + #ifdef WIN32 + int64_t rid = st.st_mtime; + #else + int64_t rid = FileModificationTime(st); + #endif + if(rid > revisionID) revisionID = rid; revisionIDplus += st.st_size; } diff --git a/lib/server/Daemon.cpp b/lib/server/Daemon.cpp index 3c21f6f9..f8082bad 100644 --- a/lib/server/Daemon.cpp +++ b/lib/server/Daemon.cpp @@ -962,9 +962,9 @@ void Daemon::SetProcessTitle(const char *format, ...) box_time_t Daemon::GetConfigFileModifiedTime() const { - struct stat st; + EMU_STRUCT_STAT st; - if(::stat(GetConfigFileName().c_str(), &st) != 0) + if(EMU_STAT(GetConfigFileName().c_str(), &st) != 0) { if (errno == ENOENT) { diff --git a/lib/win32/emu.cpp b/lib/win32/emu.cpp index 189bf587..ad8c3041 100644 --- a/lib/win32/emu.cpp +++ b/lib/win32/emu.cpp @@ -21,149 +21,9 @@ #include <sstream> // message resource definitions for syslog() - #include "messages.h" -// our implementation for a timer, based on a -// simple thread which sleeps for a period of time - -static bool gTimerInitialised = false; -static bool gFinishTimer; -static CRITICAL_SECTION gLock; - DWORD winerrno; - -typedef struct -{ - int countDown; - int interval; -} -Timer_t; - -std::list<Timer_t> gTimerList; -static void (__cdecl *gTimerFunc) (int) = NULL; - -int setitimer(int type, struct itimerval *timeout, void *arg) -{ - assert(gTimerInitialised); - - if (ITIMER_REAL != type) - { - errno = ENOSYS; - return -1; - } - - EnterCriticalSection(&gLock); - - // we only need seconds for the mo! - if (timeout->it_value.tv_sec == 0 && - timeout->it_value.tv_usec == 0) - { - gTimerList.clear(); - } - else - { - Timer_t ourTimer; - ourTimer.countDown = timeout->it_value.tv_sec; - ourTimer.interval = timeout->it_interval.tv_sec; - gTimerList.push_back(ourTimer); - } - - LeaveCriticalSection(&gLock); - - // indicate success - return 0; -} - -static unsigned int WINAPI RunTimer(LPVOID lpParameter) -{ - gFinishTimer = false; - - while (!gFinishTimer) - { - std::list<Timer_t>::iterator it; - EnterCriticalSection(&gLock); - - for (it = gTimerList.begin(); it != gTimerList.end(); it++) - { - Timer_t& rTimer(*it); - - rTimer.countDown --; - if (rTimer.countDown == 0) - { - if (gTimerFunc != NULL) - { - gTimerFunc(0); - } - if (rTimer.interval) - { - rTimer.countDown = rTimer.interval; - } - else - { - // mark for deletion - rTimer.countDown = -1; - } - } - } - - for (it = gTimerList.begin(); it != gTimerList.end(); it++) - { - Timer_t& rTimer(*it); - - if (rTimer.countDown == -1) - { - gTimerList.erase(it); - - // the iterator is now invalid, so restart search - it = gTimerList.begin(); - - // if the list is now empty, don't try to increment - // the iterator again - if (it == gTimerList.end()) break; - } - } - - LeaveCriticalSection(&gLock); - // we only need to have a 1 second resolution - Sleep(1000); - } - - return 0; -} - -int SetTimerHandler(void (__cdecl *func ) (int)) -{ - gTimerFunc = func; - return 0; -} - -void InitTimer(void) -{ - assert(!gTimerInitialised); - - InitializeCriticalSection(&gLock); - - // create our thread - HANDLE ourThread = (HANDLE)_beginthreadex(NULL, 0, RunTimer, 0, - CREATE_SUSPENDED, NULL); - SetThreadPriority(ourThread, THREAD_PRIORITY_LOWEST); - ResumeThread(ourThread); - - gTimerInitialised = true; -} - -void FiniTimer(void) -{ - assert(gTimerInitialised); - gFinishTimer = true; - EnterCriticalSection(&gLock); - DeleteCriticalSection(&gLock); - gTimerInitialised = false; -} - -//Our constants we need to keep track of -//globals struct passwd gTempPasswd; bool EnableBackupRights() @@ -715,11 +575,13 @@ HANDLE openfile(const char *pFileName, int flags, int mode) // // Function // Name: emu_fstat -// Purpose: replacement for fstat supply a windows handle +// Purpose: replacement for fstat. Supply a windows handle. +// Returns a struct emu_stat to have room for 64-bit +// file identifier in st_ino (mingw allows only 16!) // Created: 25th October 2004 // // -------------------------------------------------------------------------- -int emu_fstat(HANDLE hdir, struct stat * st) +int emu_fstat(HANDLE hdir, struct emu_stat * st) { if (hdir == INVALID_HANDLE_VALUE) { @@ -751,7 +613,7 @@ int emu_fstat(HANDLE hdir, struct stat * st) ULARGE_INTEGER conv; conv.HighPart = fi.nFileIndexHigh; conv.LowPart = fi.nFileIndexLow; - st->st_ino = (_ino_t)conv.QuadPart; + st->st_ino = conv.QuadPart; // get the time information st->st_ctime = ConvertFileTimeToTime_t(&fi.ftCreationTime); @@ -898,12 +760,14 @@ HANDLE OpenFileByNameUtf8(const char* pFileName, DWORD flags) // // Function // Name: emu_stat -// Purpose: replacement for the lstat and stat functions, -// works with unicode filenames supplied in utf8 format +// Purpose: replacement for the lstat and stat functions. +// Works with unicode filenames supplied in utf8. +// Returns a struct emu_stat to have room for 64-bit +// file identifier in st_ino (mingw allows only 16!) // Created: 25th October 2004 // // -------------------------------------------------------------------------- -int emu_stat(const char * pName, struct stat * st) +int emu_stat(const char * pName, struct emu_stat * st) { HANDLE handle = OpenFileByNameUtf8(pName, FILE_READ_ATTRIBUTES | FILE_READ_EA); diff --git a/lib/win32/emu.h b/lib/win32/emu.h index 67921264..b29c901c 100644 --- a/lib/win32/emu.h +++ b/lib/win32/emu.h @@ -1,5 +1,17 @@ // emulates unix syscalls to win32 functions +#ifdef WIN32 + #define EMU_STRUCT_STAT struct emu_stat + #define EMU_STAT emu_stat + #define EMU_FSTAT emu_fstat + #define EMU_LSTAT emu_stat +#else + #define EMU_STRUCT_STAT struct stat + #define EMU_STAT ::stat + #define EMU_FSTAT ::fstat + #define EMU_LSTAT ::lstat +#endif + #if ! defined EMU_INCLUDE && defined WIN32 #define EMU_INCLUDE @@ -25,17 +37,9 @@ #ifdef __MINGW32__ typedef uint32_t u_int32_t; - typedef uint64_t _ino_t; - typedef _ino_t ino_t; - #define _INO_T_ #else typedef unsigned int mode_t; typedef unsigned int pid_t; - - // must define _INO_T_DEFINED before including <sys/types.h> - // to replace it with our own. - typedef u_int64_t _ino_t; - #define _INO_T_DEFINED #endif // set up to include the necessary parts of Windows headers @@ -81,11 +85,6 @@ #define fileno(struct_file) _fileno(struct_file) #endif -int SetTimerHandler(void (__cdecl *func ) (int)); -int setitimer(int type, struct itimerval *timeout, void *arg); -void InitTimer(void); -void FiniTimer(void); - struct passwd { char *pw_name; char *pw_passwd; @@ -187,13 +186,6 @@ inline int geteuid(void) #define timespec timeval -//not available in win32 -struct itimerval -{ - timeval it_interval; - timeval it_value; -}; - //win32 deals in usec not nsec - so need to ensure this follows through #define tv_nsec tv_usec @@ -313,27 +305,19 @@ struct statfs TCHAR f_mntonname[MAX_PATH]; }; -#if 0 -// I think this should get us going -// Although there is a warning about -// mount points in win32 can now exists - which means inode number can be -// duplicated, so potential of a problem - perhaps this needs to be -// implemented with a little more thought... TODO - -struct stat { - //_dev_t st_dev; - u_int64_t st_ino; +struct emu_stat { + int st_dev; + uint64_t st_ino; DWORD st_mode; short st_nlink; short st_uid; short st_gid; //_dev_t st_rdev; - u_int64_t st_size; + uint64_t st_size; time_t st_atime; time_t st_mtime; time_t st_ctime; }; -#endif // 0 // need this for conversions time_t ConvertFileTimeToTime_t(FILETIME *fileTime); @@ -342,8 +326,8 @@ bool ConvertTime_tToFileTime(const time_t from, FILETIME *pTo); int emu_chdir (const char* pDirName); int emu_mkdir (const char* pPathName); int emu_unlink (const char* pFileName); -int emu_fstat (HANDLE file, struct stat* st); -int emu_stat (const char* pName, struct stat* st); +int emu_fstat (HANDLE file, struct emu_stat* st); +int emu_stat (const char* pName, struct emu_stat* st); int emu_utimes (const char* pName, const struct timeval[]); int emu_chmod (const char* pName, mode_t mode); char* emu_getcwd (char* pBuffer, int BufSize); @@ -352,14 +336,22 @@ int emu_rename (const char* pOldName, const char* pNewName); #define chdir(directory) emu_chdir (directory) #define mkdir(path, mode) emu_mkdir (path) #define unlink(file) emu_unlink (file) -#define stat(filename, struct) emu_stat (filename, struct) -#define lstat(filename, struct) emu_stat (filename, struct) -#define fstat(handle, struct) emu_fstat (handle, struct) #define utimes(buffer, times) emu_utimes (buffer, times) #define chmod(file, mode) emu_chmod (file, mode) #define getcwd(buffer, size) emu_getcwd (buffer, size) #define rename(oldname, newname) emu_rename (oldname, newname) +// Not safe to replace stat/fstat/lstat on mingw at least, as struct stat +// has a 16-bit st_ino and we need a 64-bit one. +// +// #define stat(filename, struct) emu_stat (filename, struct) +// #define lstat(filename, struct) emu_stat (filename, struct) +// #define fstat(handle, struct) emu_fstat (handle, struct) +// +// But lstat doesn't exist on Windows, so we have to provide something: + +#define lstat(filename, struct) stat(filename, struct) + int statfs(const char * name, struct statfs * s); int poll(struct pollfd *ufds, unsigned long nfds, int timeout); |