2 * Copyright (c) 2000 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/
32 #include <sys/types.h>
38 #include <lib/errtest.h>
44 /*---------------------------------------------------------------------------
46 For manually testing DMAPI functions dm_write_invis() and dm_read_invis()
50 invis_test [-Rrv] [-l len] [-o offset] [-s sid] ls_path pathname
54 reuse existing test file
56 use dm_invis_read, default is dm_invis_write.
60 offset in file for read/write
62 is the session ID whose events you you are interested in.
64 is the path to a specific copy of ls, important only for its size
66 is the filesystem to use for the test.
68 DM_WRITE_SYNC is is not supported.
69 ----------------------------------------------------------------------------*/
72 extern char *sys_errlist[];
83 fprintf(stderr, "usage:\t%s [-Rrv] [-l len] [-o offset] [-s sid] ls_path pathname\n",
96 dm_sessid_t sid = DM_NO_SESSION;
97 char *dir_name = NULL;
108 dm_size_t length = BUFSZ;
110 int reading = 0; /* writing is the default */
112 dm_size_t errblockstart, errblockend;
117 if (Progname = strrchr(argv[0], '/')) {
123 /* Crack and validate the command line options. */
125 while ((opt = getopt(argc, argv, "Rvs:rl:o:")) != EOF) {
137 length = atoi(optarg);
140 offset = atoi(optarg);
149 if (optind + 2 != argc)
151 ls_path = argv[optind];
152 dir_name = argv[optind+1];
154 if (dm_init_service(&name) == -1) {
155 fprintf(stderr, "Can't initialize the DMAPI\n");
158 if (sid == DM_NO_SESSION)
159 find_test_session(&sid);
161 sprintf(test_file, "%s/DMAPI_test_file", dir_name);
162 if( (!reading) && (!reuse_file) ){
163 sprintf(command, "cp %s %s\n", ls_path, test_file);
167 if (dm_path_to_handle(test_file, &hanp, &hlen)) {
168 fprintf(stderr, "can't get handle for %s; bypassing test\n",
174 printf("using length = %llu\n", length );
175 if( length > BUFSZ ){
176 fprintf(stderr, "length(%llu) > BUFSZ(%d)\n", length, BUFSZ);
181 memset(buf, '\0', BUFSZ);
183 rc = dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN,
184 offset, length, buf);
186 fprintf(stderr, "dm_read_invis failed, (err=%d)\n", errno);
187 dm_handle_free(hanp, hlen);
191 fprintf(stderr, "dm_read_invis read %lld bytes, wanted to write %lld bytes\n",
193 dm_handle_free(hanp, hlen);
197 printf("dm_read_invis read %lld bytes\n", rc);
201 errblockstart = errblockend = 0;
202 for( i=0; i < length; ++i ){
205 /* still in the err block */
209 /* end of bad block */
210 fprintf(stderr, "read err block: byte %lld to %lld\n", errblockstart, errblockend);
214 else if( buf[i] != ch ){
215 /* enter err block */
221 /* end of bad block */
222 fprintf(stderr, "read err block: byte %lld to %lld\n", errblockstart, errblockend);
228 memset(buf, ch, BUFSZ);
230 rc = dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
231 0, offset, length, buf);
233 fprintf(stderr, "dm_write_invis failed, (err=%d)\n", errno);
234 dm_handle_free(hanp, hlen);
238 fprintf(stderr, "dm_write_invis wrote %lld bytes, wanted to write %lld bytes\n",
240 dm_handle_free(hanp, hlen);
243 printf("dm_write_invis wrote %lld bytes\n", rc);
246 dm_handle_free(hanp, hlen);