2 * Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
40 #include <sys/types.h>
44 /*---------------------------------------------------------------------------
46 Test program used to test the DMAPI function dm_read_invis(). The
49 read_invis [-o offset] [-l length] [-s sid] [-c char] \
50 [-S storefile] {pathname|handle}
53 'offset' is the offset of the start of the write (0 is the default),
54 'length' is the length of the write in bytes (1 is the default),
55 'sid' is the session ID whose events you you are interested in.
56 'pathname' is the name of the file to be written.
57 'char' is ignored--it just allows read_invis and write_invis to have
58 interchangeable commandlines without having to fuss with the params.
60 ----------------------------------------------------------------------------*/
63 extern char *sys_errlist[];
75 fprintf(stderr, "usage:\t%s [-o offset] [-l length] "
77 "[-S storefile] {pathname|handle}\n", Progname);
87 dm_sessid_t sid = DM_NO_SESSION;
98 char *storefile = NULL;
102 if (Progname = strrchr(argv[0], '/')) {
108 /* Crack and validate the command line options. */
110 while ((opt = getopt(argc, argv, "o:l:s:c:S:")) != EOF) {
113 sscanf(optarg, "%lld", &offset);
116 sscanf(optarg, "%llu", &length);
122 /* This is a no-op, it just allows read_invis
123 * and write_invis to have interchangeable
124 * commandlines, without having to fuss with
135 if (optind + 1 != argc)
137 object = argv[optind];
139 if (dm_init_service(&name) == -1) {
140 fprintf(stderr, "Can't initialize the DMAPI\n");
143 if (sid == DM_NO_SESSION)
144 find_test_session(&sid);
146 /* Get the file's handle. */
148 if (opaque_to_handle(object, &hanp, &hlen)) {
149 fprintf(stderr, "can't get handle for %s\n", object);
154 /* In case it is a realtime file, align the buffer on a
155 sufficiently big boundary.
157 if ((bufp = memalign(4096, length)) == NULL) {
158 fprintf(stderr, "malloc of %llu bytes failed\n", length);
161 memset(bufp, '\0', length);
167 if ((storefd = open(storefile, O_WRONLY|O_CREAT, 0777)) == -1) {
168 fprintf(stderr, "unable to open store file for write (%s), errno = %d\n", storefile, errno);
171 lret = lseek(storefd, offset, SEEK_SET);
173 fprintf(stderr, "unable to lseek(%s) to offset %lld, errno = %d\n",
174 storefile, (long long)lret, errno);
179 rc = dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN, offset, length, bufp);
182 fprintf(stderr, "dm_read_invis failed, %s\n", strerror(errno));
184 } else if (rc != length) {
185 fprintf(stderr, "dm_read_invis expected to read %lld bytes, actually "
186 "read %lld\n", length, rc);
192 sret = write(storefd, bufp, rc);
194 fprintf(stderr, "unable to write to store file (%s), errno = %d\n", storefile, errno);
197 else if (sret != rc) {
198 fprintf(stderr, "write(%s) returned %lld, expected %lld\n",
199 storefile, (long long)sret, (long long)rc);
205 for (i = 0; i < rc; i++) {
206 if (isprint(bufp[i])) {
207 fprintf(stdout, "%c", bufp[i]);
209 fprintf(stdout, "\\%03d", bufp[i]);
213 dm_handle_free(hanp, hlen);