Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
7.4 KiB

  1. #ifndef _BITBUCK_INC
  2. #define _BITBUCK_INC
  3. #include "ids.h"
  4. #include "undo.h"
  5. // whacky #defines
  6. #define DELETEMAX 100000
  7. #define MAX_BITBUCKETS 27
  8. #define MAX_DRIVES 26
  9. #define OPENFILERETRYTIME 500
  10. #define OPENFILERETRYCOUNT 10
  11. #define SERVERDRIVE 26
  12. #define MAX_EMPTY_FILES 100 // if we have MAX_EMPTY_FILES or more then we use the generic "do you want to empty" message.
  13. #define TF_BITBUCKET 0x10000000
  14. // #define TF_BITBUCKET TF_ERROR
  15. //
  16. // NOTE: The on-disk format of the recycle bin should never have to change again.
  17. // If you think you need to change it, then you are wrong.
  18. //
  19. #define BITBUCKET_WIN95_VERSION 0 // (info) Ansi Win95, OSR2 wastebasket
  20. #define BITBUCKET_NT4_VERSION 2 // (info) Unicode NT4 wastebasket
  21. #define BITBUCKET_WIN98IE4INT_VERSION 4 // (info2) win9x+IE4 integrated, and win98 wastebasket
  22. #define BITBUCKET_FINAL_VERSION 5 // (info2) NT4+IE4 integraged, win2k, millenium, every future os wastebasket
  23. #define OPENBBINFO_READ 0x00000000
  24. #define OPENBBINFO_WRITE 0x00000001
  25. #define OPENBBINFO_CREATE 0x00000003
  26. #define IsDeletedEntry(pbbde) (! (((BBDATAENTRYA*)pbbde)->szOriginal[0]) )
  27. #define MarkEntryDeleted(pbbde) ((BBDATAENTRYA*)pbbde)->szOriginal[0] = '\0';
  28. // this is the old (win95) data header. it's maintained in the info file
  29. // but only used for verification. for current stuff look at the driveinfo,
  30. // which is kept in the registry.
  31. typedef struct {
  32. int idVersion;
  33. int cFiles; // the # of items in this drive's recycle bin
  34. int cCurrent; // the current file number.
  35. UINT cbDataEntrySize; // size of each entry
  36. DWORD dwSize; // total size of this recycle bin drive
  37. } BBDATAHEADER;
  38. // The bitbucket datafile (INFO on win95, INFO2 on IE4/NT5, etc...) format is as follows:
  39. //
  40. // (binary writes)
  41. //
  42. // BBDATAHEADER // header
  43. // BBDATAENTRY[X] // array of BBDATAENTRYies
  44. //
  45. typedef struct {
  46. CHAR szOriginal[MAX_PATH]; // original filename (if szOriginal[0] is 0, then it's a deleted entry)
  47. int iIndex; // index (key to name)
  48. int idDrive; // which drive bucket it's currently in
  49. FILETIME ft;
  50. DWORD dwSize;
  51. // shouldn't need file attributes because we did a move file
  52. // which should have preserved them.
  53. } BBDATAENTRYA, *LPBBDATAENTRYA;
  54. typedef struct {
  55. CHAR szShortName[MAX_PATH]; // original filename, shortened (if szOriginal[0] is 0, then it's a deleted entry)
  56. int iIndex; // index (key to name)
  57. int idDrive; // which drive bucket it's currently in
  58. FILETIME ft;
  59. DWORD dwSize;
  60. WCHAR szOriginal[MAX_PATH]; // original filename
  61. } BBDATAENTRYW, *LPBBDATAENTRYW;
  62. typedef BBDATAENTRYA UNALIGNED *PUBBDATAENTRYA;
  63. // On NT5 we are finally going to have cross-process syncrhonization to
  64. // the Recycle Bin. We replaced the global LPBBDRIVEINFO array with an
  65. // array of the following structures:
  66. typedef struct {
  67. BOOL fInited; // is this particular BBSYNCOBJECT fully inited (needed when we race to create it)
  68. HANDLE hgcNextFileNum; // a global counter that garuntees unique deleted file names
  69. HANDLE hgcDirtyCount; // a global counter to tell us if we need to re-read the bitbucket settings from the registry (percent, max size, etc)
  70. LONG lCurrentDirtyCount; // out current dirty count; we compare this to hgcDirtyCount to see if we need to update the settings from the registry
  71. HKEY hkey; // HKLM reg key, under which we store the settings for this specific bucket (iPercent and fNukeOnDelete).
  72. HKEY hkeyPerUser; // HKCU reg key, under which we have volital reg values indicatiog if there is a need to purge or compact this bucket
  73. BOOL fIsUnicode; // is this a bitbucket on a drive whose INFO2 file uses BBDATAENTRYW structs?
  74. int iPercent; // % of the drive to use for the bitbucket
  75. DWORD cbMaxSize; // maximum size of bitbucket (in bytes), NOTE: we use a dword because the biggest the BB can ever grow to is 4 gigabytes.
  76. DWORD dwClusterSize; // cluster size of this volume, needed to round all the file sizes
  77. ULONGLONG qwDiskSize; // total size of the disk - takes into account quotas on NTFS
  78. BOOL fNukeOnDelete; // I love the smell of napalm in the morning.
  79. LPITEMIDLIST pidl; // pidl = bitbucket dir for this drive
  80. int cchBBDir; // # of characters that makes up the bitbucket directory.
  81. } BBSYNCOBJECT;
  82. #define c_szInfo2 TEXT("INFO2") // version 2 of the db file (used in IE4, win98, NT5, ...)
  83. #define c_szInfo TEXT("INFO") // version 1 of the db file (used in win95, osr2, NT4)
  84. #define c_szDStarDotStar TEXT("D*.*")
  85. // globals
  86. EXTERN_C BBSYNCOBJECT *g_pBitBucket[MAX_BITBUCKETS];
  87. EXTERN_C HKEY g_hkBitBucket;
  88. EXTERN_C HANDLE g_hgcNumDeleters;
  89. // prototypes by bitbuck.c, bbckfldr.cpp
  90. STDAPI_(BOOL) InitBBGlobals();
  91. STDAPI_(void) BitBucket_Terminate();
  92. STDAPI_(BOOL) IsBitBucketableDrive(int idDrive);
  93. STDAPI_(int) DriveIDFromBBPath(LPCTSTR pszPath);
  94. STDAPI_(void) UpdateIcon(BOOL fFull);
  95. STDAPI_(void) NukeFileInfoBeforePoint(HANDLE hfile, LPBBDATAENTRYW pbbdew, DWORD dwDataEntrySize);
  96. STDAPI_(BOOL) ReadNextDataEntry(HANDLE hfile, LPBBDATAENTRYW pbbde, BOOL fSkipDeleted, int idDrive);
  97. STDAPI_(void) CloseBBInfoFile(HANDLE hFile, int idDrive);
  98. STDAPI_(HANDLE) OpenBBInfoFile(int idDrive, DWORD dwFlags, int iRetryCount);
  99. STDAPI_(int) BBPathToIndex(LPCTSTR pszPath);
  100. STDAPI BBFileNameToInfo(LPCTSTR pszFileName, int *pidDrive, int *piIndex);
  101. STDAPI_(void) GetDeletedFileName(LPTSTR pszFileName, const BBDATAENTRYW *pbbdew);
  102. STDAPI_(void) DriveIDToBBPath(int idDrive, LPTSTR pszPath);
  103. STDAPI_(void) DriveIDToBBRoot(int idDrive, LPTSTR szPath);
  104. STDAPI_(void) DriveIDToBBVolumeRoot(int idDrive, LPTSTR szPath);
  105. STDAPI_(BOOL) GetNetHomeDir(LPTSTR pszPath);
  106. STDAPI_(BOOL) PersistBBDriveSettings(int idDrive, int iPercent, BOOL fNukeOnDelete);
  107. STDAPI_(BOOL) MakeBitBucket(int idDrive);
  108. STDAPI_(DWORD) PurgeBBFiles(int idDrive);
  109. STDAPI_(BOOL) PersistGlobalSettings(BOOL fUseGlobalSettings, BOOL fNukeOnDelete, int iPercent);
  110. STDAPI_(BOOL) RefreshAllBBDriveSettings();
  111. STDAPI_(BOOL) RefreshBBDriveSettings(int idDrive);
  112. STDAPI_(void) CheckCompactAndPurge();
  113. STDAPI BBPurgeAll(HWND hwndOwner, DWORD dwFlags);
  114. STDAPI_(BOOL) BBDeleteFileInit(LPTSTR pszFile, INT* piRet);
  115. STDAPI_(BOOL) BBDeleteFile(LPTSTR pszFile, INT* piRet, LPUNDOATOM lpua, BOOL fIsDir, HDPA *phdpaDeletedFiles, ULARGE_INTEGER ulSize);
  116. STDAPI_(BOOL) BBFinishDelete(HDPA hdpaDeletedFiles);
  117. STDAPI_(BOOL) IsFileInBitBucket(LPCTSTR pszPath);
  118. STDAPI_(void) UndoBBFileDelete(LPCTSTR pszOriginal, LPCTSTR pszDelFile);
  119. STDAPI_(BOOL) BBWillRecycle(LPCTSTR pszFile, INT* piRet);
  120. STDAPI_(void) BBCheckRestoredFiles(LPCTSTR pszSrc);
  121. STDAPI_(BOOL) BBCheckDeleteFileSize(int idDrive, ULARGE_INTEGER ulSize);
  122. STDAPI_(BOOL) IsFileDeletable(LPCTSTR pszFile);
  123. STDAPI_(BOOL) IsDirectoryDeletable(LPCTSTR pszDir);
  124. STDAPI_(int) BBRecyclePathLength(int idDrive);
  125. STDAPI_(BOOL) IsRecycleBinEmpty();
  126. STDAPI_(void) SHUpdateRecycleBinIcon();
  127. STDAPI_(void) SaveRecycleBinInfo();
  128. STDAPI_(void) SetDateTimeText(HWND hdlg, int id, const FILETIME *pftUTC);
  129. STDAPI_(DWORD) ReadPolicySetting(LPCWSTR pszBaseKey, LPCWSTR pszGroup, LPCWSTR pszRestriction, LPBYTE pbData, DWORD cbData);
  130. #endif // _BITBUCK_INC