ReactOS  0.4.12-dev-57-g7050ac4
hardlink.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS FS utility tool
4  * FILE: base/applications/cmdutils/hardlink.c
5  * PURPOSE: FSutil hard links handling
6  * PROGRAMMERS: Pierre Schweitzer <pierre@reactos.org>
7  */
8 
9 #include "fsutil.h"
10 
11 /* Add handlers here for subcommands */
14 {
15  /* Proc, name, help */
16  { CreateMain, _T("create"), _T("Create a new hard link") },
17 };
18 
19 static int
20 CreateMain(int argc, const TCHAR *argv[])
21 {
23 
24  /* We need a source and a destination */
25  if (argc < 3)
26  {
27  _ftprintf(stderr, _T("Usage: fsutil hardlink create <new> <existing>\n"));
28  _ftprintf(stderr, _T("\tFor example: fsutil hardlink create c:\\target.txt c:\\source.txt\n"));
29  return 1;
30  }
31 
32  /* Get full names */
33  if (GetFullPathName(argv[1], MAX_PATH, Target, NULL) == 0)
34  {
36  return 1;
37  }
38 
39  if (GetFullPathName(argv[2], MAX_PATH, Source, NULL) == 0)
40  {
42  return 1;
43  }
44 
45  /* Simply delegate to kernel32 */
46  if (!CreateHardLink(Target, Source, NULL))
47  {
49  return 1;
50  }
51 
52  /* Print the status */
53  _ftprintf(stdout, _T("Hard link created for %s <=> %s\n"), Target, Source);
54 
55  return 0;
56 }
57 
58 static void
60 {
61  PrintDefaultUsage(_T(" HARDLINK "), Command, (HandlerItem *)&HandlersList,
62  (sizeof(HandlersList) / sizeof(HandlersList[0])));
63 }
64 
65 int
66 HardLinkMain(int argc, const TCHAR *argv[])
67 {
68  return FindHandler(argc, argv, (HandlerItem *)&HandlersList,
69  (sizeof(HandlersList) / sizeof(HandlersList[0])),
70  PrintUsage);
71 }
static int argc
Definition: ServiceArgs.c:12
void PrintDefaultUsage(const TCHAR *Command, const TCHAR *SubCommand, HandlerItem *HandlersList, int HandlerListCount)
Definition: common.c:102
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
Definition: shell.h:41
static char ** argv
Definition: ServiceArgs.c:11
FILE * stdout
int FindHandler(int argc, const TCHAR *argv[], HandlerItem *HandlersList, int HandlerListCount, void(*UsageHelper)(const TCHAR *))
Definition: common.c:11
smooth NULL
Definition: ftsmooth.c:416
#define _ftprintf
Definition: tchar.h:518
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define MAX_PATH
Definition: compat.h:26
_Must_inspect_result_ typedef _In_ ULONG _In_ BOOLEAN Target
Definition: iotypes.h:1067
#define GetFullPathName
Definition: winbase.h:3635
int() HandlerProc(int argc, const TCHAR *argv[])
Definition: fsutil.h:8
static VOID PrintErrorMessage(DWORD dwError)
Definition: at.c:308
FILE * stderr
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3149