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
21 /*---------------------------------------------------------------------------
23 Test program used to test the DMAPI function dm_get_dirattrs(). The
26 get_dirattrs [-b buflen] [-l loc] [-s sid] dirpath
28 where dirpath is the name of a directory, buflen is the size of the buffer
29 to use in the call, loc is a starting location, and sid is the session ID
30 whose attributes you are interested in.
32 ----------------------------------------------------------------------------*/
35 extern char *sys_errlist[];
48 fprintf(stderr, "usage:\t%s [-b buflen] [-l loc] [-s sid] [-1] [-q] dirpath\n",
59 dm_sessid_t sid = DM_NO_SESSION;
64 size_t buflen = 10000;
76 if (Progname = strrchr(argv[0], '/')) {
82 /* Crack and validate the command line options. */
84 while ((opt = getopt(argc, argv, "b:l:s:1q")) != EOF) {
87 buflen = atol(optarg);
105 if (optind + 1 != argc)
107 dirpath = argv[optind++];
109 if (dm_init_service(&name) == -1) {
110 fprintf(stderr, "Can't initialize the DMAPI\n");
113 if (sid == DM_NO_SESSION)
114 find_test_session(&sid);
116 /* Get the directory's handle. */
118 if (dm_path_to_handle(dirpath, &hanp, &hlen)) {
119 fprintf(stderr, "can't get handle for file %s, %s\n",
120 dirpath, strerror(errno));
124 if ((bufp = malloc(buflen == 0 ? 1 : buflen)) == NULL) {
125 fprintf(stderr, "malloc failed, %s\n", strerror(errno));
129 mask = DM_AT_HANDLE|DM_AT_EMASK|DM_AT_PMANR|DM_AT_PATTR|DM_AT_DTIME|DM_AT_CFLAG|DM_AT_STAT;
132 memset(bufp, 0, buflen);
133 if ((ret = dm_get_dirattrs(sid, hanp, hlen, DM_NO_TOKEN, mask,
134 &loc, buflen, bufp, &rlenp)) < 0) {
135 fprintf(stderr, "dm_get_dirattrs failed, %s\n",
140 fprintf(stdout, "ret = %d, rlenp is %d, loc is %lld\n", ret,
146 statp = (dm_stat_t *)bufp;
147 while (statp != NULL) {
149 hantoa((char *)statp + statp->dt_handle.vd_offset,
150 statp->dt_handle.vd_length, buffer);
152 fprintf(stdout, "%s %s\n",
153 (char *)statp + statp->dt_compname.vd_offset,
157 fprintf(stdout, "handle %s\n", buffer);
158 fprintf(stdout, "name %s\n",
159 (char *)statp + statp->dt_compname.vd_offset);
163 statp = DM_STEP_TO_NEXT(statp, dm_stat_t *);
166 else if ((ret == 1) && (rlenp == 0) && (!quiet)) {
167 fprintf(stderr, "buflen is too short to hold anything\n");
172 dm_handle_free(hanp, hlen);