diff options
Diffstat (limited to 'zen/file_id_def.h')
-rw-r--r-- | zen/file_id_def.h | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/zen/file_id_def.h b/zen/file_id_def.h index 24e45795..2880121c 100644 --- a/zen/file_id_def.h +++ b/zen/file_id_def.h @@ -20,12 +20,28 @@ namespace zen { #ifdef ZEN_WIN -typedef DWORD DeviceId; -typedef ULONGLONG FileIndex; +using VolumeId = DWORD; +using FileIndex = ULONGLONG; -typedef std::pair<DeviceId, FileIndex> FileId; //optional! (however, always set on Linux, and *generally* available on Windows) +#elif defined ZEN_LINUX || defined ZEN_MAC +namespace impl { typedef struct ::stat StatDummy; } //sigh... + +using VolumeId = decltype(impl::StatDummy::st_dev); +using FileIndex = decltype(impl::StatDummy::st_ino); +#endif + + +struct FileId //always available on Linux, and *generally* available on Windows) +{ + FileId() {} + FileId(VolumeId volId, FileIndex fIdx) : volumeId(volId), fileIndex(fIdx) {} + VolumeId volumeId = 0; + FileIndex fileIndex = 0; +}; +inline bool operator==(const FileId& lhs, const FileId& rhs) { return lhs.volumeId == rhs.volumeId && lhs.fileIndex == rhs.fileIndex; } +#ifdef ZEN_WIN inline FileId extractFileId(const BY_HANDLE_FILE_INFORMATION& fileInfo) { @@ -44,19 +60,11 @@ FileId extractFileId(DWORD volumeSerialNumber, ULONGLONG fileIndex) FileId(volumeSerialNumber, fileIndex) : FileId(); } -static_assert(sizeof(FileId().first ) == sizeof(BY_HANDLE_FILE_INFORMATION().dwVolumeSerialNumber), ""); -static_assert(sizeof(FileId().second) == sizeof(BY_HANDLE_FILE_INFORMATION().nFileIndexHigh) + sizeof(BY_HANDLE_FILE_INFORMATION().nFileIndexLow), ""); -static_assert(sizeof(FileId().second) == sizeof(ULARGE_INTEGER), ""); - +static_assert(sizeof(FileId().volumeId ) == sizeof(BY_HANDLE_FILE_INFORMATION().dwVolumeSerialNumber), ""); +static_assert(sizeof(FileId().fileIndex) == sizeof(BY_HANDLE_FILE_INFORMATION().nFileIndexHigh) + sizeof(BY_HANDLE_FILE_INFORMATION().nFileIndexLow), ""); +static_assert(sizeof(FileId().fileIndex) == sizeof(ULARGE_INTEGER), ""); #elif defined ZEN_LINUX || defined ZEN_MAC -namespace impl { typedef struct ::stat StatDummy; } //sigh... - -typedef decltype(impl::StatDummy::st_dev) DeviceId; -typedef decltype(impl::StatDummy::st_ino) FileIndex; - -typedef std::pair<DeviceId, FileIndex> FileId; - inline FileId extractFileId(const struct ::stat& fileInfo) { |