2 * Copyright (c) 2000-2001 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/
38 /*---------------------------------------------------------------------------
40 Test program used to test the DMAPI function dm_set_region(). The
43 set_region [-n nelem] [-o offset] [-l length] [-s sid] pathname [event...]
45 where pathname is the name of a file, nelem is the number of regions to pass
46 in the call, offset is the offset of the start of
47 the managed region, and length is the length. sid is the session ID whose
48 events you you are interested in, and event is zero or more managed region
51 ----------------------------------------------------------------------------*/
54 extern char *sys_errlist[];
66 { "DM_REGION_READ", DM_REGION_READ },
67 { "DM_REGION_WRITE", DM_REGION_WRITE },
68 { "DM_REGION_TRUNCATE", DM_REGION_TRUNCATE }
70 static int nevents = sizeof(rg_events)/sizeof(rg_events[0]);
78 fprintf(stderr, "usage:\t%s [-n nelem] [-o offset] [-l length] "
79 "[-s sid] pathname [event...]\n", Progname);
80 fprintf(stderr, "possible events are:\n");
81 for (i = 0; i < nevents; i++)
82 fprintf(stderr, "%s (0x%x)\n", rg_events[i].name, rg_events[i].value);
92 dm_region_t region = { 0, 0, 0 };
93 dm_sessid_t sid = DM_NO_SESSION;
94 char *pathname = NULL;
103 if (Progname = strrchr(argv[0], '/')) {
109 /* Crack and validate the command line options. */
111 while ((opt = getopt(argc, argv, "n:o:l:s:")) != EOF) {
114 nelem = atol(optarg);
117 region.rg_offset = atol(optarg);
120 region.rg_size = atol(optarg);
129 if (optind + 1 > argc)
131 pathname = argv[optind++];
133 if (dm_init_service(&name) == -1) {
134 fprintf(stderr, "Can't initialize the DMAPI\n");
137 if (sid == DM_NO_SESSION)
138 find_test_session(&sid);
140 /* Get the file's handle. */
142 if (dm_path_to_handle(pathname, &hanp, &hlen)) {
143 fprintf(stderr, "can't get handle for file %s\n", pathname);
147 for (; optind < argc; optind++) {
148 if (strspn(argv[optind], "0123456789") == strlen(argv[optind])){
149 region.rg_flags |= atol(argv[optind]);
152 for (i = 0; i < nevents; i++) {
153 if (!strcmp(argv[optind], rg_events[i].name))
157 fprintf(stderr, "invalid event %s\n", argv[optind]);
160 region.rg_flags |= rg_events[i].value;
163 if (dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem, ®ion,
165 fprintf(stderr, "dm_set_region failed, %s\n",
169 fprintf(stdout, "exactflag is %s\n",
170 exactflag == DM_TRUE ? "True" : "False");
171 dm_handle_free(hanp, hlen);