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 if (Progname = strrchr(argv[0], '/')) {
109 /* Crack and validate the command line options. */
111 while ((opt = getopt(argc, argv, "Rvs:rl:o:")) != EOF) {
123 length = atoi(optarg);
126 offset = atoi(optarg);
135 if (optind + 2 != argc)
137 ls_path = argv[optind];
138 dir_name = argv[optind+1];
140 if (dm_init_service(&name) == -1) {
141 fprintf(stderr, "Can't initialize the DMAPI\n");
144 if (sid == DM_NO_SESSION)
145 find_test_session(&sid);
147 sprintf(test_file, "%s/DMAPI_test_file", dir_name);
148 if( (!reading) && (!reuse_file) ){
149 sprintf(command, "cp %s %s\n", ls_path, test_file);
153 if (dm_path_to_handle(test_file, &hanp, &hlen)) {
154 fprintf(stderr, "can't get handle for %s; bypassing test\n",
160 printf("using length = %llu\n", length );
161 if( length > BUFSZ ){
162 fprintf(stderr, "length(%llu) > BUFSZ(%d)\n", length, BUFSZ);
167 memset(buf, '\0', BUFSZ);
169 rc = dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN,
170 offset, length, buf);
172 fprintf(stderr, "dm_read_invis failed, (err=%d)\n", errno);
173 dm_handle_free(hanp, hlen);
177 fprintf(stderr, "dm_read_invis read %lld bytes, wanted to write %lld bytes\n",
179 dm_handle_free(hanp, hlen);
183 printf("dm_read_invis read %lld bytes\n", rc);
187 errblockstart = errblockend = 0;
188 for( i=0; i < length; ++i ){
191 /* still in the err block */
195 /* end of bad block */
196 fprintf(stderr, "read err block: byte %lld to %lld\n", errblockstart, errblockend);
200 else if( buf[i] != ch ){
201 /* enter err block */
207 /* end of bad block */
208 fprintf(stderr, "read err block: byte %lld to %lld\n", errblockstart, errblockend);
214 memset(buf, ch, BUFSZ);
216 rc = dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
217 0, offset, length, buf);
219 fprintf(stderr, "dm_write_invis failed, (err=%d)\n", errno);
220 dm_handle_free(hanp, hlen);
224 fprintf(stderr, "dm_write_invis wrote %lld bytes, wanted to write %lld bytes\n",
226 dm_handle_free(hanp, hlen);
229 printf("dm_write_invis wrote %lld bytes\n", rc);
232 dm_handle_free(hanp, hlen);