_scratch_mkfs_geom(): Filter out 'k' suffix from fs block size
[xfstests-dev.git] / dmapi / src / suite1 / cmd / sync_by_handle.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000-2001 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6
7 #include <lib/hsm.h>
8
9 #include <getopt.h>
10 #include <string.h>
11
12
13 /*---------------------------------------------------------------------------
14
15 Test program used to test the DMAPI function dm_sync_by_handle().  The
16 command line is:
17
18         sync_by_handle [-s sid] pathname
19
20 where:
21 'sid' is the session ID to use for the call.
22 'pathname' is the name of the file to be sync'd.
23
24 ----------------------------------------------------------------------------*/
25
26 #ifndef linux
27 extern  char    *sys_errlist[];
28 #endif
29 extern  int     optind;
30 extern  char    *optarg;
31
32
33 char    *Progname;
34
35
36 static void
37 usage(void)
38 {
39         fprintf(stderr, "usage:\t%s [-s sid] pathname\n", Progname);
40         exit(1);
41 }
42
43
44 int
45 main(
46         int     argc, 
47         char    **argv)
48 {
49         dm_sessid_t     sid = DM_NO_SESSION;
50         char            *pathname = NULL;
51         void            *hanp;
52         size_t          hlen;
53         char            *name;
54         int             opt;
55
56         Progname = strrchr(argv[0], '/');
57         if (Progname) {
58                 Progname++;
59         } else {
60                 Progname = argv[0];
61         }
62
63         /* Crack and validate the command line options. */
64
65         while ((opt = getopt(argc, argv, "s:")) != EOF) {
66                 switch (opt) {
67                 case 's':
68                         sid = atol(optarg);
69                         break;
70                 case '?':
71                         usage();
72                 }
73         }
74         if (optind + 1 != argc)
75                 usage();
76         pathname = argv[optind];
77
78         if (dm_init_service(&name) == -1)  {
79                 fprintf(stderr, "Can't initialize the DMAPI\n");
80                 exit(1);
81         }
82         if (sid == DM_NO_SESSION)
83                 find_test_session(&sid);
84
85         /* Get the file's handle. */
86
87         if (dm_path_to_handle(pathname, &hanp, &hlen)) {
88                 fprintf(stderr, "can't get handle for file %s\n", pathname);
89                 exit(1);
90         }
91
92         if (dm_sync_by_handle(sid, hanp, hlen, DM_NO_TOKEN)) {
93                 fprintf(stderr, "dm_sync_by_handle failed, %s\n",
94                         strerror(errno));
95                 exit(1);
96         }
97         dm_handle_free(hanp, hlen);
98         exit(0);
99 }