1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2001 Silicon Graphics, Inc.
12 /*---------------------------------------------------------------------------
14 Test program used to test the DMAPI function dm_get_dmattr(). The
17 get_dmattr [-b buflen] [-s sid] [-t token] {pathname|handle} attr
19 where pathname is the name of a file, buflen is the size of the buffer to use
20 in the call, attr is the name of the DMAPI attribute, and sid is the session ID
21 whose attributes you you are interested in.
23 ----------------------------------------------------------------------------*/
26 extern char *sys_errlist[];
37 fprintf(stderr, "usage:\t%s [-b buflen] [-s sid] [-t token] "
38 "{pathname|handle} attr\n", Progname);
48 dm_sessid_t sid = DM_NO_SESSION;
49 dm_token_t token = DM_NO_TOKEN;
51 dm_attrname_t *attrnamep;
53 size_t buflen = 10000;
60 Progname = strrchr(argv[0], '/');
67 /* Crack and validate the command line options. */
69 while ((opt = getopt(argc, argv, "b:s:t:")) != EOF) {
72 buflen = atol(optarg);
84 if (optind + 2 != argc)
86 object = argv[optind++];
87 attrnamep = (dm_attrname_t *)argv[optind];
89 if (dm_init_service(&name) == -1) {
90 fprintf(stderr, "Can't initialize the DMAPI\n");
93 if (sid == DM_NO_SESSION)
94 find_test_session(&sid);
96 /* Get the file's handle. */
98 if (opaque_to_handle(object, &hanp, &hlen)) {
99 fprintf(stderr, "can't get handle for %s\n", object);
104 if ((bufp = malloc(buflen)) == NULL) {
105 fprintf(stderr, "malloc failed, %s\n", strerror(errno));
110 if (dm_get_dmattr(sid, hanp, hlen, token, attrnamep, buflen,
112 if (errno == E2BIG) {
113 fprintf(stderr, "dm_get_dmattr buffer too small, "
114 "should be %zd bytes\n", rlenp);
116 fprintf(stderr, "dm_get_dmattr failed, %s\n",
121 fprintf(stdout, "rlenp is %zd, value is '%s'\n", rlenp, (char*)bufp);
123 dm_handle_free(hanp, hlen);