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.

77 lines
2.0 KiB

  1. // offline.c
  2. #include "oidtst.h"
  3. VOID
  4. _cdecl
  5. main(
  6. int argc,
  7. char *argv[]
  8. )
  9. {
  10. HANDLE File;
  11. FILE_BASIC_INFORMATION BasicInfo;
  12. IO_STATUS_BLOCK IoStatusBlock;
  13. NTSTATUS Status;
  14. UCHAR ArgStr[2];
  15. if (argc < 3) {
  16. printf( "This program finds the object id of a file (ntfs only).\n\n" );
  17. printf( "usage: %s filename [+ | -]\n", argv[0] );
  18. printf( "example: %s foo.dll +\n", argv[0] );
  19. return;
  20. }
  21. File = CreateFile( argv[1],
  22. GENERIC_WRITE,
  23. FILE_SHARE_READ | FILE_SHARE_WRITE,
  24. NULL,
  25. OPEN_EXISTING,
  26. 0,
  27. NULL );
  28. if (File == INVALID_HANDLE_VALUE) {
  29. printf( "Error opening file %s %x\n", argv[1], GetLastError() );
  30. return;
  31. }
  32. Status = NtQueryInformationFile( File,
  33. &IoStatusBlock,
  34. &BasicInfo,
  35. sizeof(BasicInfo),
  36. FileBasicInformation );
  37. if (*argv[2] == '+') {
  38. BasicInfo.FileAttributes |= FILE_ATTRIBUTE_OFFLINE;
  39. } else if (*argv[2] == '-') {
  40. BasicInfo.FileAttributes &= ~FILE_ATTRIBUTE_OFFLINE;
  41. } else {
  42. printf( "Invalid parameter %s, use either + or -\n", argv[2] );
  43. Status = STATUS_INVALID_PARAMETER;
  44. }
  45. if (NT_SUCCESS(Status)) {
  46. printf( "\nAdjusting offline attribute for file %s", argv[1] );
  47. Status = NtSetInformationFile( File,
  48. &IoStatusBlock,
  49. &BasicInfo,
  50. sizeof(BasicInfo),
  51. FileBasicInformation );
  52. if (!NT_SUCCESS(Status)) {
  53. printf( "Error setting info%x\n", Status );
  54. }
  55. }
  56. CloseHandle( File );
  57. }