1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2002 Silicon Graphics, Inc.
13 /*---------------------------------------------------------------------------
15 Test program used to test the DMAPI function dm_set_eventlist(). The
18 set_eventlist [-F] [-m max] [-s sid] [-t token] {pathname|handle} event [...]
22 is either the pathname of a file or a handle.
24 is the value to use for the maxevent parameter of dm_set_eventlist().
26 is the dm_sessid_t value to use.
28 is the dm_token_t value to use (DM_NO_TOKEN is the default).
30 is one or more events to set.
32 ----------------------------------------------------------------------------*/
35 extern char *sys_errlist[];
49 fprintf(stderr, "usage:\t%s [-F] [-m max] [-s sid] [-t token] "
50 "{pathname|handle} event [...]\n", Progname);
51 fprintf(stderr, "possible events are:\n");
52 for (i = 0; i < ev_namecnt; i++) {
53 fprintf(stderr, "%s (%d)\n", ev_names[i].name,
65 dm_sessid_t sid = DM_NO_SESSION;
66 dm_token_t token = DM_NO_TOKEN;
68 dm_eventset_t eventset;
72 u_int maxevent = DM_EVENT_MAX;
76 Progname = strrchr(argv[0], '/');
83 /* Crack and validate the command line options. */
85 while ((opt = getopt(argc, argv, "Fm:s:t:")) != EOF) {
91 maxevent = atol(optarg);
103 if (optind + 1 > argc)
105 object = argv[optind++];
107 if (dm_init_service(&name) == -1) {
108 fprintf(stderr, "Can't initialize the DMAPI\n");
111 if (sid == DM_NO_SESSION)
112 find_test_session(&sid);
116 /* Get the file's handle or convert the external handle. */
118 if (opaque_to_handle(object, &hanp, &hlen)) {
119 fprintf(stderr, "can't get handle for %s\n", object);
127 if (dm_handle_to_fshandle(hanp, hlen, &fshanp, &fshlen)) {
128 fprintf(stderr, "can't get filesystem handle from %s\n",
132 dm_handle_free(hanp, hlen);
137 for (; optind < argc; optind++) {
138 dm_eventtype_t event;
140 event = ev_name_to_value(argv[optind]);
141 if (event == DM_EVENT_INVALID) {
142 fprintf(stderr, "invalid event %s\n", argv[optind]);
145 if ((event == DM_EVENT_READ) || (event == DM_EVENT_WRITE) ||
146 (event == DM_EVENT_TRUNCATE)) {
147 fprintf(stderr, "Use set_region to twiddle read/write/trunc events\n");
151 DMEV_SET(event, eventset);
154 if (dm_set_eventlist(sid, hanp, hlen, token, &eventset, maxevent)) {
155 fprintf(stderr, "dm_set_eventlist failed, %s\n",
160 dm_handle_free(hanp, hlen);