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
24 #include <sys/types.h>
28 /*---------------------------------------------------------------------------
30 Test program used to test the DMAPI function dm_write_invis(). The
33 write_invis [-c char] [-o offset] [-l length] [-s sid] \
34 [-S storefile] {pathname|handle}
37 'char' is the character to use as a repeated pattern ('X' is the default),
38 'offset' is the offset of the start of the write (0 is the default),
39 'length' is the length of the write in bytes (1 is the default),
40 'sid' is the session ID whose events you you are interested in.
41 'pathname' is the name of the file to be written.
43 DM_WRITE_SYNC is is not supported.
45 ----------------------------------------------------------------------------*/
48 extern char *sys_errlist[];
60 fprintf(stderr, "usage:\t%s [-c char] [-o offset] [-l length] "
61 "[-s sid] [-S storefile] {pathname|handle}\n", Progname);
71 dm_sessid_t sid = DM_NO_SESSION;
76 unsigned long long ulltemp;
84 char *storefile = NULL;
88 Progname = strrchr(argv[0], '/');
95 /* Crack and validate the command line options. */
97 while ((opt = getopt(argc, argv, "c:o:l:s:S:")) != EOF) {
103 sscanf(optarg, "%lld", &lltemp);
104 offset = (dm_off_t) offset;
107 sscanf(optarg, "%llu", &ulltemp);
108 length = (dm_size_t) ulltemp;
120 if (optind + 1 != argc)
122 object = argv[optind];
124 if (dm_init_service(&name) == -1) {
125 fprintf(stderr, "Can't initialize the DMAPI\n");
128 if (sid == DM_NO_SESSION)
129 find_test_session(&sid);
131 /* Get the file's handle. */
133 if (opaque_to_handle(object, &hanp, &hlen)) {
134 fprintf(stderr, "can't get handle for %s\n", object);
139 /* In case it is a realtime file, align the buffer on a
140 sufficiently big boundary.
142 if ((bufp = memalign(4096, length)) == NULL) {
143 fprintf(stderr, "malloc of %llu bytes failed\n",
144 (unsigned long long) length);
147 memset(bufp, ch, length);
154 if ((storefd = open(storefile, O_RDONLY)) == -1) {
155 fprintf(stderr, "unable to open store file for read (%s), errno = %d\n", storefile, errno);
160 sret = read(storefd, bufp, len);
162 fprintf(stderr, "unable to read store file (%s), errno = %d\n", storefile, errno);
165 else if (sret != length) {
166 fprintf(stderr, "read(%s) returned %lld, expected %lld\n",
167 storefile, (long long)sret, (long long)length);
173 rc = dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN, 0, offset, length, bufp);
176 fprintf(stderr, "dm_write_invis failed, %s\n", strerror(errno));
178 } else if (rc != length) {
179 fprintf(stderr, "dm_write_invis expected to write %llu bytes, "
180 "actually wrote %lld\n",
181 (unsigned long long) length, (long long)rc);
184 dm_handle_free(hanp, hlen);