jwadskquota.pas 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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. // $Id: JwaDskQuota.pas,v 1.7 2005/09/03 13:12:10 marquardt Exp $
  43. unit JwaDskQuota;
  44. {$WEAKPACKAGEUNIT}
  45. {$I jediapilib.inc}
  46. interface
  47. uses
  48. JwaActiveX, JwaWindows;
  49. {$HPPEMIT ''}
  50. {$HPPEMIT '#include "DskQuota.h"'}
  51. {$HPPEMIT ''}
  52. const
  53. //
  54. // Class IDs
  55. //
  56. // {7988B571-EC89-11cf-9C00-00AA00A14F56}
  57. CLSID_DiskQuotaControl: TGUID = (
  58. D1:$7988b571; D2:$ec89; D3:$11cf; D4:($9c, $0, $0, $aa, $0, $a1, $4f, $56));
  59. {$EXTERNALSYM CLSID_DiskQuotaControl}
  60. //
  61. // Interface IDs
  62. //
  63. // {7988B572-EC89-11cf-9C00-00AA00A14F56}
  64. IID_IDiskQuotaControl: TGUID = (
  65. D1:$7988b572; D2:$ec89; D3:$11cf; D4:($9c, $0, $0, $aa, $0, $a1, $4f, $56));
  66. {$EXTERNALSYM IID_IDiskQuotaControl}
  67. // {7988B574-EC89-11cf-9C00-00AA00A14F56}
  68. IID_IDiskQuotaUser: TGUID = (
  69. D1:$7988b574; D2:$ec89; D3:$11cf; D4:($9c, $0, $0, $aa, $0, $a1, $4f, $56));
  70. {$EXTERNALSYM IID_IDiskQuotaUser}
  71. // {7988B576-EC89-11cf-9C00-00AA00A14F56}
  72. IID_IDiskQuotaUserBatch: TGUID = (
  73. D1:$7988b576; D2:$ec89; D3:$11cf; D4:($9c, $0, $0, $aa, $0, $a1, $4f, $56));
  74. {$EXTERNALSYM IID_IDiskQuotaUserBatch}
  75. // {7988B577-EC89-11cf-9C00-00AA00A14F56}
  76. IID_IEnumDiskQuotaUsers: TGUID = (
  77. D1:$7988b577; D2:$ec89; D3:$11cf; D4:($9c, $0, $0, $aa, $0, $a1, $4f, $56));
  78. {$EXTERNALSYM IID_IEnumDiskQuotaUsers}
  79. // {7988B579-EC89-11cf-9C00-00AA00A14F56}
  80. IID_IDiskQuotaEvents: TGUID = (
  81. D1:$7988b579; D2:$ec89; D3:$11cf; D4:($9c, $0, $0, $aa, $0, $a1, $4f, $56));
  82. {$EXTERNALSYM IID_IDiskQuotaEvents}
  83. //
  84. // Definitions for value and bits in DWORD returned by
  85. // IDiskQuotaControl::GetQuotaState.
  86. //
  87. DISKQUOTA_STATE_DISABLED = $00000000;
  88. {$EXTERNALSYM DISKQUOTA_STATE_DISABLED}
  89. DISKQUOTA_STATE_TRACK = $00000001;
  90. {$EXTERNALSYM DISKQUOTA_STATE_TRACK}
  91. DISKQUOTA_STATE_ENFORCE = $00000002;
  92. {$EXTERNALSYM DISKQUOTA_STATE_ENFORCE}
  93. DISKQUOTA_STATE_MASK = $00000003;
  94. {$EXTERNALSYM DISKQUOTA_STATE_MASK}
  95. DISKQUOTA_FILESTATE_INCOMPLETE = $00000100;
  96. {$EXTERNALSYM DISKQUOTA_FILESTATE_INCOMPLETE}
  97. DISKQUOTA_FILESTATE_REBUILDING = $00000200;
  98. {$EXTERNALSYM DISKQUOTA_FILESTATE_REBUILDING}
  99. DISKQUOTA_FILESTATE_MASK = $00000300;
  100. {$EXTERNALSYM DISKQUOTA_FILESTATE_MASK}
  101. //
  102. // Helper macros for setting and testing state value.
  103. //
  104. function DISKQUOTA_SET_DISABLED(var s: DWORD): DWORD;
  105. {$EXTERNALSYM DISKQUOTA_SET_DISABLED}
  106. function DISKQUOTA_SET_TRACKED(var s: DWORD): DWORD;
  107. {$EXTERNALSYM DISKQUOTA_SET_TRACKED}
  108. function DISKQUOTA_SET_ENFORCED(var s: DWORD): DWORD;
  109. {$EXTERNALSYM DISKQUOTA_SET_ENFORCED}
  110. function DISKQUOTA_IS_DISABLED(s: DWORD): BOOL;
  111. {$EXTERNALSYM DISKQUOTA_IS_DISABLED}
  112. function DISKQUOTA_IS_TRACKED(s: DWORD): BOOL;
  113. {$EXTERNALSYM DISKQUOTA_IS_TRACKED}
  114. function DISKQUOTA_IS_ENFORCED(s: DWORD): BOOL;
  115. {$EXTERNALSYM DISKQUOTA_IS_ENFORCED}
  116. //
  117. // These file state flags are read-only.
  118. //
  119. function DISKQUOTA_FILE_INCOMPLETE(s: DWORD): BOOL;
  120. {$EXTERNALSYM DISKQUOTA_FILE_INCOMPLETE}
  121. function DISKQUOTA_FILE_REBUILDING(s: DWORD): BOOL;
  122. {$EXTERNALSYM DISKQUOTA_FILE_REBUILDING}
  123. //
  124. // Definitions for bits in DWORD returned by
  125. // IDiskQuotaControl::GetQuotaLogFlags.
  126. //
  127. const
  128. DISKQUOTA_LOGFLAG_USER_THRESHOLD = $00000001;
  129. {$EXTERNALSYM DISKQUOTA_LOGFLAG_USER_THRESHOLD}
  130. DISKQUOTA_LOGFLAG_USER_LIMIT = $00000002;
  131. {$EXTERNALSYM DISKQUOTA_LOGFLAG_USER_LIMIT}
  132. //
  133. // Helper macros to interrogate a log flags DWORD.
  134. //
  135. function DISKQUOTA_IS_LOGGED_USER_THRESHOLD(f: DWORD): BOOL;
  136. {$EXTERNALSYM DISKQUOTA_IS_LOGGED_USER_THRESHOLD}
  137. function DISKQUOTA_IS_LOGGED_USER_LIMIT(f: DWORD): BOOL;
  138. {$EXTERNALSYM DISKQUOTA_IS_LOGGED_USER_LIMIT}
  139. //
  140. // Helper macros to set/clear bits in a log flags DWORD.
  141. //
  142. function DISKQUOTA_SET_LOG_USER_THRESHOLD(f: DWORD; yn: BOOL): DWORD;
  143. {$EXTERNALSYM DISKQUOTA_SET_LOG_USER_THRESHOLD}
  144. function DISKQUOTA_SET_LOG_USER_LIMIT(f: DWORD; yn: BOOL): DWORD;
  145. {$EXTERNALSYM DISKQUOTA_SET_LOG_USER_LIMIT}
  146. //
  147. // Per-user quota information.
  148. //
  149. type
  150. PDISKQUOTA_USER_INFORMATION = ^DISKQUOTA_USER_INFORMATION;
  151. {$EXTERNALSYM PDISKQUOTA_USER_INFORMATION}
  152. DiskQuotaUserInformation = record
  153. QuotaUsed: LONGLONG;
  154. QuotaThreshold: LONGLONG;
  155. QuotaLimit: LONGLONG;
  156. end;
  157. {$EXTERNALSYM DiskQuotaUserInformation}
  158. DISKQUOTA_USER_INFORMATION = DiskQuotaUserInformation;
  159. {$EXTERNALSYM DISKQUOTA_USER_INFORMATION}
  160. TDiskQuotaUserInformation = DISKQUOTA_USER_INFORMATION;
  161. PDiskQuotaUserInformation = PDISKQUOTA_USER_INFORMATION;
  162. //
  163. // Values for fNameResolution argument to:
  164. //
  165. // IDiskQuotaControl::AddUserSid
  166. // IDiskQuotaControl::AddUserName
  167. // IDiskQuotaControl::FindUserSid
  168. // IDiskQuotaControl::CreateEnumUsers
  169. //
  170. const
  171. DISKQUOTA_USERNAME_RESOLVE_NONE = 0;
  172. {$EXTERNALSYM DISKQUOTA_USERNAME_RESOLVE_NONE}
  173. DISKQUOTA_USERNAME_RESOLVE_SYNC = 1;
  174. {$EXTERNALSYM DISKQUOTA_USERNAME_RESOLVE_SYNC}
  175. DISKQUOTA_USERNAME_RESOLVE_ASYNC = 2;
  176. {$EXTERNALSYM DISKQUOTA_USERNAME_RESOLVE_ASYNC}
  177. //
  178. // Values for status returned by IDiskQuotaUser::GetAccountStatus.
  179. //
  180. DISKQUOTA_USER_ACCOUNT_RESOLVED = 0;
  181. {$EXTERNALSYM DISKQUOTA_USER_ACCOUNT_RESOLVED}
  182. DISKQUOTA_USER_ACCOUNT_UNAVAILABLE = 1;
  183. {$EXTERNALSYM DISKQUOTA_USER_ACCOUNT_UNAVAILABLE}
  184. DISKQUOTA_USER_ACCOUNT_DELETED = 2;
  185. {$EXTERNALSYM DISKQUOTA_USER_ACCOUNT_DELETED}
  186. DISKQUOTA_USER_ACCOUNT_INVALID = 3;
  187. {$EXTERNALSYM DISKQUOTA_USER_ACCOUNT_INVALID}
  188. DISKQUOTA_USER_ACCOUNT_UNKNOWN = 4;
  189. {$EXTERNALSYM DISKQUOTA_USER_ACCOUNT_UNKNOWN}
  190. DISKQUOTA_USER_ACCOUNT_UNRESOLVED = 5;
  191. {$EXTERNALSYM DISKQUOTA_USER_ACCOUNT_UNRESOLVED}
  192. //
  193. // IDiskQuotaUser represents a single user quota record on a particular
  194. // NTFS volume. Objects using this interface are instantiated
  195. // through several IDiskQuotaControl methods.
  196. //
  197. type
  198. IDiskQuotaUser = interface (IUnknown)
  199. ['{7988B574-EC89-11cf-9C00-00AA00A14F56}']
  200. function GetID(var pulID: ULONG): HRESULT; stdcall;
  201. function GetName(pszAccountContainer: LPWSTR; cchAccountContainer: DWORD;
  202. pszLogonName: LPWSTR; cchLogonName: DWORD; pszDisplayName: LPWSTR;
  203. cchDisplayName: DWORD): HRESULT; stdcall;
  204. function GetSidLength(var pdwLength: DWORD): HRESULT; stdcall;
  205. function GetSid(pbSidBuffer: LPBYTE; cbSidBuffer: DWORD): HRESULT; stdcall;
  206. function GetQuotaThreshold(var pllThreshold: LONGLONG): HRESULT; stdcall;
  207. function GetQuotaThresholdText(pszText: LPWSTR; cchText: DWORD): HRESULT; stdcall;
  208. function GetQuotaLimit(var pllLimit: LONGLONG): HRESULT; stdcall;
  209. function GetQuotaLimitText(pszText: LPWSTR; cchText: DWORD): HRESULT; stdcall;
  210. function GetQuotaUsed(var pllUsed: LONGLONG): HRESULT; stdcall;
  211. function GetQuotaUsedText(pszText: LPWSTR; cchText: DWORD): HRESULT; stdcall;
  212. function GetQuotaInformation(pbQuotaInfo: LPVOID; cbQuotaInfo: DWORD): HRESULT; stdcall;
  213. function SetQuotaThreshold(llThreshold: LONGLONG; fWriteThrough: BOOL): HRESULT; stdcall;
  214. function SetQuotaLimit(llLimit: LONGLONG; fWriteThrough: BOOL): HRESULT; stdcall;
  215. function Invalidate: HRESULT; stdcall;
  216. function GetAccountStatus(var pdwStatus: DWORD): HRESULT; stdcall;
  217. end;
  218. {$EXTERNALSYM IDiskQuotaUser}
  219. DISKQUOTA_USER = IDiskQuotaUser;
  220. {$EXTERNALSYM DISKQUOTA_USER}
  221. PDISKQUOTA_USER = ^DISKQUOTA_USER;
  222. {$EXTERNALSYM PDISKQUOTA_USER}
  223. //
  224. // IEnumDiskQuotaUsers represents an enumerator created by
  225. // IDiskQuotaControl for the purpose of enumerating individual user quota
  226. // records on a particular volume. Each record is represented through
  227. // the IDiskQuotaUser interface.
  228. //
  229. IEnumDiskQuotaUsers = interface (IUnknown)
  230. ['{7988B577-EC89-11cf-9C00-00AA00A14F56}']
  231. function Next(cUsers: DWORD; var rgUsers: IDiskQuotaUser; pcUsersFetched: LPDWORD): HRESULT; stdcall;
  232. function Skip(cUsers: DWORD): HRESULT; stdcall;
  233. function Reset: HRESULT; stdcall;
  234. function Clone(out ppEnum: IEnumDiskQuotaUsers): HRESULT; stdcall;
  235. end;
  236. {$EXTERNALSYM IEnumDiskQuotaUsers}
  237. ENUM_DISKQUOTA_USERS = IEnumDiskQuotaUsers;
  238. {$EXTERNALSYM ENUM_DISKQUOTA_USERS}
  239. PENUM_DISKQUOTA_USERS = ^ENUM_DISKQUOTA_USERS;
  240. {$EXTERNALSYM PENUM_DISKQUOTA_USERS}
  241. //
  242. // IDiskQuotaUserBatch represents a collection of IDiskQuotaUser
  243. // pointers for the purpose of grouping updates to quota information.
  244. //
  245. IDiskQuotaUserBatch = interface (IUnknown)
  246. ['{7988B576-EC89-11cf-9C00-00AA00A14F56}']
  247. function Add(pUser: IDiskQuotaUser): HRESULT; stdcall;
  248. function Remove(pUser: IDiskQuotaUser): HRESULT; stdcall;
  249. function RemoveAll: HRESULT; stdcall;
  250. function FlushToDisk: HRESULT; stdcall;
  251. end;
  252. {$EXTERNALSYM IDiskQuotaUserBatch}
  253. DISKQUOTA_USER_BATCH = IDiskQuotaUserBatch;
  254. {$EXTERNALSYM DISKQUOTA_USER_BATCH}
  255. PDISKQUOTA_USER_BATCH = ^DISKQUOTA_USER_BATCH;
  256. {$EXTERNALSYM PDISKQUOTA_USER_BATCH}
  257. //
  258. // IDiskQuotaControl represents a disk volume, providing query and
  259. // control of that volume's quota information.
  260. //
  261. IDiskQuotaControl = interface (IConnectionPointContainer)
  262. ['{7988B571-EC89-11cf-9C00-00AA00A14F56}']
  263. function Initialize(pszPath: LPCWSTR; bReadWrite: BOOL): HRESULT; stdcall;
  264. function SetQuotaState(dwState: DWORD): HRESULT; stdcall;
  265. function GetQuotaState(var pdwState: DWORD): HRESULT; stdcall;
  266. function SetQuotaLogFlags(dwFlags: DWORD): HRESULT; stdcall;
  267. function GetQuotaLogFlags(var pdwFlags: DWORD): HRESULT; stdcall;
  268. function SetDefaultQuotaThreshold(llThreshold: LONGLONG): HRESULT; stdcall;
  269. function GetDefaultQuotaThreshold(var pllThreshold: LONGLONG): HRESULT; stdcall;
  270. function GetDefaultQuotaThresholdText(pszText: LPWSTR; cchText: DWORD): HRESULT; stdcall;
  271. function SetDefaultQuotaLimit(llLimit: LONGLONG): HRESULT; stdcall;
  272. function GetDefaultQuotaLimit(var pllLimit: LONGLONG): HRESULT; stdcall;
  273. function GetDefaultQuotaLimitText(pszText: LPWSTR; cchText: DWORD): HRESULT; stdcall;
  274. function AddUserSid(pUserSid: PSID; fNameResolution: DWORD;
  275. out ppUser: IDiskQuotaUser): HRESULT; stdcall;
  276. function AddUserName(pszLogonName: LPCWSTR; fNameResolution: DWORD;
  277. out ppUser: IDiskQuotaUser): HRESULT; stdcall;
  278. function DeleteUser(pUser: IDiskQuotaUser): HRESULT; stdcall;
  279. function FindUserSid(pUserSid: PSID; fNameResolution: DWORD;
  280. out ppUser: IDiskQuotaUser): HRESULT; stdcall;
  281. function FindUserName(pszLogonName: LPCWSTR; out ppUser: IDiskQuotaUser): HRESULT; stdcall;
  282. function CreateEnumUsers(rgpUserSids: PSID; cpSids, fNameResolution: DWORD;
  283. out ppEnum: IEnumDiskQuotaUsers): HRESULT; stdcall;
  284. function CreateUserBatch(out ppBatch: IDiskQuotaUserBatch): HRESULT; stdcall;
  285. function InvalidateSidNameCache: HRESULT; stdcall;
  286. function GiveUserNameResolutionPriority(pUser: IDiskQuotaUser): HRESULT; stdcall;
  287. function ShutdownNameResolution: HRESULT; stdcall;
  288. end;
  289. {$EXTERNALSYM IDiskQuotaControl}
  290. DISKQUOTA_CONTROL = IDiskQuotaControl;
  291. {$EXTERNALSYM DISKQUOTA_CONTROL}
  292. PDISKQUOTA_CONTROL = ^DISKQUOTA_CONTROL;
  293. {$EXTERNALSYM PDISKQUOTA_CONTROL}
  294. IDiskQuotaEvents = interface (IUnknown)
  295. ['{7988B579-EC89-11cf-9C00-00AA00A14F56}']
  296. function OnUserNameChanged(pUser: IDiskQuotaUser): HRESULT; stdcall;
  297. end;
  298. {$EXTERNALSYM IDiskQuotaEvents}
  299. DISKQUOTA_EVENTS = IDiskQuotaEvents;
  300. {$EXTERNALSYM DISKQUOTA_EVENTS;}
  301. PDISKQUOTA_EVENTS = ^DISKQUOTA_EVENTS;
  302. {$EXTERNALSYM PDISKQUOTA_EVENTS;}
  303. implementation
  304. function DISKQUOTA_SET_DISABLED(var s: DWORD): DWORD;
  305. begin
  306. s := DISKQUOTA_STATE_DISABLED;
  307. Result := s;
  308. end;
  309. function DISKQUOTA_SET_TRACKED(var s: DWORD): DWORD;
  310. begin
  311. s := DISKQUOTA_STATE_TRACK;
  312. Result := s;
  313. end;
  314. function DISKQUOTA_SET_ENFORCED(var s: DWORD): DWORD;
  315. begin
  316. s := DISKQUOTA_STATE_ENFORCE;
  317. Result := s;
  318. end;
  319. function DISKQUOTA_IS_DISABLED(s: DWORD): BOOL;
  320. begin
  321. Result := (DISKQUOTA_STATE_DISABLED = (s and DISKQUOTA_STATE_MASK));
  322. end;
  323. function DISKQUOTA_IS_TRACKED(s: DWORD): BOOL;
  324. begin
  325. Result := (DISKQUOTA_STATE_TRACK = (s and DISKQUOTA_STATE_MASK));
  326. end;
  327. function DISKQUOTA_IS_ENFORCED(s: DWORD): BOOL;
  328. begin
  329. Result := (DISKQUOTA_STATE_ENFORCE = (s and DISKQUOTA_STATE_MASK));
  330. end;
  331. function DISKQUOTA_FILE_INCOMPLETE(s: DWORD): BOOL;
  332. begin
  333. Result := (0 <> (s and DISKQUOTA_FILESTATE_INCOMPLETE));
  334. end;
  335. function DISKQUOTA_FILE_REBUILDING(s: DWORD): BOOL;
  336. begin
  337. Result := (0 <> (s and DISKQUOTA_FILESTATE_REBUILDING));
  338. end;
  339. function DISKQUOTA_IS_LOGGED_USER_THRESHOLD(f: DWORD): BOOL;
  340. begin
  341. Result := (0 <> (f and DISKQUOTA_LOGFLAG_USER_THRESHOLD));
  342. end;
  343. function DISKQUOTA_IS_LOGGED_USER_LIMIT(f: DWORD): BOOL;
  344. begin
  345. Result := (0 <> (f and DISKQUOTA_LOGFLAG_USER_LIMIT));
  346. end;
  347. function DISKQUOTA_SET_LOG_USER_THRESHOLD(f: DWORD; yn: BOOL): DWORD;
  348. begin
  349. Result := f and (not DISKQUOTA_LOGFLAG_USER_THRESHOLD);
  350. if yn then
  351. Result := Result or DISKQUOTA_LOGFLAG_USER_THRESHOLD;
  352. end;
  353. function DISKQUOTA_SET_LOG_USER_LIMIT(f: DWORD; yn: BOOL): DWORD;
  354. begin
  355. Result := f and (not DISKQUOTA_LOGFLAG_USER_LIMIT);
  356. if yn then
  357. Result := Result or DISKQUOTA_LOGFLAG_USER_LIMIT;
  358. end;
  359. end.