2 Apt is copyright 1997, 1998, 1999 Jason Gunthorpe and others.
3 Apt is currently developed by APT Development Team <deity@lists.debian.org>.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 See /usr/share/common-licenses/GPL-2, or
22 <http://www.gnu.org/copyleft/gpl.txt> for the terms of the latest version
23 of the GNU General Public License.
26 // -*- mode: cpp; mode: fold -*-
27 // Description /*{{{*/
28 // $Id: pkgcache.h,v 1.25 2001/07/01 22:28:24 jgg Exp $
29 /* ######################################################################
31 Cache - Structure definitions for the cache file
33 Please see doc/apt-pkg/cache.sgml for a more detailed description of
34 this format. Also be sure to keep that file up-to-date!!
36 Clients should always use the CacheIterators classes for access to the
37 cache. They provide a simple STL-like method for traversing the links
40 See pkgcachegen.h for information about generating cache structures.
42 ##################################################################### */
44 #ifndef PKGLIB_PKGCACHE_H
45 #define PKGLIB_PKGCACHE_H
54 class pkgVersioningSystem;
58 // Cache element predeclarations
76 class PkgFileIterator;
77 class VerFileIterator;
78 class DescFileIterator;
79 friend class PkgIterator;
80 friend class VerIterator;
81 friend class DescInterator;
82 friend class DepIterator;
83 friend class PrvIterator;
84 friend class PkgFileIterator;
85 friend class VerFileIterator;
86 friend class DescFileIterator;
90 // These are all the constants used in the cache structures
92 // WARNING - if you change these lists you must also edit
93 // the stringification in pkgcache.cc and also consider whether
94 // the cache file will become incompatible.
97 enum DepType {Depends=1,PreDepends=2,Suggests=3,Recommends=4,
98 Conflicts=5,Replaces=6,Obsoletes=7,DpkgBreaks=8};
99 enum DepCompareOp {Or=0x10,NoOp=0,LessEq=0x1,GreaterEq=0x2,Less=0x3,
100 Greater=0x4,Equals=0x5,NotEquals=0x6};
105 enum VerPriority {Important=1,Required=2,Standard=3,Optional=4,Extra=5};
106 enum PkgSelectedState {Unknown=0,Install=1,Hold=2,DeInstall=3,Purge=4};
107 enum PkgInstState {Ok=0,ReInstReq=1,HoldInst=2,HoldReInstReq=3};
108 enum PkgCurrentState {NotInstalled=0,UnPacked=1,HalfConfigured=2,
109 HalfInstalled=4,ConfigFiles=5,Installed=6,
110 TriggersAwaited=7,TriggersPending=8};
115 enum PkgFlags {Auto=(1<<0),Essential=(1<<3),Important=(1<<4)};
116 enum PkgFFlags {NotSource=(1<<0),NotAutomatic=(1<<1)};
121 // Memory mapped cache file
125 unsigned long sHash(const string &S) const;
126 unsigned long sHash(const char *S) const;
130 // Pointers to the arrays of items
135 PackageFile *PkgFileP;
140 StringItem *StringItemP;
143 virtual bool ReMap();
144 inline bool Sync() {return Map.Sync();};
145 inline MMap &GetMap() {return Map;};
146 inline void *DataEnd() {return ((unsigned char *)Map.Data()) + Map.Size();};
148 // String hashing function (512 range)
149 inline unsigned long Hash(const string &S) const {return sHash(S);};
150 inline unsigned long Hash(const char *S) const {return sHash(S);};
152 // Usefull transformation things
153 const char *Priority(unsigned char Priority);
156 PkgIterator FindPkg(const string &Name);
157 Header &Head() {return *HeaderP;};
158 inline PkgIterator PkgBegin();
159 inline PkgIterator PkgEnd();
160 inline PkgFileIterator FileBegin();
161 inline PkgFileIterator FileEnd();
163 // Make me a function
164 pkgVersioningSystem *VS;
167 static const char *CompTypeDeb(unsigned char Comp);
168 static const char *CompType(unsigned char Comp);
169 static const char *DepType(unsigned char Dep);
171 pkgCache(MMap *Map,bool DoMap = true);
172 virtual ~pkgCache() {};
176 struct pkgCache::Header
178 // Signature information
179 unsigned long Signature;
184 // Size of structure values
185 unsigned short HeaderSz;
186 unsigned short PackageSz;
187 unsigned short PackageFileSz;
188 unsigned short VersionSz;
189 unsigned short DescriptionSz;
190 unsigned short DependencySz;
191 unsigned short ProvidesSz;
192 unsigned short VerFileSz;
193 unsigned short DescFileSz;
196 unsigned long PackageCount;
197 unsigned long VersionCount;
198 unsigned long DescriptionCount;
199 unsigned long DependsCount;
200 unsigned long PackageFileCount;
201 unsigned long VerFileCount;
202 unsigned long DescFileCount;
203 unsigned long ProvidesCount;
206 map_ptrloc FileList; // struct PackageFile
207 map_ptrloc StringList; // struct StringItem
208 map_ptrloc VerSysName; // StringTable
209 map_ptrloc Architecture; // StringTable
210 unsigned long MaxVerFileSize;
211 unsigned long MaxDescFileSize;
213 /* Allocation pools, there should be one of these for each structure
214 excluding the header */
215 DynamicMMap::Pool Pools[8];
217 // Rapid package name lookup
218 map_ptrloc HashTable[2*1048];
220 bool CheckSizes(Header &Against) const;
224 struct pkgCache::Package
227 map_ptrloc Name; // Stringtable
228 map_ptrloc VersionList; // Version
229 map_ptrloc CurrentVer; // Version
230 map_ptrloc Section; // StringTable (StringItem)
233 map_ptrloc NextPackage; // Package
234 map_ptrloc RevDepends; // Dependency
235 map_ptrloc ProvidesList; // Provides
237 // Install/Remove/Purge etc
238 unsigned char SelectedState; // What
239 unsigned char InstState; // Flags
240 unsigned char CurrentState; // State
246 struct pkgCache::PackageFile
249 map_ptrloc FileName; // Stringtable
250 map_ptrloc Archive; // Stringtable
251 map_ptrloc Component; // Stringtable
252 map_ptrloc Version; // Stringtable
253 map_ptrloc Origin; // Stringtable
254 map_ptrloc Label; // Stringtable
255 map_ptrloc Architecture; // Stringtable
256 map_ptrloc Site; // Stringtable
257 map_ptrloc IndexType; // Stringtable
262 map_ptrloc NextFile; // PackageFile
264 time_t mtime; // Modification time for the file
267 struct pkgCache::VerFile
269 map_ptrloc File; // PackageFile
270 map_ptrloc NextFile; // PkgVerFile
271 map_ptrloc Offset; // File offset
275 struct pkgCache::DescFile
277 map_ptrloc File; // PackageFile
278 map_ptrloc NextFile; // PkgVerFile
279 map_ptrloc Offset; // File offset
283 struct pkgCache::Version
285 map_ptrloc VerStr; // Stringtable
286 map_ptrloc Section; // StringTable (StringItem)
287 map_ptrloc Arch; // StringTable
290 map_ptrloc FileList; // VerFile
291 map_ptrloc NextVer; // Version
292 map_ptrloc DescriptionList; // Description
293 map_ptrloc DependsList; // Dependency
294 map_ptrloc ParentPkg; // Package
295 map_ptrloc ProvidesList; // Provides
297 map_ptrloc Size; // These are the .deb size
298 map_ptrloc InstalledSize;
301 unsigned char Priority;
304 struct pkgCache::Description
306 // Language Code store the description translation language code. If
307 // the value has a 0 lenght then this is readed using the Package
308 // file else the Translation-CODE are used.
309 map_ptrloc language_code; // StringTable
310 map_ptrloc md5sum; // StringTable
313 map_ptrloc FileList; // DescFile
314 map_ptrloc NextDesc; // Description
315 map_ptrloc ParentPkg; // Package
320 struct pkgCache::Dependency
322 map_ptrloc Version; // Stringtable
323 map_ptrloc Package; // Package
324 map_ptrloc NextDepends; // Dependency
325 map_ptrloc NextRevDepends; // Dependency
326 map_ptrloc ParentVer; // Version
328 // Specific types of depends
331 unsigned char CompareOp;
334 struct pkgCache::Provides
336 map_ptrloc ParentPkg; // Pacakge
337 map_ptrloc Version; // Version
338 map_ptrloc ProvideVersion; // Stringtable
339 map_ptrloc NextProvides; // Provides
340 map_ptrloc NextPkgProv; // Provides
343 struct pkgCache::StringItem
345 map_ptrloc String; // Stringtable
346 map_ptrloc NextItem; // StringItem
349 #include "cacheiterators.h"
351 inline pkgCache::PkgIterator pkgCache::PkgBegin()
352 {return PkgIterator(*this);};
353 inline pkgCache::PkgIterator pkgCache::PkgEnd()
354 {return PkgIterator(*this,PkgP);};
355 inline pkgCache::PkgFileIterator pkgCache::FileBegin()
356 {return PkgFileIterator(*this,PkgFileP + HeaderP->FileList);};
357 inline pkgCache::PkgFileIterator pkgCache::FileEnd()
358 {return PkgFileIterator(*this,PkgFileP);};
360 // Oh I wish for Real Name Space Support
361 class pkgCache::Namespace
365 typedef pkgCache::PkgIterator PkgIterator;
366 typedef pkgCache::VerIterator VerIterator;
367 typedef pkgCache::DescIterator DescIterator;
368 typedef pkgCache::DepIterator DepIterator;
369 typedef pkgCache::PrvIterator PrvIterator;
370 typedef pkgCache::PkgFileIterator PkgFileIterator;
371 typedef pkgCache::VerFileIterator VerFileIterator;
372 typedef pkgCache::Version Version;
373 typedef pkgCache::Description Description;
374 typedef pkgCache::Package Package;
375 typedef pkgCache::Header Header;
376 typedef pkgCache::Dep Dep;
377 typedef pkgCache::Flag Flag;