Source code of Windows XP (NT5)
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.

89 lines
1.7 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. hardlink.c
  5. Abstract:
  6. This file contains code for commands that affect hardlinks.
  7. Author:
  8. Wesley Witt [wesw] 1-March-2000
  9. Revision History:
  10. --*/
  11. #include <precomp.h>
  12. INT
  13. HardLinkHelp(
  14. IN INT argc,
  15. IN PWSTR argv[]
  16. )
  17. {
  18. DisplayMsg( MSG_USAGE_HARDLINK );
  19. return EXIT_CODE_SUCCESS;
  20. }
  21. INT
  22. CreateHardLinkFile(
  23. IN INT argc,
  24. IN PWSTR argv[]
  25. )
  26. {
  27. PWSTR Filename1 = NULL;
  28. PWSTR Filename2 = NULL;
  29. INT ExitCode = EXIT_CODE_SUCCESS;
  30. do {
  31. if (argc != 2) {
  32. DisplayMsg( MSG_USAGE_HARDLINK_CREATE );
  33. if (argc != 0) {
  34. ExitCode = EXIT_CODE_FAILURE;
  35. }
  36. break;
  37. }
  38. Filename1 = GetFullPath( argv[0] );
  39. if (!Filename1) {
  40. DisplayError();
  41. ExitCode = EXIT_CODE_FAILURE;
  42. break;
  43. }
  44. Filename2 = GetFullPath( argv[1] );
  45. if (!Filename2) {
  46. DisplayError();
  47. ExitCode = EXIT_CODE_FAILURE;
  48. break;
  49. }
  50. if ((!IsVolumeLocalNTFS( Filename1[0] )) || (!IsVolumeLocalNTFS( Filename2[0] ))) {
  51. DisplayMsg( MSG_NTFS_REQUIRED );
  52. ExitCode = EXIT_CODE_FAILURE;
  53. break;
  54. }
  55. if (CreateHardLink( Filename1, Filename2, NULL )) {
  56. DisplayMsg( MSG_HARDLINK_CREATED, Filename1, Filename2 );
  57. } else {
  58. if (GetLastError( ) == ERROR_NOT_SAME_DEVICE) {
  59. DisplayMsg( MSG_NOT_SAME_DEVICE );
  60. } else {
  61. DisplayError();
  62. }
  63. ExitCode = EXIT_CODE_FAILURE;
  64. }
  65. } while ( FALSE );
  66. free( Filename1 );
  67. free( Filename2 );
  68. return ExitCode;
  69. }