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.

1048 lines
18 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. fsnode.hxx
  5. Abstract:
  6. This module contains the declaration for the FSNODE class. FSNODE stands
  7. for File System NODE and is an abstract class for all user visible
  8. objects that exist in a file system (e.g. files, directories).
  9. Author:
  10. David J. Gilman (davegi) 09-Jan-1991
  11. Environment:
  12. ULIB, User Mode
  13. Notes:
  14. Do not confuse this class or it's derived classes with the IFS class
  15. sub-hierarchy. FSNODE related classes are user visible classes. They
  16. are not intended to be used for low level file system tasks such as
  17. format or chkdsk. FSNODE classes are as file system independent as the
  18. underlying system allows.
  19. --*/
  20. #if ! defined( _FSNODE_ )
  21. #define _FSNODE_
  22. #include "path.hxx"
  23. //
  24. // Forward references
  25. //
  26. DECLARE_CLASS( ARRAY );
  27. DECLARE_CLASS( FSN_DIRECTORY );
  28. DECLARE_CLASS( FSNODE );
  29. DECLARE_CLASS( TIMEINFO );
  30. DECLARE_CLASS( WSTRING );
  31. //
  32. // Extend the set of system defined FILE_ATTRIBUTEs to include
  33. //
  34. // - all files (no directories)
  35. // - all file and directories
  36. //
  37. #define FILE_ATTRIBUTE_FILES ( FILE_ATTRIBUTE_ARCHIVE | \
  38. FILE_ATTRIBUTE_HIDDEN | \
  39. FILE_ATTRIBUTE_NORMAL | \
  40. FILE_ATTRIBUTE_READONLY | \
  41. FILE_ATTRIBUTE_COMPRESSED | \
  42. FILE_ATTRIBUTE_SYSTEM )
  43. #define FILE_ATTRIBUTE_ALL ( FILE_ATTRIBUTE_FILES | \
  44. FILE_ATTRIBUTE_DIRECTORY )
  45. typedef ULONG FSN_ATTRIBUTE;
  46. #define FSN_ATTRIBUTE_ARCHIVE FILE_ATTRIBUTE_ARCHIVE
  47. #define FSN_ATTRIBUTE_DIRECTORY FILE_ATTRIBUTE_DIRECTORY
  48. #define FSN_ATTRIBUTE_HIDDEN FILE_ATTRIBUTE_HIDDEN
  49. #define FSN_ATTRIBUTE_NORMAL FILE_ATTRIBUTE_NORMAL
  50. #define FSN_ATTRIBUTE_READONLY FILE_ATTRIBUTE_READONLY
  51. #define FSN_ATTRIBUTE_COMPRESSED FILE_ATTRIBUTE_COMPRESSED
  52. #define FSN_ATTRIBUTE_SYSTEM FILE_ATTRIBUTE_SYSTEM
  53. #define FSN_ATTRIBUTE_FILES FILE_ATTRIBUTE_FILES
  54. #define FSN_ATTRIBUTE_ALL FILE_ATTRIBUTE_ALL
  55. //
  56. // FSNODE time & date types
  57. //
  58. enum FSN_TIME {
  59. FSN_TIME_MODIFIED = 0,
  60. FSN_TIME_CREATED = 1,
  61. FSN_TIME_ACCESSED = 2
  62. };
  63. class FSNODE : public OBJECT {
  64. friend class FSN_FILTER;
  65. public:
  66. VIRTUAL
  67. ~FSNODE (
  68. );
  69. NONVIRTUAL
  70. PCPATH
  71. GetPath (
  72. ) CONST;
  73. NONVIRTUAL
  74. BOOLEAN
  75. IsArchived (
  76. ) CONST;
  77. NONVIRTUAL
  78. BOOLEAN
  79. IsDirectory (
  80. ) CONST;
  81. NONVIRTUAL
  82. BOOLEAN
  83. IsHidden (
  84. ) CONST;
  85. NONVIRTUAL
  86. BOOLEAN
  87. IsNormal (
  88. ) CONST;
  89. NONVIRTUAL
  90. BOOLEAN
  91. IsReadOnly (
  92. ) CONST;
  93. NONVIRTUAL
  94. BOOLEAN
  95. IsSystem (
  96. ) CONST;
  97. NONVIRTUAL
  98. BOOLEAN
  99. IsEncrypted (
  100. ) CONST;
  101. NONVIRTUAL
  102. BOOLEAN
  103. MakeArchived (
  104. OUT LPDWORD Win32Error DEFAULT NULL
  105. );
  106. NONVIRTUAL
  107. BOOLEAN
  108. MakeHidden (
  109. OUT LPDWORD Win32Error DEFAULT NULL
  110. );
  111. NONVIRTUAL
  112. BOOLEAN
  113. MakeNormal (
  114. OUT LPDWORD Win32Error DEFAULT NULL
  115. );
  116. NONVIRTUAL
  117. BOOLEAN
  118. MakeReadOnly (
  119. OUT LPDWORD Win32Error DEFAULT NULL
  120. );
  121. NONVIRTUAL
  122. BOOLEAN
  123. MakeSystem (
  124. OUT LPDWORD Win32Error DEFAULT NULL
  125. );
  126. NONVIRTUAL
  127. PWSTRING
  128. QueryBase (
  129. ) CONST;
  130. NONVIRTUAL
  131. PWSTRING
  132. QueryName (
  133. ) CONST;
  134. VIRTUAL
  135. PFSN_DIRECTORY
  136. QueryParentDirectory (
  137. ) CONST;
  138. VIRTUAL
  139. PTIMEINFO
  140. QueryTimeInfo (
  141. IN FSN_TIME TimeInfoType DEFAULT FSN_TIME_MODIFIED
  142. ) CONST;
  143. VIRTUAL
  144. BOOLEAN
  145. Rename(
  146. IN PCPATH NewName
  147. );
  148. NONVIRTUAL
  149. BOOLEAN
  150. ResetArchivedAttribute (
  151. OUT LPDWORD Win32Error DEFAULT NULL
  152. );
  153. NONVIRTUAL
  154. BOOLEAN
  155. ResetHiddenAttribute (
  156. OUT LPDWORD Win32Error DEFAULT NULL
  157. );
  158. NONVIRTUAL
  159. BOOLEAN
  160. ResetReadOnlyAttribute (
  161. OUT LPDWORD Win32Error DEFAULT NULL
  162. );
  163. NONVIRTUAL
  164. BOOLEAN
  165. ResetSystemAttribute (
  166. OUT LPDWORD Win32Error DEFAULT NULL
  167. );
  168. VIRTUAL
  169. BOOLEAN
  170. SetTimeInfo (
  171. IN PCTIMEINFO TimeInfo,
  172. IN FSN_TIME TimeInfoType DEFAULT FSN_TIME_MODIFIED
  173. );
  174. VIRTUAL
  175. BOOLEAN
  176. DeleteFromDisk(
  177. IN BOOLEAN Force DEFAULT FALSE
  178. );
  179. VIRTUAL
  180. BOOLEAN
  181. UpdateFsNode(
  182. );
  183. NONVIRTUAL
  184. FSN_ATTRIBUTE
  185. QueryAttributes(
  186. ) CONST;
  187. NONVIRTUAL
  188. BOOLEAN
  189. SetAttributes (
  190. IN FSN_ATTRIBUTE Attributes,
  191. OUT LPDWORD Win32Error DEFAULT NULL
  192. );
  193. NONVIRTUAL
  194. ULIB_EXPORT
  195. BOOLEAN
  196. UseAlternateName(
  197. );
  198. protected:
  199. DECLARE_CONSTRUCTOR( FSNODE );
  200. VIRTUAL
  201. BOOLEAN
  202. Initialize (
  203. IN PCWSTR PathName,
  204. IN PCFSN_DIRECTORY ParentDirectory,
  205. IN PWIN32_FIND_DATA FileData
  206. );
  207. VIRTUAL
  208. BOOLEAN
  209. Initialize (
  210. IN PCWSTRING PathName,
  211. IN PWIN32_FIND_DATA FileData
  212. );
  213. NONVIRTUAL
  214. PFILETIME
  215. GetCreationTime(
  216. );
  217. NONVIRTUAL
  218. PFILETIME
  219. GetLastAccessTime(
  220. );
  221. NONVIRTUAL
  222. PFILETIME
  223. GetLastWriteTime(
  224. );
  225. PATH _Path;
  226. WIN32_FIND_DATAW _FileData;
  227. private:
  228. };
  229. INLINE
  230. PCPATH
  231. FSNODE::GetPath (
  232. ) CONST
  233. /*++
  234. Routine Description:
  235. Return the contained PATH object.
  236. Arguments:
  237. None.
  238. Return Value:
  239. PCPATH - returns a constant pointer to the contained PATH object
  240. --*/
  241. {
  242. return( &_Path );
  243. }
  244. INLINE
  245. PFILETIME
  246. FSNODE::GetCreationTime(
  247. )
  248. /*++
  249. Routine Description:
  250. Returns pointer to creation time.
  251. Arguments:
  252. None.
  253. Return Value:
  254. PFILETIME - pointer to creation time
  255. --*/
  256. {
  257. return( &_FileData.ftCreationTime );
  258. }
  259. INLINE
  260. PFILETIME
  261. FSNODE::GetLastAccessTime(
  262. )
  263. /*++
  264. Routine Description:
  265. Returns pointer to last access time.
  266. Arguments:
  267. None.
  268. Return Value:
  269. PFILETIME - pointer to last access time
  270. --*/
  271. {
  272. return( &_FileData.ftLastAccessTime );
  273. }
  274. INLINE
  275. PFILETIME
  276. FSNODE::GetLastWriteTime(
  277. )
  278. /*++
  279. Routine Description:
  280. Returns pointer to last write time.
  281. Arguments:
  282. None.
  283. Return Value:
  284. PFILETIME - pointer to last write time
  285. --*/
  286. {
  287. return( &_FileData.ftLastWriteTime );
  288. }
  289. INLINE
  290. BOOLEAN
  291. FSNODE::IsArchived (
  292. ) CONST
  293. /*++
  294. Routine Description:
  295. Determine if this FSNODE's archived attribute is set.
  296. Arguments:
  297. None.
  298. Return Value:
  299. BOOLEAN - Returns TRUE if this FSNODE's archived attribute is set.
  300. --*/
  301. {
  302. return( ( _FileData.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE ) != 0 );
  303. }
  304. INLINE
  305. BOOLEAN
  306. FSNODE::IsDirectory (
  307. ) CONST
  308. /*++
  309. Routine Description:
  310. Determine if this FSNODE's directory attribute is set.
  311. Arguments:
  312. None.
  313. Return Value:
  314. BOOLEAN - Returns TRUE if this FSNODE's directory attribute is set.
  315. --*/
  316. {
  317. return( ( _FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) != 0 );
  318. }
  319. INLINE
  320. BOOLEAN
  321. FSNODE::IsHidden (
  322. ) CONST
  323. /*++
  324. Routine Description:
  325. Determine if this FSNODE's hidden attribute is set.
  326. Arguments:
  327. None.
  328. Return Value:
  329. BOOLEAN - Returns TRUE if this FSNODE's hidden attribute is set.
  330. --*/
  331. {
  332. return( ( _FileData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN ) != 0 );
  333. }
  334. INLINE
  335. BOOLEAN
  336. FSNODE::IsNormal (
  337. ) CONST
  338. /*++
  339. Routine Description:
  340. Determine if this FSNODE's normal attribute is set.
  341. Arguments:
  342. None.
  343. Return Value:
  344. BOOLEAN - Returns TRUE if this FSNODE's normal attribute is set.
  345. --*/
  346. {
  347. return( ( _FileData.dwFileAttributes & FILE_ATTRIBUTE_NORMAL ) != 0 );
  348. }
  349. INLINE
  350. BOOLEAN
  351. FSNODE::IsReadOnly (
  352. ) CONST
  353. /*++
  354. Routine Description:
  355. Determine if this FSNODE's readonly attribute is set.
  356. Arguments:
  357. None.
  358. Return Value:
  359. BOOLEAN - Returns TRUE if this FSNODE's readonly attribute is set.
  360. --*/
  361. {
  362. return( ( _FileData.dwFileAttributes & FILE_ATTRIBUTE_READONLY ) != 0 );
  363. }
  364. INLINE
  365. BOOLEAN
  366. FSNODE::IsSystem (
  367. ) CONST
  368. /*++
  369. Routine Description:
  370. Determine if this FSNODE's system attribute is set.
  371. Arguments:
  372. None.
  373. Return Value:
  374. BOOLEAN - Returns TRUE if this FSNODE's system attribute is set.
  375. --*/
  376. {
  377. return( ( _FileData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM ) != 0 );
  378. }
  379. INLINE
  380. BOOLEAN
  381. FSNODE::IsEncrypted (
  382. ) CONST
  383. /*++
  384. Routine Description:
  385. Determine if this FSNODE's encrypted attribute is set.
  386. Arguments:
  387. None.
  388. Return Value:
  389. BOOLEAN - Returns TRUE if this FSNODE's encrypted attribute is set.
  390. --*/
  391. {
  392. return( ( _FileData.dwFileAttributes & FILE_ATTRIBUTE_ENCRYPTED ) != 0 );
  393. }
  394. INLINE
  395. BOOLEAN
  396. FSNODE::MakeArchived (
  397. OUT LPDWORD Win32Error
  398. )
  399. /*++
  400. Routine Description:
  401. Make the underlying 'file' archived.
  402. Arguments:
  403. Win32Error - Optional parameter that will contain a Win32 error code
  404. if the method is unable to change attribute.
  405. Return Value:
  406. BOOLEAN - Returns the result of setting the file's archived attribute.
  407. --*/
  408. {
  409. if( SetFileAttributesW(( LPWSTR ) _FileData.cFileName,
  410. _FileData.dwFileAttributes | FILE_ATTRIBUTE_ARCHIVE )) {
  411. _FileData.dwFileAttributes |= FILE_ATTRIBUTE_ARCHIVE;
  412. return( TRUE );
  413. } else {
  414. if( Win32Error != NULL ) {
  415. *Win32Error = GetLastError();
  416. }
  417. return( FALSE );
  418. }
  419. }
  420. INLINE
  421. BOOLEAN
  422. FSNODE::MakeHidden (
  423. OUT LPDWORD Win32Error
  424. )
  425. /*++
  426. Routine Description:
  427. Make the underlying 'file' hidden.
  428. Arguments:
  429. Win32Error - Optional parameter that will contain a Win32 error code
  430. if the method is unable to change attribute.
  431. Return Value:
  432. BOOLEAN - Returns the result of setting the file's hidden attribute.
  433. --*/
  434. {
  435. if( SetFileAttributesW(( LPWSTR ) _FileData.cFileName,
  436. _FileData.dwFileAttributes | FILE_ATTRIBUTE_HIDDEN )) {
  437. _FileData.dwFileAttributes |= FILE_ATTRIBUTE_HIDDEN;
  438. return( TRUE );
  439. } else {
  440. if( Win32Error != NULL ) {
  441. *Win32Error = GetLastError();
  442. }
  443. return( FALSE );
  444. }
  445. }
  446. INLINE
  447. BOOLEAN
  448. FSNODE::MakeNormal (
  449. OUT LPDWORD Win32Error
  450. )
  451. /*++
  452. Routine Description:
  453. Make the underlying 'file' normal.
  454. Arguments:
  455. Win32Error - Optional parameter that will contain a Win32 error code
  456. if the method is unable to change attribute.
  457. Return Value:
  458. BOOLEAN - Returns the result of resetting all the file's resettable
  459. attributes.
  460. Note:
  461. Making a 'file' normal means resetting all but the
  462. FILE_ATTRIBUTE_DIRECTORY attributes.
  463. --*/
  464. {
  465. if( SetFileAttributesW(( LPWSTR ) _FileData.cFileName,
  466. FILE_ATTRIBUTE_NORMAL )) {
  467. _FileData.dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
  468. return( TRUE );
  469. } else {
  470. if( Win32Error != NULL ) {
  471. *Win32Error = GetLastError();
  472. }
  473. return( FALSE );
  474. }
  475. }
  476. INLINE
  477. BOOLEAN
  478. FSNODE::MakeReadOnly (
  479. OUT LPDWORD Win32Error
  480. )
  481. /*++
  482. Routine Description:
  483. Make the underlying 'file' read-only.
  484. Arguments:
  485. Win32Error - Optional parameter that will contain a Win32 error code
  486. if the method is unable to change attribute.
  487. Return Value:
  488. BOOLEAN - Returns the result of setting the file's read-only attribute.
  489. --*/
  490. {
  491. if( SetFileAttributesW(( LPWSTR ) _FileData.cFileName,
  492. _FileData.dwFileAttributes | FILE_ATTRIBUTE_READONLY )) {
  493. _FileData.dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
  494. return( TRUE );
  495. } else {
  496. if( Win32Error != NULL ) {
  497. *Win32Error = GetLastError();
  498. }
  499. return( FALSE );
  500. }
  501. }
  502. INLINE
  503. BOOLEAN
  504. FSNODE::MakeSystem (
  505. OUT LPDWORD Win32Error
  506. )
  507. /*++
  508. Routine Description:
  509. Make the underlying 'file' a system file.
  510. Arguments:
  511. Win32Error - Optional parameter that will contain a Win32 error code
  512. if the method is unable to change attribute.
  513. Return Value:
  514. BOOLEAN - Returns the result of setting the file's system attribute.
  515. --*/
  516. {
  517. if( SetFileAttributesW(( LPWSTR ) _FileData.cFileName,
  518. _FileData.dwFileAttributes | FILE_ATTRIBUTE_SYSTEM )) {
  519. _FileData.dwFileAttributes |= FILE_ATTRIBUTE_SYSTEM;
  520. return( TRUE );
  521. } else {
  522. if( Win32Error != NULL ) {
  523. *Win32Error = GetLastError();
  524. }
  525. return( FALSE );
  526. }
  527. }
  528. INLINE
  529. PWSTRING
  530. FSNODE::QueryBase (
  531. ) CONST
  532. /*++
  533. Routine Description:
  534. Return the base name maintained by the contained PATH object.
  535. Arguments:
  536. None.
  537. Return Value:
  538. PWSTRING - Returns a pointer to the base name.
  539. --*/
  540. {
  541. return( ((PFSNODE) this)->_Path.QueryBase( ));
  542. }
  543. INLINE
  544. FSN_ATTRIBUTE
  545. FSNODE::QueryAttributes (
  546. ) CONST
  547. /*++
  548. Routine Description:
  549. Return the node's attributes
  550. Arguments:
  551. None.
  552. Return Value:
  553. FSN_ATTRIBUTE - The attributes
  554. --*/
  555. {
  556. return( (FSN_ATTRIBUTE)_FileData.dwFileAttributes );
  557. }
  558. INLINE
  559. PWSTRING
  560. FSNODE::QueryName (
  561. ) CONST
  562. /*++
  563. Routine Description:
  564. Return the name maintained by the contained PATH object.
  565. Arguments:
  566. None.
  567. Return Value:
  568. PWSTRING - Returns a pointer to the name.
  569. --*/
  570. {
  571. return( ((PFSNODE) this)->_Path.QueryName( ));
  572. }
  573. INLINE
  574. BOOLEAN
  575. FSNODE::ResetArchivedAttribute (
  576. OUT LPDWORD Win32Error
  577. )
  578. /*++
  579. Routine Description:
  580. Make the underlying 'file' non archived.
  581. Arguments:
  582. Win32Error - Optional parameter that will contain a Win32 error code
  583. if the method is unable to change attribute.
  584. Return Value:
  585. BOOLEAN - Returns the result of resetting the file's archived attribute.
  586. --*/
  587. {
  588. if( SetFileAttributesW(( LPWSTR ) _FileData.cFileName,
  589. _FileData.dwFileAttributes & ~FILE_ATTRIBUTE_ARCHIVE )) {
  590. _FileData.dwFileAttributes &= ~FILE_ATTRIBUTE_ARCHIVE;
  591. return( TRUE );
  592. } else {
  593. if( Win32Error != NULL ) {
  594. *Win32Error = GetLastError();
  595. }
  596. return( FALSE );
  597. }
  598. }
  599. INLINE
  600. BOOLEAN
  601. FSNODE::ResetHiddenAttribute (
  602. OUT LPDWORD Win32Error
  603. )
  604. /*++
  605. Routine Description:
  606. Make the underlying 'file' non-hidden.
  607. Arguments:
  608. Win32Error - Optional parameter that will contain a Win32 error code
  609. if the method is unable to change attribute.
  610. Return Value:
  611. BOOLEAN - Returns the result of resetting the file's hidden attribute.
  612. --*/
  613. {
  614. if( SetFileAttributesW(( LPWSTR ) _FileData.cFileName,
  615. _FileData.dwFileAttributes & ~FILE_ATTRIBUTE_HIDDEN )) {
  616. _FileData.dwFileAttributes &= ~FILE_ATTRIBUTE_HIDDEN;
  617. return( TRUE );
  618. } else {
  619. if( Win32Error != NULL ) {
  620. *Win32Error = GetLastError();
  621. }
  622. return( FALSE );
  623. }
  624. }
  625. INLINE
  626. BOOLEAN
  627. FSNODE::ResetReadOnlyAttribute (
  628. OUT LPDWORD Win32Error
  629. )
  630. /*++
  631. Routine Description:
  632. Make the underlying 'file' non-read-only.
  633. Arguments:
  634. Win32Error - Optional parameter that will contain a Win32 error code
  635. if the method is unable to change attribute.
  636. Return Value:
  637. BOOLEAN - Returns the result of resetting the file's read-only attribute.
  638. --*/
  639. {
  640. if( SetFileAttributesW(( LPWSTR ) _FileData.cFileName,
  641. _FileData.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY )) {
  642. _FileData.dwFileAttributes &= ~FILE_ATTRIBUTE_READONLY;
  643. return( TRUE );
  644. } else {
  645. if( Win32Error != NULL ) {
  646. *Win32Error = GetLastError();
  647. }
  648. return( FALSE );
  649. }
  650. }
  651. INLINE
  652. BOOLEAN
  653. FSNODE::ResetSystemAttribute (
  654. OUT LPDWORD Win32Error
  655. )
  656. /*++
  657. Routine Description:
  658. Make the underlying 'file' a non-system file.
  659. Arguments:
  660. Win32Error - Optional parameter that will contain a Win32 error code
  661. if the method is unable to change attribute.
  662. Return Value:
  663. BOOLEAN - Returns the result of setting the file's system attribute.
  664. --*/
  665. {
  666. if( SetFileAttributesW(( LPWSTR ) _FileData.cFileName,
  667. _FileData.dwFileAttributes & ~FILE_ATTRIBUTE_SYSTEM )) {
  668. _FileData.dwFileAttributes &= ~FILE_ATTRIBUTE_SYSTEM;
  669. return( TRUE );
  670. } else {
  671. if( Win32Error != NULL ) {
  672. *Win32Error = GetLastError();
  673. }
  674. return( FALSE );
  675. }
  676. }
  677. INLINE
  678. BOOLEAN
  679. FSNODE::SetAttributes (
  680. IN FSN_ATTRIBUTE Attributes,
  681. OUT LPDWORD Win32Error
  682. )
  683. /*++
  684. Routine Description:
  685. Set the attributes of the underlying 'file'.
  686. (This method was added to improve performance of attrib.exe).
  687. Arguments:
  688. Attributes - New attributes for the file.
  689. Win32Error - Optional parameter that will contain a Win32 error code
  690. if the method is unable to change attribute.
  691. Return Value:
  692. BOOLEAN - Returns the result of setting the file's system attribute.
  693. --*/
  694. {
  695. if( SetFileAttributesW(( LPWSTR ) _FileData.cFileName,
  696. (_FileData.dwFileAttributes & ~FILE_ATTRIBUTE_FILES) | Attributes )) {
  697. _FileData.dwFileAttributes &= ~FILE_ATTRIBUTE_FILES;
  698. _FileData.dwFileAttributes |= Attributes;
  699. return( TRUE );
  700. } else {
  701. if( Win32Error != NULL ) {
  702. *Win32Error = GetLastError();
  703. }
  704. return( FALSE );
  705. }
  706. }
  707. #endif // _FSNODE_