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_READDIR(9) [or similar] entry $
6 # $Copyright: 2014-2018 Devin Teske. All rights reserved. $
9 ############################################################ DESCRIPTION
11 # Print directory paths being read by VOP_READDIR(9) [or similar]
12 # NB: All paths are shown even if error prevents their reading.
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->mount = this->vp != NULL ?
28 this->vp->v_mount : NULL; /* ptr to vfs we are in */
29 this->fi_fs = this->mount != NULL ?
30 stringof(this->mount->mnt_stat.f_fstypename) : "";
31 this->fi_mount = this->mount != NULL ?
32 stringof(this->mount->mnt_stat.f_mntonname) : "";
33 this->d_name = args[0]->v_cache_dd != NULL ?
34 stringof(args[0]->v_cache_dd->nc_name) : "";
36 $( awk -v MAX_DEPTH=$MAX_DEPTH '
37 { sub(/^\\\t/, "\t") }
38 { buf = buf "\t" $0 "\n" }
42 sub(/^[[:space:]]*/, "")
43 for (DEPTH = 1; DEPTH <= MAX_DEPTH + 1; DEPTH++) {
55 $PROBE /this->vp == 0 || this->fi_fs == 0 ||
56 this->fi_fs == "devfs" || this->fi_fs == ""/ /* probe ID $((
60 printf("<$(( $ID + 1 ))>");}
64 /*********************************************************/
66 $PROBE /this->ncp/ /* probe ID $(( $ID + 2 )) (depth 1) */
68 printf("<$(( $ID + 2 ))>");}
69 this->dvp = this->ncp->nc_dvp != NULL ?
70 this->ncp->nc_dvp->v_cache_dst.tqh_first : 0;
71 this->name1 = this->dvp != 0 ? (
72 this->dvp->nc_name != 0 ? stringof(this->dvp->nc_name) : ""
76 $PROBE /this->name1 == 0 || this->fi_fs == 0 ||
77 this->fi_fs == "devfs" || this->fi_fs == "" ||
78 this->name1 == "/" || this->name1 == ""/ /* probe ID $(( $ID + 3 )) */
80 printf("<$(( $ID + 3 ))>");}
84 /*********************************************************/
87 * BEGIN Pathname-depth iterators
90 $( awk -v ID=$(( $ID + 4 )) -v MAX_DEPTH=$MAX_DEPTH '
94 for (DEPTH = 2; DEPTH <= MAX_DEPTH; DEPTH++) {
102 $PROBE /this->dvp/ /* probe ID IDNUM (depth DEPTH) */
105 this->dvp = this->dvp->nc_dvp != NULL ?
106 this->dvp->nc_dvp->v_cache_dst.tqh_first : 0;
107 this->nameDEPTH = this->dvp != 0 ? (
108 this->dvp->nc_name != 0 ? stringof(this->dvp->nc_name) : ""
115 $PROBE /this->dvp/ /* probe ID $(( $ID + $MAX_DEPTH + 3 )) */
117 printf("<$(( $ID + $MAX_DEPTH + 3 ))>");}
118 this->dvp = this->dvp->nc_dvp != NULL ?
119 this->dvp->nc_dvp->v_cache_dst.tqh_first : 0;
120 this->name$(( $MAX_DEPTH + 1 )) = this->dvp != 0 ? (
121 this->dvp->nc_dvp != NULL ? "..." : ""
126 * END Pathname-depth iterators
129 /*********************************************************/
131 $PROBE /this->fi_mount != 0/ /* probe ID $(( $ID + $MAX_DEPTH + 4 )) */
133 printf("<$(( $ID + $MAX_DEPTH + 4 ))>");
137 * NB: Up-to but not including the parent directory (joined below)
139 this->path = this->fi_mount;
140 this->path = strjoin(this->path, this->fi_mount != 0 ? (
141 this->fi_mount == "/" ? "" : "/"
143 $( awk -v MAX_DEPTH=$MAX_DEPTH '
144 { sub(/^\\\t/, "\t") }
145 { buf = buf "\t" $0 "\n" }
149 sub(/^[[:space:]]*/, "")
150 for (N = MAX_DEPTH + 1; N > 0; N--) {
157 this->path = strjoin(this->path,
158 \ strjoin(this->nameN, this->nameN != "" ? "/" : ""));
162 /* Join the parent directory name */
163 this->path = strjoin(this->path, strjoin(this->name =
164 (this->d_name != 0 ? this->d_name : ""),
165 this->name != "" ? "/" : ""));
169 ID=$(( $ID + $MAX_DEPTH + 5 ))
171 ############################################################ EVENT ACTION
173 EVENT_TEST="this->fi_mount != 0"
175 ############################################################ EVENT DETAILS
177 if [ ! "$CUSTOM_DETAILS" ]; then
182 printf("%s", this->path);
184 EVENT_DETAILS=$( cat <&9 )
187 ################################################################################
189 ################################################################################