2 * Copyright (c) 2000-2001 Silicon Graphics, Inc.
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.
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.
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
24 /*---------------------------------------------------------------------------
26 Test program used to test the DMAPI function dm_get_dmattr(). The
29 get_dmattr [-b buflen] [-s sid] [-t token] {pathname|handle} attr
31 where pathname is the name of a file, buflen is the size of the buffer to use
32 in the call, attr is the name of the DMAPI attribute, and sid is the session ID
33 whose attributes you you are interested in.
35 ----------------------------------------------------------------------------*/
38 extern char *sys_errlist[];
49 fprintf(stderr, "usage:\t%s [-b buflen] [-s sid] [-t token] "
50 "{pathname|handle} attr\n", Progname);
60 dm_sessid_t sid = DM_NO_SESSION;
61 dm_token_t token = DM_NO_TOKEN;
63 dm_attrname_t *attrnamep;
65 size_t buflen = 10000;
72 Progname = strrchr(argv[0], '/');
79 /* Crack and validate the command line options. */
81 while ((opt = getopt(argc, argv, "b:s:t:")) != EOF) {
84 buflen = atol(optarg);
96 if (optind + 2 != argc)
98 object = argv[optind++];
99 attrnamep = (dm_attrname_t *)argv[optind];
101 if (dm_init_service(&name) == -1) {
102 fprintf(stderr, "Can't initialize the DMAPI\n");
105 if (sid == DM_NO_SESSION)
106 find_test_session(&sid);
108 /* Get the file's handle. */
110 if (opaque_to_handle(object, &hanp, &hlen)) {
111 fprintf(stderr, "can't get handle for %s\n", object);
116 if ((bufp = malloc(buflen)) == NULL) {
117 fprintf(stderr, "malloc failed, %s\n", strerror(errno));
122 if (dm_get_dmattr(sid, hanp, hlen, token, attrnamep, buflen,
124 if (errno == E2BIG) {
125 fprintf(stderr, "dm_get_dmattr buffer too small, "
126 "should be %zd bytes\n", rlenp);
128 fprintf(stderr, "dm_get_dmattr failed, %s\n",
133 fprintf(stdout, "rlenp is %zd, value is '%s'\n", rlenp, (char*)bufp);
135 dm_handle_free(hanp, hlen);