tbutc-make-tsm-a-configure-option-20011009
[openafs.git] / src / config / make_vnode.pl
1 #!/usr/bin/perl
2 #
3 # Make VNODE structure from INODE structure
4 #
5 # Created By:   Derek Atkins <warlord@MIT.EDU>
6 #
7
8 $linux_header_dir="/usr/src/linux";
9 $outdir="./src/afs/LINUX";
10
11 $sepline="/* LINUX VNODE INCLUDED BELOW -- DO NOT MODIFY */\n";
12
13 # makeVfs (fs.h, vfs.hin, vfs.out)
14 sub makeVfs {
15     my ($in,$base,$out) = @_;
16     my ($seplinefound);
17
18     open (IN, "$in") || die "Cannot open $in for reading";
19     open (BASE, "$base" ) || die "Cannot open base file $base";
20     open (OUT, ">$out") || die "Cannot open tempfile $out";
21
22     while (<BASE>) {
23         print OUT;
24         if ($_ eq $sepline) {
25             $seplinefound = 1;
26             last;
27         }
28     }
29
30     print OUT $sepline if !$seplinefound;
31
32     my ($state) = 0;
33     while (<IN>) {
34
35         # Look for 'struct inode' definition
36         if ($state == 0) {
37             next unless m/^struct\s+inode\s*\{/;
38             $state++;
39             s/inode/vnode/;
40             # Fallthrough
41         }
42
43         # Look for 'union {' -- print otherwise
44         if ($state == 1) {
45             if (m/^\s*union\s*\{/) {
46                 $state++;
47                 print OUT "#ifdef notdef\n";
48             }
49             print OUT;
50             next;
51         }
52
53         # Look for the end of the union -- ignore otherwise
54         if ($state == 2) {
55             print OUT;
56             next unless (m/^\s+\}\s*u;/);
57             $state++;
58             print OUT "#endif /* notdef */\n";
59             next;
60         }
61
62         # Look for end brace -- print until we find it
63         if ($state == 3) {
64             print OUT;
65             if (m/^\s*\};/) { $state++ }
66         }
67     }
68
69     while (<BASE>) { print OUT; }
70
71     close (IN);
72     close (BASE);
73     close (OUT);
74 }
75
76 sub usage {
77     print "usage: $0 [-i linux_header_dir] [-o output_dir] [-h]\n";
78     exit 1;
79 }
80
81 sub testArg {
82     my ($arg) = @_;
83     return $arg if ($arg && $arg ne "");
84     usage;
85 }
86
87 while ($_ = shift @ARGV) {
88     if (m/^-i/) { $linux_header_dir = testArg(shift @ARGV); next; }
89     if (m/^-o/) { $outdir = testArg(shift @ARGV); next; }
90     usage;
91 }
92
93 $linux_fs_h="$linux_header_dir/include/linux/fs.h";
94 $vfs_h="$outdir/osi_vfs.h";
95 $vfs_hin="$outdir/osi_vfs.hin";
96
97 makeVfs ($linux_fs_h, $vfs_hin, "$vfs_h.new");
98
99 system ("cmp", "-s", $vfs_h, "$vfs_h.new");
100 $exit_value = $? >> 8;
101 $signal_num = $? & 127;
102 $core_dump  = $? & 128;
103
104 if ($exit_value == 0 || $signal_num > 0) {
105     unlink "$vfs_h.new";
106     print "nothing to do... $vfs_h not changed.\n"
107 } else {
108     unlink "$vfs_h";
109     rename ("$vfs_h.new", $vfs_h);
110     print "wrote $vfs_h\n";
111 }
112
113 exit 0;