1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2001 Silicon Graphics, Inc.
12 #include <lib/errtest.h>
18 /*---------------------------------------------------------------------------
20 For manually testing DMAPI functions dm_write_invis() and dm_read_invis()
24 invis_test [-Rrv] [-l len] [-o offset] [-s sid] ls_path pathname
28 reuse existing test file
30 use dm_invis_read, default is dm_invis_write.
34 offset in file for read/write
36 is the session ID whose events you you are interested in.
38 is the path to a specific copy of ls, important only for its size
40 is the filesystem to use for the test.
42 DM_WRITE_SYNC is is not supported.
43 ----------------------------------------------------------------------------*/
46 extern char *sys_errlist[];
57 fprintf(stderr, "usage:\t%s [-Rrv] [-l len] [-o offset] [-s sid] ls_path pathname\n",
70 dm_sessid_t sid = DM_NO_SESSION;
71 char *dir_name = NULL;
82 dm_size_t length = BUFSZ;
84 int reading = 0; /* writing is the default */
86 dm_size_t errblockstart, errblockend;
91 Progname = strrchr(argv[0], '/');
98 /* Crack and validate the command line options. */
100 while ((opt = getopt(argc, argv, "Rvs:rl:o:")) != EOF) {
112 length = atoi(optarg);
115 offset = atoi(optarg);
124 if (optind + 2 != argc)
126 ls_path = argv[optind];
127 dir_name = argv[optind+1];
129 if (dm_init_service(&name) == -1) {
130 fprintf(stderr, "Can't initialize the DMAPI\n");
133 if (sid == DM_NO_SESSION)
134 find_test_session(&sid);
136 sprintf(test_file, "%s/DMAPI_test_file", dir_name);
137 if( (!reading) && (!reuse_file) ){
138 sprintf(command, "cp %s %s\n", ls_path, test_file);
142 if (dm_path_to_handle(test_file, &hanp, &hlen)) {
143 fprintf(stderr, "can't get handle for %s; bypassing test\n",
149 printf("using length = %llu\n", (unsigned long long) length);
150 if( length > BUFSZ ){
151 fprintf(stderr, "length(%llu) > BUFSZ(%d)\n",
152 (unsigned long long) length, BUFSZ);
157 memset(buf, '\0', BUFSZ);
159 rc = dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN,
160 offset, length, buf);
162 fprintf(stderr, "dm_read_invis failed, (err=%d)\n", errno);
163 dm_handle_free(hanp, hlen);
167 fprintf(stderr, "dm_read_invis read %llu bytes, "
168 "wanted to write %lld bytes\n",
169 (long long) rc, (unsigned long long) length);
170 dm_handle_free(hanp, hlen);
174 printf("dm_read_invis read %lld bytes\n",
179 errblockstart = errblockend = 0;
180 for( i=0; i < length; ++i ){
183 /* still in the err block */
187 /* end of bad block */
188 fprintf(stderr, "read err block: "
189 "byte %lld to %lld\n",
190 (long long) errblockstart,
191 (long long) errblockend);
195 else if( buf[i] != ch ){
196 /* enter err block */
202 /* end of bad block */
203 fprintf(stderr, "read err block: byte %lld to %lld\n",
204 (long long) errblockstart,
205 (long long) errblockend);
211 memset(buf, ch, BUFSZ);
213 rc = dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
214 0, offset, length, buf);
216 fprintf(stderr, "dm_write_invis failed, (err=%d)\n", errno);
217 dm_handle_free(hanp, hlen);
221 fprintf(stderr, "dm_write_invis wrote %lld bytes, "
222 "wanted to write %lld bytes\n",
223 (long long) rc, (long long) length );
224 dm_handle_free(hanp, hlen);
227 printf("dm_write_invis wrote %lld bytes\n", (long long) rc);
230 dm_handle_free(hanp, hlen);