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_getall_dmattr(). The
29 getall_dmattr [-b buflen] [-s sid] pathname
31 where pathname is the name of a file, buflen is the size of the buffer to use
32 in the call, and sid is the session ID whose attributes you are interested in.
34 ----------------------------------------------------------------------------*/
37 extern char *sys_errlist[];
48 fprintf(stderr, "usage:\t%s [-b buflen] [-s sid] pathname\n",
59 dm_sessid_t sid = DM_NO_SESSION;
62 size_t buflen = 10000;
69 Progname = strrchr(argv[0], '/');
76 /* Crack and validate the command line options. */
78 while ((opt = getopt(argc, argv, "b:s:")) != EOF) {
81 buflen = atol(optarg);
90 if (optind + 1 != argc)
92 pathname = argv[optind++];
94 if (dm_init_service(&name) == -1) {
95 fprintf(stderr, "Can't initialize the DMAPI\n");
98 if (sid == DM_NO_SESSION)
99 find_test_session(&sid);
101 /* Get the file's handle. */
103 if (dm_path_to_handle(pathname, &hanp, &hlen)) {
104 fprintf(stderr, "can't get handle for file %s, %s\n",
105 pathname, strerror(errno));
109 if ((bufp = malloc(buflen == 0 ? 1 : buflen)) == NULL) {
110 fprintf(stderr, "malloc failed, %s\n", strerror(errno));
114 if (dm_getall_dmattr(sid, hanp, hlen, DM_NO_TOKEN, buflen,
116 if (errno == E2BIG) {
117 fprintf(stderr, "dm_getall_dmattr buffer too small, "
118 "should be %zd bytes\n", rlenp);
120 fprintf(stderr, "dm_getall_dmattr failed, %s\n",
125 fprintf(stdout, "rlenp is %zd\n", rlenp);
127 dm_attrlist_t *attrlist;
129 fprintf(stdout, "DMAPI attributes are:\n");
131 attrlist = (dm_attrlist_t *)bufp;
132 while (attrlist != NULL) {
133 fprintf(stdout, "Name: %s, length %d, value '%s'\n",
134 attrlist->al_name.an_chars,
135 DM_GET_LEN(attrlist, al_data),
136 DM_GET_VALUE(attrlist, al_data, char *));
138 attrlist = DM_STEP_TO_NEXT(attrlist, dm_attrlist_t *);
142 dm_handle_free(hanp, hlen);