1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2001 Silicon Graphics, Inc.
18 * Define some standard formats for the printf statements below.
21 #define HDR "type=%s token=%d sequence=%d\n"
22 #define VALS "\t%s=%s\n"
23 #define VALD "\t%s=%d\n"
24 #define VALLLD "\t%s=%lld\n"
28 Convert a mode_t field into a printable string.
30 Returns non-zero if the mode_t is invalid. The string is
31 returned in *ptr, whether there is an error or not.
39 static char modestr[100];
43 if (S_ISFIFO(mode)) typestr = "FIFO";
44 else if(S_ISCHR (mode)) typestr = "Character Device";
45 else if(S_ISBLK (mode)) typestr = "Block Device";
46 else if(S_ISDIR (mode)) typestr = "Directory";
47 else if(S_ISREG (mode)) typestr = "Regular File";
48 else if(S_ISLNK (mode)) typestr = "Symbolic Link";
49 else if(S_ISSOCK(mode)) typestr = "Socket";
51 typestr = "<unknown type>";
55 sprintf(modestr, "mode %06o: perm %c%c%c %c%c%c %c%c%c %c%c%c, type %s",
57 mode & S_ISUID ? 's':' ',
58 mode & S_ISGID ? 'g':' ',
59 mode & S_ISVTX ? 't':' ',
60 mode & S_IRUSR ? 'r':'-',
61 mode & S_IWUSR ? 'w':'-',
62 mode & S_IXUSR ? 'x':'-',
63 mode & S_IRGRP ? 'r':'-',
64 mode & S_IWGRP ? 'w':'-',
65 mode & S_IXGRP ? 'x':'-',
66 mode & S_IROTH ? 'r':'-',
67 mode & S_IWOTH ? 'w':'-',
68 mode & S_IXOTH ? 'x':'-',
76 print_one_mount_event(
79 void *hanp1, *hanp2, *hanp3;
80 size_t hlen1, hlen2, hlen3;
81 char hans1[HANDLE_STR], hans2[HANDLE_STR], hans3[HANDLE_STR];
84 char nams1[NAME_MAX + 1], nams2[NAME_MAX + 1];
88 dm_namesp_event_t *msg_ne = (dm_namesp_event_t *)msg;
91 msg_ne = DM_GET_VALUE(msg, ev_data, dm_namesp_event_t *);
93 hanp1 = DM_GET_VALUE(msg_ne, ne_handle1, void *);
94 hlen1 = DM_GET_LEN (msg_ne, ne_handle1);
95 hanp2 = DM_GET_VALUE(msg_ne, ne_handle2, void *);
96 hlen2 = DM_GET_LEN (msg_ne, ne_handle2);
97 namp1 = DM_GET_VALUE(msg_ne, ne_name1, void *);
98 nlen1 = DM_GET_LEN (msg_ne, ne_name1);
99 namp2 = DM_GET_VALUE(msg_ne, ne_name2, void *);
100 nlen2 = DM_GET_LEN (msg_ne, ne_name2);
103 mode = msg_ne->ne_mode;
105 dm_mount_event_t *msg_me = (dm_mount_event_t *)msg;
107 hanp1 = DM_GET_VALUE(msg_me, me_handle1, void *);
108 hlen1 = DM_GET_LEN(msg_me, me_handle1);
109 hanp2 = DM_GET_VALUE(msg_me, me_handle2, void *);
110 hlen2 = DM_GET_LEN(msg_me, me_handle2);
111 namp1 = DM_GET_VALUE(msg_me, me_name1, void *);
112 nlen1 = DM_GET_LEN(msg_me, me_name1);
113 namp2 = DM_GET_VALUE(msg_me, me_name2, void *);
114 nlen2 = DM_GET_LEN(msg_me, me_name2);
115 hanp3 = DM_GET_VALUE(msg_me, me_roothandle, void *);
116 hlen3 = DM_GET_LEN(msg_me, me_roothandle);
117 mode = msg_me->me_mode;
118 #endif /* VERITAS_21 */
120 if (hanp1 && hlen1) {
121 hantoa(hanp1, hlen1, hans1);
123 sprintf(hans1, "<BAD HANDLE, hlen %zd>", hlen1);
125 if (hanp2 && hlen2) {
126 hantoa(hanp2, hlen2, hans2);
128 sprintf(hans2, "<BAD HANDLE, hlen %zd>", hlen2);
130 if (hanp3 && hlen3) {
131 hantoa(hanp3, hlen3, hans3);
133 sprintf(hans3, "<BAD HANDLE, hlen %zd>", hlen3);
135 if (namp1 && nlen1) {
136 strncpy(nams1, namp1, nlen1);
137 if (nlen1 != sizeof(nams1))
140 sprintf(nams1, "<BAD STRING, nlen %zd>", nlen1);
142 if (namp2 && nlen2) {
143 strncpy(nams2, namp2, nlen2);
144 if (nlen2 != sizeof(nams2))
147 sprintf(nams2, "<BAD STRING, nlen %zd>", nlen2);
150 printf(VALS VALS VALS VALS VALS VALD,
152 "mtpt handle", hans2,
154 "media desig", nams2,
155 "root handle", hans3,
161 print_one_data_event(
162 dm_data_event_t *msg_de)
164 char handle[HANDLE_STR];
168 hanp = DM_GET_VALUE(msg_de, de_handle, void *);
169 hlen = DM_GET_LEN (msg_de, de_handle);
172 hantoa(hanp, hlen, handle);
174 sprintf(handle, "<BAD HANDLE, hlen %zd>", hlen);
177 printf(VALS VALLLD VALLLD,
178 "file_handle", handle,
179 "offset", (long long) msg_de->de_offset,
180 "length", (long long) msg_de->de_length);
191 dm_namesp_event_t *msg_ne;
192 void *hanp1, *hanp2, *namp1, *namp2;
193 u_int hlen1, hlen2, nlen1, nlen2;
194 char hans1[HANDLE_STR], hans2[HANDLE_STR];
195 char nams1[NAME_MAX + 1], nams2[NAME_MAX + 1];
197 /***** USER EVENTS *****/
199 if (msg->ev_type == DM_EVENT_USER) {
204 "user", msg->ev_token, msg->ev_sequence);
206 /* print private data as ascii or hex if it exists DM_CONFIG_MAX_MESSAGE_DATA */
208 privp = DM_GET_VALUE(msg, ev_data, char *);
209 plen = DM_GET_LEN (msg, ev_data);
211 for (i = 0; i < plen; i++) {
212 if (!isprint(privp[i]) && !isspace(privp[i]))
215 if (i == plen - 1 && privp[i] == '\0') {
219 printf("\t%-15s ", "privdata");
220 for (i = 0; i < plen; i++) {
221 printf("%.2x", privp[i]);
227 "privdata", "<NONE>");
230 /***** CANCEL EVENT *****/
232 /* Not implemented on SGI or Veritas */
234 } else if (msg->ev_type == DM_EVENT_CANCEL) {
235 dm_cancel_event_t *msg_ce;
237 msg_ce = DM_GET_VALUE(msg, ev_data, dm_cancel_event_t *);
238 printf(HDR VALD VALD,
239 "cancel", msg->ev_token, msg->ev_sequence,
240 "sequence", msg_ce->ce_sequence,
241 "token", msg_ce->ce_token);
243 /***** DATA EVENTS *****/
245 } else if (msg->ev_type == DM_EVENT_READ ||
246 msg->ev_type == DM_EVENT_WRITE ||
247 msg->ev_type == DM_EVENT_TRUNCATE) {
248 dm_data_event_t *msg_de;
250 msg_de = DM_GET_VALUE(msg, ev_data, dm_data_event_t *);
252 switch (msg->ev_type) {
254 printf(HDR, "read", msg->ev_token, msg->ev_sequence);
258 printf(HDR, "write", msg->ev_token, msg->ev_sequence);
261 case DM_EVENT_TRUNCATE:
262 printf(HDR, "truncate", msg->ev_token,
267 print_one_data_event(msg_de);
269 /***** DESTROY EVENT *****/
271 } else if (msg->ev_type == DM_EVENT_DESTROY) {
272 dm_destroy_event_t *msg_ds;
273 char attrname[DM_ATTR_NAME_SIZE + 1];
278 msg_ds= DM_GET_VALUE(msg, ev_data, dm_destroy_event_t *);
279 hanp1 = DM_GET_VALUE(msg_ds, ds_handle, void *);
280 hlen1 = DM_GET_LEN (msg_ds, ds_handle);
281 if (hanp1 && hlen1) {
282 hantoa(hanp1, hlen1, hans1);
284 sprintf(hans1, "<BAD HANDLE, hlen %d>", hlen1);
286 if (msg_ds->ds_attrname.an_chars[0] != '\0') {
287 strncpy(attrname, (char *)msg_ds->ds_attrname.an_chars, sizeof(attrname));
289 strcpy(attrname, "<NONE>");
291 printf(HDR VALS VALS,
292 "destroy", msg->ev_token, msg->ev_sequence,
294 "attrname", attrname);
295 copy = DM_GET_VALUE(msg_ds, ds_attrcopy, u_char *);
296 clen = DM_GET_LEN (msg_ds, ds_attrcopy);
298 printf("\t%-15s ", "attrcopy");
299 for (i = 0; i < clen; i++) {
300 printf("%.2x", copy[i]);
304 printf(VALS, "attrcopy", "<NONE>");
307 /***** MOUNT EVENT *****/
309 } else if (msg->ev_type == DM_EVENT_MOUNT) {
312 printf(HDR, "mount", msg->ev_token, msg->ev_sequence);
314 msg_body = DM_GET_VALUE(msg, ev_data, dm_mount_event_t *);
315 #else /* VERITAS_21 */
316 msg_body = DM_GET_VALUE(msg, ev_data, dm_namesp_event_t *);
317 #endif /* VERITAS_21 */
318 print_one_mount_event(msg_body);
320 /***** NAMESPACE EVENTS *****/
325 msg_ne = DM_GET_VALUE(msg, ev_data, dm_namesp_event_t *);
326 hanp1 = DM_GET_VALUE(msg_ne, ne_handle1, void *);
327 hlen1 = DM_GET_LEN (msg_ne, ne_handle1);
328 hanp2 = DM_GET_VALUE(msg_ne, ne_handle2, void *);
329 hlen2 = DM_GET_LEN (msg_ne, ne_handle2);
330 namp1 = DM_GET_VALUE(msg_ne, ne_name1, void *);
331 nlen1 = DM_GET_LEN (msg_ne, ne_name1);
332 namp2 = DM_GET_VALUE(msg_ne, ne_name2, void *);
333 nlen2 = DM_GET_LEN (msg_ne, ne_name2);
335 if (hanp1 && hlen1) {
336 hantoa(hanp1, hlen1, hans1);
338 if (hanp2 && hlen2) {
339 hantoa(hanp2, hlen2, hans2);
341 if (namp1 && nlen1) {
342 strncpy(nams1, namp1, nlen1);
343 if (nlen1 != sizeof(nams1))
346 if (namp2 && nlen2) {
347 strncpy(nams2, namp2, nlen2);
348 if (nlen2 != sizeof(nams2))
352 if (msg->ev_type == DM_EVENT_PREUNMOUNT ||
353 msg->ev_type == DM_EVENT_UNMOUNT) {
354 if (msg_ne->ne_mode == 0) {
357 } else if (msg_ne->ne_mode == DM_UNMOUNT_FORCE) {
359 } else if (msg_ne->ne_mode > 0) {
366 } else if (msg->ev_type == DM_EVENT_CREATE ||
367 msg->ev_type == DM_EVENT_POSTCREATE ||
368 msg->ev_type == DM_EVENT_REMOVE ||
369 msg->ev_type == DM_EVENT_POSTREMOVE) {
370 if (format_mode(msg_ne->ne_mode, &type)) {
375 switch(msg->ev_type) {
377 case DM_EVENT_PREUNMOUNT:
378 printf(HDR VALS VALS VALS,
379 "preunmount", msg->ev_token, msg->ev_sequence,
382 "unmount mode", type);
385 case DM_EVENT_UNMOUNT:
386 printf(HDR VALS VALS VALD,
387 "unmount", msg->ev_token, msg->ev_sequence,
389 "unmount mode", type,
390 "retcode", msg_ne->ne_retcode);
393 case DM_EVENT_NOSPACE:
395 "nospace", msg->ev_token, msg->ev_sequence,
399 case DM_EVENT_DEBUT: /* not supported on SGI */
401 "debut", msg->ev_token, msg->ev_sequence,
405 case DM_EVENT_CREATE:
406 printf(HDR VALS VALS VALS,
407 "create", msg->ev_token, msg->ev_sequence,
413 case DM_EVENT_POSTCREATE:
414 printf(HDR VALS VALS VALS VALS VALD,
415 "postcreate", msg->ev_token, msg->ev_sequence,
420 "retcode", msg_ne->ne_retcode);
423 case DM_EVENT_REMOVE:
424 printf(HDR VALS VALS VALS,
425 "remove", msg->ev_token, msg->ev_sequence,
431 case DM_EVENT_POSTREMOVE:
432 printf(HDR VALS VALS VALS VALD,
433 "postremove", msg->ev_token, msg->ev_sequence,
437 "retcode", msg_ne->ne_retcode);
440 case DM_EVENT_RENAME:
441 printf(HDR VALS VALS VALS VALS,
442 "rename", msg->ev_token, msg->ev_sequence,
449 case DM_EVENT_POSTRENAME:
450 printf(HDR VALS VALS VALS VALS VALD,
451 "postrename", msg->ev_token, msg->ev_sequence,
456 "retcode", msg_ne->ne_retcode);
459 case DM_EVENT_SYMLINK:
460 printf(HDR VALS VALS VALS,
461 "symlink", msg->ev_token, msg->ev_sequence,
467 case DM_EVENT_POSTSYMLINK:
468 printf(HDR VALS VALS VALS VALS VALD,
469 "postsymlink", msg->ev_token, msg->ev_sequence,
474 "retcode", msg_ne->ne_retcode);
478 printf(HDR VALS VALS VALS,
479 "link", msg->ev_token, msg->ev_sequence,
485 case DM_EVENT_POSTLINK:
486 printf(HDR VALS VALS VALS VALD,
487 "postlink", msg->ev_token, msg->ev_sequence,
491 "retcode", msg_ne->ne_retcode);
494 case DM_EVENT_ATTRIBUTE:
496 "attribute", msg->ev_token, msg->ev_sequence,
500 case DM_EVENT_CLOSE: /* not supported on SGI */
502 "close", msg->ev_token, msg->ev_sequence,
509 "<UNKNOWN>", msg->ev_token, msg->ev_sequence,
510 "ev_type", msg->ev_type);
523 dm_response_t response;
524 int respond, respcode;
527 if (print_one_message(msg))
530 /* Set the defaults for responding to events. */
533 response = DM_RESP_CONTINUE;
536 /***** USER EVENTS *****/
538 switch (msg->ev_type) {
540 if (msg->ev_token == DM_INVALID_TOKEN)
544 case DM_EVENT_CANCEL:
545 case DM_EVENT_DESTROY:
546 case DM_EVENT_POSTCREATE:
547 case DM_EVENT_POSTREMOVE:
548 case DM_EVENT_POSTRENAME:
549 case DM_EVENT_POSTSYMLINK:
550 case DM_EVENT_POSTLINK:
551 case DM_EVENT_ATTRIBUTE:
559 case DM_EVENT_TRUNCATE:
560 case DM_EVENT_PREUNMOUNT:
561 case DM_EVENT_UNMOUNT:
563 case DM_EVENT_CREATE:
564 case DM_EVENT_REMOVE:
565 case DM_EVENT_RENAME:
566 case DM_EVENT_SYMLINK:
570 case DM_EVENT_NOSPACE:
571 response = DM_RESP_ABORT;
576 if (msg->ev_token == DM_INVALID_TOKEN)
581 /* Respond to those messages which require a response. */
584 if (dm_respond_event(sid, msg->ev_token, response, respcode, 0, 0)) {
585 errno_msg("Can't respond to event");