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
26 #include <sys/types.h>
30 /*---------------------------------------------------------------------------
32 Test program used to test the DMAPI function dm_read_invis(). The
35 read_invis [-o offset] [-l length] [-s sid] [-c char] \
36 [-S storefile] {pathname|handle}
39 'offset' is the offset of the start of the write (0 is the default),
40 'length' is the length of the write in bytes (1 is the default),
41 'sid' is the session ID whose events you you are interested in.
42 'pathname' is the name of the file to be written.
43 'char' is ignored--it just allows read_invis and write_invis to have
44 interchangeable commandlines without having to fuss with the params.
46 ----------------------------------------------------------------------------*/
49 extern char *sys_errlist[];
61 fprintf(stderr, "usage:\t%s [-o offset] [-l length] "
63 "[-S storefile] {pathname|handle}\n", Progname);
73 dm_sessid_t sid = DM_NO_SESSION;
78 unsigned long long ulltemp;
86 char *storefile = NULL;
90 Progname = strrchr(argv[0], '/');
97 /* Crack and validate the command line options. */
99 while ((opt = getopt(argc, argv, "o:l:s:c:S:")) != EOF) {
102 sscanf(optarg, "%lld", &lltemp);
103 offset = (dm_off_t) lltemp;
106 sscanf(optarg, "%llu", &ulltemp);
107 length = (dm_size_t) ulltemp;
113 /* This is a no-op, it just allows read_invis
114 * and write_invis to have interchangeable
115 * commandlines, without having to fuss with
126 if (optind + 1 != argc)
128 object = argv[optind];
130 if (dm_init_service(&name) == -1) {
131 fprintf(stderr, "Can't initialize the DMAPI\n");
134 if (sid == DM_NO_SESSION)
135 find_test_session(&sid);
137 /* Get the file's handle. */
139 if (opaque_to_handle(object, &hanp, &hlen)) {
140 fprintf(stderr, "can't get handle for %s\n", object);
145 /* In case it is a realtime file, align the buffer on a
146 sufficiently big boundary.
148 if ((bufp = memalign(4096, length)) == NULL) {
149 fprintf(stderr, "malloc of %llu bytes failed\n",
150 (unsigned long long) length);
153 memset(bufp, '\0', length);
159 if ((storefd = open(storefile, O_WRONLY|O_CREAT, 0777)) == -1) {
160 fprintf(stderr, "unable to open store file for write (%s), errno = %d\n", storefile, errno);
163 lret = lseek(storefd, offset, SEEK_SET);
165 fprintf(stderr, "unable to lseek(%s) to offset %lld, errno = %d\n",
166 storefile, (long long)lret, errno);
171 rc = dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN, offset, length, bufp);
174 fprintf(stderr, "dm_read_invis failed, %s\n", strerror(errno));
176 } else if (rc != length) {
177 fprintf(stderr, "dm_read_invis expected to read %llu bytes, actually "
178 "read %lld\n", (unsigned long long) length,
185 sret = write(storefd, bufp, rc);
187 fprintf(stderr, "unable to write to store file (%s), errno = %d\n", storefile, errno);
190 else if (sret != rc) {
191 fprintf(stderr, "write(%s) returned %lld, expected %lld\n",
192 storefile, (long long)sret, (long long)rc);
198 for (i = 0; i < rc; i++) {
199 if (isprint(bufp[i])) {
200 fprintf(stdout, "%c", bufp[i]);
202 fprintf(stdout, "\\%03d", bufp[i]);
206 dm_handle_free(hanp, hlen);