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[];
85 fprintf(stderr, "usage:\t%s [-Rrv] [-l len] [-o offset] [-s sid] ls_path pathname\n",
98 dm_sessid_t sid = DM_NO_SESSION;
99 char *dir_name = NULL;
100 char *ls_path = NULL;
110 dm_size_t length = BUFSZ;
112 int reading = 0; /* writing is the default */
114 dm_size_t errblockstart, errblockend;
119 if (Progname = strrchr(argv[0], '/')) {
125 /* Crack and validate the command line options. */
127 while ((opt = getopt(argc, argv, "Rvs:rl:o:")) != EOF) {
139 length = atoi(optarg);
142 offset = atoi(optarg);
151 if (optind + 2 != argc)
153 ls_path = argv[optind];
154 dir_name = argv[optind+1];
156 if (dm_init_service(&name) == -1) {
157 fprintf(stderr, "Can't inititalize the DMAPI\n");
160 if (sid == DM_NO_SESSION)
161 find_test_session(&sid);
163 sprintf(test_file, "%s/DMAPI_test_file", dir_name);
164 if( (!reading) && (!reuse_file) ){
165 sprintf(command, "cp %s %s\n", ls_path, test_file);
169 if (dm_path_to_handle(test_file, &hanp, &hlen)) {
170 fprintf(stderr, "can't get handle for %s; bypassing test\n",
176 printf("using length = %lld\n", length );
177 if( length > BUFSZ ){
178 fprintf(stderr, "length(%lld) > BUFSZ(%lld)\n", length, BUFSZ);
183 memset(buf, '\0', BUFSZ);
185 rc = dm_read_invis(sid, hanp, hlen, DM_NO_TOKEN,
186 offset, length, buf);
188 fprintf(stderr, "dm_read_invis failed, (err=%d)\n", errno);
189 dm_handle_free(hanp, hlen);
193 fprintf(stderr, "dm_read_invis read %lld bytes, wanted to write %lld bytes\n",
195 dm_handle_free(hanp, hlen);
199 printf("dm_read_invis read %lld bytes\n", rc);
203 errblockstart = errblockend = 0;
204 for( i=0; i < length; ++i ){
207 /* still in the err block */
211 /* end of bad block */
212 fprintf(stderr, "read err block: byte %lld to %lld\n", errblockstart, errblockend);
216 else if( buf[i] != ch ){
217 /* enter err block */
223 /* end of bad block */
224 fprintf(stderr, "read err block: byte %lld to %lld\n", errblockstart, errblockend);
230 memset(buf, ch, BUFSZ);
232 rc = dm_write_invis(sid, hanp, hlen, DM_NO_TOKEN,
233 0, offset, length, buf);
235 fprintf(stderr, "dm_write_invis failed, (err=%d)\n", errno);
236 dm_handle_free(hanp, hlen);
240 fprintf(stderr, "dm_write_invis wrote %lld bytes, wanted to write %lld bytes\n",
242 dm_handle_free(hanp, hlen);
245 printf("dm_write_invis wrote %lld bytes\n", rc);
248 dm_handle_free(hanp, hlen);