From 4d4933fd97b85a52e48a5fa1a97bd34532864e32 Mon Sep 17 00:00:00 2001 From: Francisco Alecrim Date: Mon, 16 Nov 2009 10:56:59 -0400 Subject: [PATCH 022/118] apt-0.7.20.2: allow to work on jffs2 Allows apt to work on file systems that don't support read-write mmaps such as JFFS2 http://www.mail-archive.com/maemo-commits@maemo.org/msg00201.html Signed-off-by: Francisco Alecrim --- recipes/apt/apt-0.7.20.2/apt-fix-mmap-jffs2.patch | 143 +++++++++++++++++++++ recipes/apt/apt_0.7.20.2.bb | 3 +- 2 files changed, 145 insertions(+), 1 deletions(-) create mode 100644 recipes/apt/apt-0.7.20.2/apt-fix-mmap-jffs2.patch diff --git a/recipes/apt/apt-0.7.20.2/apt-fix-mmap-jffs2.patch b/recipes/apt/apt-0.7.20.2/apt-fix-mmap-jffs2.patch new file mode 100644 index 0000000..e14b143 --- /dev/null +++ b/recipes/apt/apt-0.7.20.2/apt-fix-mmap-jffs2.patch @@ -0,0 +1,143 @@ +diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc +index 04a4581..8a41b23 100644 +--- a/apt-pkg/contrib/mmap.cc ++++ b/apt-pkg/contrib/mmap.cc +@@ -31,6 +31,7 @@ + #include + #include + #include ++#include + + #include + /*}}}*/ +@@ -39,7 +40,7 @@ + // --------------------------------------------------------------------- + /* */ + MMap::MMap(FileFd &F,unsigned long Flags) : Flags(Flags), iSize(0), +- Base(0) ++ Base(0), fd(0) + { + if ((Flags & NoImmMap) != NoImmMap) + Map(F); +@@ -49,7 +50,7 @@ MMap::MMap(FileFd &F,unsigned long Flags) : Flags(Flags), iSize(0), + // --------------------------------------------------------------------- + /* */ + MMap::MMap(unsigned long Flags) : Flags(Flags), iSize(0), +- Base(0) ++ Base(0), fd(0) + { + } + /*}}}*/ +@@ -82,7 +83,26 @@ bool MMap::Map(FileFd &Fd) + // 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; + } +@@ -97,10 +117,19 @@ bool MMap::Close(bool DoSync) + + 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; + return true; +@@ -117,8 +146,18 @@ bool MMap::Sync() + + #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; + } +@@ -134,8 +173,20 @@ bool MMap::Sync(unsigned long Start,unsigned long Stop) + #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 --git a/apt-pkg/contrib/mmap.h b/apt-pkg/contrib/mmap.h +index 19cf758..ebbad9b 100644 +--- a/apt-pkg/contrib/mmap.h ++++ b/apt-pkg/contrib/mmap.h +@@ -44,6 +44,12 @@ class MMap + 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); + diff --git a/recipes/apt/apt_0.7.20.2.bb b/recipes/apt/apt_0.7.20.2.bb index 7fb5edf..aba3f7e 100644 --- a/recipes/apt/apt_0.7.20.2.bb +++ b/recipes/apt/apt_0.7.20.2.bb @@ -5,8 +5,9 @@ require apt.inc SRC_URI += "file://no-doxygen.patch;patch=1 \ file://no-ko-translation.patch;patch=1 \ + file://apt-fix-mmap-jffs2.patch;patch=1 \ file://use-host.patch;patch=1 " -PR = "r2" +PR = "r3" require apt-package.inc -- 1.6.3.3