X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/f55a958ff2251f0061ab907157c99a350e56025f..93bf083d699c60f1ac40297bfa6783fb0cb800d8:/apt-pkg/contrib/mmap.cc diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc index 9febc5cdd..e12e077c6 100644 --- a/apt-pkg/contrib/mmap.cc +++ b/apt-pkg/contrib/mmap.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: mmap.cc,v 1.2 1998/07/04 05:57:42 jgg Exp $ +// $Id: mmap.cc,v 1.8 1998/07/26 04:49:34 jgg Exp $ /* ###################################################################### MMap Class - Provides 'real' mmap or a faked mmap using read(). @@ -21,9 +21,13 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ +#ifdef __GNUG__ +#pragma implementation "apt-pkg/mmap.h" +#endif + #define _BSD_SOURCE -#include -#include +#include +#include #include #include @@ -35,7 +39,7 @@ // MMap::MMap - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -MMap::MMap(File &F,unsigned long Flags) : Fd(F), Flags(Flags), iSize(0), +MMap::MMap(FileFd &F,unsigned long Flags) : Fd(F), Flags(Flags), iSize(0), Base(0) { if ((Flags & NoImmMap) != NoImmMap) @@ -65,6 +69,9 @@ bool MMap::Map() if ((Flags & Public) != Public) Map = MAP_PRIVATE; + if (iSize == 0) + return _error->Error("Can't mmap an empty file"); + // Map it. Base = mmap(0,iSize,Prot,Map,Fd.Fd(),0); if (Base == (void *)-1) @@ -76,12 +83,13 @@ bool MMap::Map() // MMap::Close - Close the map /*{{{*/ // --------------------------------------------------------------------- /* */ -bool MMap::Close(bool DoClose) +bool MMap::Close(bool DoClose, bool DoSync) { if (Fd.IsOpen() == false) return true; - Sync(); + if (DoSync == true) + Sync(); if (munmap((char *)Base,iSize) != 0) _error->Warning("Unable to munmap"); @@ -94,10 +102,11 @@ bool MMap::Close(bool DoClose) /*}}}*/ // MMap::Sync - Syncronize the map with the disk /*{{{*/ // --------------------------------------------------------------------- -/* */ +/* This is done in syncronous mode - the docs indicate that this will + not return till all IO is complete */ bool MMap::Sync() { - if ((Flags & ReadOnly) == ReadOnly) + if ((Flags & ReadOnly) != ReadOnly) if (msync((char *)Base,iSize,MS_SYNC) != 0) return _error->Error("msync","Unable to write mmap"); return true; @@ -108,7 +117,7 @@ bool MMap::Sync() /* */ bool MMap::Sync(unsigned long Start,unsigned long Stop) { - if ((Flags & ReadOnly) == ReadOnly) + if ((Flags & ReadOnly) != ReadOnly) if (msync((char *)Base+(int)(Start/PAGE_SIZE)*PAGE_SIZE,Stop - Start,MS_SYNC) != 0) return _error->Error("msync","Unable to write mmap"); return true; @@ -118,7 +127,7 @@ bool MMap::Sync(unsigned long Start,unsigned long Stop) // DynamicMMap::DynamicMMap - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -DynamicMMap::DynamicMMap(File &F,unsigned long Flags,unsigned long WorkSpace) : +DynamicMMap::DynamicMMap(FileFd &F,unsigned long Flags,unsigned long WorkSpace) : MMap(F,Flags | NoImmMap), WorkSpace(WorkSpace) { unsigned long EndOfFile = Fd.Size(); @@ -135,7 +144,9 @@ DynamicMMap::DynamicMMap(File &F,unsigned long Flags,unsigned long WorkSpace) : DynamicMMap::~DynamicMMap() { unsigned long EndOfFile = iSize; - Close(false); + Sync(); + iSize = WorkSpace; + Close(false,false); ftruncate(Fd.Fd(),EndOfFile); Fd.Close(); }