2 * Copyright (c) 2000-2001 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include <sys/types.h>
20 #include <sys/param.h>
29 #define MAXNAMELEN 256
33 * Define some standard formats for the printf statements below.
36 #define HDR "type=%s token=%d sequence=%d\n"
37 #define VALS "\t%s=%s\n"
38 #define VALD "\t%s=%d\n"
39 #define VALLLD "\t%s=%lld\n"
43 Convert a mode_t field into a printable string.
45 Returns non-zero if the mode_t is invalid. The string is
46 returned in *ptr, whether there is an error or not.
54 static char modestr[100];
58 if (S_ISFIFO(mode)) typestr = "FIFO";
59 else if(S_ISCHR (mode)) typestr = "Character Device";
60 else if(S_ISBLK (mode)) typestr = "Block Device";
61 else if(S_ISDIR (mode)) typestr = "Directory";
62 else if(S_ISREG (mode)) typestr = "Regular File";
63 else if(S_ISLNK (mode)) typestr = "Symbolic Link";
64 else if(S_ISSOCK(mode)) typestr = "Socket";
66 typestr = "<unknown type>";
70 sprintf(modestr, "mode %06o: perm %c%c%c %c%c%c %c%c%c %c%c%c, type %s",
72 mode & S_ISUID ? 's':' ',
73 mode & S_ISGID ? 'g':' ',
74 mode & S_ISVTX ? 't':' ',
75 mode & S_IRUSR ? 'r':'-',
76 mode & S_IWUSR ? 'w':'-',
77 mode & S_IXUSR ? 'x':'-',
78 mode & S_IRGRP ? 'r':'-',
79 mode & S_IWGRP ? 'w':'-',
80 mode & S_IXGRP ? 'x':'-',
81 mode & S_IROTH ? 'r':'-',
82 mode & S_IWOTH ? 'w':'-',
83 mode & S_IXOTH ? 'x':'-',
91 print_one_mount_event(
94 void *hanp1, *hanp2, *hanp3;
95 size_t hlen1, hlen2, hlen3;
96 char hans1[HANDLE_STR], hans2[HANDLE_STR], hans3[HANDLE_STR];
99 char nams1[MAXNAMELEN], nams2[MAXNAMELEN];
103 dm_namesp_event_t *msg_ne = (dm_namesp_event_t *)msg;
106 msg_ne = DM_GET_VALUE(msg, ev_data, dm_namesp_event_t *);
108 hanp1 = DM_GET_VALUE(msg_ne, ne_handle1, void *);
109 hlen1 = DM_GET_LEN (msg_ne, ne_handle1);
110 hanp2 = DM_GET_VALUE(msg_ne, ne_handle2, void *);
111 hlen2 = DM_GET_LEN (msg_ne, ne_handle2);
112 namp1 = DM_GET_VALUE(msg_ne, ne_name1, void *);
113 nlen1 = DM_GET_LEN (msg_ne, ne_name1);
114 namp2 = DM_GET_VALUE(msg_ne, ne_name2, void *);
115 nlen2 = DM_GET_LEN (msg_ne, ne_name2);
118 mode = msg_ne->ne_mode;
120 dm_mount_event_t *msg_me = (dm_mount_event_t *)msg;
122 hanp1 = DM_GET_VALUE(msg_me, me_handle1, void *);
123 hlen1 = DM_GET_LEN(msg_me, me_handle1);
124 hanp2 = DM_GET_VALUE(msg_me, me_handle2, void *);
125 hlen2 = DM_GET_LEN(msg_me, me_handle2);
126 namp1 = DM_GET_VALUE(msg_me, me_name1, void *);
127 nlen1 = DM_GET_LEN(msg_me, me_name1);
128 namp2 = DM_GET_VALUE(msg_me, me_name2, void *);
129 nlen2 = DM_GET_LEN(msg_me, me_name2);
130 hanp3 = DM_GET_VALUE(msg_me, me_roothandle, void *);
131 hlen3 = DM_GET_LEN(msg_me, me_roothandle);
132 mode = msg_me->me_mode;
133 #endif /* VERITAS_21 */
135 if (hanp1 && hlen1) {
136 hantoa(hanp1, hlen1, hans1);
138 sprintf(hans1, "<BAD HANDLE, hlen %d>", hlen1);
140 if (hanp2 && hlen2) {
141 hantoa(hanp2, hlen2, hans2);
143 sprintf(hans2, "<BAD HANDLE, hlen %d>", hlen2);
145 if (hanp3 && hlen3) {
146 hantoa(hanp3, hlen3, hans3);
148 sprintf(hans3, "<BAD HANDLE, hlen %d>", hlen3);
150 if (namp1 && nlen1) {
151 strncpy(nams1, namp1, nlen1);
152 if (nlen1 != sizeof(nams1))
155 sprintf(nams1, "<BAD STRING, nlen %d>", nlen1);
157 if (namp2 && nlen2) {
158 strncpy(nams2, namp2, nlen2);
159 if (nlen2 != sizeof(nams2))
162 sprintf(nams2, "<BAD STRING, nlen %d>", nlen2);
165 printf(VALS VALS VALS VALS VALS VALD,
167 "mtpt handle", hans2,
169 "media desig", nams2,
170 "root handle", hans3,
176 print_one_data_event(
177 dm_data_event_t *msg_de)
179 char handle[HANDLE_STR];
183 hanp = DM_GET_VALUE(msg_de, de_handle, void *);
184 hlen = DM_GET_LEN (msg_de, de_handle);
187 hantoa(hanp, hlen, handle);
189 sprintf(handle, "<BAD HANDLE, hlen %d>", hlen);
192 printf(VALS VALLLD VALLLD,
193 "file_handle", handle,
194 "offset", msg_de->de_offset,
195 "length", msg_de->de_length);
206 dm_namesp_event_t *msg_ne;
207 void *hanp1, *hanp2, *namp1, *namp2;
208 u_int hlen1, hlen2, nlen1, nlen2;
209 char hans1[HANDLE_STR], hans2[HANDLE_STR];
210 char nams1[MAXNAMELEN], nams2[MAXNAMELEN];
212 /***** USER EVENTS *****/
214 if (msg->ev_type == DM_EVENT_USER) {
219 "user", msg->ev_token, msg->ev_sequence);
221 /* print private data as ascii or hex if it exists DM_CONFIG_MAX_MESSAGE_DATA */
223 privp = DM_GET_VALUE(msg, ev_data, char *);
224 plen = DM_GET_LEN (msg, ev_data);
226 for (i = 0; i < plen; i++) {
227 if (!isprint(privp[i]) && !isspace(privp[i]))
230 if (i == plen - 1 && privp[i] == '\0') {
234 printf("\t%-15s ", "privdata");
235 for (i = 0; i < plen; i++) {
236 printf("%.2x", privp[i]);
242 "privdata", "<NONE>");
245 /***** CANCEL EVENT *****/
247 /* Not implemented on SGI or Veritas */
249 } else if (msg->ev_type == DM_EVENT_CANCEL) {
250 dm_cancel_event_t *msg_ce;
252 msg_ce = DM_GET_VALUE(msg, ev_data, dm_cancel_event_t *);
253 printf(HDR VALD VALD,
254 "cancel", msg->ev_token, msg->ev_sequence,
255 "sequence", msg_ce->ce_sequence,
256 "token", msg_ce->ce_token);
258 /***** DATA EVENTS *****/
260 } else if (msg->ev_type == DM_EVENT_READ ||
261 msg->ev_type == DM_EVENT_WRITE ||
262 msg->ev_type == DM_EVENT_TRUNCATE) {
263 dm_data_event_t *msg_de;
265 msg_de = DM_GET_VALUE(msg, ev_data, dm_data_event_t *);
267 switch (msg->ev_type) {
269 printf(HDR, "read", msg->ev_token, msg->ev_sequence);
273 printf(HDR, "write", msg->ev_token, msg->ev_sequence);
276 case DM_EVENT_TRUNCATE:
277 printf(HDR, "truncate", msg->ev_token,
282 print_one_data_event(msg_de);
284 /***** DESTROY EVENT *****/
286 } else if (msg->ev_type == DM_EVENT_DESTROY) {
287 dm_destroy_event_t *msg_ds;
288 char attrname[DM_ATTR_NAME_SIZE + 1];
293 msg_ds= DM_GET_VALUE(msg, ev_data, dm_destroy_event_t *);
294 hanp1 = DM_GET_VALUE(msg_ds, ds_handle, void *);
295 hlen1 = DM_GET_LEN (msg_ds, ds_handle);
296 if (hanp1 && hlen1) {
297 hantoa(hanp1, hlen1, hans1);
299 sprintf(hans1, "<BAD HANDLE, hlen %d>", hlen1);
301 if (msg_ds->ds_attrname.an_chars[0] != '\0') {
302 strncpy(attrname, (char *)msg_ds->ds_attrname.an_chars, sizeof(attrname));
304 strcpy(attrname, "<NONE>");
306 printf(HDR VALS VALS,
307 "destroy", msg->ev_token, msg->ev_sequence,
309 "attrname", attrname);
310 copy = DM_GET_VALUE(msg_ds, ds_attrcopy, u_char *);
311 clen = DM_GET_LEN (msg_ds, ds_attrcopy);
313 printf("\t%-15s ", "attrcopy");
314 for (i = 0; i < clen; i++) {
315 printf("%.2x", copy[i]);
319 printf(VALS, "attrcopy", "<NONE>");
322 /***** MOUNT EVENT *****/
324 } else if (msg->ev_type == DM_EVENT_MOUNT) {
327 printf(HDR, "mount", msg->ev_token, msg->ev_sequence);
329 msg_body = DM_GET_VALUE(msg, ev_data, dm_mount_event_t *);
330 #else /* VERITAS_21 */
331 msg_body = DM_GET_VALUE(msg, ev_data, dm_namesp_event_t *);
332 #endif /* VERITAS_21 */
333 print_one_mount_event(msg_body);
335 /***** NAMESPACE EVENTS *****/
340 msg_ne = DM_GET_VALUE(msg, ev_data, dm_namesp_event_t *);
341 hanp1 = DM_GET_VALUE(msg_ne, ne_handle1, void *);
342 hlen1 = DM_GET_LEN (msg_ne, ne_handle1);
343 hanp2 = DM_GET_VALUE(msg_ne, ne_handle2, void *);
344 hlen2 = DM_GET_LEN (msg_ne, ne_handle2);
345 namp1 = DM_GET_VALUE(msg_ne, ne_name1, void *);
346 nlen1 = DM_GET_LEN (msg_ne, ne_name1);
347 namp2 = DM_GET_VALUE(msg_ne, ne_name2, void *);
348 nlen2 = DM_GET_LEN (msg_ne, ne_name2);
350 if (hanp1 && hlen1) {
351 hantoa(hanp1, hlen1, hans1);
353 if (hanp2 && hlen2) {
354 hantoa(hanp2, hlen2, hans2);
356 if (namp1 && nlen1) {
357 strncpy(nams1, namp1, nlen1);
358 if (nlen1 != sizeof(nams1))
361 if (namp2 && nlen2) {
362 strncpy(nams2, namp2, nlen2);
363 if (nlen2 != sizeof(nams2))
367 if (msg->ev_type == DM_EVENT_PREUNMOUNT ||
368 msg->ev_type == DM_EVENT_UNMOUNT) {
369 if (msg_ne->ne_mode == 0) {
372 } else if (msg_ne->ne_mode == DM_UNMOUNT_FORCE) {
374 } else if (msg_ne->ne_mode > 0) {
381 } else if (msg->ev_type == DM_EVENT_CREATE ||
382 msg->ev_type == DM_EVENT_POSTCREATE ||
383 msg->ev_type == DM_EVENT_REMOVE ||
384 msg->ev_type == DM_EVENT_POSTREMOVE) {
385 if (format_mode(msg_ne->ne_mode, &type)) {
390 switch(msg->ev_type) {
392 case DM_EVENT_PREUNMOUNT:
393 printf(HDR VALS VALS VALS,
394 "preunmount", msg->ev_token, msg->ev_sequence,
397 "unmount mode", type);
400 case DM_EVENT_UNMOUNT:
401 printf(HDR VALS VALS VALD,
402 "unmount", msg->ev_token, msg->ev_sequence,
404 "unmount mode", type,
405 "retcode", msg_ne->ne_retcode);
408 case DM_EVENT_NOSPACE:
410 "nospace", msg->ev_token, msg->ev_sequence,
414 case DM_EVENT_DEBUT: /* not supported on SGI */
416 "debut", msg->ev_token, msg->ev_sequence,
420 case DM_EVENT_CREATE:
421 printf(HDR VALS VALS VALS,
422 "create", msg->ev_token, msg->ev_sequence,
428 case DM_EVENT_POSTCREATE:
429 printf(HDR VALS VALS VALS VALS VALD,
430 "postcreate", msg->ev_token, msg->ev_sequence,
435 "retcode", msg_ne->ne_retcode);
438 case DM_EVENT_REMOVE:
439 printf(HDR VALS VALS VALS,
440 "remove", msg->ev_token, msg->ev_sequence,
446 case DM_EVENT_POSTREMOVE:
447 printf(HDR VALS VALS VALS VALD,
448 "postremove", msg->ev_token, msg->ev_sequence,
452 "retcode", msg_ne->ne_retcode);
455 case DM_EVENT_RENAME:
456 printf(HDR VALS VALS VALS VALS,
457 "rename", msg->ev_token, msg->ev_sequence,
464 case DM_EVENT_POSTRENAME:
465 printf(HDR VALS VALS VALS VALS VALD,
466 "postrename", msg->ev_token, msg->ev_sequence,
471 "retcode", msg_ne->ne_retcode);
474 case DM_EVENT_SYMLINK:
475 printf(HDR VALS VALS VALS,
476 "symlink", msg->ev_token, msg->ev_sequence,
482 case DM_EVENT_POSTSYMLINK:
483 printf(HDR VALS VALS VALS VALS VALD,
484 "postsymlink", msg->ev_token, msg->ev_sequence,
489 "retcode", msg_ne->ne_retcode);
493 printf(HDR VALS VALS VALS,
494 "link", msg->ev_token, msg->ev_sequence,
500 case DM_EVENT_POSTLINK:
501 printf(HDR VALS VALS VALS VALD,
502 "postlink", msg->ev_token, msg->ev_sequence,
506 "retcode", msg_ne->ne_retcode);
509 case DM_EVENT_ATTRIBUTE:
511 "attribute", msg->ev_token, msg->ev_sequence,
515 case DM_EVENT_CLOSE: /* not supported on SGI */
517 "close", msg->ev_token, msg->ev_sequence,
524 "<UNKNOWN>", msg->ev_token, msg->ev_sequence,
525 "ev_type", msg->ev_type);
538 dm_response_t response;
539 int respond, respcode;
542 if (print_one_message(msg))
545 /* Set the defaults for responding to events. */
548 response = DM_RESP_CONTINUE;
551 /***** USER EVENTS *****/
553 switch (msg->ev_type) {
555 if (msg->ev_token == DM_INVALID_TOKEN)
559 case DM_EVENT_CANCEL:
560 case DM_EVENT_DESTROY:
561 case DM_EVENT_POSTCREATE:
562 case DM_EVENT_POSTREMOVE:
563 case DM_EVENT_POSTRENAME:
564 case DM_EVENT_POSTSYMLINK:
565 case DM_EVENT_POSTLINK:
566 case DM_EVENT_ATTRIBUTE:
574 case DM_EVENT_TRUNCATE:
575 case DM_EVENT_PREUNMOUNT:
576 case DM_EVENT_UNMOUNT:
578 case DM_EVENT_CREATE:
579 case DM_EVENT_REMOVE:
580 case DM_EVENT_RENAME:
581 case DM_EVENT_SYMLINK:
585 case DM_EVENT_NOSPACE:
586 response = DM_RESP_ABORT;
591 if (msg->ev_token == DM_INVALID_TOKEN)
596 /* Respond to those messages which require a response. */
599 if (dm_respond_event(sid, msg->ev_token, response, respcode, 0, 0)) {
600 errno_msg("Can't respond to event");