[maemo-commits] [maemo-commits] r9917 - projects/haf/trunk/apt

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Thu Feb 15 17:49:48 EET 2007
Author: marivoll
Date: 2007-02-15 17:49:47 +0200 (Thu, 15 Feb 2007)
New Revision: 9917

Added:
   projects/haf/trunk/apt/mmap.patch
Log:
New.


Added: projects/haf/trunk/apt/mmap.patch
===================================================================
--- projects/haf/trunk/apt/mmap.patch	2007-02-15 15:44:34 UTC (rev 9916)
+++ projects/haf/trunk/apt/mmap.patch	2007-02-15 15:49:47 UTC (rev 9917)
@@ -0,0 +1,146 @@
+diff -rN -u old-apt/apt-pkg/contrib/mmap.cc new-apt/apt-pkg/contrib/mmap.cc
+--- old-apt/apt-pkg/contrib/mmap.cc	2006-04-10 19:40:50.000000000 +0300
++++ new-apt/apt-pkg/contrib/mmap.cc	2006-04-10 19:40:50.000000000 +0300
+@@ -35,13 +35,15 @@
+ #include <sys/stat.h>
+ #include <unistd.h>
+ #include <fcntl.h>
++#include <errno.h>
++
+    									/*}}}*/
+ 
+ // MMap::MMap - Constructor						/*{{{*/
+ // ---------------------------------------------------------------------
+ /* */
+ MMap::MMap(FileFd &F,unsigned long Flags) : Flags(Flags), iSize(0),
+-                     Base(0)
++					    Base(0), fd(0)
+ {
+    if ((Flags & NoImmMap) != NoImmMap)
+       Map(F);
+@@ -51,7 +53,7 @@
+ // ---------------------------------------------------------------------
+ /* */
+ MMap::MMap(unsigned long Flags) : Flags(Flags), iSize(0),
+-                     Base(0)
++                     Base(0), fd(0)
+ {
+ }
+ 									/*}}}*/
+@@ -84,7 +86,26 @@
+    // Map it.
+    Base = mmap(0,iSize,Prot,Map,Fd.Fd(),0);
+    if (Base == (void *)-1)
+-      return _error->Errno("mmap",_("Couldn't make mmap of %lu bytes"),iSize);
++     {
++       if (errno == ENODEV || errno == EINVAL)
++        {
++          // The filesystem doesn't support this particular kind of
++          // mmap.  So we allocate a buffer and read the whole file
++          // into it.
++          //
++	  int dupped_fd = dup (Fd.Fd());
++	  if (dupped_fd == -1)
++	    return _error->Errno("mmap",_("Couldn't dup filedescriptor"));
++	    
++	  Base = new unsigned char[iSize];
++          fd = new FileFd (dupped_fd);
++          if (!fd->Seek(0L) || !fd->Read(Base, iSize))
++	    return false;
++        }
++       else
++        return _error->Errno("mmap",_("Couldn't make mmap of %lu bytes"),
++                             iSize);
++     }
+ 
+    return true;
+ }
+@@ -99,9 +120,18 @@
+    
+    if (DoSync == true)
+       Sync();
+-   
+-   if (munmap((char *)Base,iSize) != 0)
+-      _error->Warning("Unable to munmap");
++
++   if (fd)
++     {
++       delete[] (char *)Base;
++       delete fd;
++       fd = NULL;
++     }
++   else
++     {
++       if (munmap((char *)Base,iSize) != 0)
++	 _error->Warning("Unable to munmap");
++     }
+    
+    iSize = 0;
+    Base = 0;
+@@ -113,14 +143,24 @@
+ /* This is done in syncronous mode - the docs indicate that this will 
+    not return till all IO is complete */
+ bool MMap::Sync()
+-{   
++{
+    if ((Flags & UnMapped) == UnMapped)
+       return true;
+    
+ #ifdef _POSIX_SYNCHRONIZED_IO   
+    if ((Flags & ReadOnly) != ReadOnly)
+-      if (msync((char *)Base,iSize,MS_SYNC) != 0)
+-	 return _error->Errno("msync","Unable to write mmap");
++     {
++       if (fd)
++	 {
++	   if (!fd->Seek (0) || !fd->Write (Base, iSize))
++	     return false;
++	 }
++       else
++	 {
++	   if (msync((char *)Base,iSize,MS_SYNC) != 0)
++	     return _error->Errno("msync","Unable to write mmap");
++	 }
++     }
+ #endif   
+    return true;
+ }
+@@ -136,8 +176,20 @@
+ #ifdef _POSIX_SYNCHRONIZED_IO
+    unsigned long PSize = sysconf(_SC_PAGESIZE);
+    if ((Flags & ReadOnly) != ReadOnly)
+-      if (msync((char *)Base+(int)(Start/PSize)*PSize,Stop - Start,MS_SYNC) != 0)
+-	 return _error->Errno("msync","Unable to write mmap");
++     {
++       if (fd)
++	 {
++	   if (!fd->Seek (Start)
++	       || !fd->Write (((char *)Base)+Start, Stop-Start))
++	     return false;
++	 }
++       else
++	 {
++	   if (msync((char *)Base+(int)(Start/PSize)*PSize,Stop - Start,
++		     MS_SYNC) != 0)
++	     return _error->Errno("msync","Unable to write mmap");
++	 }
++     }
+ #endif   
+    return true;
+ }
+diff -rN -u old-apt/apt-pkg/contrib/mmap.h new-apt/apt-pkg/contrib/mmap.h
+--- old-apt/apt-pkg/contrib/mmap.h	2006-04-10 19:40:50.000000000 +0300
++++ new-apt/apt-pkg/contrib/mmap.h	2006-04-10 19:41:00.000000000 +0300
+@@ -47,6 +47,12 @@
+    unsigned long iSize;
+    void *Base;
+ 
++   // In case mmap can not be used, we keep a dup of the file
++   // descriptor that should have been mmaped so that we can write to
++   // the file in Sync().
++   //
++   FileFd *fd;
++
+    bool Map(FileFd &Fd);
+    bool Close(bool DoSync = true);
+    


More information about the maemo-commits mailing list