os/persistentdata/featuremgmt/featureregistry/tools/featregconfig/scripts/checkfeatregconfig.pl
First public contribution.
1 # Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
3 # This component and the accompanying materials are made available
4 # under the terms of "Eclipse Public License v1.0"
5 # which accompanies this distribution, and is available
6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 # Initial Contributors:
9 # Nokia Corporation - initial contribution.
14 # Feature Registry Configuration File Lister/Checker
21 my $usage = "Feature Registry Configuration File Lister/Checker\n" .
22 "Copyright (c) 2005 Symbian Software Ltd. All rights reserved\n\n" .
23 "Usage: perl $0 BINCONFIGFILE\n\n" .
24 "Returns 0 if config file is valid, non-zero and reasons otherwise\n";
26 # Process command line
27 if (1 != scalar(@ARGV))
32 my $binConfigFile = $ARGV[0];
34 # open config file in binary mode
36 if (!open ($BINCONFIG, $binConfigFile))
38 print "ERROR: Binary config file is missing or cannot be opened";
44 my ($dev, $ino, $mode, $nlink, $_uid, $_gid, $redv, $size, $atime, $mtime, $ctime, $blksize, $blocks)
47 if ($size < $headerSize)
49 print "INVALID Feature Registry Config File: file is too small, must have at least 16 byte header";
52 my $KMaxLargePropertySize = 65535;
53 if ($size > $KMaxLargePropertySize)
55 print "INVALID Feature Registry Config File: File is larger than limit of 65535 bytes";
58 if ($size > 4096) # arbitrarily chosen; it may be sensible to change the way featreg works if config files become this big
60 print "WARNING: Large Feature Registry config file (", $ARGV[0], "); something may be wrong\n";
63 # Read and check header
65 if (!read($BINCONFIG, $packedHeader, $headerSize) ||
66 (length $packedHeader < 16))
68 print "INVALID Feature Registry Config File: Could not read 16-byte header";
71 my ($feat, $version, $entryCount, $rangeCount) = unpack 'a4I3', $packedHeader;
74 print "INVALID Feature Registry Config File: First 4 bytes of header must be ASCII 'f' 'e' 'a' 't'";
79 print "INVALID Feature Registry Config File: Second 32-bit word in header (version/flags) must be zero";
84 my $expectedSize = $headerSize + $entryCount*$entrySize + $rangeCount*$rangeSize;
85 if ($expectedSize != $size)
87 print "INVALID Feature Registry Config File: Size of file ($size bytes) does not match size expected from header" .
88 " ($expectedSize bytes) for $entryCount feature entries and $rangeCount default ranges";
92 # Write information from the header:
93 print "Feature Registry Configuration file '$binConfigFile'\n";
94 print "Contains $entryCount feature entries and $rangeCount default ranges\n";
98 # Check individual feature entries are listed by increasing (and non-repeating) UID, and write them to STDOUT
99 my $lastFeatureUid = 0;
100 for (my $e = 0; $e < $entryCount; $e++)
103 if (!read($BINCONFIG, $packedEntry, $entrySize) ||
104 (length $packedEntry < $entrySize))
106 print "INVALID Feature Registry Config File: Unable to read feature entry $e";
109 my ($featureUid, $status) = unpack 'I2', $packedEntry;
110 printf "Feature UID 0x%08X, status = 0x%08X (%s)\n", $featureUid, $status, ($status & 1) ? 'supported' : 'not supported';
111 if (($e > 0) && ($featureUid <= $lastFeatureUid))
113 print "INVALID Feature Registry Config File: Feature entries not listed by increasing (and non-repeating) UID";
118 print "WARNING Feature Registry Config File: Feature entry status bits 2-31 should be zero\n";
120 $lastFeatureUid = $featureUid;
125 # Check default supported ranges are in low-UID / high-UID pairs
126 # AND that the Symbian Essential default range is covered:
127 my $EssentialDefaultSupportedRangeLowUid = 271030278;
128 my $EssentialDefaultSupportedRangeHighUid = 271063045;
129 if (($EssentialDefaultSupportedRangeLowUid != 0x10279806) ||
130 ($EssentialDefaultSupportedRangeHighUid != 0x10281805))
132 print "ERROR Mismatch on Feature Registry Symbian essential default-supported range";
135 my $haveEssentialRange;
136 for (my $r = 0; $r < $rangeCount; $r++)
139 if (!read($BINCONFIG, $packedRange, $entrySize) ||
140 (length $packedRange < $rangeSize))
142 print "INVALID Feature Registry Config File: Unable to read default-supported range $r";
145 my ($lowUid, $highUid) = unpack 'I2', $packedRange;
146 printf "Feature UID range 0x%08X to 0x%08X supported by default\n", $lowUid, $highUid;
147 if (($lowUid <= $EssentialDefaultSupportedRangeLowUid) &&
148 ($highUid >= $EssentialDefaultSupportedRangeHighUid))
150 $haveEssentialRange = 1;
152 if ($lowUid > $highUid)
154 print "INVALID Feature Registry Config File: Default-supported range is not listed in order Low-UID High-Uid";
159 if (!$haveEssentialRange)
161 printf "INVALID Feature Registry Config File: Symbian essential default-supported UID range 0x%08X to 0x%08X is not present\n",
162 $EssentialDefaultSupportedRangeLowUid, $EssentialDefaultSupportedRangeHighUid;
166 # Confirm there's nothing more to read
168 if (read $BINCONFIG, $junk, 1)
170 printf "INVALID Feature Registry Config File: Unexpected data at end of binary configuration file";
174 # Warn if the filename is not 'featreg.cfg' (case insensitive)
175 if ($binConfigFile !~ m/[Ff][Ee][Aa][Tt][Rr][Ee][Gg]\.[Cc][Ff][Gg]$/)
177 printf "WARNING Feature Registry Config File must be called 'featreg.cfg'";
180 # Success - a valid configuration file (but it's up to you to guarantee the entries and ranges are correct,
181 # and to put the file in the correct location