jwadskquota.pas 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. {******************************************************************************}
  2. { }
  3. { Disk Quota's API interface Unit for Object Pascal }
  4. { }
  5. { Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft }
  6. { Corporation. All Rights Reserved. }
  7. { }
  8. { The original file is: dskquota.h, released June 2000. The original Pascal }
  9. { code is: DskQuota.pas, released December 2000. The initial developer of the }
  10. { Pascal code is Marcel van Brakel (brakelm att chello dott nl). }
  11. { }
  12. { Portions created by Marcel van Brakel are Copyright (C) 1999-2001 }
  13. { Marcel van Brakel. All Rights Reserved. }
  14. { }
  15. { Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI) }
  16. { }
  17. { You may retrieve the latest version of this file at the Project JEDI }
  18. { APILIB home page, located at http://jedi-apilib.sourceforge.net }
  19. { }
  20. { The contents of this file are used with permission, subject to the Mozilla }
  21. { Public License Version 1.1 (the "License"); you may not use this file except }
  22. { in compliance with the License. You may obtain a copy of the License at }
  23. { http://www.mozilla.org/MPL/MPL-1.1.html }
  24. { }
  25. { Software distributed under the License is distributed on an "AS IS" basis, }
  26. { WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
  27. { the specific language governing rights and limitations under the License. }
  28. { }
  29. { Alternatively, the contents of this file may be used under the terms of the }
  30. { GNU Lesser General Public License (the "LGPL License"), in which case the }
  31. { provisions of the LGPL License are applicable instead of those above. }
  32. { If you wish to allow use of your version of this file only under the terms }
  33. { of the LGPL License and not to allow others to use your version of this file }
  34. { under the MPL, indicate your decision by deleting the provisions above and }
  35. { replace them with the notice and other provisions required by the LGPL }
  36. { License. If you do not delete the provisions above, a recipient may use }
  37. { your version of this file under either the MPL or the LGPL License. }
  38. { }
  39. { For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
  40. { }
  41. {******************************************************************************}
  42. unit JwaDskQuota;
  43. {$WEAKPACKAGEUNIT}
  44. {$HPPEMIT ''}
  45. {$HPPEMIT '#include "DskQuota.h"'}
  46. {$HPPEMIT ''}
  47. {$I jediapilib.inc}
  48. interface
  49. uses
  50. ActiveX {TODO}, JwaWinNT, JwaWinType;
  51. const
  52. //
  53. // Class IDs
  54. //
  55. // {7988B571-EC89-11cf-9C00-00AA00A14F56}
  56. CLSID_DiskQuotaControl: TGUID = (
  57. D1:$7988b571; D2:$ec89; D3:$11cf; D4:($9c, $0, $0, $aa, $0, $a1, $4f, $56));
  58. {$EXTERNALSYM CLSID_DiskQuotaControl}
  59. //
  60. // Interface IDs
  61. //
  62. // {7988B572-EC89-11cf-9C00-00AA00A14F56}
  63. IID_IDiskQuotaControl: TGUID = (
  64. D1:$7988b572; D2:$ec89; D3:$11cf; D4:($9c, $0, $0, $aa, $0, $a1, $4f, $56));
  65. {$EXTERNALSYM IID_IDiskQuotaControl}
  66. // {7988B574-EC89-11cf-9C00-00AA00A14F56}
  67. IID_IDiskQuotaUser: TGUID = (
  68. D1:$7988b574; D2:$ec89; D3:$11cf; D4:($9c, $0, $0, $aa, $0, $a1, $4f, $56));
  69. {$EXTERNALSYM IID_IDiskQuotaUser}
  70. // {7988B576-EC89-11cf-9C00-00AA00A14F56}
  71. IID_IDiskQuotaUserBatch: TGUID = (
  72. D1:$7988b576; D2:$ec89; D3:$11cf; D4:($9c, $0, $0, $aa, $0, $a1, $4f, $56));
  73. {$EXTERNALSYM IID_IDiskQuotaUserBatch}
  74. // {7988B577-EC89-11cf-9C00-00AA00A14F56}
  75. IID_IEnumDiskQuotaUsers: TGUID = (
  76. D1:$7988b577; D2:$ec89; D3:$11cf; D4:($9c, $0, $0, $aa, $0, $a1, $4f, $56));
  77. {$EXTERNALSYM IID_IEnumDiskQuotaUsers}
  78. // {7988B579-EC89-11cf-9C00-00AA00A14F56}
  79. IID_IDiskQuotaEvents: TGUID = (
  80. D1:$7988b579; D2:$ec89; D3:$11cf; D4:($9c, $0, $0, $aa, $0, $a1, $4f, $56));
  81. {$EXTERNALSYM IID_IDiskQuotaEvents}
  82. //
  83. // Definitions for value and bits in DWORD returned by
  84. // IDiskQuotaControl::GetQuotaState.
  85. //
  86. DISKQUOTA_STATE_DISABLED = $00000000;
  87. {$EXTERNALSYM DISKQUOTA_STATE_DISABLED}
  88. DISKQUOTA_STATE_TRACK = $00000001;
  89. {$EXTERNALSYM DISKQUOTA_STATE_TRACK}
  90. DISKQUOTA_STATE_ENFORCE = $00000002;
  91. {$EXTERNALSYM DISKQUOTA_STATE_ENFORCE}
  92. DISKQUOTA_STATE_MASK = $00000003;
  93. {$EXTERNALSYM DISKQUOTA_STATE_MASK}
  94. DISKQUOTA_FILESTATE_INCOMPLETE = $00000100;
  95. {$EXTERNALSYM DISKQUOTA_FILESTATE_INCOMPLETE}
  96. DISKQUOTA_FILESTATE_REBUILDING = $00000200;
  97. {$EXTERNALSYM DISKQUOTA_FILESTATE_REBUILDING}
  98. DISKQUOTA_FILESTATE_MASK = $00000300;
  99. {$EXTERNALSYM DISKQUOTA_FILESTATE_MASK}
  100. //
  101. // Helper macros for setting and testing state value.
  102. //
  103. function DISKQUOTA_SET_DISABLED(var s: DWORD): DWORD;
  104. {$EXTERNALSYM DISKQUOTA_SET_DISABLED}
  105. function DISKQUOTA_SET_TRACKED(var s: DWORD): DWORD;
  106. {$EXTERNALSYM DISKQUOTA_SET_TRACKED}
  107. function DISKQUOTA_SET_ENFORCED(var s: DWORD): DWORD;
  108. {$EXTERNALSYM DISKQUOTA_SET_ENFORCED}
  109. function DISKQUOTA_IS_DISABLED(s: DWORD): BOOL;
  110. {$EXTERNALSYM DISKQUOTA_IS_DISABLED}
  111. function DISKQUOTA_IS_TRACKED(s: DWORD): BOOL;
  112. {$EXTERNALSYM DISKQUOTA_IS_TRACKED}
  113. function DISKQUOTA_IS_ENFORCED(s: DWORD): BOOL;
  114. {$EXTERNALSYM DISKQUOTA_IS_ENFORCED}
  115. //
  116. // These file state flags are read-only.
  117. //
  118. function DISKQUOTA_FILE_INCOMPLETE(s: DWORD): BOOL;
  119. {$EXTERNALSYM DISKQUOTA_FILE_INCOMPLETE}
  120. function DISKQUOTA_FILE_REBUILDING(s: DWORD): BOOL;
  121. {$EXTERNALSYM DISKQUOTA_FILE_REBUILDING}
  122. //
  123. // Definitions for bits in DWORD returned by
  124. // IDiskQuotaControl::GetQuotaLogFlags.
  125. //
  126. const
  127. DISKQUOTA_LOGFLAG_USER_THRESHOLD = $00000001;
  128. {$EXTERNALSYM DISKQUOTA_LOGFLAG_USER_THRESHOLD}
  129. DISKQUOTA_LOGFLAG_USER_LIMIT = $00000002;
  130. {$EXTERNALSYM DISKQUOTA_LOGFLAG_USER_LIMIT}
  131. //
  132. // Helper macros to interrogate a log flags DWORD.
  133. //
  134. function DISKQUOTA_IS_LOGGED_USER_THRESHOLD(f: DWORD): BOOL;
  135. {$EXTERNALSYM DISKQUOTA_IS_LOGGED_USER_THRESHOLD}
  136. function DISKQUOTA_IS_LOGGED_USER_LIMIT(f: DWORD): BOOL;
  137. {$EXTERNALSYM DISKQUOTA_IS_LOGGED_USER_LIMIT}
  138. //
  139. // Helper macros to set/clear bits in a log flags DWORD.
  140. //
  141. function DISKQUOTA_SET_LOG_USER_THRESHOLD(f: DWORD; yn: BOOL): DWORD;
  142. {$EXTERNALSYM DISKQUOTA_SET_LOG_USER_THRESHOLD}
  143. function DISKQUOTA_SET_LOG_USER_LIMIT(f: DWORD; yn: BOOL): DWORD;
  144. {$EXTERNALSYM DISKQUOTA_SET_LOG_USER_LIMIT}
  145. //
  146. // Per-user quota information.
  147. //
  148. type
  149. PDISKQUOTA_USER_INFORMATION = ^DISKQUOTA_USER_INFORMATION;
  150. {$EXTERNALSYM PDISKQUOTA_USER_INFORMATION}
  151. DiskQuotaUserInformation = record
  152. QuotaUsed: LONGLONG;
  153. QuotaThreshold: LONGLONG;
  154. QuotaLimit: LONGLONG;
  155. end;
  156. {$EXTERNALSYM DiskQuotaUserInformation}
  157. DISKQUOTA_USER_INFORMATION = DiskQuotaUserInformation;
  158. {$EXTERNALSYM DISKQUOTA_USER_INFORMATION}
  159. TDiskQuotaUserInformation = DISKQUOTA_USER_INFORMATION;
  160. PDiskQuotaUserInformation = PDISKQUOTA_USER_INFORMATION;
  161. //
  162. // Values for fNameResolution argument to:
  163. //
  164. // IDiskQuotaControl::AddUserSid
  165. // IDiskQuotaControl::AddUserName
  166. // IDiskQuotaControl::FindUserSid
  167. // IDiskQuotaControl::CreateEnumUsers
  168. //
  169. const
  170. DISKQUOTA_USERNAME_RESOLVE_NONE = 0;
  171. {$EXTERNALSYM DISKQUOTA_USERNAME_RESOLVE_NONE}
  172. DISKQUOTA_USERNAME_RESOLVE_SYNC = 1;
  173. {$EXTERNALSYM DISKQUOTA_USERNAME_RESOLVE_SYNC}
  174. DISKQUOTA_USERNAME_RESOLVE_ASYNC = 2;
  175. {$EXTERNALSYM DISKQUOTA_USERNAME_RESOLVE_ASYNC}
  176. //
  177. // Values for status returned by IDiskQuotaUser::GetAccountStatus.
  178. //
  179. DISKQUOTA_USER_ACCOUNT_RESOLVED = 0;
  180. {$EXTERNALSYM DISKQUOTA_USER_ACCOUNT_RESOLVED}
  181. DISKQUOTA_USER_ACCOUNT_UNAVAILABLE = 1;
  182. {$EXTERNALSYM DISKQUOTA_USER_ACCOUNT_UNAVAILABLE}
  183. DISKQUOTA_USER_ACCOUNT_DELETED = 2;
  184. {$EXTERNALSYM DISKQUOTA_USER_ACCOUNT_DELETED}
  185. DISKQUOTA_USER_ACCOUNT_INVALID = 3;
  186. {$EXTERNALSYM DISKQUOTA_USER_ACCOUNT_INVALID}
  187. DISKQUOTA_USER_ACCOUNT_UNKNOWN = 4;
  188. {$EXTERNALSYM DISKQUOTA_USER_ACCOUNT_UNKNOWN}
  189. DISKQUOTA_USER_ACCOUNT_UNRESOLVED = 5;
  190. {$EXTERNALSYM DISKQUOTA_USER_ACCOUNT_UNRESOLVED}
  191. //
  192. // IDiskQuotaUser represents a single user quota record on a particular
  193. // NTFS volume. Objects using this interface are instantiated
  194. // through several IDiskQuotaControl methods.
  195. //
  196. type
  197. IDiskQuotaUser = interface (IUnknown)
  198. ['{7988B574-EC89-11cf-9C00-00AA00A14F56}']
  199. function GetID(var pulID: ULONG): HRESULT; stdcall;
  200. function GetName(pszAccountContainer: LPWSTR; cchAccountContainer: DWORD;
  201. pszLogonName: LPWSTR; cchLogonName: DWORD; pszDisplayName: LPWSTR;
  202. cchDisplayName: DWORD): HRESULT; stdcall;
  203. function GetSidLength(var pdwLength: DWORD): HRESULT; stdcall;
  204. function GetSid(pbSidBuffer: LPBYTE; cbSidBuffer: DWORD): HRESULT; stdcall;
  205. function GetQuotaThreshold(var pllThreshold: LONGLONG): HRESULT; stdcall;
  206. function GetQuotaThresholdText(pszText: LPWSTR; cchText: DWORD): HRESULT; stdcall;
  207. function GetQuotaLimit(var pllLimit: LONGLONG): HRESULT; stdcall;
  208. function GetQuotaLimitText(pszText: LPWSTR; cchText: DWORD): HRESULT; stdcall;
  209. function GetQuotaUsed(var pllUsed: LONGLONG): HRESULT; stdcall;
  210. function GetQuotaUsedText(pszText: LPWSTR; cchText: DWORD): HRESULT; stdcall;
  211. function GetQuotaInformation(pbQuotaInfo: LPVOID; cbQuotaInfo: DWORD): HRESULT; stdcall;
  212. function SetQuotaThreshold(llThreshold: LONGLONG; fWriteThrough: BOOL): HRESULT; stdcall;
  213. function SetQuotaLimit(llLimit: LONGLONG; fWriteThrough: BOOL): HRESULT; stdcall;
  214. function Invalidate: HRESULT; stdcall;
  215. function GetAccountStatus(var pdwStatus: DWORD): HRESULT; stdcall;
  216. end;
  217. {$EXTERNALSYM IDiskQuotaUser}
  218. DISKQUOTA_USER = IDiskQuotaUser;
  219. {$EXTERNALSYM DISKQUOTA_USER}
  220. PDISKQUOTA_USER = ^DISKQUOTA_USER;
  221. {$EXTERNALSYM PDISKQUOTA_USER}
  222. //
  223. // IEnumDiskQuotaUsers represents an enumerator created by
  224. // IDiskQuotaControl for the purpose of enumerating individual user quota
  225. // records on a particular volume. Each record is represented through
  226. // the IDiskQuotaUser interface.
  227. //
  228. IEnumDiskQuotaUsers = interface (IUnknown)
  229. ['{7988B577-EC89-11cf-9C00-00AA00A14F56}']
  230. function Next(cUsers: DWORD; var rgUsers: IDiskQuotaUser; pcUsersFetched: LPDWORD): HRESULT; stdcall;
  231. function Skip(cUsers: DWORD): HRESULT; stdcall;
  232. function Reset: HRESULT; stdcall;
  233. function Clone(out ppEnum: IEnumDiskQuotaUsers): HRESULT; stdcall;
  234. end;
  235. {$EXTERNALSYM IEnumDiskQuotaUsers}
  236. ENUM_DISKQUOTA_USERS = IEnumDiskQuotaUsers;
  237. {$EXTERNALSYM ENUM_DISKQUOTA_USERS}
  238. PENUM_DISKQUOTA_USERS = ^ENUM_DISKQUOTA_USERS;
  239. {$EXTERNALSYM PENUM_DISKQUOTA_USERS}
  240. //
  241. // IDiskQuotaUserBatch represents a collection of IDiskQuotaUser
  242. // pointers for the purpose of grouping updates to quota information.
  243. //
  244. IDiskQuotaUserBatch = interface (IUnknown)
  245. ['{7988B576-EC89-11cf-9C00-00AA00A14F56}']
  246. function Add(pUser: IDiskQuotaUser): HRESULT; stdcall;
  247. function Remove(pUser: IDiskQuotaUser): HRESULT; stdcall;
  248. function RemoveAll: HRESULT; stdcall;
  249. function FlushToDisk: HRESULT; stdcall;
  250. end;
  251. {$EXTERNALSYM IDiskQuotaUserBatch}
  252. DISKQUOTA_USER_BATCH = IDiskQuotaUserBatch;
  253. {$EXTERNALSYM DISKQUOTA_USER_BATCH}
  254. PDISKQUOTA_USER_BATCH = ^DISKQUOTA_USER_BATCH;
  255. {$EXTERNALSYM PDISKQUOTA_USER_BATCH}
  256. //
  257. // IDiskQuotaControl represents a disk volume, providing query and
  258. // control of that volume's quota information.
  259. //
  260. IDiskQuotaControl = interface (IConnectionPointContainer)
  261. ['{7988B571-EC89-11cf-9C00-00AA00A14F56}']
  262. function Initialize(pszPath: LPCWSTR; bReadWrite: BOOL): HRESULT; stdcall;
  263. function SetQuotaState(dwState: DWORD): HRESULT; stdcall;
  264. function GetQuotaState(var pdwState: DWORD): HRESULT; stdcall;
  265. function SetQuotaLogFlags(dwFlags: DWORD): HRESULT; stdcall;
  266. function GetQuotaLogFlags(var pdwFlags: DWORD): HRESULT; stdcall;
  267. function SetDefaultQuotaThreshold(llThreshold: LONGLONG): HRESULT; stdcall;
  268. function GetDefaultQuotaThreshold(var pllThreshold: LONGLONG): HRESULT; stdcall;
  269. function GetDefaultQuotaThresholdText(pszText: LPWSTR; cchText: DWORD): HRESULT; stdcall;
  270. function SetDefaultQuotaLimit(llLimit: LONGLONG): HRESULT; stdcall;
  271. function GetDefaultQuotaLimit(var pllLimit: LONGLONG): HRESULT; stdcall;
  272. function GetDefaultQuotaLimitText(pszText: LPWSTR; cchText: DWORD): HRESULT; stdcall;
  273. function AddUserSid(pUserSid: PSID; fNameResolution: DWORD;
  274. out ppUser: IDiskQuotaUser): HRESULT; stdcall;
  275. function AddUserName(pszLogonName: LPCWSTR; fNameResolution: DWORD;
  276. out ppUser: IDiskQuotaUser): HRESULT; stdcall;
  277. function DeleteUser(pUser: IDiskQuotaUser): HRESULT; stdcall;
  278. function FindUserSid(pUserSid: PSID; fNameResolution: DWORD;
  279. out ppUser: IDiskQuotaUser): HRESULT; stdcall;
  280. function FindUserName(pszLogonName: LPCWSTR; out ppUser: IDiskQuotaUser): HRESULT; stdcall;
  281. function CreateEnumUsers(rgpUserSids: PSID; cpSids, fNameResolution: DWORD;
  282. out ppEnum: IEnumDiskQuotaUsers): HRESULT; stdcall;
  283. function CreateUserBatch(out ppBatch: IDiskQuotaUserBatch): HRESULT; stdcall;
  284. function InvalidateSidNameCache: HRESULT; stdcall;
  285. function GiveUserNameResolutionPriority(pUser: IDiskQuotaUser): HRESULT; stdcall;
  286. function ShutdownNameResolution: HRESULT; stdcall;
  287. end;
  288. {$EXTERNALSYM IDiskQuotaControl}
  289. DISKQUOTA_CONTROL = IDiskQuotaControl;
  290. {$EXTERNALSYM DISKQUOTA_CONTROL}
  291. PDISKQUOTA_CONTROL = ^DISKQUOTA_CONTROL;
  292. {$EXTERNALSYM PDISKQUOTA_CONTROL}
  293. IDiskQuotaEvents = interface (IUnknown)
  294. ['{7988B579-EC89-11cf-9C00-00AA00A14F56}']
  295. function OnUserNameChanged(pUser: IDiskQuotaUser): HRESULT; stdcall;
  296. end;
  297. {$EXTERNALSYM IDiskQuotaEvents}
  298. DISKQUOTA_EVENTS = IDiskQuotaEvents;
  299. {$EXTERNALSYM DISKQUOTA_EVENTS;}
  300. PDISKQUOTA_EVENTS = ^DISKQUOTA_EVENTS;
  301. {$EXTERNALSYM PDISKQUOTA_EVENTS;}
  302. implementation
  303. function DISKQUOTA_SET_DISABLED(var s: DWORD): DWORD;
  304. begin
  305. s := DISKQUOTA_STATE_DISABLED;
  306. Result := s;
  307. end;
  308. function DISKQUOTA_SET_TRACKED(var s: DWORD): DWORD;
  309. begin
  310. s := DISKQUOTA_STATE_TRACK;
  311. Result := s;
  312. end;
  313. function DISKQUOTA_SET_ENFORCED(var s: DWORD): DWORD;
  314. begin
  315. s := DISKQUOTA_STATE_ENFORCE;
  316. Result := s;
  317. end;
  318. function DISKQUOTA_IS_DISABLED(s: DWORD): BOOL;
  319. begin
  320. Result := (DISKQUOTA_STATE_DISABLED = (s and DISKQUOTA_STATE_MASK));
  321. end;
  322. function DISKQUOTA_IS_TRACKED(s: DWORD): BOOL;
  323. begin
  324. Result := (DISKQUOTA_STATE_TRACK = (s and DISKQUOTA_STATE_MASK));
  325. end;
  326. function DISKQUOTA_IS_ENFORCED(s: DWORD): BOOL;
  327. begin
  328. Result := (DISKQUOTA_STATE_ENFORCE = (s and DISKQUOTA_STATE_MASK));
  329. end;
  330. function DISKQUOTA_FILE_INCOMPLETE(s: DWORD): BOOL;
  331. begin
  332. Result := (0 <> (s and DISKQUOTA_FILESTATE_INCOMPLETE));
  333. end;
  334. function DISKQUOTA_FILE_REBUILDING(s: DWORD): BOOL;
  335. begin
  336. Result := (0 <> (s and DISKQUOTA_FILESTATE_REBUILDING));
  337. end;
  338. function DISKQUOTA_IS_LOGGED_USER_THRESHOLD(f: DWORD): BOOL;
  339. begin
  340. Result := (0 <> (f and DISKQUOTA_LOGFLAG_USER_THRESHOLD));
  341. end;
  342. function DISKQUOTA_IS_LOGGED_USER_LIMIT(f: DWORD): BOOL;
  343. begin
  344. Result := (0 <> (f and DISKQUOTA_LOGFLAG_USER_LIMIT));
  345. end;
  346. function DISKQUOTA_SET_LOG_USER_THRESHOLD(f: DWORD; yn: BOOL): DWORD;
  347. begin
  348. Result := f and (not DISKQUOTA_LOGFLAG_USER_THRESHOLD);
  349. if yn then
  350. Result := Result or DISKQUOTA_LOGFLAG_USER_THRESHOLD;
  351. end;
  352. function DISKQUOTA_SET_LOG_USER_LIMIT(f: DWORD; yn: BOOL): DWORD;
  353. begin
  354. Result := f and (not DISKQUOTA_LOGFLAG_USER_LIMIT);
  355. if yn then
  356. Result := Result or DISKQUOTA_LOGFLAG_USER_LIMIT;
  357. end;
  358. end.