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