1 # -*- tab-width: 4 -*- ;; Emacs
2 # vi: set filetype=sh tabstop=8 shiftwidth=8 noexpandtab :: Vi/ViM
3 ############################################################ IDENT(1)
5 # $Title: dwatch(8) module for VOP_CREATE(9) [or similar] entry $
6 # $Copyright: 2014-2018 Devin Teske. All rights reserved. $
9 ############################################################ DESCRIPTION
11 # Print filesystem paths being operated-on by VOP_CREATE(9) [or similar]
12 # NB: All paths are shown even if error prevents operation.
14 ############################################################ PROBE
16 : ${PROBE:=vfs:vop:$PROFILE:entry}
18 ############################################################ ACTIONS
21 $PROBE /* probe ID $ID */
24 this->vp = (struct vnode *)arg0;
25 this->ncp = this->vp != NULL ?
26 this->vp->v_cache_dst.tqh_first : 0;
27 this->fi_name = args[1] ? (
28 args[1]->a_cnp != NULL ?
29 stringof(args[1]->a_cnp->cn_nameptr) : ""
31 this->mount = this->vp != NULL ?
32 this->vp->v_mount : NULL; /* ptr to vfs we are in */
33 this->fi_fs = this->mount != NULL ?
34 stringof(this->mount->mnt_stat.f_fstypename) : "";
35 this->fi_mount = this->mount != NULL ?
36 stringof(this->mount->mnt_stat.f_mntonname) : "";
37 this->d_name = args[0]->v_cache_dd != NULL ?
38 stringof(args[0]->v_cache_dd->nc_name) : "";
40 $( awk -v MAX_DEPTH=$MAX_DEPTH '
41 { sub(/^\\\t/, "\t") }
42 { buf = buf "\t" $0 "\n" }
46 sub(/^[[:space:]]*/, "")
47 for (DEPTH = 1; DEPTH <= MAX_DEPTH + 1; DEPTH++) {
59 $PROBE /this->vp == 0 || this->fi_fs == 0 ||
60 this->fi_fs == "devfs" || this->fi_fs == "" ||
61 this->fi_name == ""/ /* probe ID $(( $ID + 1 )) */
63 printf("<$(( $ID + 1 ))>");}
67 /*********************************************************/
69 $PROBE /this->ncp/ /* probe ID $(( $ID + 2 )) (depth 1) */
71 printf("<$(( $ID + 2 ))>");}
72 this->dvp = this->ncp->nc_dvp != NULL ?
73 this->ncp->nc_dvp->v_cache_dst.tqh_first : 0;
74 this->name1 = this->dvp != 0 ? (
75 this->dvp->nc_name != 0 ? stringof(this->dvp->nc_name) : ""
79 $PROBE /this->name1 == 0 || this->fi_fs == 0 ||
80 this->fi_fs == "devfs" || this->fi_fs == "" ||
81 this->name1 == "/" || this->name1 == ""/ /* probe ID $(( $ID + 3 )) */
83 printf("<$(( $ID + 3 ))>");}
87 /*********************************************************/
90 * BEGIN Pathname-depth iterators
93 $( awk -v ID=$(( $ID + 4 )) -v MAX_DEPTH=$MAX_DEPTH '
97 for (DEPTH = 2; DEPTH <= MAX_DEPTH; DEPTH++) {
105 $PROBE /this->dvp/ /* probe ID IDNUM (depth DEPTH) */
108 this->dvp = this->dvp->nc_dvp != NULL ?
109 this->dvp->nc_dvp->v_cache_dst.tqh_first : 0;
110 this->nameDEPTH = this->dvp != 0 ? (
111 this->dvp->nc_name != 0 ? stringof(this->dvp->nc_name) : ""
118 $PROBE /this->dvp/ /* probe ID $(( $ID + $MAX_DEPTH + 3 )) */
120 printf("<$(( $ID + $MAX_DEPTH + 3 ))>");}
121 this->dvp = this->dvp->nc_dvp != NULL ?
122 this->dvp->nc_dvp->v_cache_dst.tqh_first : 0;
123 this->name$(( $MAX_DEPTH + 1 )) = this->dvp != 0 ? (
124 this->dvp->nc_dvp != NULL ? "..." : ""
129 * END Pathname-depth iterators
132 /*********************************************************/
134 $PROBE /this->fi_mount != 0/ /* probe ID $(( $ID + $MAX_DEPTH + 4 )) */
136 printf("<$(( $ID + $MAX_DEPTH + 4 ))>");
140 * NB: Up-to but not including the parent directory (joined below)
142 this->path = this->fi_mount;
143 this->path = strjoin(this->path, this->fi_mount != 0 ? (
144 this->fi_mount == "/" ? "" : "/"
146 $( awk -v MAX_DEPTH=$MAX_DEPTH '
147 { sub(/^\\\t/, "\t") }
148 { buf = buf "\t" $0 "\n" }
152 sub(/^[[:space:]]*/, "")
153 for (N = MAX_DEPTH + 1; N > 0; N--) {
160 this->path = strjoin(this->path,
161 \ strjoin(this->nameN, this->nameN != "" ? "/" : ""));
165 /* Join the parent directory name */
166 this->path = strjoin(this->path, strjoin(this->name =
167 (this->d_name != 0 ? this->d_name : ""),
168 this->name != "" ? "/" : ""));
170 /* Join the entry name */
171 this->path = strjoin(this->path,
172 this->name = (this->fi_name != 0 ? this->fi_name : ""));
176 ID=$(( $ID + $MAX_DEPTH + 5 ))
178 ############################################################ EVENT ACTION
180 EVENT_TEST="this->fi_mount != 0"
182 ############################################################ EVENT DETAILS
184 if [ ! "$CUSTOM_DETAILS" ]; then
189 printf("%s", this->path);
191 EVENT_DETAILS=$( cat <&9 )
194 ################################################################################
196 ################################################################################