Leaked source code of windows server 2003
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.

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