xref: /freebsd/tools/tools/vop_table/vop_table.tcl (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1#!/usr/local/bin/tclsh8.3
2
3set fo [open _.html w]
4
5proc do_file {file} {
6	global names ops op
7	set f [open $file]
8
9	set s 0
10
11	while {[gets $f a] >= 0} {
12		if {$s == 0} {
13			if {[regexp {struct[ 	]*vnodeopv_entry_desc} "$a"]} {
14				regsub {.*vnodeopv_entry_desc[ 	]*} $a {} a
15				regsub {\[.*} $a {} a
16				regsub {_entries} $a {} a
17				set name $a
18				set names($a) 0
19				set s 1
20			}
21			continue
22		}
23		if {$s == 1} {
24			if {[regexp {NULL} "$a"]} {
25				set s 0
26				continue
27			}
28			if {![regexp {vop.*_desc} "$a"]} continue
29			regsub -all {[,&]} $a " " a
30			regsub -all {\(vop_t \*\)} $a " " a
31			set b [lindex $a 0]
32			if {"$b" == "/*"} {
33				set s 0
34				continue
35			}
36			#puts "$name>> [lindex $b 0] >> [lindex $b 3]"
37			set o [lindex $b 0]
38			regsub {_desc} $o "" o
39			set ops($o) 0
40			set op([list $name $o]) [lindex $b 1]
41			continue
42		}
43		puts "$s>> $a"
44	}
45	close $f
46}
47
48set fi [open "|find /usr/src/sys -type f -name *.c -print | xargs grep VNODEOP_SET" ]
49while {[gets $fi a] >= 0} {
50	puts stderr $a
51	if {[regexp {#define} $a]} continue
52	if {[regexp {mallocfs} $a]} continue
53	do_file [lindex [split $a :] 0]
54}
55close $fi
56
57puts $fo {<HTML>
58<HEAD></HEAD><BODY>
59<TABLE BORDER WIDTH="100%" NOSAVE>
60}
61
62set opn [lsort [array names ops]]
63set a [lsort [array names names]]
64
65set tbn default_vnodeop
66foreach i $a {
67	if {$i == "default_vnodeop"} continue
68	lappend tbn $i
69}
70
71foreach i $opn {
72	if {$i == "vop_default"} continue
73	regsub "vop_" $i "" i
74        lappend fl [format "%12s" $i]
75}
76
77lappend fl [format "%12s" default]
78
79puts $fo {<TR>}
80puts $fo {<TD>}
81puts $fo {</TD>}
82puts $fo "<TR>"
83        puts $fo "<TD></TD>"
84	foreach j $fl {
85		puts $fo "<TD>"
86
87		for {set i 0} {$i < 12} {incr i} {
88			puts $fo "[string index $j $i]<BR>"
89		}
90		puts $fo "</TD>"
91	}
92puts $fo "</TR>"
93
94set fnames(vop_defaultop) *
95
96set fnames(vop_null) -
97set fnames(vop_ebadf) b
98set fnames(vop_einval) i
99set fnames(vop_enotty) t
100set fnames(vop_panic) !
101set fnames(vfs_cache_lookup) C
102set fnames(vop_eopnotsupp) *
103
104set fn 0
105set nop(aa) 0
106unset nop(aa)
107foreach i $tbn {
108	puts $fo {<TR>}
109	puts $fo "<TD>$i</TD>"
110	set pfx [lindex [split $i _] 0]
111	foreach j $opn {
112		if {$j == "vop_default"} continue
113		set sfx [lindex [split $j _] 1]
114		if {![info exists op([list $i $j])]} {
115			puts $fo "<TD BGCOLOR=\"#d0d0d0\"></TD>"
116			continue
117		}
118		set t $op([list $i $j])
119
120		set c "#00ddd0"
121		if {[info exists fnames($t)]} {
122			set t $fnames($t)
123		} elseif { $t == "${pfx}_${sfx}" } {
124			set t "F"
125		} elseif { $t == "vop_${sfx}" } {
126			set t "V"
127		} elseif { $t == "vop_no${sfx}" } {
128			set t "N"
129		} elseif { $t == "vop_std${sfx}" } {
130			set t "S"
131		} elseif { $sfx == "cachedlookup" && $t == "${pfx}_lookup" } {
132			set t "L"
133		} else {
134			if {![info exists nop($t)]} {
135				incr fn
136				set nop($t) $fn
137				set nfn($fn) $t
138				set use($fn) 0
139			}
140			incr use($nop($t))
141			set t "<FONT SIZE=-1>$nop($t)</FONT>"
142			set c "#ffff00"
143		}
144		puts $fo "<TD BGCOLOR=\"$c\">$t</TD>"
145	}
146	set j vop_default
147	if {![info exists op([list $i $j])]} {
148		puts $fo "<TD></TD>"
149		continue
150	}
151	puts $fo "<TD>$op([list $i $j])</TD>"
152
153	puts $fo "</TR>"
154}
155puts $fo "</TABLE>"
156puts $fo "<HR>"
157puts $fo {<PRE>}
158foreach i [lsort [array names fnames]] {
159	puts $fo [format "%-2s %s" $fnames($i)  $i]
160}
161puts $fo [format "%-2s %s" "F" "<fs>_<vop>"]
162puts $fo [format "%-2s %s" "V" "vop_<vop>"]
163puts $fo [format "%-2s %s" "N" "vop_no<vop>"]
164puts $fo [format "%-2s %s" "S" "vop_std<vop>"]
165puts $fo [format "%-2s %s" "L" "<fs>_lookup"]
166puts $fo {
167</PRE>
168}
169puts $fo "<HR>"
170puts $fo {<TABLE BORDER NOSAVE>}
171set m 8
172for {set i 1} {$i <= $fn} {incr i $m} {
173	puts $fo "<TR>"
174	for {set j 0} {$j < $m} {incr j} {
175		set k [expr $i + $j]
176		if {$k <= $fn} {
177			#puts $fo "<TD>$k</TD><TD><FONT SIZE=-1>$nfn($k)/$use($k)</FONT></TD>"
178			puts $fo "<TD>$k</TD><TD><FONT SIZE=-1>$nfn($k)</FONT></TD>"
179		}
180	}
181	puts $fo "</TR>"
182}
183puts $fo "</TABLE>"
184
185puts $fo "</TABLE>"
186puts $fo "</BODY>"
187puts $fo "</HTML>"
188foreach i $tbn {
189	if {$i == "default_vnodeop"} {
190		continue
191	}
192	foreach j $opn {
193		set sfx [lindex [split $j _] 1]
194		if {![info exists op([list $i $j])]} {
195			continue
196		}
197		set v $op([list $i $j])
198		if {$v != "vop_std$sfx"} {
199			continue
200		}
201		if {![info exists op([list default_vnodeop $j])]} {
202			continue
203		}
204		if {$op([list default_vnodeop $j]) != $v} {
205			continue
206		}
207		if {$op([list $i vop_default]) != "vop_defaultop"} {
208			continue
209		}
210		puts "Suspect: uses explicit default, $i $j $v $op([list $i vop_default])"
211	}
212}
213