xfstests: eliminate warnings under dmapi/src/suite1/cmd (3)
[xfstests-dev.git] / dmapi / src / suite1 / cmd / set_dmattr.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_set_dmattr().  The
28 command line is:
29
30         set_dmattr [-b buflen] [-s sid] [-u] {pathname|handle} attr value
31
32 where pathname is the name of a file, buflen is the size of the buffer to use
33 in the call, attr is the name of the DMAPI attribute, -u is selected if 
34 setdtime should be updated, and sid is the session ID whose attributes you
35 are interested in.
36
37 ----------------------------------------------------------------------------*/
38
39 #ifndef linux
40 extern  char    *sys_errlist[];
41 #endif
42 extern  int     optind;
43 extern  char    *optarg;
44
45
46 char    *Progname;
47
48 static void
49 usage(void)
50 {
51         fprintf(stderr, "usage:\t%s [-b buflen] [-s sid] [-u] "
52                 "{pathname|handle} attr value\n", Progname);
53         exit(1);
54 }
55
56
57 int
58 main(
59         int     argc, 
60         char    **argv)
61 {
62         dm_sessid_t     sid = DM_NO_SESSION;
63         char            *object;
64         dm_attrname_t   *attrnamep;
65         char            *bufp;
66         size_t          buflen = 0;
67         int             bflag = 0;
68         int             setdtime = 0;
69         void            *hanp;
70         size_t          hlen;
71         char            *name;
72         int             opt;
73
74         Progname = strrchr(argv[0], '/');
75         if (Progname) {
76                 Progname++;
77         } else {
78                 Progname = argv[0];
79         }
80
81         /* Crack and validate the command line options. */
82
83         while ((opt = getopt(argc, argv, "b:s:u")) != EOF) {
84                 switch (opt) {
85                 case 'b':
86                         bflag++;
87                         buflen = atol(optarg);
88                         break;
89                 case 's':
90                         sid = atol(optarg);
91                         break;
92                 case 'u':
93                         setdtime = 1;
94                         break;
95                 case '?':
96                         usage();
97                 }
98         }
99         if (optind + 3 != argc)
100                 usage();
101         object = argv[optind++];
102         attrnamep = (dm_attrname_t *)argv[optind++];
103         bufp = argv[optind];
104         if (!bflag)
105                 buflen = strlen(bufp) + 1;
106
107         if (dm_init_service(&name) == -1)  {
108                 fprintf(stderr, "Can't initialize the DMAPI\n");
109                 exit(1);
110         }
111         if (sid == DM_NO_SESSION)
112                 find_test_session(&sid);
113
114         /* Get the file's handle. */
115
116         if (opaque_to_handle(object, &hanp, &hlen)) {
117                 fprintf(stderr, "can't get handle for %s\n", object);
118                 exit(1);
119         }
120
121         if (dm_set_dmattr(sid, hanp, hlen, DM_NO_TOKEN, attrnamep, setdtime,
122             buflen, bufp)) {
123                 fprintf(stderr, "dm_set_dmattr failed, %s\n",
124                         strerror(errno));
125                 exit(1);
126         }
127
128         dm_handle_free(hanp, hlen);
129         exit(0);
130 }