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
22 /*---------------------------------------------------------------------------
24 Test program used to test the DMAPI function dm_get_dirattrs(). The
27 get_dirattrs [-b buflen] [-l loc] [-s sid] dirpath
29 where dirpath is the name of a directory, buflen is the size of the buffer
30 to use in the call, loc is a starting location, and sid is the session ID
31 whose attributes you are interested in.
33 ----------------------------------------------------------------------------*/
36 extern char *sys_errlist[];
47 fprintf(stderr, "usage:\t%s [-b buflen] [-l loc] [-s sid] [-1] [-q] dirpath\n",
58 dm_sessid_t sid = DM_NO_SESSION;
63 size_t buflen = 10000;
74 Progname = strrchr(argv[0], '/');
81 /* Crack and validate the command line options. */
83 while ((opt = getopt(argc, argv, "b:l:s:1q")) != EOF) {
86 buflen = atol(optarg);
104 if (optind + 1 != argc)
106 dirpath = argv[optind++];
108 if (dm_init_service(&name) == -1) {
109 fprintf(stderr, "Can't initialize the DMAPI\n");
112 if (sid == DM_NO_SESSION)
113 find_test_session(&sid);
115 /* Get the directory's handle. */
117 if (dm_path_to_handle(dirpath, &hanp, &hlen)) {
118 fprintf(stderr, "can't get handle for file %s, %s\n",
119 dirpath, strerror(errno));
123 if ((bufp = malloc(buflen == 0 ? 1 : buflen)) == NULL) {
124 fprintf(stderr, "malloc failed, %s\n", strerror(errno));
128 mask = DM_AT_HANDLE|DM_AT_EMASK|DM_AT_PMANR|DM_AT_PATTR|DM_AT_DTIME|DM_AT_CFLAG|DM_AT_STAT;
131 memset(bufp, 0, buflen);
132 if ((ret = dm_get_dirattrs(sid, hanp, hlen, DM_NO_TOKEN, mask,
133 &loc, buflen, bufp, &rlenp)) < 0) {
134 fprintf(stderr, "dm_get_dirattrs failed, %s\n",
139 fprintf(stdout, "ret = %d, rlenp is %zd, loc is %lld\n",
140 ret, rlenp, (long long) loc);
145 statp = (dm_stat_t *)bufp;
146 while (statp != NULL) {
148 hantoa((char *)statp + statp->dt_handle.vd_offset,
149 statp->dt_handle.vd_length, buffer);
151 fprintf(stdout, "%s %s\n",
152 (char *)statp + statp->dt_compname.vd_offset,
156 fprintf(stdout, "handle %s\n", buffer);
157 fprintf(stdout, "name %s\n",
158 (char *)statp + statp->dt_compname.vd_offset);
162 statp = DM_STEP_TO_NEXT(statp, dm_stat_t *);
165 else if ((ret == 1) && (rlenp == 0) && (!quiet)) {
166 fprintf(stderr, "buflen is too short to hold anything\n");
171 dm_handle_free(hanp, hlen);