1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2001 Silicon Graphics, Inc.
10 /*---------------------------------------------------------------------------
12 Test program used to test the DMAPI function dm_get_dirattrs(). The
15 get_dirattrs [-b buflen] [-l loc] [-s sid] dirpath
17 where dirpath is the name of a directory, buflen is the size of the buffer
18 to use in the call, loc is a starting location, and sid is the session ID
19 whose attributes you are interested in.
21 ----------------------------------------------------------------------------*/
24 extern char *sys_errlist[];
35 fprintf(stderr, "usage:\t%s [-b buflen] [-l loc] [-s sid] [-1] [-q] dirpath\n",
46 dm_sessid_t sid = DM_NO_SESSION;
51 size_t buflen = 10000;
62 Progname = strrchr(argv[0], '/');
69 /* Crack and validate the command line options. */
71 while ((opt = getopt(argc, argv, "b:l:s:1q")) != EOF) {
74 buflen = atol(optarg);
92 if (optind + 1 != argc)
94 dirpath = argv[optind++];
96 if (dm_init_service(&name) == -1) {
97 fprintf(stderr, "Can't initialize the DMAPI\n");
100 if (sid == DM_NO_SESSION)
101 find_test_session(&sid);
103 /* Get the directory's handle. */
105 if (dm_path_to_handle(dirpath, &hanp, &hlen)) {
106 fprintf(stderr, "can't get handle for file %s, %s\n",
107 dirpath, strerror(errno));
111 if ((bufp = malloc(buflen == 0 ? 1 : buflen)) == NULL) {
112 fprintf(stderr, "malloc failed, %s\n", strerror(errno));
116 mask = DM_AT_HANDLE|DM_AT_EMASK|DM_AT_PMANR|DM_AT_PATTR|DM_AT_DTIME|DM_AT_CFLAG|DM_AT_STAT;
119 memset(bufp, 0, buflen);
120 if ((ret = dm_get_dirattrs(sid, hanp, hlen, DM_NO_TOKEN, mask,
121 &loc, buflen, bufp, &rlenp)) < 0) {
122 fprintf(stderr, "dm_get_dirattrs failed, %s\n",
127 fprintf(stdout, "ret = %d, rlenp is %zd, loc is %lld\n",
128 ret, rlenp, (long long) loc);
133 statp = (dm_stat_t *)bufp;
134 while (statp != NULL) {
136 hantoa((char *)statp + statp->dt_handle.vd_offset,
137 statp->dt_handle.vd_length, buffer);
139 fprintf(stdout, "%s %s\n",
140 (char *)statp + statp->dt_compname.vd_offset,
144 fprintf(stdout, "handle %s\n", buffer);
145 fprintf(stdout, "name %s\n",
146 (char *)statp + statp->dt_compname.vd_offset);
150 statp = DM_STEP_TO_NEXT(statp, dm_stat_t *);
153 else if ((ret == 1) && (rlenp == 0) && (!quiet)) {
154 fprintf(stderr, "buflen is too short to hold anything\n");
159 dm_handle_free(hanp, hlen);