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.

269 lines
7.8 KiB

  1. #include <pch.cxx>
  2. //+---------------------------------------------------------------------------
  3. //
  4. // Microsoft Windows
  5. // Copyright (C) Microsoft Corporation, 1994 - 1998.
  6. //
  7. // File: names.cxx
  8. //
  9. //+---------------------------------------------------------------------------
  10. ///////////////////////// CONTENTS STREAM ////////////////////////////////////
  11. const WCHAR g_wszContentsStreamName[] = L"CONTENTS";
  12. //+----------------------------------------------------------------------------
  13. //
  14. // Routine IsContentStream
  15. // Calls String Compare with "CONTENTS".
  16. //
  17. //+----------------------------------------------------------------------------
  18. BOOL IsContentStream( const WCHAR* pwszName )
  19. {
  20. return ( 0 == dfwcsnicmp( pwszName, g_wszContentsStreamName, -1 ) );
  21. }
  22. //+----------------------------------------------------------------------------
  23. //
  24. // Routine GetContentStreamName
  25. // returns the string "CONTENTS".
  26. //
  27. //+----------------------------------------------------------------------------
  28. const WCHAR* GetContentStreamName()
  29. {
  30. return g_wszContentsStreamName;
  31. }
  32. ///////////////////////// NTFS $Data Name Mangling ///////////////////////////
  33. //+----------------------------------------------------------------------------
  34. //
  35. // CNtfsStreamName "constructor"
  36. // converts "name" into ":name:$DATA"
  37. //
  38. //+----------------------------------------------------------------------------
  39. const WCHAR g_wszNtfsDollarDataSuffix[] = L":$DATA";
  40. CNtfsStreamName::CNtfsStreamName( const WCHAR *pwsz)
  41. {
  42. nffAssert( NULL != pwsz);
  43. if( IsContentStream( pwsz ) )
  44. pwsz = L"";
  45. _count = wcslen( pwsz ) + CCH_NTFS_DOLLAR_DATA + 1;
  46. nffAssert( NTFS_MAX_ATTR_NAME_LEN >= _count );
  47. wcscpy( _wsz, L":" );
  48. wcscat( _wsz, pwsz );
  49. wcscat( _wsz, g_wszNtfsDollarDataSuffix );
  50. }
  51. //+----------------------------------------------------------------------------
  52. //
  53. // Routine IsDataStream
  54. // Does the name have a ":$Data" On the end.
  55. //
  56. //+----------------------------------------------------------------------------
  57. BOOL IsDataStream( const PFILE_STREAM_INFORMATION pFSInfo )
  58. {
  59. BOOL ret;
  60. LONG ccnt = pFSInfo->StreamNameLength/sizeof(WCHAR) - CCH_NTFS_DOLLAR_DATA;
  61. ret = pFSInfo->StreamNameLength >= CCH_NTFS_DOLLAR_DATA*sizeof(WCHAR)
  62. && !dfwcsnicmp( &pFSInfo->StreamName[ ccnt ],
  63. g_wszNtfsDollarDataSuffix,
  64. CCH_NTFS_DOLLAR_DATA );
  65. return ret;
  66. }
  67. //+----------------------------------------------------------------------------
  68. //
  69. // Routine GetNtfsUnmangledNameInfo
  70. // Take an FILE_STREAM_INFORMATION record and compute the unmangled name.
  71. // No memory allocation, just return pointers into the existing data.
  72. // The given FILE_STREAM_INFORMATION record must be a $DATA record.
  73. // Also invent "CONTENTS" if necessary.
  74. //
  75. //+----------------------------------------------------------------------------
  76. void
  77. GetNtfsUnmangledNameInfo(const FILE_STREAM_INFORMATION *pFSI,
  78. const WCHAR** ppwcs,
  79. ULONG* pcch)
  80. {
  81. // The stream names in pFSI are "mangled"; they have the ":" prefix
  82. // and ":$DATA" suffix. Get the size and address of the beginning of
  83. // the unmangled name, which is what we'll return to the caller.
  84. LONG cbName = pFSI->StreamNameLength
  85. - sizeof(WCHAR) // leading colon
  86. - sizeof(WCHAR)*CCH_NTFS_DOLLAR_DATA; // ":$DATA"
  87. nffAssert(cbName >=0 && cbName <= NTFS_MAX_ATTR_NAME_LEN);
  88. if(0 == cbName )
  89. {
  90. *ppwcs = GetContentStreamName();
  91. *pcch = wcslen(*ppwcs); // *ppwcs is NULL terminated in this case
  92. }
  93. else
  94. {
  95. *ppwcs = &pFSI->StreamName[1];
  96. *pcch = cbName/sizeof(WCHAR); // *ppwcs is not NULL terminated!
  97. }
  98. }
  99. ///////////////////////// NFF CONTROL STREAM ////////////////////////////////
  100. //+----------------------------------------------------------------------------
  101. //
  102. // Routine IsControlStream
  103. //
  104. //+----------------------------------------------------------------------------
  105. const WCHAR g_wszNFFControlStreamName[] = L"{4c8cc155-6c1e-11d1-8e41-00c04fb9386d}";
  106. BOOL IsControlStream( const WCHAR* pwszName )
  107. {
  108. return ( 0 == dfwcsnicmp( pwszName, g_wszNFFControlStreamName, -1 ) );
  109. }
  110. //+----------------------------------------------------------------------------
  111. //
  112. // Routine GetControlStreamName
  113. //
  114. //+----------------------------------------------------------------------------
  115. const WCHAR* GetControlStreamName()
  116. {
  117. return g_wszNFFControlStreamName;
  118. }
  119. //+----------------------------------------------------------------------------
  120. //
  121. // Routine IsSpecifiedStream
  122. //
  123. //+----------------------------------------------------------------------------
  124. BOOL IsSpecifiedStream(const FILE_STREAM_INFORMATION *pFSI,
  125. const WCHAR *pwszStream // Without the :*:$data adornments
  126. )
  127. {
  128. DWORD cch = wcslen(pwszStream);
  129. // The cch plus the ::$data decorations should match the stream length
  130. if( cch + CCH_NTFS_DOLLAR_DATA + 1
  131. !=
  132. pFSI->StreamNameLength / sizeof(WCHAR) )
  133. {
  134. return FALSE;
  135. }
  136. return ( 0 == dfwcsnicmp( &( pFSI->StreamName[1] ),
  137. pwszStream,
  138. cch ) );
  139. }
  140. //+----------------------------------------------------------------------------
  141. //
  142. // Routine HasVisibleNamedStreams
  143. //
  144. // Returns TRUE if there is a stream other than the contents
  145. // and control streams.
  146. //
  147. //+----------------------------------------------------------------------------
  148. BOOL HasVisibleNamedStreams( const FILE_STREAM_INFORMATION *pfsi )
  149. {
  150. for( ; NULL != pfsi; pfsi = NextFSI(pfsi) )
  151. {
  152. if( !IsHiddenStream(pfsi) && !IsContentsStream(pfsi) )
  153. return( TRUE );
  154. }
  155. return( FALSE );
  156. }
  157. ///////////////////////// Docfile Stream Name Mangling ///////////////////////
  158. //+----------------------------------------------------------------------------
  159. //
  160. // CDocfileStreamName "constructor"
  161. // converts "name" into "Docf_name"
  162. //
  163. //+----------------------------------------------------------------------------
  164. const WCHAR g_wszDocfileStreamPrefix[] = L"Docf_";
  165. CDocfileStreamName::CDocfileStreamName( const WCHAR *pwsz)
  166. {
  167. wcscpy( _wszName, g_wszDocfileStreamPrefix );
  168. wcscat( _wszName, pwsz );
  169. }
  170. //+----------------------------------------------------------------------------
  171. //
  172. // Routine IsDocfileStream
  173. // Does the name have a "Docf_" On the front.
  174. //
  175. //+----------------------------------------------------------------------------
  176. BOOL IsDocfileStream( const WCHAR *pwsz )
  177. {
  178. return( 0 == wcsncmp( pwsz, g_wszDocfileStreamPrefix,
  179. CCH_DOCFILESTREAMPREFIX ) );
  180. }
  181. const WCHAR *
  182. UnmangleDocfileStreamName( const WCHAR *pwszName )
  183. {
  184. nffAssert( IsDocfileStream( pwszName ));
  185. return( &pwszName[ CCH_DOCFILESTREAMPREFIX ] );
  186. }
  187. ///////////////////////// Update Stream Name Mangling ///////////////////////
  188. //+----------------------------------------------------------------------------
  189. //
  190. // CDocfileStreamName "constructor"
  191. // converts "name" into "Updt_name"
  192. //
  193. //+----------------------------------------------------------------------------
  194. const WCHAR g_wszNtfsUpdateStreamPrefix[] = L"Updt_";
  195. CNtfsUpdateStreamName::CNtfsUpdateStreamName( const WCHAR *pwsz)
  196. {
  197. wcscpy( _wszName, g_wszNtfsUpdateStreamPrefix );
  198. wcscat( _wszName, pwsz );
  199. }
  200. //+----------------------------------------------------------------------------
  201. //
  202. // CNtfsUpdateStreamName statics
  203. //
  204. //+----------------------------------------------------------------------------
  205. BOOL
  206. IsUpdateStream( const WCHAR *pwsz )
  207. {
  208. return( 0 == wcsncmp( pwsz, g_wszNtfsUpdateStreamPrefix,
  209. sizeof(g_wszNtfsUpdateStreamPrefix)/sizeof(WCHAR) ));
  210. }