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.

105 lines
3.1 KiB

  1. // notify.c
  2. #include "oidtst.h"
  3. int
  4. FsTestNotifyOidChange (
  5. IN HANDLE hFile
  6. )
  7. {
  8. IO_STATUS_BLOCK IoStatusBlock;
  9. NTSTATUS Status;
  10. UCHAR Buffer1[128];
  11. UCHAR Buffer2[128];
  12. PFILE_NOTIFY_INFORMATION NotifyBuffer1;
  13. PFILE_NOTIFY_INFORMATION NotifyBuffer2;
  14. // KEVENT Event1;
  15. // KEVENT Event2;
  16. RtlZeroMemory( &Buffer1[0], sizeof(Buffer1) );
  17. RtlZeroMemory( &Buffer2[0], sizeof(Buffer2) );
  18. // KeInitializeEvent( &Event1, NotificationEvent, FALSE );
  19. // KeInitializeEvent( &Event2, NotificationEvent, FALSE );
  20. Status = NtNotifyChangeDirectoryFile( hFile,
  21. NULL, // Event
  22. NULL, // ApcRoutine
  23. NULL, // ApcContext
  24. &IoStatusBlock,
  25. &Buffer1[0],
  26. sizeof(Buffer1),
  27. FILE_NOTIFY_CHANGE_FILE_NAME,
  28. TRUE );
  29. #if 0
  30. Status = NtNotifyChangeDirectoryFile( hFile,
  31. NULL, // Event
  32. NULL, // ApcRoutine
  33. NULL, // ApcContext
  34. &IoStatusBlock,
  35. &Buffer2[0],
  36. sizeof(Buffer2),
  37. FILE_NOTIFY_CHANGE_FILE_NAME,
  38. TRUE );
  39. #endif
  40. NotifyBuffer1 = (PFILE_NOTIFY_INFORMATION) &Buffer1[0];
  41. // NextEntryOffset
  42. printf( "\nAction %d", NotifyBuffer1->Action );
  43. printf( "\nLength %d", NotifyBuffer1->FileNameLength );
  44. printf( "\nObjectId " );
  45. FsTestHexDump( NotifyBuffer1->FileName, NotifyBuffer1->FileNameLength );
  46. printf( "\n" );
  47. return FsTestDecipherStatus( Status );
  48. }
  49. VOID
  50. _cdecl
  51. main (
  52. int argc,
  53. char *argv[]
  54. )
  55. {
  56. HANDLE hFile;
  57. char Buffer[80];
  58. char Buff2[4];
  59. //
  60. // Get parameters
  61. //
  62. if (argc < 2) {
  63. printf("This program watches for changes to the object id index for a volume (ntfs only).\n\n");
  64. printf("usage: %s driveletter\n", argv[0]);
  65. return;
  66. }
  67. strcpy( Buffer, argv[1] );
  68. strcat( Buffer, "\\$Extend\\$ObjId:$O:$INDEX_ALLOCATION" );
  69. hFile = CreateFile( Buffer,
  70. GENERIC_READ,
  71. FILE_SHARE_READ,
  72. NULL,
  73. OPEN_EXISTING,
  74. FILE_FLAG_BACKUP_SEMANTICS | SECURITY_IMPERSONATION,
  75. NULL );
  76. if ( hFile == INVALID_HANDLE_VALUE ) {
  77. printf( "Error opening directory %s (dec) %d\n", Buffer, GetLastError() );
  78. return;
  79. }
  80. printf( "\nUsing directory:%s\n", Buffer );
  81. FsTestNotifyOidChange( hFile );
  82. CloseHandle( hFile );
  83. return;
  84. }