]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/DiskIO/Mmapped/MmappedFile.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / DiskIO / Mmapped / MmappedFile.cc
index 0b54105c6b1c49609d2ed41b66b08bf0f6d4ff66..88f5424102de7c9be8ed9f753ae26fde48e8a8be 100644 (file)
@@ -1,15 +1,34 @@
 /*
- * $Id$
+ * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
  *
- * DEBUG: section 47    Store Directory Routines
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
+/* DEBUG: section 47    Store Directory Routines */
+
 #include "squid.h"
+#include "Debug.h"
+#include "disk.h"
 #include "DiskIO/IORequestor.h"
 #include "DiskIO/Mmapped/MmappedFile.h"
 #include "DiskIO/ReadRequest.h"
 #include "DiskIO/WriteRequest.h"
+#include "globals.h"
+
+#include <cerrno>
+#if HAVE_SYS_MMAN_H
 #include <sys/mman.h>
+#endif
+#if HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+// Some systems such as Hurd provide mmap() API but do not support MAP_NORESERVE
+#ifndef MAP_NORESERVE
+#define MAP_NORESERVE 0
+#endif
 
 CBDATA_CLASS_INIT(MmappedFile);
 
@@ -34,26 +53,8 @@ private:
     void *buf; ///< buffer returned by mmap, needed for munmap
 };
 
-
-void *
-MmappedFile::operator new(size_t sz)
-{
-    CBDATA_INIT_TYPE(MmappedFile);
-    MmappedFile *result = cbdataAlloc(MmappedFile);
-    /* Mark result as being owned - we want the refcounter to do the delete
-     * call */
-    return result;
-}
-
-void
-MmappedFile::operator delete(void *address)
-{
-    MmappedFile *t = static_cast<MmappedFile *>(address);
-    cbdataFree(t);
-}
-
 MmappedFile::MmappedFile(char const *aPath): fd(-1),
-        minOffset(0), maxOffset(-1), error_(false)
+    minOffset(0), maxOffset(-1), error_(false)
 {
     assert(aPath);
     path_ = xstrdup(aPath);
@@ -68,7 +69,7 @@ MmappedFile::~MmappedFile()
 
 // XXX: almost a copy of BlockingFile::open
 void
-MmappedFile::open(int flags, mode_t mode, RefCount<IORequestor> callback)
+MmappedFile::open(int flags, mode_t, RefCount<IORequestor> callback)
 {
     assert(fd < 0);
 
@@ -80,7 +81,7 @@ MmappedFile::open(int flags, mode_t mode, RefCount<IORequestor> callback)
         debugs(79,3, HERE << "open error: " << xstrerror());
         error_ = true;
     } else {
-        store_open_disk_fd++;
+        ++store_open_disk_fd;
         debugs(79,3, HERE << "FD " << fd);
 
         // setup mapping boundaries
@@ -108,7 +109,7 @@ void MmappedFile::doClose()
     if (fd >= 0) {
         file_close(fd);
         fd = -1;
-        store_open_disk_fd--;
+        --store_open_disk_fd;
     }
 }
 
@@ -187,10 +188,10 @@ MmappedFile::write(WriteRequest *aRequest)
     const ssize_t written =
         pwrite(fd, aRequest->buf, aRequest->len, aRequest->offset);
     if (written < 0) {
-        debugs(79,1, HERE << "error: " << xstrerr(errno));
+        debugs(79, DBG_IMPORTANT, HERE << "error: " << xstrerr(errno));
         error_ = true;
     } else if (static_cast<size_t>(written) != aRequest->len) {
-        debugs(79,1, HERE << "problem: " << written << " < " << aRequest->len);
+        debugs(79, DBG_IMPORTANT, HERE << "problem: " << written << " < " << aRequest->len);
         error_ = true;
     }
 
@@ -216,8 +217,8 @@ MmappedFile::ioInProgress() const
 }
 
 Mmapping::Mmapping(int aFd, size_t aLength, int aProt, int aFlags, off_t anOffset):
-        fd(aFd), length(aLength), prot(aProt), flags(aFlags), offset(anOffset),
-        delta(-1), buf(NULL)
+    fd(aFd), length(aLength), prot(aProt), flags(aFlags), offset(anOffset),
+    delta(-1), buf(NULL)
 {
 }
 
@@ -268,3 +269,4 @@ Mmapping::unmap()
 }
 
 // TODO: check MAP_NORESERVE, consider MAP_POPULATE and MAP_FIXED
+