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
18 #include <sys/types.h>
24 #include <lib/errtest.h>
30 /*---------------------------------------------------------------------------
32 For manually testing DMAPI functions dm_write_invis() and dm_read_invis()
36 invis_test [-Rrv] [-l len] [-o offset] [-s sid] ls_path pathname
40 reuse existing test file
42 use dm_invis_read, default is dm_invis_write.
46 offset in file for read/write
48 is the session ID whose events you you are interested in.
50 is the path to a specific copy of ls, important only for its size
52 is the filesystem to use for the test.
54 DM_WRITE_SYNC is is not supported.
55 ----------------------------------------------------------------------------*/
58 extern char *sys_errlist[];
69 fprintf(stderr, "usage:\t%s [-Rrv] [-l len] [-o offset] [-s sid] ls_path pathname\n",
82 dm_sessid_t sid = DM_NO_SESSION;
83 char *dir_name = NULL;
94 dm_size_t length = BUFSZ;
96 int reading = 0; /* writing is the default */
98 dm_size_t errblockstart, errblockend;
103 Progname = strrchr(argv[0], '/');
110 /* Crack and validate the command line options. */
112 while ((opt = getopt(argc, argv, "Rvs:rl:o:")) != EOF) {
124 length = atoi(optarg);
127 offset = atoi(optarg);
136 if (optind + 2 != argc)
138 ls_path = argv[optind];
139 dir_name = argv[optind+1];
141 if (dm_init_service(&name) == -1) {
142 fprintf(stderr, "Can't initialize the DMAPI\n");
145 if (sid == DM_NO_SESSION)
146 find_test_session(&sid);
148 sprintf(test_file, "%s/DMAPI_test_file", dir_name);
149 if( (!reading) && (!reuse_file) ){
150 sprintf(command, "cp %s %s\n", ls_path, test_file);
154 if (dm_path_to_handle(test_file, &hanp, &hlen)) {
155 fprintf(stderr, "can't get handle for %s; bypassing test\n",
161 printf("using length = %llu\n", (unsigned long long) length);
162 if( length > BUFSZ ){
163 fprintf(stderr, "length(%llu) > BUFSZ(%d)\n",
164 (unsigned long long) length, BUFSZ);
169 memset(buf, '\0', BUFSZ);
171 rc = dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN,
172 offset, length, buf);
174 fprintf(stderr, "dm_read_invis failed, (err=%d)\n", errno);
175 dm_handle_free(hanp, hlen);
179 fprintf(stderr, "dm_read_invis read %llu bytes, "
180 "wanted to write %lld bytes\n",
181 (long long) rc, (unsigned long long) length);
182 dm_handle_free(hanp, hlen);
186 printf("dm_read_invis read %lld bytes\n",
191 errblockstart = errblockend = 0;
192 for( i=0; i < length; ++i ){
195 /* still in the err block */
199 /* end of bad block */
200 fprintf(stderr, "read err block: "
201 "byte %lld to %lld\n",
202 (long long) errblockstart,
203 (long long) errblockend);
207 else if( buf[i] != ch ){
208 /* enter err block */
214 /* end of bad block */
215 fprintf(stderr, "read err block: byte %lld to %lld\n",
216 (long long) errblockstart,
217 (long long) errblockend);
223 memset(buf, ch, BUFSZ);
225 rc = dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
226 0, offset, length, buf);
228 fprintf(stderr, "dm_write_invis failed, (err=%d)\n", errno);
229 dm_handle_free(hanp, hlen);
233 fprintf(stderr, "dm_write_invis wrote %lld bytes, "
234 "wanted to write %lld bytes\n",
235 (long long) rc, (long long) length );
236 dm_handle_free(hanp, hlen);
239 printf("dm_write_invis wrote %lld bytes\n", (long long) rc);
242 dm_handle_free(hanp, hlen);