1330559Sdteske# -*- tab-width: 4 -*- ;; Emacs 2330559Sdteske# vi: set filetype=sh tabstop=8 shiftwidth=8 noexpandtab :: Vi/ViM 3330559Sdteske############################################################ IDENT(1) 4330559Sdteske# 5330559Sdteske# $Title: dwatch(8) module for VOP_RENAME(9) [or similar] entry $ 6330559Sdteske# $Copyright: 2014-2018 Devin Teske. All rights reserved. $ 7330559Sdteske# $FreeBSD: stable/11/cddl/usr.sbin/dwatch/libexec/vop_rename 333617 2018-05-15 00:00:44Z dteske $ 8330559Sdteske# 9330559Sdteske############################################################ DESCRIPTION 10330559Sdteske# 11330559Sdteske# Print filesystem paths being renamed by VOP_RENAME(9) [or similar] 12330559Sdteske# NB: All paths are shown even if error prevents their rename. 13330559Sdteske# 14330559Sdteske############################################################ PROBE 15330559Sdteske 16330559Sdteske: ${PROBE:=vfs:vop:$PROFILE:entry} 17330559Sdteske 18330559Sdteske############################################################ ACTIONS 19330559Sdteske 20330559Sdteskeexec 9<<EOF 21330559Sdteske$PROBE /* probe ID $ID */ 22330559Sdteske{${TRACE:+ 23330559Sdteske printf("<$ID>");} 24330559Sdteske this->fvp = args[1] ? args[1]->a_fdvp : NULL; 25330559Sdteske this->fncp = this->fvp != NULL ? 26330559Sdteske this->fvp->v_cache_dst.tqh_first : 0; 27330559Sdteske this->ffi_name = args[1] ? ( 28330559Sdteske args[1]->a_fcnp != NULL ? 29330559Sdteske stringof(args[1]->a_fcnp->cn_nameptr) : "" 30330559Sdteske ) : ""; 31330559Sdteske this->fmount = this->fvp != NULL ? 32330559Sdteske this->fvp->v_mount : NULL; /* ptr to vfs we are in */ 33330559Sdteske this->ffi_fs = this->fmount != NULL ? 34330559Sdteske stringof(this->fmount->mnt_stat.f_fstypename) : ""; 35330559Sdteske this->ffi_mount = this->fmount != NULL ? 36330559Sdteske stringof(this->fmount->mnt_stat.f_mntonname) : ""; 37330559Sdteske this->fd_name = args[0]->v_cache_dd != NULL ? 38330559Sdteske stringof(args[0]->v_cache_dd->nc_name) : ""; 39330559Sdteske 40330559Sdteske this->tvp = args[1] ? args[1]->a_tdvp : NULL; 41330559Sdteske this->tncp = this->tvp != NULL ? 42330559Sdteske this->tvp->v_cache_dst.tqh_first : 0; 43330559Sdteske this->tfi_name = args[1] ? ( 44330559Sdteske args[1]->a_tcnp != NULL ? 45330559Sdteske stringof(args[1]->a_tcnp->cn_nameptr) : "" 46330559Sdteske ) : ""; 47330559Sdteske this->tmount = this->tvp != NULL ? 48330559Sdteske this->tvp->v_mount : NULL; /* ptr to vfs we are in */ 49330559Sdteske this->tfi_fs = this->tmount != NULL ? 50330559Sdteske stringof(this->tmount->mnt_stat.f_fstypename) : ""; 51330559Sdteske this->tfi_mount = this->tmount != NULL ? 52330559Sdteske stringof(this->tmount->mnt_stat.f_mntonname) : ""; 53330559Sdteske this->td_name = this->tvp != NULL ? ( 54330559Sdteske this->tvp->v_cache_dd != NULL ? 55330559Sdteske stringof(this->tvp->v_cache_dd->nc_name) : "" 56330559Sdteske ) : ""; 57330559Sdteske 58330559Sdteske $( awk -v MAX_DEPTH=$MAX_DEPTH ' 59330559Sdteske { sub(/^\\\t/, "\t") } 60330559Sdteske { buf = buf "\t" $0 "\n" } 61330559Sdteske END { 62330559Sdteske sub(/\n$/, "", buf) 63330559Sdteske $0 = buf 64330559Sdteske sub(/^[[:space:]]*/, "") 65330559Sdteske for (DEPTH = 1; DEPTH <= MAX_DEPTH + 1; DEPTH++) { 66330559Sdteske gsub(/DEPTH/, DEPTH) 67330559Sdteske print 68330559Sdteske $0 = buf 69330559Sdteske } 70330559Sdteske } 71330559Sdteske ' <<-EOFDEPTH 72330559Sdteske this->fnameDEPTH = this->tnameDEPTH = ""; 73330559Sdteske EOFDEPTH 74330559Sdteske ) 75330559Sdteske} 76330559Sdteske 77330559Sdteske$PROBE /this->fvp == 0 || this->ffi_fs == 0 || 78330559Sdteske this->ffi_fs == "devfs" || this->ffi_fs == "" || 79330559Sdteske this->ffi_name == ""/ /* probe ID $(( $ID + 1 )) */ 80330559Sdteske{${TRACE:+ 81330559Sdteske printf("<$(( $ID + 1 ))>");} 82330559Sdteske this->fncp = 0; 83330559Sdteske} 84330559Sdteske 85330559Sdteske$PROBE /this->tvp == 0 || this->tfi_fs == 0 || 86330559Sdteske this->tfi_fs == "devfs" || this->tfi_fs == "" || 87330559Sdteske this->tfi_name == ""/ /* probe ID $(( $ID + 2 )) */ 88330559Sdteske{${TRACE:+ 89330559Sdteske printf("<$(( $ID + 2 ))>");} 90330559Sdteske this->tncp = 0; 91330559Sdteske} 92330559Sdteske 93330559Sdteske/*********************************************************/ 94330559Sdteske 95330559Sdteske$PROBE /this->fncp/ /* probe ID $(( $ID + 3 )) (depth 1) */ 96330559Sdteske{${TRACE:+ 97330559Sdteske printf("<$(( $ID + 3 ))>");} 98330559Sdteske this->fdvp = this->fncp->nc_dvp != NULL ? 99330559Sdteske this->fncp->nc_dvp->v_cache_dst.tqh_first : 0; 100330559Sdteske this->fname1 = this->fdvp != 0 ? ( 101330559Sdteske this->fdvp->nc_name != 0 ? stringof(this->fdvp->nc_name) : "" 102330559Sdteske ) : ""; 103330559Sdteske} 104330559Sdteske 105330559Sdteske$PROBE /this->tncp/ /* probe ID $(( $ID + 4 )) (depth 1) */ 106330559Sdteske{${TRACE:+ 107330559Sdteske printf("<$(( $ID + 4 ))>");} 108330559Sdteske this->tdvp = this->tncp->nc_dvp != NULL ? 109330559Sdteske this->tncp->nc_dvp->v_cache_dst.tqh_first : 0; 110330559Sdteske this->tname1 = this->tdvp != 0 ? ( 111330559Sdteske this->tdvp->nc_name != 0 ? stringof(this->tdvp->nc_name) : "" 112330559Sdteske ) : ""; 113330559Sdteske} 114330559Sdteske 115330559Sdteske$PROBE /this->fname1 == 0 || this->ffi_fs == 0 || 116330559Sdteske this->ffi_fs == "devfs" || this->ffi_fs == "" || 117330559Sdteske this->fname1 == "/" || this->fname1 == ""/ /* probe ID $(( 118330559Sdteske $ID + 5 119330559Sdteske )) */ 120330559Sdteske{${TRACE:+ 121330559Sdteske printf("<$(( $ID + 5 ))>");} 122330559Sdteske this->fdvp = 0; 123330559Sdteske} 124330559Sdteske 125330559Sdteske$PROBE /this->tname1 == 0 || this->tfi_fs == 0 || 126330559Sdteske this->tfi_fs == "devfs" || this->tfi_fs == "" || 127330559Sdteske this->tname1 == "/" || this->tname1 == ""/ /* probe ID $(( 128330559Sdteske $ID + 6 129330559Sdteske )) */ 130330559Sdteske{${TRACE:+ 131330559Sdteske printf("<$(( $ID + 6 ))>");} 132330559Sdteske this->tdvp = 0; 133330559Sdteske} 134330559Sdteske 135330559Sdteske/*********************************************************/ 136330559Sdteske 137330559Sdteske/* 138330559Sdteske * BEGIN Pathname-depth iterators 139330559Sdteske */ 140330559Sdteske 141330559Sdteske$( awk -v ID=$(( $ID + 7 )) -v MAX_DEPTH=$MAX_DEPTH ' 142330559Sdteske { buf = buf $0 "\n" } 143330559Sdteske END { 144330559Sdteske sub(/\n$/, "", buf) 145330559Sdteske for (DEPTH = 2; DEPTH <= MAX_DEPTH; DEPTH++) { 146330559Sdteske $0 = buf 147330559Sdteske gsub(/DEPTH/, DEPTH) 148330559Sdteske gsub(/IDNUM1/, ID) 149330559Sdteske gsub(/IDNUM2/, ID + 1) 150330559Sdteske print 151330559Sdteske ID = ID + 2 152330559Sdteske } 153330559Sdteske } 154330559Sdteske' <<EOFDEPTH 155330559Sdteske$PROBE /this->fdvp/ /* probe ID IDNUM1 (depth DEPTH) */ 156330559Sdteske{${TRACE:+ 157330559Sdteske printf("<IDNUM1>");} 158330559Sdteske this->fdvp = this->fdvp->nc_dvp != NULL ? 159330559Sdteske this->fdvp->nc_dvp->v_cache_dst.tqh_first : 0; 160330559Sdteske this->fnameDEPTH = this->fdvp != 0 ? ( 161330559Sdteske this->fdvp->nc_name != 0 ? stringof(this->fdvp->nc_name) : "" 162330559Sdteske ) : ""; 163330559Sdteske} 164330559Sdteske$PROBE /this->tdvp/ /* probe ID IDNUM2 (depth DEPTH) */ 165330559Sdteske{${TRACE:+ 166330559Sdteske printf("<IDNUM2>");} 167330559Sdteske this->tdvp = this->tdvp->nc_dvp != NULL ? 168330559Sdteske this->tdvp->nc_dvp->v_cache_dst.tqh_first : 0; 169330559Sdteske this->tnameDEPTH = this->tdvp != 0 ? ( 170330559Sdteske this->tdvp->nc_name != 0 ? stringof(this->tdvp->nc_name) : "" 171330559Sdteske ) : ""; 172330559Sdteske} 173330559Sdteske 174330559SdteskeEOFDEPTH 175330559Sdteske) 176330559Sdteske 177330559Sdteske$PROBE /this->fdvp/ /* probe ID $(( $ID + $MAX_DEPTH * 2 + 5 )) */ 178330559Sdteske{${TRACE:+ 179330559Sdteske printf("<$(( $ID + $MAX_DEPTH * 2 + 5 ))>");} 180330559Sdteske this->fdvp = this->fdvp->nc_dvp != NULL ? 181330559Sdteske this->fdvp->nc_dvp->v_cache_dst.tqh_first : 0; 182330559Sdteske this->fname$(( $MAX_DEPTH + 1 )) = this->fdvp != 0 ? ( 183330559Sdteske this->fdvp->nc_dvp != NULL ? "..." : "" 184330559Sdteske ) : ""; 185330559Sdteske} 186330559Sdteske$PROBE /this->tdvp/ /* probe ID $(( $ID + $MAX_DEPTH * 2 + 6 )) */ 187330559Sdteske{${TRACE:+ 188330559Sdteske printf("<$(( $ID + $MAX_DEPTH * 2 + 6 ))>");} 189330559Sdteske this->tdvp = this->tdvp->nc_dvp != NULL ? 190330559Sdteske this->tdvp->nc_dvp->v_cache_dst.tqh_first : 0; 191330559Sdteske this->tname$(( $MAX_DEPTH + 1 )) = this->tdvp != 0 ? ( 192330559Sdteske this->tdvp->nc_dvp != NULL ? "..." : "" 193330559Sdteske ) : ""; 194330559Sdteske} 195330559Sdteske 196330559Sdteske/* 197330559Sdteske * END Pathname-depth iterators 198330559Sdteske */ 199330559Sdteske 200330559Sdteske/*********************************************************/ 201330559Sdteske 202330559Sdteske$PROBE /this->ffi_mount != 0 && this->tfi_mount != 0/ /* probe ID $(( 203330559Sdteske $ID + $MAX_DEPTH * 2 + 7 204330559Sdteske)) */ 205330559Sdteske{${TRACE:+ 206330559Sdteske printf("<$(( $ID + $MAX_DEPTH * 2 + 7 ))>"); 207330559Sdteske} 208330559Sdteske /* 209330559Sdteske * Join 'from' full path 210330559Sdteske * NB: Up-to but not including the parent directory (joined below) 211330559Sdteske */ 212330559Sdteske this->fpath = this->ffi_mount; 213330559Sdteske this->fpath = strjoin(this->fpath, this->ffi_mount != 0 ? ( 214330559Sdteske this->ffi_mount == "/" ? "" : "/" 215330559Sdteske ) : "/"); 216330559Sdteske $( awk -v MAX_DEPTH=$MAX_DEPTH ' 217330559Sdteske { sub(/^\\\t/, "\t") } 218330559Sdteske { buf = buf "\t" $0 "\n" } 219330559Sdteske END { 220330559Sdteske sub(/\n$/, "", buf) 221330559Sdteske $0 = buf 222330559Sdteske sub(/^[[:space:]]*/, "") 223330559Sdteske for (N = MAX_DEPTH + 1; N > 0; N--) { 224330559Sdteske gsub(/N/, N) 225330559Sdteske print 226330559Sdteske $0 = buf 227330559Sdteske } 228330559Sdteske } 229330559Sdteske ' <<-EOFDEPTH 230330559Sdteske this->fpath = strjoin(this->fpath, 231330559Sdteske \ strjoin(this->fnameN, this->fnameN != "" ? "/" : "")); 232330559Sdteske EOFDEPTH 233330559Sdteske ) 234330559Sdteske 235330559Sdteske /* Join the 'from' parent directory name */ 236330559Sdteske this->fpath = strjoin(this->fpath, strjoin(this->fname = 237330559Sdteske (this->fd_name != 0 ? this->fd_name : ""), 238330559Sdteske this->fname != "" ? "/" : "")); 239330559Sdteske 240330559Sdteske /* Join the 'from' entry name */ 241330559Sdteske this->fpath = strjoin(this->fpath, 242330559Sdteske this->fname = (this->ffi_name != 0 ? this->ffi_name : "")); 243330559Sdteske 244330559Sdteske /* 245330559Sdteske * Join 'to' full path 246330559Sdteske * NB: Up-to but not including the parent directory (joined below) 247330559Sdteske */ 248330559Sdteske this->tpath = this->tfi_mount; 249330559Sdteske this->tpath = strjoin(this->tpath, this->tfi_mount != 0 ? ( 250330559Sdteske this->tfi_mount == "/" ? "" : "/" 251330559Sdteske ) : "/"); 252330559Sdteske $( awk -v MAX_DEPTH=$MAX_DEPTH ' 253330559Sdteske { sub(/^\\\t/, "\t") } 254330559Sdteske { buf = buf "\t" $0 "\n" } 255330559Sdteske END { 256330559Sdteske sub(/\n$/, "", buf) 257330559Sdteske $0 = buf 258330559Sdteske sub(/^[[:space:]]*/, "") 259330559Sdteske for (N = MAX_DEPTH + 1; N > 0; N--) { 260330559Sdteske gsub(/N/, N) 261330559Sdteske print 262330559Sdteske $0 = buf 263330559Sdteske } 264330559Sdteske } 265330559Sdteske ' <<-EOFDEPTH 266330559Sdteske this->tpath = strjoin(this->tpath, 267330559Sdteske \ strjoin(this->tnameN, this->tnameN != "" ? "/" : "")); 268330559Sdteske EOFDEPTH 269330559Sdteske ) 270330559Sdteske 271330559Sdteske /* Join the 'to' parent directory name */ 272330559Sdteske this->tpath = strjoin(this->tpath, strjoin(this->tname = 273330559Sdteske (this->td_name != 0 ? this->td_name : ""), 274330559Sdteske this->tname != "" ? "/" : "")); 275330559Sdteske 276330559Sdteske /* Join the 'to' entry name */ 277330559Sdteske this->tpath = strjoin(this->tpath, 278330559Sdteske this->tname = (this->tfi_name != 0 ? this->tfi_name : "")); 279330559Sdteske} 280330559SdteskeEOF 281330559SdteskeACTIONS=$( cat <&9 ) 282330559SdteskeID=$(( $ID + $MAX_DEPTH * 2 + 8 )) 283330559Sdteske 284330559Sdteske############################################################ EVENT ACTION 285330559Sdteske 286330559SdteskeEVENT_TEST="this->ffi_mount != 0 && this->tfi_mount != 0" 287330559Sdteske 288330559Sdteske############################################################ EVENT DETAILS 289330559Sdteske 290333617Sdteskeif [ ! "$CUSTOM_DETAILS" ]; then 291330559Sdteskeexec 9<<EOF 292330559Sdteske /* 293330559Sdteske * Print 'from' and 'to' full paths 294330559Sdteske */ 295330559Sdteske printf("%s -> %s", this->fpath, this->tpath); 296330559SdteskeEOF 297330559SdteskeEVENT_DETAILS=$( cat <&9 ) 298333617Sdteskefi 299330559Sdteske 300330559Sdteske################################################################################ 301330559Sdteske# END 302330559Sdteske################################################################################ 303