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[];
46 fprintf(stderr, "usage:\t%s [-b buflen] [-l loc] [-s sid] [-1] [-q] dirpath\n",
57 dm_sessid_t sid = DM_NO_SESSION;
62 size_t buflen = 10000;
73 Progname = strrchr(argv[0], '/');
80 /* Crack and validate the command line options. */
82 while ((opt = getopt(argc, argv, "b:l:s:1q")) != EOF) {
85 buflen = atol(optarg);
103 if (optind + 1 != argc)
105 dirpath = argv[optind++];
107 if (dm_init_service(&name) == -1) {
108 fprintf(stderr, "Can't initialize the DMAPI\n");
111 if (sid == DM_NO_SESSION)
112 find_test_session(&sid);
114 /* Get the directory's handle. */
116 if (dm_path_to_handle(dirpath, &hanp, &hlen)) {
117 fprintf(stderr, "can't get handle for file %s, %s\n",
118 dirpath, strerror(errno));
122 if ((bufp = malloc(buflen == 0 ? 1 : buflen)) == NULL) {
123 fprintf(stderr, "malloc failed, %s\n", strerror(errno));
127 mask = DM_AT_HANDLE|DM_AT_EMASK|DM_AT_PMANR|DM_AT_PATTR|DM_AT_DTIME|DM_AT_CFLAG|DM_AT_STAT;
130 memset(bufp, 0, buflen);
131 if ((ret = dm_get_dirattrs(sid, hanp, hlen, DM_NO_TOKEN, mask,
132 &loc, buflen, bufp, &rlenp)) < 0) {
133 fprintf(stderr, "dm_get_dirattrs failed, %s\n",
138 fprintf(stdout, "ret = %d, rlenp is %zd, loc is %lld\n",
139 ret, rlenp, (long long) loc);
144 statp = (dm_stat_t *)bufp;
145 while (statp != NULL) {
147 hantoa((char *)statp + statp->dt_handle.vd_offset,
148 statp->dt_handle.vd_length, buffer);
150 fprintf(stdout, "%s %s\n",
151 (char *)statp + statp->dt_compname.vd_offset,
155 fprintf(stdout, "handle %s\n", buffer);
156 fprintf(stdout, "name %s\n",
157 (char *)statp + statp->dt_compname.vd_offset);
161 statp = DM_STEP_TO_NEXT(statp, dm_stat_t *);
164 else if ((ret == 1) && (rlenp == 0) && (!quiet)) {
165 fprintf(stderr, "buflen is too short to hold anything\n");
170 dm_handle_free(hanp, hlen);