1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2001 Silicon Graphics, Inc.
12 /*---------------------------------------------------------------------------
14 Test program used to test the DMAPI function dm_set_region(). The
17 set_region [-n nelem] [-o offset] [-l length] [-s sid] {pathname|handle} [event...]
19 where pathname is the name of a file, nelem is the number of regions to pass
20 in the call, offset is the offset of the start of
21 the managed region, and length is the length. sid is the session ID whose
22 events you you are interested in, and event is zero or more managed region
25 ----------------------------------------------------------------------------*/
28 extern char *sys_errlist[];
40 { "DM_REGION_READ", DM_REGION_READ },
41 { "DM_REGION_WRITE", DM_REGION_WRITE },
42 { "DM_REGION_TRUNCATE", DM_REGION_TRUNCATE }
44 static int nevents = sizeof(rg_events)/sizeof(rg_events[0]);
52 fprintf(stderr, "usage:\t%s [-n nelem] [-o offset] [-l length] "
53 "[-s sid] {pathname|handle} [event...]\n", Progname);
54 fprintf(stderr, "possible events are:\n");
55 for (i = 0; i < nevents; i++)
56 fprintf(stderr, "%s (0x%x)\n", rg_events[i].name, rg_events[i].value);
66 dm_region_t region = { 0, 0, 0 };
67 dm_sessid_t sid = DM_NO_SESSION;
77 Progname = strrchr(argv[0], '/');
84 /* Crack and validate the command line options. */
86 while ((opt = getopt(argc, argv, "n:o:l:s:")) != EOF) {
92 region.rg_offset = atol(optarg);
95 region.rg_size = atol(optarg);
104 if (optind + 1 > argc)
106 object = argv[optind++];
108 if (dm_init_service(&name) == -1) {
109 fprintf(stderr, "Can't initialize the DMAPI\n");
112 if (sid == DM_NO_SESSION)
113 find_test_session(&sid);
115 /* Get the file's handle. */
117 if (opaque_to_handle(object, &hanp, &hlen)) {
118 fprintf(stderr, "can't get handle for %s\n", object);
122 for (; optind < argc; optind++) {
123 if (strspn(argv[optind], "0123456789") == strlen(argv[optind])){
124 region.rg_flags |= atol(argv[optind]);
127 for (i = 0; i < nevents; i++) {
128 if (!strcmp(argv[optind], rg_events[i].name))
132 fprintf(stderr, "invalid event %s\n", argv[optind]);
135 region.rg_flags |= rg_events[i].value;
138 if (dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelem, ®ion,
140 fprintf(stderr, "dm_set_region failed, %s\n",
144 fprintf(stdout, "exactflag is %s\n",
145 exactflag == DM_TRUE ? "True" : "False");
146 dm_handle_free(hanp, hlen);