Update copyright annotations and license boilerplates to correspond with SGI Legals...
[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         if (Progname = strrchr(argv[0], '/')) {
69                 Progname++;
70         } else {
71                 Progname = argv[0];
72         }
73
74         /* Crack and validate the command line options. */
75
76         while ((opt = getopt(argc, argv, "s:")) != EOF) {
77                 switch (opt) {
78                 case 's':
79                         sid = atol(optarg);
80                         break;
81                 case '?':
82                         usage();
83                 }
84         }
85         if (optind + 1 != argc)
86                 usage();
87         pathname = argv[optind];
88
89         if (dm_init_service(&name) == -1)  {
90                 fprintf(stderr, "Can't initialize the DMAPI\n");
91                 exit(1);
92         }
93         if (sid == DM_NO_SESSION)
94                 find_test_session(&sid);
95
96         /* Get the file's handle. */
97
98         if (dm_path_to_handle(pathname, &hanp, &hlen)) {
99                 fprintf(stderr, "can't get handle for file %s\n", pathname);
100                 exit(1);
101         }
102
103         if (dm_sync_by_handle(sid, hanp, hlen, DM_NO_TOKEN)) {
104                 fprintf(stderr, "dm_sync_by_handle failed, %s\n",
105                         strerror(errno));
106                 exit(1);
107         }
108         dm_handle_free(hanp, hlen);
109         exit(0);
110 }