VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/lzma/LzFindMt.h
blob: 660b7244d19f90ea1c98220b39d6022b8fa2bbcd (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* LzFindMt.h -- multithreaded Match finder for LZ algorithms
2021-07-12 : Igor Pavlov : Public domain */

#ifndef __LZ_FIND_MT_H
#define __LZ_FIND_MT_H

#include "LzFind.h"
#include "Threads.h"

EXTERN_C_BEGIN

typedef struct _CMtSync
{
  UInt32 numProcessedBlocks;
  CThread thread;
  UInt64 affinity;

  BoolInt wasCreated;
  BoolInt needStart;
  BoolInt csWasInitialized;
  BoolInt csWasEntered;

  BoolInt exit;
  BoolInt stopWriting;

  CAutoResetEvent canStart;
  CAutoResetEvent wasStopped;
  CSemaphore freeSemaphore;
  CSemaphore filledSemaphore;
  CCriticalSection cs;
  // UInt32 numBlocks_Sent;
} CMtSync;

typedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances);

/* kMtCacheLineDummy must be >= size_of_CPU_cache_line */
#define kMtCacheLineDummy 128

typedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos,
  UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc);

typedef struct _CMatchFinderMt
{
  /* LZ */
  const Byte *pointerToCurPos;
  UInt32 *btBuf;
  const UInt32 *btBufPos;
  const UInt32 *btBufPosLimit;
  UInt32 lzPos;
  UInt32 btNumAvailBytes;

  UInt32 *hash;
  UInt32 fixedHashSize;
  // UInt32 hash4Mask;
  UInt32 historySize;
  const UInt32 *crc;

  Mf_Mix_Matches MixMatchesFunc;
  UInt32 failure_LZ_BT; // failure in BT transfered to LZ
  // UInt32 failure_LZ_LZ; // failure in LZ tables
  UInt32 failureBuf[1];
  // UInt32 crc[256];

  /* LZ + BT */
  CMtSync btSync;
  Byte btDummy[kMtCacheLineDummy];

  /* BT */
  UInt32 *hashBuf;
  UInt32 hashBufPos;
  UInt32 hashBufPosLimit;
  UInt32 hashNumAvail;
  UInt32 failure_BT;


  CLzRef *son;
  UInt32 matchMaxLen;
  UInt32 numHashBytes;
  UInt32 pos;
  const Byte *buffer;
  UInt32 cyclicBufferPos;
  UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */
  UInt32 cutValue;

  /* BT + Hash */
  CMtSync hashSync;
  /* Byte hashDummy[kMtCacheLineDummy]; */
  
  /* Hash */
  Mf_GetHeads GetHeadsFunc;
  CMatchFinder *MatchFinder;
  // CMatchFinder MatchFinder;
} CMatchFinderMt;

// only for Mt part
void MatchFinderMt_Construct(CMatchFinderMt *p);
void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAllocPtr alloc);

SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
    UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAllocPtr alloc);
void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder2 *vTable);

/* call MatchFinderMt_InitMt() before IMatchFinder::Init() */
SRes MatchFinderMt_InitMt(CMatchFinderMt *p);
void MatchFinderMt_ReleaseStream(CMatchFinderMt *p);

EXTERN_C_END

#endif
">, args); break; } catch (ExecutedProcessFailed&) { if (t > 5) throw; Thread::Sleep (200); } } } HostDeviceList CoreFreeBSD::GetHostDevices (bool pathListOnly) const { HostDeviceList devices; #ifdef TC_MACOSX const string busType = "rdisk"; #else foreach (const string &busType, StringConverter::Split ("ad da")) #endif { for (int devNumber = 0; devNumber < 64; devNumber++) { stringstream devPath; devPath << "/dev/" << busType << devNumber; if (FilesystemPath (devPath.str()).IsBlockDevice() || FilesystemPath (devPath.str()).IsCharacterDevice()) { make_shared_auto (HostDevice, device); device->Path = devPath.str(); if (!pathListOnly) { try { device->Size = GetDeviceSize (device->Path); } catch (...) { device->Size = 0; } device->MountPoint = GetDeviceMountPoint (device->Path); device->SystemNumber = 0; } devices.push_back (device); for (int partNumber = 1; partNumber < 32; partNumber++) { #ifdef TC_MACOSX const string partLetter = ""; #else foreach (const string &partLetter, StringConverter::Split (",a,b,c,d,e,f,g,h", ",", true)) #endif { stringstream partPath; partPath << devPath.str() << "s" << partNumber << partLetter; if (FilesystemPath (partPath.str()).IsBlockDevice() || FilesystemPath (partPath.str()).IsCharacterDevice()) { make_shared_auto (HostDevice, partition); partition->Path = partPath.str(); if (!pathListOnly) { try { partition->Size = GetDeviceSize (partition->Path); } catch (...) { partition->Size = 0; } partition->MountPoint = GetDeviceMountPoint (partition->Path); partition->SystemNumber = 0; } device->Partitions.push_back (partition); } } } } } } return devices; } MountedFilesystemList CoreFreeBSD::GetMountedFilesystems (const DevicePath &devicePath, const DirectoryPath &mountPoint) const { static Mutex mutex; ScopeLock sl (mutex); struct statfs *sysMountList; int count = getmntinfo (&sysMountList, MNT_NOWAIT); throw_sys_if (count == 0); MountedFilesystemList mountedFilesystems; for (int i = 0; i < count; i++) { make_shared_auto (MountedFilesystem, mf); if (sysMountList[i].f_mntfromname[0]) mf->Device = DevicePath (sysMountList[i].f_mntfromname); else continue; if (sysMountList[i].f_mntonname[0]) mf->MountPoint = DirectoryPath (sysMountList[i].f_mntonname); mf->Type = sysMountList[i].f_fstypename; if ((devicePath.IsEmpty() || devicePath == mf->Device) && (mountPoint.IsEmpty() || mountPoint == mf->MountPoint)) mountedFilesystems.push_back (mf); } return mountedFilesystems; } void CoreFreeBSD::MountFilesystem (const DevicePath &devicePath, const DirectoryPath &mountPoint, const string &filesystemType, bool readOnly, const string &systemMountOptions) const { try { // Try to mount FAT by default as mount is unable to probe filesystem type on BSD CoreUnix::MountFilesystem (devicePath, mountPoint, filesystemType.empty() ? "msdos" : filesystemType, readOnly, systemMountOptions); } catch (ExecutedProcessFailed&) { if (!filesystemType.empty()) throw; CoreUnix::MountFilesystem (devicePath, mountPoint, filesystemType, readOnly, systemMountOptions); } } #ifdef TC_FREEBSD auto_ptr <CoreBase> Core (new CoreServiceProxy <CoreFreeBSD>); auto_ptr <CoreBase> CoreDirect (new CoreFreeBSD); #endif }