Microsoft KB Archive/105763: Difference between revisions
m (1 revision imported: importing part 2) |
m (Text replacement - "&" to "&") |
||
(3 intermediate revisions by the same user not shown) | |||
Line 42: | Line 42: | ||
=== Sample Code === | === Sample Code === | ||
<pre class="CODESAMP"> #include | <pre class="CODESAMP"> #include <windows.h> | ||
#include | #include <stdio.h> | ||
void main( ) | void main( ) | ||
Line 50: | Line 50: | ||
DWORD dwRet; | DWORD dwRet; | ||
hFile = CreateFile( | hFile = CreateFile( "testfile", | ||
GENERIC_WRITE, | GENERIC_WRITE, | ||
FILE_SHARE_WRITE, | FILE_SHARE_WRITE, | ||
Line 58: | Line 58: | ||
NULL ); | NULL ); | ||
if( hFile == INVALID_HANDLE_VALUE ) | if( hFile == INVALID_HANDLE_VALUE ) | ||
printf( | printf( "Cannot open testfile\n" ); | ||
else | else | ||
WriteFile( hFile, | WriteFile( hFile, "This is testfile", 16, &dwRet, NULL ); | ||
hStream = CreateFile( | hStream = CreateFile( "testfile:stream", | ||
GENERIC_WRITE, | GENERIC_WRITE, | ||
FILE_SHARE_WRITE, | FILE_SHARE_WRITE, | ||
Line 70: | Line 70: | ||
NULL ); | NULL ); | ||
if( hStream == INVALID_HANDLE_VALUE ) | if( hStream == INVALID_HANDLE_VALUE ) | ||
printf( | printf( "Cannot open testfile:stream\n" ); | ||
else | else | ||
WriteFile(hStream, | WriteFile(hStream, "This is testfile:stream", 23, &dwRet, NULL); | ||
} </pre> | } </pre> | ||
The file size obtained in a directory listing is 16, because you are looking only at | The file size obtained in a directory listing is 16, because you are looking only at "testfile", and therefore | ||
<blockquote>'''type testfile'''</blockquote> | <blockquote>'''type testfile'''</blockquote> | ||
Line 88: | Line 88: | ||
In order to view what is in testfile:stream, use: | In order to view what is in testfile:stream, use: | ||
<blockquote>'''more | <blockquote>'''more < testfile:stream'''</blockquote> | ||
<blockquote>-or-</blockquote> | <blockquote>-or-</blockquote> | ||
<blockquote>'''mep testfile:stream'''</blockquote> | <blockquote>'''mep testfile:stream'''</blockquote> | ||
where | where "mep" is the Microsoft Editor available in the Platform SDK. | ||
Additional query words: | Additional query words: |
Latest revision as of 12:24, 21 July 2020
HOWTO: Use NTFS Alternate Data Streams |
Q105763
The information in this article applies to:
- Microsoft Win32 Application Programming Interface (API), used with:
- the operating system: Microsoft Windows NT, versions 3.1, 3.5, 3.51, 4.0
- the operating system: Microsoft Windows 2000
SUMMARY
The documentation for the NTFS file system states that NTFS supports multiple streams of data; however, the documentation does not address the syntax for the streams themselves.
The Windows NT Resource Kit documents the stream syntax as follows:
filename:stream
Alternate data streams are strictly a feature of the NTFS file system and may not be supported in future file systems. However, NTFS will be supported in future versions of Windows NT.
Future file systems will support a model based on OLE 2.0 structured storage (IStream and IStorage). By using OLE 2.0, an application can support multiple streams on any file system and all supported operating systems (Windows, Macintosh, Windows NT, and Win32s), not just Windows NT.
MORE INFORMATION
The following sample code demonstrates NTFS streams:
Sample Code
#include <windows.h> #include <stdio.h> void main( ) { HANDLE hFile, hStream; DWORD dwRet; hFile = CreateFile( "testfile", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL ); if( hFile == INVALID_HANDLE_VALUE ) printf( "Cannot open testfile\n" ); else WriteFile( hFile, "This is testfile", 16, &dwRet, NULL ); hStream = CreateFile( "testfile:stream", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL ); if( hStream == INVALID_HANDLE_VALUE ) printf( "Cannot open testfile:stream\n" ); else WriteFile(hStream, "This is testfile:stream", 23, &dwRet, NULL); }
The file size obtained in a directory listing is 16, because you are looking only at "testfile", and therefore
type testfile
produces the following:
This is testfile
However
type testfile:stream
produces the following:
The filename syntax is incorrect
In order to view what is in testfile:stream, use:
more < testfile:stream
-or-
mep testfile:stream
where "mep" is the Microsoft Editor available in the Platform SDK.
Additional query words:
Keywords : kbAPI kbFileIO kbKernBase kbOSWin2000 kbDSupport kbGrpDSKernBase
Issue type : kbhowto
Technology : kbAudDeveloper kbWin32sSearch kbWin32API
Last Reviewed: October 27, 2000 |