X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FFilesystems%2FInitRD%2FGenerateInitRD.php;h=03b7d81a3591fe0e07fb7f5b32b129e828c1ba6a;hb=3545d4228478c0bd19b2426366b2f2af5a06ee07;hp=031ad5907002a338ebba033485ed960e41556b77;hpb=c3d486ba13c6cd12558d4c0cf01d3fd93e797d64;p=tpg%2Facess2.git diff --git a/Modules/Filesystems/InitRD/GenerateInitRD.php b/Modules/Filesystems/InitRD/GenerateInitRD.php index 031ad590..03b7d81a 100644 --- a/Modules/Filesystems/InitRD/GenerateInitRD.php +++ b/Modules/Filesystems/InitRD/GenerateInitRD.php @@ -10,6 +10,15 @@ $gOutput = << 3 ? $argv[3] : false); + +$gDependencies = array(); + $lines = file($argv[1]); $lDepth = 0; @@ -18,6 +27,7 @@ $lStack = array( array("",array()) ); foreach($lines as $line) { $line = trim($line); + // Directory if(preg_match('/^Dir\s+"([^"]+)"\s+{$/', $line, $matches)) { $new = array($matches[1], array()); @@ -25,12 +35,14 @@ foreach($lines as $line) $lDepth ++; continue; } + // End of a block if($line == "}") { $lDepth --; $lStack[$lDepth][1][] = array_pop($lStack); continue; } + // File if(preg_match('/^File\s+"([^"]+)"\s+"([^"]+)"$/', $line, $matches)) { $lStack[$lDepth][1][] = array($matches[1], $matches[2]); @@ -41,15 +53,27 @@ foreach($lines as $line) } function hd($fp) +{ + //return "0x".str_pad( dechex(ord(fgetc($fp))), 8, "0", STR_PAD_LEFT ); + $val = unpack("I", fread($fp, 4)); + //print_r($val); exit -1; + return "0x".dechex($val[1]); +} + +function hd8($fp) { return "0x".str_pad( dechex(ord(fgetc($fp))), 2, "0", STR_PAD_LEFT ); } +$inode = 0; function ProcessFolder($prefix, $items) { - global $gOutput; + global $gOutput, $gDependencies; + global $ACESSDIR, $ARCH; + global $inode; foreach($items as $i=>$item) { + $inode ++; if(is_array($item[1])) { ProcessFolder("{$prefix}_{$i}", $item[1]); @@ -69,6 +93,7 @@ tVFS_Node {$prefix}_{$i} = { .ACLs = &gVFS_ACL_EveryoneRX, .Flags = VFS_FFLAG_DIRECTORY, .Size = $size, + .Inode = {$inode}, .ImplPtr = {$prefix}_{$i}_entries, .ReadDir = InitRD_ReadDir, .FindDir = InitRD_FindDir @@ -76,32 +101,42 @@ tVFS_Node {$prefix}_{$i} = { EOF; } - else { - if(!file_exists($item[1])) { - echo "ERROR: '{$item[1]}' does not exist\n", + else + { + $path = $item[1]; + + // Parse path components + $path = str_replace("__BIN__", "$ACESSDIR/Usermode/Output/$ARCH", $path); + $path = str_replace("__FS__", "$ACESSDIR/Usermode/Filesystem", $path); + echo $path,"\n"; + // --- + + $gDependencies[] = $path; + + if(!file_exists($path)) { + echo "ERROR: '{$path}' does not exist\n", exit(1); } - $size = filesize($item[1]); + $size = filesize($path); + + $fp = fopen($path, "rb"); $gOutput .= "Uint8 {$prefix}_{$i}_data[] = {\n"; - $fp = fopen($item[1], "rb"); - for( $j = 0; $j + 16 < $size; $j += 16 ) - { + for( $j = 0; $j + 16 < $size; $j += 16 ) { $gOutput .= "\t"; - $gOutput .= hd($fp).",".hd($fp).","; - $gOutput .= hd($fp).",".hd($fp).","; - $gOutput .= hd($fp).",".hd($fp).","; - $gOutput .= hd($fp).",".hd($fp).","; - $gOutput .= hd($fp).",".hd($fp).","; - $gOutput .= hd($fp).",".hd($fp).","; - $gOutput .= hd($fp).",".hd($fp).","; - $gOutput .= hd($fp).",".hd($fp).",\n"; + $gOutput .= hd8($fp).",".hd8($fp).","; + $gOutput .= hd8($fp).",".hd8($fp).","; + $gOutput .= hd8($fp).",".hd8($fp).","; + $gOutput .= hd8($fp).",".hd8($fp).","; + $gOutput .= hd8($fp).",".hd8($fp).","; + $gOutput .= hd8($fp).",".hd8($fp).","; + $gOutput .= hd8($fp).",".hd8($fp).","; + $gOutput .= hd8($fp).",".hd8($fp).",\n"; } $gOutput .= "\t"; - for( ; $j < $size; $j ++ ) - { + for( ; $j < $size; $j ++ ) { if( $j & 15 ) $gOutput .= ","; - $gOutput .= hd($fp); + $gOutput .= hd8($fp); } fclose($fp); $gOutput .= "\n};\n"; @@ -111,6 +146,7 @@ tVFS_Node {$prefix}_{$i} = { .ACLs = &gVFS_ACL_EveryoneRX, .Flags = 0, .Size = $size, + .Inode = {$inode}, .ImplPtr = {$prefix}_{$i}_data, .Read = InitRD_ReadFile }; @@ -145,7 +181,45 @@ tVFS_Node gInitRD_RootNode = { }; EOF; -$fp = fopen($argv[2], "w"); +$gOutput .= <<$item) + { + $gOutput .= ",&{$prefix}_{$i}"; + if(is_array($item[1])) + { + PutNodePointers("{$prefix}_{$i}", $item[1]); + } + } +} + +PutNodePointers("gInitRD_Files", $lStack[0][1]); + +$gOutput .= <<