blob: 7e729eb19a2703734c012cdc2f987246d5e95d4e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
// **************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
// * GNU General Public License: http://www.gnu.org/licenses/gpl.html *
// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) *
// **************************************************************************
#ifndef FILE_ID_INTERNAL_HEADER_013287632486321493
#define FILE_ID_INTERNAL_HEADER_013287632486321493
#include <utility>
#include "assert_static.h"
#ifdef FFS_WIN
#include "win.h" //includes "windows.h"
#elif defined FFS_LINUX
#include <sys/stat.h>
#endif
namespace zen
{
#ifdef FFS_WIN
typedef std::pair<decltype(BY_HANDLE_FILE_INFORMATION().dwVolumeSerialNumber), decltype(ULARGE_INTEGER().QuadPart)> FileId; //(volume serial number, file ID)
inline
FileId extractFileID(const BY_HANDLE_FILE_INFORMATION& fileInfo)
{
ULARGE_INTEGER uint = {};
uint.HighPart = fileInfo.nFileIndexHigh;
uint.LowPart = fileInfo.nFileIndexLow;
return fileInfo.dwVolumeSerialNumber != 0 && uint.QuadPart != 0 ?
FileId(fileInfo.dwVolumeSerialNumber, uint.QuadPart) : FileId();
}
inline
FileId extractFileID(DWORD dwVolumeSerialNumber, ULARGE_INTEGER fileId)
{
return dwVolumeSerialNumber != 0 && fileId.QuadPart != 0 ?
FileId(dwVolumeSerialNumber, fileId.QuadPart) : FileId();
}
namespace impl
{
inline
void validate(const FileId& id, const BY_HANDLE_FILE_INFORMATION& fileInfo)
{
assert_static(sizeof(id.second) == sizeof(fileInfo.nFileIndexHigh) + sizeof(fileInfo.nFileIndexLow));
assert_static(sizeof(id.first ) == sizeof(DWORD));
assert_static(sizeof(id.second) == sizeof(ULARGE_INTEGER));
}
}
#elif defined FFS_LINUX
namespace impl { typedef struct ::stat StatDummy; } //sigh...
typedef std::pair<decltype(impl::StatDummy::st_dev), decltype(impl::StatDummy::st_ino)> FileId; //(device id, inode)
inline
FileId extractFileID(const struct stat& fileInfo)
{
return fileInfo.st_dev != 0 && fileInfo.st_ino != 0 ?
FileId(fileInfo.st_dev, fileInfo.st_ino) : FileId();
}
#endif
}
#endif //FILE_ID_INTERNAL_HEADER_013287632486321493
|