Uso de secuencias

En el ejemplo de este tema se muestra cómo usar secuencias básicas del sistema de archivos NTFS.

En este ejemplo se crea un archivo, denominado "TestFile", con un tamaño de 16 bytes. Sin embargo, el archivo también tiene un tipo de secuencia ::$DATA adicional, denominado "Stream", que agrega 23 bytes adicionales que el sistema operativo no notifica. Por lo tanto, al ver la propiedad de tamaño de archivo del archivo, solo verá el tamaño del flujo predeterminado ::$DATA para el archivo.

#include <windows.h>
#include <stdio.h>

void main( )
 {
  HANDLE hFile, hStream;
  DWORD dwRet;

  hFile = CreateFile( TEXT("TestFile"), // Filename
                      GENERIC_WRITE,    // Desired access
                      FILE_SHARE_WRITE, // Share flags
                      NULL,             // Security Attributes
                      OPEN_ALWAYS,      // Creation Disposition
                      0,                // Flags and Attributes
                      NULL );           // OVERLAPPED pointer
  if( hFile == INVALID_HANDLE_VALUE )
   {
    printf( "Cannot open TestFile\n" );
    return;
   }
  else
   {
    WriteFile( hFile,              // Handle
               "This is TestFile", // Data to be written
               16,                 // Size of data, in bytes
               &dwRet,             // Number of bytes written
               NULL );             // OVERLAPPED pointer
    CloseHandle( hFile );
    hFile = INVALID_HANDLE_VALUE;
   }

  hStream = CreateFile( TEXT("TestFile:Stream"), // Filename
                        GENERIC_WRITE,           // Desired access
                        FILE_SHARE_WRITE,        // Share flags
                        NULL,                    // Security Attributes
                        OPEN_ALWAYS,             // Creation Disposition
                        0,                       // Flags and Attributes
                        NULL );                  // OVERLAPPED pointer
  if( hStream == INVALID_HANDLE_VALUE )
    printf( "Cannot open TestFile:Stream\n" );
  else
   {
    WriteFile( hStream,                   // Handle
               "This is TestFile:Stream", // Data to be written
               23,                        // Size of data
               &dwRet,                    // Number of bytes written
               NULL);                     // OVERLAPPED pointer
    CloseHandle( hStream );
    hStream = INVALID_HANDLE_VALUE;
   }
}

Si escribe Type TestFile en un símbolo del sistema, muestra la siguiente salida:

This is TestFile

Sin embargo, si escribe las palabras Type TestFile:Stream, genera el siguiente error:

"La sintaxis de nombre de archivo, nombre de directorio o etiqueta de volumen es incorrecta".

Para ver lo que está en TestFile:stream, use uno de los siguientes comandos:

Más < testFile:Stream

Más < testFile:Stream:$DATA

El texto que se muestra es el siguiente:

This is TestFile:Stream

Secuencias de archivos