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/
33 #include <sys/types.h>
34 #include <sys/param.h>
43 #define MAXNAMELEN 256
47 * Define some standard formats for the printf statements below.
50 #define HDR "type=%s token=%d sequence=%d\n"
51 #define VALS "\t%s=%s\n"
52 #define VALD "\t%s=%d\n"
53 #define VALLLD "\t%s=%lld\n"
57 Convert a mode_t field into a printable string.
59 Returns non-zero if the mode_t is invalid. The string is
60 returned in *ptr, whether there is an error or not.
68 static char modestr[100];
72 if (S_ISFIFO(mode)) typestr = "FIFO";
73 else if(S_ISCHR (mode)) typestr = "Character Device";
74 else if(S_ISBLK (mode)) typestr = "Block Device";
75 else if(S_ISDIR (mode)) typestr = "Directory";
76 else if(S_ISREG (mode)) typestr = "Regular File";
77 else if(S_ISLNK (mode)) typestr = "Symbolic Link";
78 else if(S_ISSOCK(mode)) typestr = "Socket";
80 typestr = "<unknown type>";
84 sprintf(modestr, "mode %06o: perm %c%c%c %c%c%c %c%c%c %c%c%c, type %s",
86 mode & S_ISUID ? 's':' ',
87 mode & S_ISGID ? 'g':' ',
88 mode & S_ISVTX ? 't':' ',
89 mode & S_IRUSR ? 'r':'-',
90 mode & S_IWUSR ? 'w':'-',
91 mode & S_IXUSR ? 'x':'-',
92 mode & S_IRGRP ? 'r':'-',
93 mode & S_IWGRP ? 'w':'-',
94 mode & S_IXGRP ? 'x':'-',
95 mode & S_IROTH ? 'r':'-',
96 mode & S_IWOTH ? 'w':'-',
97 mode & S_IXOTH ? 'x':'-',
105 print_one_mount_event(
108 void *hanp1, *hanp2, *hanp3;
109 size_t hlen1, hlen2, hlen3;
110 char hans1[HANDLE_STR], hans2[HANDLE_STR], hans3[HANDLE_STR];
113 char nams1[MAXNAMELEN], nams2[MAXNAMELEN];
117 dm_namesp_event_t *msg_ne = (dm_namesp_event_t *)msg;
120 msg_ne = DM_GET_VALUE(msg, ev_data, dm_namesp_event_t *);
122 hanp1 = DM_GET_VALUE(msg_ne, ne_handle1, void *);
123 hlen1 = DM_GET_LEN (msg_ne, ne_handle1);
124 hanp2 = DM_GET_VALUE(msg_ne, ne_handle2, void *);
125 hlen2 = DM_GET_LEN (msg_ne, ne_handle2);
126 namp1 = DM_GET_VALUE(msg_ne, ne_name1, void *);
127 nlen1 = DM_GET_LEN (msg_ne, ne_name1);
128 namp2 = DM_GET_VALUE(msg_ne, ne_name2, void *);
129 nlen2 = DM_GET_LEN (msg_ne, ne_name2);
132 mode = msg_ne->ne_mode;
134 dm_mount_event_t *msg_me = (dm_mount_event_t *)msg;
136 hanp1 = DM_GET_VALUE(msg_me, me_handle1, void *);
137 hlen1 = DM_GET_LEN(msg_me, me_handle1);
138 hanp2 = DM_GET_VALUE(msg_me, me_handle2, void *);
139 hlen2 = DM_GET_LEN(msg_me, me_handle2);
140 namp1 = DM_GET_VALUE(msg_me, me_name1, void *);
141 nlen1 = DM_GET_LEN(msg_me, me_name1);
142 namp2 = DM_GET_VALUE(msg_me, me_name2, void *);
143 nlen2 = DM_GET_LEN(msg_me, me_name2);
144 hanp3 = DM_GET_VALUE(msg_me, me_roothandle, void *);
145 hlen3 = DM_GET_LEN(msg_me, me_roothandle);
146 mode = msg_me->me_mode;
147 #endif /* VERITAS_21 */
149 if (hanp1 && hlen1) {
150 hantoa(hanp1, hlen1, hans1);
152 sprintf(hans1, "<BAD HANDLE, hlen %d>", hlen1);
154 if (hanp2 && hlen2) {
155 hantoa(hanp2, hlen2, hans2);
157 sprintf(hans2, "<BAD HANDLE, hlen %d>", hlen2);
159 if (hanp3 && hlen3) {
160 hantoa(hanp3, hlen3, hans3);
162 sprintf(hans3, "<BAD HANDLE, hlen %d>", hlen3);
164 if (namp1 && nlen1) {
165 strncpy(nams1, namp1, nlen1);
166 if (nlen1 != sizeof(nams1))
169 sprintf(nams1, "<BAD STRING, nlen %d>", nlen1);
171 if (namp2 && nlen2) {
172 strncpy(nams2, namp2, nlen2);
173 if (nlen2 != sizeof(nams2))
176 sprintf(nams2, "<BAD STRING, nlen %d>", nlen2);
179 printf(VALS VALS VALS VALS VALS VALD,
181 "mtpt handle", hans2,
183 "media desig", nams2,
184 "root handle", hans3,
190 print_one_data_event(
191 dm_data_event_t *msg_de)
193 char handle[HANDLE_STR];
197 hanp = DM_GET_VALUE(msg_de, de_handle, void *);
198 hlen = DM_GET_LEN (msg_de, de_handle);
201 hantoa(hanp, hlen, handle);
203 sprintf(handle, "<BAD HANDLE, hlen %d>", hlen);
206 printf(VALS VALLLD VALLLD,
207 "file_handle", handle,
208 "offset", msg_de->de_offset,
209 "length", msg_de->de_length);
220 dm_namesp_event_t *msg_ne;
221 void *hanp1, *hanp2, *namp1, *namp2;
222 u_int hlen1, hlen2, nlen1, nlen2;
223 char hans1[HANDLE_STR], hans2[HANDLE_STR];
224 char nams1[MAXNAMELEN], nams2[MAXNAMELEN];
226 /***** USER EVENTS *****/
228 if (msg->ev_type == DM_EVENT_USER) {
233 "user", msg->ev_token, msg->ev_sequence);
235 /* print private data as ascii or hex if it exists DM_CONFIG_MAX_MESSAGE_DATA */
237 privp = DM_GET_VALUE(msg, ev_data, char *);
238 plen = DM_GET_LEN (msg, ev_data);
240 for (i = 0; i < plen; i++) {
241 if (!isprint(privp[i]) && !isspace(privp[i]))
244 if (i == plen - 1 && privp[i] == '\0') {
248 printf("\t%-15s ", "privdata");
249 for (i = 0; i < plen; i++) {
250 printf("%.2x", privp[i]);
256 "privdata", "<NONE>");
259 /***** CANCEL EVENT *****/
261 /* Not implemented on SGI or Veritas */
263 } else if (msg->ev_type == DM_EVENT_CANCEL) {
264 dm_cancel_event_t *msg_ce;
266 msg_ce = DM_GET_VALUE(msg, ev_data, dm_cancel_event_t *);
267 printf(HDR VALD VALD,
268 "cancel", msg->ev_token, msg->ev_sequence,
269 "sequence", msg_ce->ce_sequence,
270 "token", msg_ce->ce_token);
272 /***** DATA EVENTS *****/
274 } else if (msg->ev_type == DM_EVENT_READ ||
275 msg->ev_type == DM_EVENT_WRITE ||
276 msg->ev_type == DM_EVENT_TRUNCATE) {
277 dm_data_event_t *msg_de;
279 msg_de = DM_GET_VALUE(msg, ev_data, dm_data_event_t *);
281 switch (msg->ev_type) {
283 printf(HDR, "read", msg->ev_token, msg->ev_sequence);
287 printf(HDR, "write", msg->ev_token, msg->ev_sequence);
290 case DM_EVENT_TRUNCATE:
291 printf(HDR, "truncate", msg->ev_token,
296 print_one_data_event(msg_de);
298 /***** DESTROY EVENT *****/
300 } else if (msg->ev_type == DM_EVENT_DESTROY) {
301 dm_destroy_event_t *msg_ds;
302 char attrname[DM_ATTR_NAME_SIZE + 1];
307 msg_ds= DM_GET_VALUE(msg, ev_data, dm_destroy_event_t *);
308 hanp1 = DM_GET_VALUE(msg_ds, ds_handle, void *);
309 hlen1 = DM_GET_LEN (msg_ds, ds_handle);
310 if (hanp1 && hlen1) {
311 hantoa(hanp1, hlen1, hans1);
313 sprintf(hans1, "<BAD HANDLE, hlen %d>", hlen1);
315 if (msg_ds->ds_attrname.an_chars[0] != '\0') {
316 strncpy(attrname, (char *)msg_ds->ds_attrname.an_chars, sizeof(attrname));
318 strcpy(attrname, "<NONE>");
320 printf(HDR VALS VALS,
321 "destroy", msg->ev_token, msg->ev_sequence,
323 "attrname", attrname);
324 copy = DM_GET_VALUE(msg_ds, ds_attrcopy, u_char *);
325 clen = DM_GET_LEN (msg_ds, ds_attrcopy);
327 printf("\t%-15s ", "attrcopy");
328 for (i = 0; i < clen; i++) {
329 printf("%.2x", copy[i]);
333 printf(VALS, "attrcopy", "<NONE>");
336 /***** MOUNT EVENT *****/
338 } else if (msg->ev_type == DM_EVENT_MOUNT) {
341 printf(HDR, "mount", msg->ev_token, msg->ev_sequence);
343 msg_body = DM_GET_VALUE(msg, ev_data, dm_mount_event_t *);
344 #else /* VERITAS_21 */
345 msg_body = DM_GET_VALUE(msg, ev_data, dm_namesp_event_t *);
346 #endif /* VERITAS_21 */
347 print_one_mount_event(msg_body);
349 /***** NAMESPACE EVENTS *****/
354 msg_ne = DM_GET_VALUE(msg, ev_data, dm_namesp_event_t *);
355 hanp1 = DM_GET_VALUE(msg_ne, ne_handle1, void *);
356 hlen1 = DM_GET_LEN (msg_ne, ne_handle1);
357 hanp2 = DM_GET_VALUE(msg_ne, ne_handle2, void *);
358 hlen2 = DM_GET_LEN (msg_ne, ne_handle2);
359 namp1 = DM_GET_VALUE(msg_ne, ne_name1, void *);
360 nlen1 = DM_GET_LEN (msg_ne, ne_name1);
361 namp2 = DM_GET_VALUE(msg_ne, ne_name2, void *);
362 nlen2 = DM_GET_LEN (msg_ne, ne_name2);
364 if (hanp1 && hlen1) {
365 hantoa(hanp1, hlen1, hans1);
367 if (hanp2 && hlen2) {
368 hantoa(hanp2, hlen2, hans2);
370 if (namp1 && nlen1) {
371 strncpy(nams1, namp1, nlen1);
372 if (nlen1 != sizeof(nams1))
375 if (namp2 && nlen2) {
376 strncpy(nams2, namp2, nlen2);
377 if (nlen2 != sizeof(nams2))
381 if (msg->ev_type == DM_EVENT_PREUNMOUNT ||
382 msg->ev_type == DM_EVENT_UNMOUNT) {
383 if (msg_ne->ne_mode == 0) {
386 } else if (msg_ne->ne_mode == DM_UNMOUNT_FORCE) {
388 } else if (msg_ne->ne_mode > 0) {
395 } else if (msg->ev_type == DM_EVENT_CREATE ||
396 msg->ev_type == DM_EVENT_POSTCREATE ||
397 msg->ev_type == DM_EVENT_REMOVE ||
398 msg->ev_type == DM_EVENT_POSTREMOVE) {
399 if (format_mode(msg_ne->ne_mode, &type)) {
404 switch(msg->ev_type) {
406 case DM_EVENT_PREUNMOUNT:
407 printf(HDR VALS VALS VALS,
408 "preunmount", msg->ev_token, msg->ev_sequence,
411 "unmount mode", type);
414 case DM_EVENT_UNMOUNT:
415 printf(HDR VALS VALS VALD,
416 "unmount", msg->ev_token, msg->ev_sequence,
418 "unmount mode", type,
419 "retcode", msg_ne->ne_retcode);
422 case DM_EVENT_NOSPACE:
424 "nospace", msg->ev_token, msg->ev_sequence,
428 case DM_EVENT_DEBUT: /* not supported on SGI */
430 "debut", msg->ev_token, msg->ev_sequence,
434 case DM_EVENT_CREATE:
435 printf(HDR VALS VALS VALS,
436 "create", msg->ev_token, msg->ev_sequence,
442 case DM_EVENT_POSTCREATE:
443 printf(HDR VALS VALS VALS VALS VALD,
444 "postcreate", msg->ev_token, msg->ev_sequence,
449 "retcode", msg_ne->ne_retcode);
452 case DM_EVENT_REMOVE:
453 printf(HDR VALS VALS VALS,
454 "remove", msg->ev_token, msg->ev_sequence,
460 case DM_EVENT_POSTREMOVE:
461 printf(HDR VALS VALS VALS VALD,
462 "postremove", msg->ev_token, msg->ev_sequence,
466 "retcode", msg_ne->ne_retcode);
469 case DM_EVENT_RENAME:
470 printf(HDR VALS VALS VALS VALS,
471 "rename", msg->ev_token, msg->ev_sequence,
478 case DM_EVENT_POSTRENAME:
479 printf(HDR VALS VALS VALS VALS VALD,
480 "postrename", msg->ev_token, msg->ev_sequence,
485 "retcode", msg_ne->ne_retcode);
488 case DM_EVENT_SYMLINK:
489 printf(HDR VALS VALS VALS,
490 "symlink", msg->ev_token, msg->ev_sequence,
496 case DM_EVENT_POSTSYMLINK:
497 printf(HDR VALS VALS VALS VALS VALD,
498 "postsymlink", msg->ev_token, msg->ev_sequence,
503 "retcode", msg_ne->ne_retcode);
507 printf(HDR VALS VALS VALS,
508 "link", msg->ev_token, msg->ev_sequence,
514 case DM_EVENT_POSTLINK:
515 printf(HDR VALS VALS VALS VALD,
516 "postlink", msg->ev_token, msg->ev_sequence,
520 "retcode", msg_ne->ne_retcode);
523 case DM_EVENT_ATTRIBUTE:
525 "attribute", msg->ev_token, msg->ev_sequence,
529 case DM_EVENT_CLOSE: /* not supported on SGI */
531 "close", msg->ev_token, msg->ev_sequence,
538 "<UNKNOWN>", msg->ev_token, msg->ev_sequence,
539 "ev_type", msg->ev_type);
552 dm_response_t response;
553 int respond, respcode;
556 if (print_one_message(msg))
559 /* Set the defaults for responding to events. */
562 response = DM_RESP_CONTINUE;
565 /***** USER EVENTS *****/
567 switch (msg->ev_type) {
569 if (msg->ev_token == DM_INVALID_TOKEN)
573 case DM_EVENT_CANCEL:
574 case DM_EVENT_DESTROY:
575 case DM_EVENT_POSTCREATE:
576 case DM_EVENT_POSTREMOVE:
577 case DM_EVENT_POSTRENAME:
578 case DM_EVENT_POSTSYMLINK:
579 case DM_EVENT_POSTLINK:
580 case DM_EVENT_ATTRIBUTE:
588 case DM_EVENT_TRUNCATE:
589 case DM_EVENT_PREUNMOUNT:
590 case DM_EVENT_UNMOUNT:
592 case DM_EVENT_CREATE:
593 case DM_EVENT_REMOVE:
594 case DM_EVENT_RENAME:
595 case DM_EVENT_SYMLINK:
599 case DM_EVENT_NOSPACE:
600 response = DM_RESP_ABORT;
605 if (msg->ev_token == DM_INVALID_TOKEN)
610 /* Respond to those messages which require a response. */
613 if (dm_respond_event(sid, msg->ev_token, response, respcode, 0, 0)) {
614 errno_msg("Can't respond to event");