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.

504 lines
13 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. fileenum.h
  5. Abstract:
  6. Set of APIs to enumerate a file system using Win32 APIs.
  7. Author:
  8. 20-Oct-1999 Ovidiu Temereanca (ovidiut) - File creation.
  9. Revision History:
  10. <alias> <date> <comments>
  11. --*/
  12. //
  13. // Types
  14. //
  15. //
  16. // Drive enumeration structures
  17. //
  18. #define DRIVEENUM_NONE 0x000000
  19. #define DRIVEENUM_UNKNOWN 0x000001
  20. #define DRIVEENUM_NOROOTDIR 0x000002
  21. #define DRIVEENUM_REMOVABLE 0x000004
  22. #define DRIVEENUM_FIXED 0x000008
  23. #define DRIVEENUM_REMOTE 0x000010
  24. #define DRIVEENUM_CDROM 0x000020
  25. #define DRIVEENUM_RAMDISK 0x000040
  26. #define DRIVEENUM_ALL (DRIVEENUM_UNKNOWN|DRIVEENUM_NOROOTDIR|DRIVEENUM_REMOVABLE|DRIVEENUM_FIXED|DRIVEENUM_REMOTE|DRIVEENUM_CDROM|DRIVEENUM_RAMDISK)
  27. #define DRIVEENUM_ALLVALID (DRIVEENUM_REMOVABLE|DRIVEENUM_FIXED|DRIVEENUM_REMOTE|DRIVEENUM_CDROM|DRIVEENUM_RAMDISK)
  28. typedef struct {
  29. PCSTR DriveName;
  30. UINT DriveType;
  31. //
  32. // private members, maintained by enumeration
  33. //
  34. PSTR AllLogicalDrives;
  35. UINT WantedDriveTypes;
  36. } DRIVE_ENUMA, *PDRIVE_ENUMA;
  37. typedef struct {
  38. PCWSTR DriveName;
  39. UINT DriveType;
  40. //
  41. // private members, maintained by enumeration
  42. //
  43. PWSTR AllLogicalDrives;
  44. UINT WantedDriveTypes;
  45. } DRIVE_ENUMW, *PDRIVE_ENUMW;
  46. //
  47. // file enumeration structures
  48. //
  49. #define FILEENUM_ALL_SUBLEVELS 0xFFFFFFFF
  50. typedef enum {
  51. FECF_SKIPDIR = 0x0001,
  52. FECF_SKIPSUBDIRS = 0x0002,
  53. FECF_SKIPFILES = 0x0004,
  54. } FILEENUM_CONTROLFLAGS;
  55. typedef enum {
  56. FEIF_RETURN_DIRS = 0x0001,
  57. FEIF_FILES_FIRST = 0x0002,
  58. FEIF_DEPTH_FIRST = 0x0004,
  59. FEIF_USE_EXCLUSIONS = 0x0008,
  60. FEIF_CONTAINERS_FIRST = 0x0010,
  61. } FILEENUM_INFOFLAGS;
  62. typedef enum {
  63. DNS_ENUM_INIT,
  64. DNS_FILE_FIRST,
  65. DNS_FILE_NEXT,
  66. DNS_FILE_DONE,
  67. DNS_SUBDIR_FIRST,
  68. DNS_SUBDIR_NEXT,
  69. DNS_SUBDIR_DONE,
  70. DNS_ENUM_DONE
  71. } DNS_ENUM_STATE;
  72. typedef enum {
  73. FES_ROOT_FIRST,
  74. FES_ROOT_NEXT,
  75. FES_ROOT_DONE
  76. } FES_ROOT_STATE;
  77. typedef enum {
  78. DNF_RETURN_DIRNAME = 0x0001,
  79. DNF_DIRNAME_MATCHES = 0x0002,
  80. } DIRNODE_FLAGS;
  81. typedef struct {
  82. PCSTR DirName;
  83. DWORD DirAttributes;
  84. PSTR FileName;
  85. HANDLE FindHandle;
  86. WIN32_FIND_DATAA FindData;
  87. DWORD EnumState;
  88. DWORD Flags;
  89. DWORD SubLevel;
  90. } DIRNODEA, *PDIRNODEA;
  91. typedef struct {
  92. PCWSTR DirName;
  93. DWORD DirAttributes;
  94. PWSTR FileName;
  95. HANDLE FindHandle;
  96. WIN32_FIND_DATAW FindData;
  97. DWORD EnumState;
  98. DWORD Flags;
  99. DWORD SubLevel;
  100. } DIRNODEW, *PDIRNODEW;
  101. typedef BOOL (*FPE_ERROR_CALLBACKA)(PDIRNODEA);
  102. typedef struct {
  103. POBSPARSEDPATTERNA PathPattern;
  104. DWORD Flags;
  105. DWORD RootLevel;
  106. DWORD MaxSubLevel;
  107. FPE_ERROR_CALLBACKA CallbackOnError;
  108. } FILEENUMINFOA, *PFILEENUMINFOA;
  109. typedef BOOL (*FPE_ERROR_CALLBACKW)(PDIRNODEW);
  110. typedef struct {
  111. POBSPARSEDPATTERNW PathPattern;
  112. DWORD Flags;
  113. DWORD RootLevel;
  114. DWORD MaxSubLevel;
  115. FPE_ERROR_CALLBACKW CallbackOnError;
  116. } FILEENUMINFOW, *PFILEENUMINFOW;
  117. typedef struct {
  118. PCSTR EncodedFullName;
  119. PCSTR Name;
  120. PCSTR Location;
  121. CHAR NativeFullName[MAX_MBCHAR_PATH];
  122. DWORD Attributes;
  123. DWORD CurrentLevel;
  124. //
  125. // Private members
  126. //
  127. DWORD ControlFlags;
  128. FILEENUMINFOA FileEnumInfo;
  129. GROWBUFFER FileNodes;
  130. DWORD RootState;
  131. PDRIVE_ENUMA DriveEnum;
  132. UINT DriveEnumTypes;
  133. PDIRNODEA LastNode;
  134. PSTR FileNameAppendPos;
  135. PSTR LastWackPtr;
  136. } FILETREE_ENUMA, *PFILETREE_ENUMA;
  137. typedef struct {
  138. PCWSTR EncodedFullName;
  139. PCWSTR Name;
  140. PCWSTR Location;
  141. WCHAR NativeFullName[MAX_WCHAR_PATH];
  142. DWORD Attributes;
  143. DWORD CurrentLevel;
  144. //
  145. // Private members
  146. //
  147. DWORD ControlFlags;
  148. FILEENUMINFOW FileEnumInfo;
  149. GROWBUFFER FileNodes;
  150. DWORD RootState;
  151. PDRIVE_ENUMW DriveEnum;
  152. UINT DriveEnumTypes;
  153. PDIRNODEW LastNode;
  154. PWSTR FileNameAppendPos;
  155. PWSTR LastWackPtr;
  156. } FILETREE_ENUMW, *PFILETREE_ENUMW;
  157. typedef struct {
  158. PCSTR OriginalArg;
  159. PCSTR CleanedUpArg;
  160. BOOL Quoted;
  161. } CMDLINEARGA, *PCMDLINEARGA;
  162. typedef struct {
  163. PCSTR CmdLine;
  164. UINT ArgCount;
  165. CMDLINEARGA Args[];
  166. } CMDLINEA, *PCMDLINEA;
  167. typedef struct {
  168. PCWSTR OriginalArg;
  169. PCWSTR CleanedUpArg;
  170. BOOL Quoted;
  171. } CMDLINEARGW, *PCMDLINEARGW;
  172. typedef struct {
  173. PCWSTR CmdLine;
  174. UINT ArgCount;
  175. CMDLINEARGW Args[];
  176. } CMDLINEW, *PCMDLINEW;
  177. typedef BOOL(WINAPI FINDFILEA)(
  178. IN PCSTR FileName
  179. );
  180. typedef FINDFILEA *PFINDFILEA;
  181. typedef BOOL(WINAPI FINDFILEW)(
  182. IN PCWSTR FileName
  183. );
  184. typedef FINDFILEW *PFINDFILEW;
  185. typedef BOOL(WINAPI SEARCHPATHA)(
  186. IN PCSTR FileName,
  187. IN DWORD BufferLength,
  188. OUT PSTR Buffer
  189. );
  190. typedef SEARCHPATHA *PSEARCHPATHA;
  191. typedef BOOL(WINAPI SEARCHPATHW)(
  192. IN PCWSTR FileName,
  193. IN DWORD BufferLength,
  194. OUT PWSTR Buffer
  195. );
  196. typedef SEARCHPATHW *PSEARCHPATHW;
  197. //
  198. // API
  199. //
  200. BOOL
  201. FileEnumInitialize (
  202. VOID
  203. );
  204. VOID
  205. FileEnumTerminate (
  206. VOID
  207. );
  208. //
  209. // File enumeration APIs
  210. //
  211. BOOL
  212. EnumFirstFileInTreeExA (
  213. OUT PFILETREE_ENUMA FileEnum,
  214. IN PCSTR EncodedPathPattern,
  215. IN UINT DriveEnumTypes,
  216. IN BOOL EnumContainers,
  217. IN BOOL ContainersFirst,
  218. IN BOOL FilesFirst,
  219. IN BOOL DepthFirst,
  220. IN DWORD MaxSubLevels,
  221. IN BOOL UseExclusions,
  222. IN FPE_ERROR_CALLBACKA CallbackOnError OPTIONAL
  223. );
  224. #define EnumFirstFileInTreeA(e,p) EnumFirstFileInTreeExA(e,p,DRIVEENUM_ALLVALID,TRUE,TRUE,TRUE,TRUE,FILEENUM_ALL_SUBLEVELS,FALSE,NULL)
  225. BOOL
  226. EnumFirstFileInTreeExW (
  227. OUT PFILETREE_ENUMW FileEnum,
  228. IN PCWSTR EncodedPathPattern,
  229. IN UINT DriveEnumTypes,
  230. IN BOOL EnumContainers,
  231. IN BOOL ContainersFirst,
  232. IN BOOL FilesFirst,
  233. IN BOOL DepthFirst,
  234. IN DWORD MaxSubLevels,
  235. IN BOOL UseExclusions,
  236. IN FPE_ERROR_CALLBACKW CallbackOnError OPTIONAL
  237. );
  238. #define EnumFirstFileInTreeW(e,p) EnumFirstFileInTreeExW(e,p,DRIVEENUM_ALLVALID,TRUE,TRUE,TRUE,TRUE,FILEENUM_ALL_SUBLEVELS,FALSE,NULL)
  239. BOOL
  240. EnumNextFileInTreeA (
  241. IN OUT PFILETREE_ENUMA FileEnum
  242. );
  243. BOOL
  244. EnumNextFileInTreeW (
  245. IN OUT PFILETREE_ENUMW FileEnum
  246. );
  247. VOID
  248. AbortEnumFileInTreeA (
  249. IN OUT PFILETREE_ENUMA FileEnum
  250. );
  251. VOID
  252. AbortEnumFileInTreeW (
  253. IN OUT PFILETREE_ENUMW FileEnum
  254. );
  255. //
  256. // Drive enumeration APIs
  257. //
  258. BOOL
  259. EnumFirstDriveA (
  260. OUT PDRIVE_ENUMA DriveEnum,
  261. IN UINT WantedDriveTypes
  262. );
  263. BOOL
  264. EnumFirstDriveW (
  265. OUT PDRIVE_ENUMW DriveEnum,
  266. IN UINT WantedDriveTypes
  267. );
  268. BOOL
  269. EnumNextDriveA (
  270. IN OUT PDRIVE_ENUMA DriveEnum
  271. );
  272. BOOL
  273. EnumNextDriveW (
  274. IN OUT PDRIVE_ENUMW DriveEnum
  275. );
  276. VOID
  277. AbortEnumDriveA (
  278. IN OUT PDRIVE_ENUMA DriveEnum
  279. );
  280. VOID
  281. AbortEnumDriveW (
  282. IN OUT PDRIVE_ENUMW DriveEnum
  283. );
  284. //
  285. // Routines built on enum
  286. //
  287. BOOL
  288. FiRemoveAllFilesInDirA (
  289. IN PCSTR Dir
  290. );
  291. BOOL
  292. FiRemoveAllFilesInDirW (
  293. IN PCWSTR Dir
  294. );
  295. BOOL
  296. FiRemoveAllFilesInTreeExA (
  297. IN PCSTR Dir,
  298. IN BOOL RemoveRoot
  299. );
  300. #define FiRemoveAllFilesInTreeA(dir) FiRemoveAllFilesInTreeExA(dir,TRUE)
  301. BOOL
  302. FiRemoveAllFilesInTreeExW (
  303. IN PCWSTR Dir,
  304. IN BOOL RemoveRoot
  305. );
  306. #define FiRemoveAllFilesInTreeW(dir) FiRemoveAllFilesInTreeExW(dir,TRUE)
  307. BOOL
  308. FiCopyAllFilesInDirA (
  309. IN PCSTR Source,
  310. IN PCSTR Dest,
  311. IN BOOL SkipExisting
  312. );
  313. #define FiCopyAllFilesInDirA(source,dest) FiCopyAllFilesInDirExA(source,dest,FALSE)
  314. BOOL
  315. FiCopyAllFilesInDirW (
  316. IN PCWSTR Source,
  317. IN PCWSTR Dest,
  318. IN BOOL SkipExisting
  319. );
  320. #define FiCopyAllFilesInDirW(source,dest) FiCopyAllFilesInDirExW(source,dest,FALSE)
  321. BOOL
  322. FiCopyAllFilesInTreeExA (
  323. IN PCSTR Source,
  324. IN PCSTR Dest,
  325. IN BOOL SkipExisting
  326. );
  327. #define FiCopyAllFilesInTreeA(source,dest) FiCopyAllFilesInTreeExA(source,dest,FALSE)
  328. BOOL
  329. FiCopyAllFilesInTreeExW (
  330. IN PCWSTR Source,
  331. IN PCWSTR Dest,
  332. IN BOOL SkipExisting
  333. );
  334. #define FiCopyAllFilesInTreeW(source,dest) FiCopyAllFilesInTreeExW(source,dest,FALSE)
  335. PCMDLINEA
  336. ParseCmdLineExA (
  337. IN PCSTR CmdLine,
  338. IN PCSTR Separators, OPTIONAL
  339. IN PFINDFILEA FindFileCallback, OPTIONAL
  340. IN PSEARCHPATHA SearchPathCallback, OPTIONAL
  341. IN OUT PGROWBUFFER Buffer
  342. );
  343. #define ParseCmdLineA(c,b) ParseCmdLineExA(c,NULL,NULL,NULL,b)
  344. PCMDLINEW
  345. ParseCmdLineExW (
  346. IN PCWSTR CmdLine,
  347. IN PCWSTR Separators, OPTIONAL
  348. IN PFINDFILEW FindFileCallback, OPTIONAL
  349. IN PSEARCHPATHW SearchPathCallback, OPTIONAL
  350. IN OUT PGROWBUFFER Buffer
  351. );
  352. #define ParseCmdLineW(c,b) ParseCmdLineExW(c,NULL,NULL,NULL,b)
  353. //
  354. // Macros
  355. //
  356. #ifdef UNICODE
  357. #define DIRNODE DIRNODEW
  358. #define PDIRNODE PDIRNODEW
  359. #define FILENODE FILENODEW
  360. #define PFILENODE PFILENODEW
  361. #define RPE_ERROR_CALLBACK RPE_ERROR_CALLBACKW
  362. #define FILEENUMINFO FILEENUMINFOW
  363. #define PFILEENUMINFO PFILEENUMINFOW
  364. #define FILETREE_ENUM FILETREE_ENUMW
  365. #define PFILETREE_ENUM PFILETREE_ENUMW
  366. #define EnumFirstFileInTree EnumFirstFileInTreeW
  367. #define EnumFirstFileInTreeEx EnumFirstFileInTreeExW
  368. #define EnumNextFileInTree EnumNextFileInTreeW
  369. #define AbortEnumFileInTree AbortEnumFileInTreeW
  370. #define DRIVE_ENUM DRIVE_ENUMW
  371. #define EnumFirstDrive EnumFirstDriveW
  372. #define EnumNextDrive EnumNextDriveW
  373. #define AbortEnumDrive AbortEnumDriveW
  374. #define FiRemoveAllFilesInDir FiRemoveAllFilesInDirW
  375. #define FiRemoveAllFilesInTreeEx FiRemoveAllFilesInTreeExW
  376. #define FiRemoveAllFilesInTree FiRemoveAllFilesInTreeW
  377. #define FiCopyAllFilesInDir FiCopyAllFilesInDirW
  378. #define FiCopyAllFilesInDirEx FiCopyAllFilesInDirExW
  379. #define FiCopyAllFilesInTree FiCopyAllFilesInTreeW
  380. #define FiCopyAllFilesInTreeEx FiCopyAllFilesInTreeExW
  381. #define CMDLINE CMDLINEW
  382. #define PCMDLINE PCMDLINEW
  383. #define ParseCmdLineEx ParseCmdLineExW
  384. #define ParseCmdLine ParseCmdLineW
  385. #else
  386. #define DIRNODE DIRNODEA
  387. #define PDIRNODE PDIRNODEA
  388. #define FILENODE FILENODEA
  389. #define PFILENODE PFILENODEA
  390. #define RPE_ERROR_CALLBACK RPE_ERROR_CALLBACKA
  391. #define FILEENUMINFO FILEENUMINFOA
  392. #define PFILEENUMINFO PFILEENUMINFOA
  393. #define FILETREE_ENUM FILETREE_ENUMA
  394. #define PFILETREE_ENUM PFILETREE_ENUMA
  395. #define EnumFirstFileInTree EnumFirstFileInTreeA
  396. #define EnumFirstFileInTreeEx EnumFirstFileInTreeExA
  397. #define EnumNextFileInTree EnumNextFileInTreeA
  398. #define AbortEnumFileInTree AbortEnumFileInTreeA
  399. #define DRIVE_ENUM DRIVE_ENUMA
  400. #define EnumFirstDrive EnumFirstDriveA
  401. #define EnumNextDrive EnumNextDriveA
  402. #define AbortEnumDrive AbortEnumDriveA
  403. #define FiRemoveAllFilesInDir FiRemoveAllFilesInDirA
  404. #define FiRemoveAllFilesInTreeEx FiRemoveAllFilesInTreeExA
  405. #define FiRemoveAllFilesInTree FiRemoveAllFilesInTreeA
  406. #define FiCopyAllFilesInDirEx FiCopyAllFilesInDirExA
  407. #define FiCopyAllFilesInDir FiCopyAllFilesInDirA
  408. #define FiCopyAllFilesInTreeEx FiCopyAllFilesInTreeExA
  409. #define FiCopyAllFilesInTree FiCopyAllFilesInTreeA
  410. #define CMDLINE CMDLINEA
  411. #define PCMDLINE PCMDLINEA
  412. #define ParseCmdLineEx ParseCmdLineExA
  413. #define ParseCmdLine ParseCmdLineA
  414. #endif