Various changes, most of them involving the FAT and Ext2 Drivers, adding write support
[tpg/acess2.git] / Modules / Filesystems / InitRD / GenerateInitRD.php
1 /*
2  * Acess2 InitRD
3  * InitRD Data
4  * Generated <?php echo date("Y-m-d H:i"),"\n"; ?>
5  */
6 #include "initrd.h"
7 <?php
8 $lines = file($argv[1]);
9
10 $lDepth = 0;
11 $lTree = array();
12 $lStack = array( array("",array()) );
13 foreach($lines as $line)
14 {
15         $line = trim($line);
16         if(preg_match('/^Dir\s+"([^"]+)"\s+{$/', $line, $matches))
17         {
18                 $new = array($matches[1], array());
19                 array_push($lStack, $new);
20                 $lDepth ++;
21                 continue;
22         }
23         if($line == "}")
24         {
25                 $lDepth --;
26                 $lStack[$lDepth][1][] = array_pop($lStack);
27                 continue;
28         }
29         if(preg_match('/^File\s+"([^"]+)"\s+"([^"]+)"$/', $line, $matches))
30         {
31                 $lStack[$lDepth][1][] = array($matches[1], $matches[2]);
32                 continue;
33         }
34 }
35
36 function hd($fp)
37 {
38         return "0x".str_pad( dechex(ord(fgetc($fp))), 2, "0", STR_PAD_LEFT );
39 }
40
41 function ProcessFolder($prefix, $items)
42 {
43         foreach($items as $i=>$item)
44         {
45                 if(is_array($item[1])) {
46                         
47                         ProcessFolder("{$prefix}_{$i}", $item[1]);
48                         
49                         echo "tInitRD_File {$prefix}_{$i}_entries[] = {\n";
50                         foreach($item[1] as $j=>$child)
51                         {
52                                 if($j)  echo ",\n";
53                                 echo "\t{\"".addslashes($child[0])."\",&{$prefix}_{$i}_{$j}}";
54                         }
55                         echo "\n};\n";
56                         
57                         $size = count($item[1]);
58                         echo <<<EOF
59 tVFS_Node {$prefix}_{$i} = {
60         .NumACLs = 1,
61         .ACLs = &gVFS_ACL_EveryoneRX,
62         .Flags = VFS_FFLAG_DIRECTORY,
63         .Size = $size,
64         .ImplPtr = {$prefix}_{$i}_entries,
65         .ReadDir = InitRD_ReadDir,
66         .FindDir = InitRD_FindDir
67 };
68
69 EOF;
70                 }
71                 else {
72                         $size = filesize($item[1]);
73                         
74                         echo "Uint8 {$prefix}_{$i}_data[] = {\n";
75                         $fp = fopen($item[1], "rb");
76                         for( $j = 0; $j + 16 < $size; $j += 16 )
77                         {
78                                 echo "\t";
79                                 echo hd($fp),",",hd($fp),",";
80                                 echo hd($fp),",",hd($fp),",";
81                                 echo hd($fp),",",hd($fp),",";
82                                 echo hd($fp),",",hd($fp),",";
83                                 echo hd($fp),",",hd($fp),",";
84                                 echo hd($fp),",",hd($fp),",";
85                                 echo hd($fp),",",hd($fp),",";
86                                 echo hd($fp),",",hd($fp),",\n";
87                         }
88                         echo "\t";
89                         for( ; $j < $size; $j ++ )
90                         {
91                                 if( $j & 15 )   echo ",";
92                                 echo hd($fp);
93                         }
94                         fclose($fp);
95                         echo "\n};\n";
96                         echo <<<EOF
97 tVFS_Node {$prefix}_{$i} = {
98         .NumACLs = 1,
99         .ACLs = &gVFS_ACL_EveryoneRX,
100         .Flags = 0,
101         .Size = $size,
102         .ImplPtr = {$prefix}_{$i}_data,
103         .Read = InitRD_ReadFile
104 };
105
106 EOF;
107                 }
108         }
109 }
110
111 ProcessFolder("gInitRD_Files", $lStack[0][1]);
112
113 echo "tInitRD_File gInitRD_Root_Files[] = {\n";
114 foreach($lStack[0][1] as $j=>$child)
115 {
116         if($j)  echo ",\n";
117         echo "\t{\"".addslashes($child[0])."\",&gInitRD_Files_{$j}}";
118 }
119 echo "\n};\n";
120 ?>
121 tVFS_Node gInitRD_RootNode = {
122         .NumACLs = 1,
123         .ACLs = &gVFS_ACL_EveryoneRX,
124         .Flags = VFS_FFLAG_DIRECTORY,
125         .Size = <?php echo count($lStack[0][1]);?>,
126         .ImplPtr = gInitRD_Root_Files,
127         .ReadDir = InitRD_ReadDir,
128         .FindDir = InitRD_FindDir
129 };

UCC git Repository :: git.ucc.asn.au