common/rc: factor out _scratch_xfs_[get|set]_sb_field
[xfstests-dev.git] / dmapi / src / suite1 / cmd / sync_by_handle.c
1 /*
2  * Copyright (c) 2000-2001 Silicon Graphics, Inc.
3  * All Rights Reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it would be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write the Free Software Foundation,
16  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18
19 #include <lib/hsm.h>
20
21 #include <getopt.h>
22 #include <string.h>
23
24
25 /*---------------------------------------------------------------------------
26
27 Test program used to test the DMAPI function dm_sync_by_handle().  The
28 command line is:
29
30         sync_by_handle [-s sid] pathname
31
32 where:
33 'sid' is the session ID to use for the call.
34 'pathname' is the name of the file to be sync'd.
35
36 ----------------------------------------------------------------------------*/
37
38 #ifndef linux
39 extern  char    *sys_errlist[];
40 #endif
41 extern  int     optind;
42 extern  char    *optarg;
43
44
45 char    *Progname;
46
47
48 static void
49 usage(void)
50 {
51         fprintf(stderr, "usage:\t%s [-s sid] pathname\n", Progname);
52         exit(1);
53 }
54
55
56 int
57 main(
58         int     argc, 
59         char    **argv)
60 {
61         dm_sessid_t     sid = DM_NO_SESSION;
62         char            *pathname = NULL;
63         void            *hanp;
64         size_t          hlen;
65         char            *name;
66         int             opt;
67
68         Progname = strrchr(argv[0], '/');
69         if (Progname) {
70                 Progname++;
71         } else {
72                 Progname = argv[0];
73         }
74
75         /* Crack and validate the command line options. */
76
77         while ((opt = getopt(argc, argv, "s:")) != EOF) {
78                 switch (opt) {
79                 case 's':
80                         sid = atol(optarg);
81                         break;
82                 case '?':
83                         usage();
84                 }
85         }
86         if (optind + 1 != argc)
87                 usage();
88         pathname = argv[optind];
89
90         if (dm_init_service(&name) == -1)  {
91                 fprintf(stderr, "Can't initialize the DMAPI\n");
92                 exit(1);
93         }
94         if (sid == DM_NO_SESSION)
95                 find_test_session(&sid);
96
97         /* Get the file's handle. */
98
99         if (dm_path_to_handle(pathname, &hanp, &hlen)) {
100                 fprintf(stderr, "can't get handle for file %s\n", pathname);
101                 exit(1);
102         }
103
104         if (dm_sync_by_handle(sid, hanp, hlen, DM_NO_TOKEN)) {
105                 fprintf(stderr, "dm_sync_by_handle failed, %s\n",
106                         strerror(errno));
107                 exit(1);
108         }
109         dm_handle_free(hanp, hlen);
110         exit(0);
111 }