MWS_SRX644: migrate branch mws_srx644 -> HEAD

This commit is contained in:
Jens-Heiner Rechtien
2003-03-27 13:06:40 +00:00
parent 414c097c65
commit f26f117c6c
12 changed files with 1501 additions and 511 deletions

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: filelckb.cxx,v $
*
* $Revision: 1.10 $
* $Revision: 1.11 $
*
* last change: $Author: obo $ $Date: 2002-09-03 13:59:45 $
* last change: $Author: hr $ $Date: 2003-03-27 14:06:30 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -58,9 +58,18 @@
*
*
************************************************************************/
#include <string.h>
#define _STORE_FILELCKB_CXX_ "$Revision: 1.10 $"
#include <store/filelckb.hxx>
#ifndef INCLUDED_STDDEF_H
#include <stddef.h>
#define INCLUDED_STDDEF_H
#endif
#ifndef INCLUDED_STRING_H
#include <string.h>
#define INCLUDED_STRING_H
#endif
#ifndef _SAL_TYPES_H_
#include <sal/types.h>
@@ -76,38 +85,24 @@
#include <rtl/ustring.hxx>
#endif
#ifndef _OSL_FILE_HXX_
#include <osl/file.hxx>
#endif
#ifndef _OSL_MUTEX_HXX_
#include <osl/mutex.hxx>
#ifndef _OSL_FILE_H_
#include <osl/file.h>
#endif
#ifndef _OSL_THREAD_H_
#include <osl/thread.h>
#endif
#ifndef _STORE_OBJECT_HXX_
#include <store/object.hxx>
#endif
#ifndef _STORE_LOCKBYTE_HXX_
#include <store/lockbyte.hxx>
#endif
#ifndef _STORE_FILELCKB_HXX_
#include <store/filelckb.hxx>
#ifndef _OSL_MUTEX_HXX_
#include <osl/mutex.hxx>
#endif
#ifndef _STORE_TYPES_H_
#include <store/types.h>
#endif
#ifndef INCLUDED_CSTDDEF
#include <cstddef>
#define INCLUDED_CSTDDEF
#ifndef _STORE_OBJECT_HXX_
#include <store/object.hxx>
#endif
#ifndef INCLUDED_CSTRING
#include <cstring>
#define INCLUDED_CSTRING
#ifndef _STORE_LOCKBYTE_HXX_
#include <store/lockbyte.hxx>
#endif
using namespace store;
@@ -117,13 +112,6 @@ using namespace store;
* OFileLockBytes internals.
*
*======================================================================*/
/* MSVC 6.0 still has std functions in global namespace */
#if defined(_MSC_VER) && (_MSC_VER <= 1200)
#define __STORE_CSTD
#else
#define __STORE_CSTD std
#endif /* _MSC_VER */
#ifdef DEBUG
#define inline static
#endif /* DEBUG */
@@ -133,7 +121,7 @@ using namespace store;
*/
inline void __store_memcpy (void * dst, const void * src, sal_uInt32 n)
{
__STORE_CSTD::memcpy (dst, src, n);
::memcpy (dst, src, n);
}
/*
@@ -153,29 +141,18 @@ static storeError __store_errnoToErrCode (sal_uInt32 nErrno);
*/
#define store_File_OpenRead 0x01L
#define store_File_OpenWrite 0x02L
#define store_File_OpenNoBuffer 0x04L
#define store_File_OpenNoCreate 0x08L
#define store_File_OpenTruncate 0x10L
#define store_File_OpenNoCreate 0x04L
#define store_File_OpenTruncate 0x08L
#ifdef __STORE_IO_NATIVE
#undef __STORE_IO_NATIVE
#endif
#ifdef SAL_OS2
#include <fileos2.cxx>
#endif /* SAL_OS2 */
#ifdef SAL_UNX
#include <fileunx.cxx>
#endif /* SAL_UNX */
#ifdef SAL_W32
#include <filew32.cxx>
#endif /* SAL_W32 */
#ifndef __STORE_IO_NATIVE
#include <filestd.cxx>
#endif /* !_STORE_IO_NATIVE */
#if defined(SAL_OS2)
#include <fileos2.hxx>
#elif defined(SAL_UNX)
#include <fileunx.hxx>
#elif defined(SAL_W32)
#include <filew32.hxx>
#else /* !(OS2 | UNX | W32) */
#include <filestd.hxx>
#endif /* !(OS2 | UNX | W32) */
/*
* __store_errnoToErrCode.
@@ -200,13 +177,73 @@ static storeError __store_errnoToErrCode (sal_uInt32 nErrno)
/*========================================================================
*
* OMappingDescriptor_Impl.
* FileMapping_Impl.
*
*======================================================================*/
struct OMappingDescriptor_Impl
namespace // unnamed
{
typedef OMappingDescriptor_Impl self;
struct FileMapping_Impl
{
/** Representation.
*/
sal_uInt32 m_nAlignment;
sal_uInt32 m_nSize;
HSTORE m_hMap;
/** Construction.
*/
FileMapping_Impl (void);
~FileMapping_Impl (void);
/** Create readonly file mapping.
*/
storeError create (HSTORE hFile);
};
/*
* FileMapping_Impl.
*/
inline FileMapping_Impl::FileMapping_Impl (void)
: m_nAlignment (__store_malign()), m_nSize (0), m_hMap (0)
{
}
/*
* ~FileMapping_Impl.
*/
inline FileMapping_Impl::~FileMapping_Impl (void)
{
if (m_hMap != 0)
__store_funmap (m_hMap);
}
/*
* create.
*/
inline storeError FileMapping_Impl::create (HSTORE hFile)
{
if (m_nAlignment == (sal_uInt32)(-1))
return store_E_Unknown; // E_Unsupported
if ((m_hMap = __store_fmap (hFile)) == 0)
return ERROR_FROM_NATIVE(__store_errno());
return __store_fsize (hFile, m_nSize);
}
} // unnamed namespace
/*========================================================================
*
* MemoryMapping_Impl.
*
*======================================================================*/
namespace // unnamed
{
struct MemoryMapping_Impl
{
/** Representation.
*/
sal_uInt32 m_nOffset;
@@ -215,103 +252,39 @@ struct OMappingDescriptor_Impl
/** Construction.
*/
inline OMappingDescriptor_Impl (
sal_uInt32 nOffset = 0xffffffff,
sal_uInt32 nSize = 0);
MemoryMapping_Impl (void);
~MemoryMapping_Impl (void);
/** Assignment.
/** Check for a valid memory mapping.
*/
inline self& operator= (const self& rDescr);
bool isValid (void) const { return (m_pData != 0); }
/** Comparison.
/** Create a readonly memory mapping.
*/
inline bool operator== (const self& rDescr) const;
inline bool operator<= (const self& rDescr) const;
storeError create (
const FileMapping_Impl & fmap,
sal_uInt32 nOffset,
sal_uInt32 nSize);
/** normalize.
/** Cleanup (unmap) memory mapping.
*/
inline void normalize (
sal_uInt32 nAlignment,
sal_uInt32 nSizeLimit);
/** cleanup.
*/
inline void cleanup (void);
/** unmap.
*/
inline void unmap (void);
/** sync.
*/
inline void sync (void);
void cleanup (void);
};
/*
* OMappingDescriptor_Impl.
* MemoryMapping_Impl.
*/
inline OMappingDescriptor_Impl::OMappingDescriptor_Impl (
sal_uInt32 nOffset, sal_uInt32 nSize)
: m_nOffset (nOffset),
m_nSize (nSize),
m_pData (NULL)
inline MemoryMapping_Impl::MemoryMapping_Impl (void)
: m_nOffset (0), m_nSize (0), m_pData (0)
{
}
/*
* operator=().
* ~MemoryMapping_Impl.
*/
inline OMappingDescriptor_Impl&
OMappingDescriptor_Impl::operator= (const self& rDescr)
inline MemoryMapping_Impl::~MemoryMapping_Impl (void)
{
m_nOffset = rDescr.m_nOffset;
m_nSize = rDescr.m_nSize;
m_pData = rDescr.m_pData;
return *this;
}
/*
* operator==().
*/
inline bool
OMappingDescriptor_Impl::operator== (const self& rDescr) const
{
return ((m_nOffset == rDescr.m_nOffset) &&
(m_nSize == rDescr.m_nSize ) );
}
/*
* operator<=().
*/
inline bool
OMappingDescriptor_Impl::operator<= (const self& rDescr) const
{
return ((m_nOffset == rDescr.m_nOffset) &&
(m_nSize <= rDescr.m_nSize ) );
}
/*
* normalize.
*/
inline void OMappingDescriptor_Impl::normalize (
sal_uInt32 nAlignment, sal_uInt32 nSizeLimit)
{
sal_uInt32 nRemain = (m_nSize % nAlignment);
if (nRemain)
m_nSize += (nAlignment - nRemain);
m_nOffset -= (m_nOffset % nAlignment);
if ((m_nOffset + m_nSize) > nSizeLimit)
m_nSize = nSizeLimit - m_nOffset;
}
/*
* unmap.
*/
inline void OMappingDescriptor_Impl::unmap (void)
{
if (m_pData)
if (m_pData != 0)
{
__store_munmap (m_pData, m_nSize);
m_pData = 0, m_nSize = 0;
@@ -319,27 +292,42 @@ inline void OMappingDescriptor_Impl::unmap (void)
}
/*
* sync.
* create.
*/
inline void OMappingDescriptor_Impl::sync (void)
inline storeError MemoryMapping_Impl::create (
const FileMapping_Impl & fmap, sal_uInt32 nOffset, sal_uInt32 nSize)
{
if (m_pData)
__store_msync (m_pData, m_nSize);
storeError result = store_E_None;
sal_uInt32 nAlign = (nOffset % fmap.m_nAlignment);
nOffset -= nAlign;
nSize += nAlign;
if ((nOffset + nSize) > fmap.m_nSize)
nSize = fmap.m_nSize - nOffset;
m_pData = __store_mmap (fmap.m_hMap, nOffset, nSize);
if (m_pData == 0)
result = ERROR_FROM_NATIVE(__store_errno());
else
m_nOffset = nOffset, m_nSize = nSize;
return (result);
}
/*
* cleanup.
*/
inline void OMappingDescriptor_Impl::cleanup (void)
inline void MemoryMapping_Impl::cleanup (void)
{
if (m_pData)
if (m_pData != 0)
{
__store_msync (m_pData, m_nSize);
__store_munmap (m_pData, m_nSize);
m_pData = 0, m_nSize = 0;
}
}
} // unnamed namespace
/*========================================================================
*
* OFileLockBytes_Impl interface.
@@ -350,36 +338,37 @@ namespace store
class OFileLockBytes_Impl
{
HSTORE m_hFile;
#ifdef DEBUG
sal_Char *m_pszFilename;
#endif /* DEBUG */
bool m_bMemmap : 1;
bool m_bWriteable : 1;
HSTORE m_hMap; // OMappingDescriptor (?)
sal_uInt32 m_nAlignment; // mapping alignment
sal_uInt32 m_nSize; // mapping size
OMappingDescriptor_Impl m_aDescrOne; // OMemoryDescriptor (?)
OMappingDescriptor_Impl m_aDescrAny;
/** Representation.
*/
HSTORE m_hFile;
MemoryMapping_Impl m_aMemmap;
bool m_bWriteable;
public:
static void * operator new (std::size_t n) SAL_THROW(())
/** Allocation.
*/
static void * operator new (size_t n) SAL_THROW(())
{
return rtl_allocateMemory (sal_uInt32(n));
}
static void operator delete (void * p, std::size_t) SAL_THROW(())
static void operator delete (void * p, size_t) SAL_THROW(())
{
rtl_freeMemory (p);
}
/** Construction.
*/
OFileLockBytes_Impl (void);
~OFileLockBytes_Impl (void);
/** Check for a valid file handle.
*/
bool isValid (void) const { return (m_hFile != 0); }
/** Operation.
*/
storeError close (void);
storeError create (
const sal_Char *pszFilename,
storeAccessMode eAccessMode);
@@ -387,9 +376,6 @@ public:
rtl_uString *pFilename,
storeAccessMode eAccessMode);
storeError memmap (OMappingDescriptor_Impl &rDescr);
storeError size (void);
storeError resize (sal_uInt32 nSize);
storeError readAt (
@@ -419,15 +405,8 @@ public:
*/
inline OFileLockBytes_Impl::OFileLockBytes_Impl (void)
: m_hFile (0),
#ifdef DEBUG
m_pszFilename (0),
#endif /* DEBUG */
m_bWriteable (sal_False),
m_hMap (0),
m_nSize (0)
m_bWriteable (false)
{
m_nAlignment = __store_malign();
m_bMemmap = (!(m_nAlignment == (sal_uInt32)(-1)));
}
/*
@@ -435,27 +414,12 @@ inline OFileLockBytes_Impl::OFileLockBytes_Impl (void)
*/
inline OFileLockBytes_Impl::~OFileLockBytes_Impl (void)
{
m_aMemmap.cleanup();
if (m_hFile)
{
if (m_hMap)
{
m_aDescrOne.cleanup();
m_aDescrAny.cleanup();
__store_funmap (m_hMap);
m_hMap = 0;
}
__store_fclose (m_hFile);
m_hFile = 0;
}
#ifdef DEBUG
if (m_pszFilename)
{
::free (m_pszFilename);
m_pszFilename = 0;
}
#endif /* DEBUG */
}
/*
@@ -463,17 +427,9 @@ inline OFileLockBytes_Impl::~OFileLockBytes_Impl (void)
*/
inline storeError OFileLockBytes_Impl::close (void)
{
m_aMemmap.cleanup();
if (m_hFile)
{
if (m_hMap)
{
m_aDescrOne.cleanup();
m_aDescrAny.cleanup();
__store_funmap (m_hMap);
m_hMap = 0;
}
__store_fclose (m_hFile);
m_hFile = 0;
}
@@ -486,17 +442,9 @@ inline storeError OFileLockBytes_Impl::close (void)
inline storeError OFileLockBytes_Impl::create (
const sal_Char *pszFilename, storeAccessMode eAccessMode)
{
m_aMemmap.cleanup();
if (m_hFile)
{
if (m_hMap)
{
m_aDescrOne.cleanup();
m_aDescrAny.cleanup();
__store_funmap (m_hMap);
m_hMap = 0;
}
__store_fclose (m_hFile);
m_hFile = 0;
}
@@ -514,18 +462,20 @@ inline storeError OFileLockBytes_Impl::create (
if (eAccessMode == store_AccessReadWrite)
nMode |= store_File_OpenNoCreate;
if (m_bMemmap)
nMode |= store_File_OpenNoBuffer;
storeError eErrCode = __store_fopen (pszFilename, nMode, m_hFile);
#ifdef DEBUG
if (eErrCode == store_E_None)
{
sal_uInt32 nLen = ::strlen (pszFilename);
m_pszFilename = (sal_Char*)(::realloc (m_pszFilename, nLen + 1));
::memcpy (m_pszFilename, pszFilename, nLen + 1);
if (!m_bWriteable)
{
// Readonly, try Memory mapped I/O, ignore errors.
FileMapping_Impl fmap;
if (fmap.create (m_hFile) == store_E_None)
{
// Try to map the entire file into memory.
m_aMemmap.create (fmap, 0, fmap.m_nSize);
}
}
}
#endif /* DEBUG */
return eErrCode;
}
@@ -555,31 +505,6 @@ inline storeError OFileLockBytes_Impl::create (
rtl_uString_assign (&(aSystemPath.pData), pFilename);
}
// Check access mode for memory mapped I/O.
if (m_bMemmap && (!(eAccessMode == store_AccessReadOnly)))
{
// Memory mapped write access. Obtain FileUrl.
rtl::OUString aFileUrl;
osl_getFileURLFromSystemPath (aSystemPath.pData, &(aFileUrl.pData));
// Obtain directory.
sal_Int32 k = aFileUrl.lastIndexOf (sal_Unicode('/'));
if (k > 0)
{
// Cut off last segment.
aFileUrl = aFileUrl.copy (0, k);
}
// Obtain volume attributes.
osl::VolumeInfo aInfo (VolumeInfoMask_Attributes);
osl::Directory::getVolumeInfo (aFileUrl, aInfo);
if (aInfo.isValid (VolumeInfoMask_Attributes) && aInfo.getRemoteFlag())
{
// Remote volume. Turn off memory mapped write access.
m_bMemmap = sal_False;
}
}
// Convert into system text encoding.
rtl::OString aFilename (
aSystemPath.pData->buffer,
@@ -590,96 +515,6 @@ inline storeError OFileLockBytes_Impl::create (
return create (aFilename.pData->buffer, eAccessMode);
}
/*
* memmap.
*/
inline storeError OFileLockBytes_Impl::memmap (OMappingDescriptor_Impl &rDescr)
{
if (rDescr <= m_aDescrOne)
rDescr = m_aDescrOne;
if (rDescr <= m_aDescrAny)
rDescr = m_aDescrAny;
if (!rDescr.m_pData)
{
if (rDescr.m_nOffset == 0)
m_aDescrOne.unmap();
else
m_aDescrAny.unmap();
if (!m_hMap)
{
if (m_bWriteable)
m_hMap = __store_fmap_rw (m_hFile);
else
m_hMap = __store_fmap_ro (m_hFile);
if (!m_hMap)
return ERROR_FROM_NATIVE(__store_errno());
}
if (m_bWriteable)
rDescr.m_pData = __store_mmap_rw (
m_hMap, rDescr.m_nOffset, rDescr.m_nSize);
else
rDescr.m_pData = __store_mmap_ro (
m_hMap, rDescr.m_nOffset, rDescr.m_nSize);
if (!rDescr.m_pData)
return ERROR_FROM_NATIVE(__store_errno());
if (rDescr.m_nOffset == 0)
m_aDescrOne = rDescr;
else
m_aDescrAny = rDescr;
}
return store_E_None;
}
/*
* size.
*/
inline storeError OFileLockBytes_Impl::size (void)
{
if (!m_hMap)
return __store_fsize (m_hFile, m_nSize);
else
return store_E_None;
}
/*
* resize.
*/
inline storeError OFileLockBytes_Impl::resize (sal_uInt32 nSize)
{
storeError eErrCode = size();
if (eErrCode != store_E_None)
return eErrCode;
if (nSize != m_nSize)
{
if (m_hMap)
{
#ifdef __STORE_FEATURE_WRITETHROUGH
// Note: file creation slowed down by about 60 percent.
m_aDescrOne.cleanup();
m_aDescrAny.cleanup();
#else
m_aDescrOne.unmap();
m_aDescrAny.unmap();
#endif /* __STORE_FEATURE_WRITETHROUGH */
__store_funmap (m_hMap);
m_hMap = 0;
}
eErrCode = __store_ftrunc (m_hFile, nSize);
if (eErrCode != store_E_None)
return eErrCode;
m_nSize = nSize;
}
return store_E_None;
}
/*
* readAt.
*/
@@ -689,47 +524,26 @@ inline storeError OFileLockBytes_Impl::readAt (
sal_uInt32 nBytes,
sal_uInt32 &rnDone)
{
storeError eErrCode = store_E_None;
if (m_bMemmap)
if (m_aMemmap.isValid())
{
// Memory mapped I/O.
eErrCode = size();
if (eErrCode != store_E_None)
return eErrCode;
if (!(nOffset < m_nSize))
if (!(nOffset < m_aMemmap.m_nSize))
return store_E_None;
nBytes = SAL_MIN(nOffset + nBytes, m_nSize) - nOffset;
nBytes = SAL_MIN(nOffset + nBytes, m_aMemmap.m_nSize) - nOffset;
if (!(nBytes > 0))
return store_E_None;
OMappingDescriptor_Impl aDescr;
if (m_bWriteable)
aDescr = OMappingDescriptor_Impl (nOffset, nBytes);
else
aDescr = OMappingDescriptor_Impl (0, m_nSize);
aDescr.normalize (m_nAlignment, m_nSize);
eErrCode = memmap (aDescr);
if (eErrCode != store_E_None)
return eErrCode;
aDescr.m_pData += (nOffset - aDescr.m_nOffset);
__store_memcpy (pBuffer, aDescr.m_pData, nBytes);
__store_memcpy (pBuffer, m_aMemmap.m_pData + nOffset, nBytes);
rnDone = nBytes;
return store_E_None;
}
else
{
// File I/O.
eErrCode = __store_fseek (m_hFile, nOffset);
if (eErrCode != store_E_None)
return eErrCode;
eErrCode = __store_fread (m_hFile, pBuffer, nBytes, rnDone);
return __store_fread (m_hFile, nOffset, pBuffer, nBytes, rnDone);
}
return eErrCode;
}
/*
@@ -741,45 +555,21 @@ inline storeError OFileLockBytes_Impl::writeAt (
sal_uInt32 nBytes,
sal_uInt32 &rnDone)
{
storeError eErrCode = store_E_None;
if (m_bMemmap)
{
// Memory mapped I/O. Determine current size.
eErrCode = size();
if (eErrCode != store_E_None)
return eErrCode;
// Check current size.
if (m_nSize < (nOffset + nBytes))
{
// Extend.
eErrCode = resize (nOffset + nBytes);
if (eErrCode != store_E_None)
return eErrCode;
}
OMappingDescriptor_Impl aDescr (nOffset, nBytes);
aDescr.normalize (m_nAlignment, m_nSize);
eErrCode = memmap (aDescr);
if (eErrCode != store_E_None)
return eErrCode;
aDescr.m_pData += (nOffset - aDescr.m_nOffset);
__store_memcpy (aDescr.m_pData, pBuffer, nBytes);
rnDone = nBytes;
}
if (m_bWriteable)
return __store_fwrite (m_hFile, nOffset, pBuffer, nBytes, rnDone);
else
{
// File I/O.
eErrCode = __store_fseek (m_hFile, nOffset);
if (eErrCode != store_E_None)
return eErrCode;
return store_E_AccessViolation;
}
eErrCode = __store_fwrite (m_hFile, pBuffer, nBytes, rnDone);
}
return eErrCode;
/*
* resize.
*/
inline storeError OFileLockBytes_Impl::resize (sal_uInt32 nSize)
{
if (m_bWriteable)
return __store_ftrunc (m_hFile, nSize);
else
return store_E_AccessViolation;
}
/*
@@ -787,13 +577,7 @@ inline storeError OFileLockBytes_Impl::writeAt (
*/
inline storeError OFileLockBytes_Impl::sync (void)
{
if (m_bMemmap)
{
// Memory mapped I/O.
m_aDescrOne.sync();
m_aDescrAny.sync();
}
else
if (m_bWriteable)
{
// File I/O.
__store_fsync (m_hFile);
@@ -806,10 +590,13 @@ inline storeError OFileLockBytes_Impl::sync (void)
*/
inline storeError OFileLockBytes_Impl::stat (sal_uInt32 &rnSize)
{
storeError eErrCode = size();
if (eErrCode == store_E_None)
rnSize = m_nSize;
return eErrCode;
if (m_aMemmap.isValid())
{
// Memory mapped I/O.
rnSize = m_aMemmap.m_nSize;
return store_E_None;
}
return __store_fsize (m_hFile, rnSize);
}
/*========================================================================
@@ -821,10 +608,8 @@ inline storeError OFileLockBytes_Impl::stat (sal_uInt32 &rnSize)
* OFileLockBytes.
*/
OFileLockBytes::OFileLockBytes (void)
: m_pImpl (new OFileLockBytes_Impl())
{
// Acquire exclusive access.
osl::MutexGuard aGuard (m_aMutex);
m_pImpl = new OFileLockBytes_Impl();
}
/*
@@ -832,8 +617,6 @@ OFileLockBytes::OFileLockBytes (void)
*/
OFileLockBytes::~OFileLockBytes (void)
{
// Acquire exclusive access.
osl::MutexGuard aGuard (m_aMutex);
delete m_pImpl;
}
@@ -978,4 +761,3 @@ storeError OFileLockBytes::unlockRange (
else
return store_E_InvalidHandle;
}

280
store/source/fileos2.hxx Normal file
View File

@@ -0,0 +1,280 @@
/*************************************************************************
*
* $RCSfile: fileos2.hxx,v $
*
* $Revision: 1.2 $
*
* last change: $Author: hr $ $Date: 2003-03-27 14:06:31 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#ifndef INCLUDED_STORE_FILEOS2_HXX
#define INCLUDED_STORE_FILEOS2_HXX
#define INCL_DOS
#define INCL_DOSERRORS
#include <os2def.h>
#include <bsedos.h>
#include <bseerr.h>
typedef HFILE HSTORE;
/*========================================================================
*
* File I/O (inline) implementation.
*
*======================================================================*/
/*
* __store_errcode_map.
*/
static const __store_errcode_mapping_st __store_errcode_map[] =
{
{ NO_ERROR, store_E_None },
{ ERROR_FILE_NOT_FOUND, store_E_NotExists },
{ ERROR_PATH_NOT_FOUND, store_E_NotExists },
{ ERROR_ACCESS_DENIED, store_E_AccessViolation },
{ ERROR_SHARING_VIOLATION, store_E_AccessViolation },
{ ERROR_LOCK_VIOLATION, store_E_LockingViolation },
{ ERROR_INVALID_ACCESS, store_E_InvalidAccess },
{ ERROR_INVALID_HANDLE, store_E_InvalidHandle },
{ ERROR_INVALID_PARAMETER, store_E_InvalidParameter },
{ ERROR_FILENAME_EXCED_RANGE, store_E_NameTooLong },
{ ERROR_TOO_MANY_OPEN_FILES, store_E_NoMoreFiles }
};
/*
* __store_errno.
*/
inline sal_Int32 __store_errno (void)
{
return (sal_Int32)errno;
}
/*
* __store_malign (unsupported).
*/
inline sal_uInt32 __store_malign (void)
{
return (sal_uInt32)(-1);
}
/*
* __store_fmap (readonly, unsupported).
*/
inline HSTORE __store_fmap (HSTORE hFile)
{
return ((HSTORE)0);
}
/*
* __store_funmap.
*/
inline void __store_funmap (HSTORE hMap)
{
}
/*
* __store_mmap (readonly, unsupported).
*/
inline sal_uInt8* __store_mmap (HSTORE h, sal_uInt32 k, sal_uInt32 n)
{
return (sal_uInt8*)NULL;
}
/*
* __store_munmap (unsupported).
*/
inline void __store_munmap (sal_uInt8 *p, sal_uInt32 n)
{
}
/*
* __store_fopen.
*/
inline storeError __store_fopen (
const sal_Char *pszName, sal_uInt32 nMode, HSTORE &rhFile)
{
// Initialize [out] param.
rhFile = 0;
// Access mode.
sal_uInt32 nAccessMode = OPEN_ACCESS_READONLY;
if (nMode & store_File_OpenWrite)
nAccessMode = OPEN_ACCESS_READWRITE;
if (nAccessMode == OPEN_ACCESS_READONLY)
{
nMode |= store_File_OpenNoCreate;
nMode &= ~store_File_OpenTruncate;
}
// Share mode.
sal_uInt32 nShareMode = OPEN_SHARE_DENYNONE;
if (nMode & store_File_OpenWrite)
nShareMode = OPEN_SHARE_DENYWRITE;
// Open action.
sal_uInt32 nOpenAction = 0, nDoneAction = 0;
if (!(nMode & store_File_OpenNoCreate))
nOpenAction = OPEN_ACTION_CREATE_IF_NEW; // Open always.
else
nOpenAction = OPEN_ACTION_FAIL_IF_NEW; // Open existing.
if (nMode & store_File_OpenTruncate)
nOpenAction |= OPEN_ACTION_REPLACE_IF_EXISTS;
else
nOpenAction |= OPEN_ACTION_OPEN_IF_EXISTS;
// Create file handle.
APIRET result = ::DosOpen (
pszName,
&rhFile,
&nDoneAction,
0L,
FILE_NORMAL,
nOpenAction,
nAccessMode | nShareMode | OPEN_FLAGS_NOINHERIT,
0L);
// Check result.
if (result)
return ERROR_FROM_NATIVE(result);
else
return store_E_None;
}
/*
* __store_fread.
*/
inline storeError __store_fread (
HSTORE h, sal_uInt32 offset, void *p, sal_uInt32 n, sal_uInt32 &k)
{
APIRET result;
if ((result = ::DosSetFilePtr (h, (long)offset, FILE_BEGIN, &k)) != 0)
return ERROR_FROM_NATIVE(result);
if ((result = ::DosRead (h, p, n, &k)) != 0)
return ERROR_FROM_NATIVE(result);
else
return store_E_None;
}
/*
* __store_fwrite.
*/
inline storeError __store_fwrite (
HSTORE h, sal_uInt32 offset, const void *p, sal_uInt32 n, sal_uInt32 &k)
{
APIRET result;
if ((result = ::DosSetFilePtr (h, (long)offset, FILE_BEGIN, &k)) != 0)
return ERROR_FROM_NATIVE(result);
if ((result = ::DosWrite (h, (PVOID)p, n, &k)) != 0)
return ERROR_FROM_NATIVE(result);
else
return store_E_None;
}
/*
* __store_fseek.
*/
inline storeError __store_fseek (HSTORE h, sal_uInt32 n)
{
sal_uInt32 k = 0;
APIRET result = ::DosSetFilePtr (h, (long)n, FILE_BEGIN, &k);
if (result)
return ERROR_FROM_NATIVE(result);
else
return store_E_None;
}
/*
* __store_fsize.
*/
inline storeError __store_fsize (HSTORE h, sal_uInt32 &k)
{
APIRET result = ::DosSetFilePtr (h, 0L, FILE_END, &k);
if (result)
return ERROR_FROM_NATIVE(result);
else
return store_E_None;
}
/*
* __store_ftrunc.
*/
inline storeError __store_ftrunc (HSTORE h, sal_uInt32 n)
{
APIRET result = ::DosSetFileSize (h, n);
if (result)
return ERROR_FROM_NATIVE(result);
else
return store_E_None;
}
/*
* __store_fsync.
*/
inline void __store_fsync (HSTORE h)
{
::DosResetBuffer (h);
}
/*
* __store_fclose.
*/
inline void __store_fclose (HSTORE h)
{
::DosClose (h);
}
#endif /* INCLUDED_STORE_FILEOS2_HXX */

266
store/source/filestd.hxx Normal file
View File

@@ -0,0 +1,266 @@
/*************************************************************************
*
* $RCSfile: filestd.hxx,v $
*
* $Revision: 1.2 $
*
* last change: $Author: hr $ $Date: 2003-03-27 14:06:32 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#ifndef INCLUDED_STORE_FILESTD_HXX
#define INCLUDED_STORE_FILESTD_HXX
#ifndef INCLUDED_ERRNO_H
#include <errno.h>
#define INCLUDED_ERRNO_H
#endif
#ifndef INCLUDED_STDIO_H
#include <stdio.h>
#define INCLUDED_STDIO_H
#endif
typedef FILE* HSTORE;
/*========================================================================
*
* File I/O (inline) implementation.
*
*======================================================================*/
/*
* __store_errcode_map.
*/
static const __store_errcode_mapping_st __store_errcode_map[] =
{
{ 0, store_E_None },
{ ENOENT, store_E_NotExists },
{ EACCES, store_E_AccessViolation },
{ EPERM, store_E_AccessViolation },
{ EAGAIN, store_E_LockingViolation },
{ EDEADLOCK, store_E_LockingViolation },
{ EBADF, store_E_InvalidHandle },
{ EINVAL, store_E_InvalidParameter },
};
/*
* __store_errno.
*/
inline sal_Int32 __store_errno (void)
{
return (sal_Int32)errno;
}
/*
* __store_malign (unsupported).
*/
inline sal_uInt32 __store_malign (void)
{
return (sal_uInt32)(-1);
}
/*
* __store_fmap (readonly, unsupported).
*/
inline HSTORE __store_fmap (HSTORE hFile)
{
return ((HSTORE)0);
}
/*
* __store_funmap.
*/
inline void __store_funmap (HSTORE hMap)
{
}
/*
* __store_mmap (readonly, unsupported).
*/
inline sal_uInt8* __store_mmap (HSTORE h, sal_uInt32 k, sal_uInt32 n)
{
return (sal_uInt8*)NULL;
}
/*
* __store_munmap (unsupported).
*/
inline void __store_munmap (sal_uInt8 *p, sal_uInt32 n)
{
}
/*
* __store_fopen.
*/
inline storeError __store_fopen (
const sal_Char *pszName, sal_uInt32 nMode, HSTORE &rhFile)
{
// Access mode.
if (!(nMode & store_File_OpenWrite))
{
nMode |= store_File_OpenNoCreate;
nMode &= ~store_File_OpenTruncate;
}
// Create file handle.
if (nMode & store_File_OpenTruncate)
{
// Create always, truncate existing.
rhFile = fopen (pszName, "wb+");
}
else if (nMode & store_File_OpenWrite)
{
// Open existing (rw).
rhFile = fopen (pszName, "rb+");
if (!(rhFile || (nMode & store_File_OpenNoCreate)))
{
// Try create (rw).
rhFile = fopen (pszName, "wb+");
}
}
else
{
// Open existing (ro).
rhFile = fopen (pszName, "rb");
}
// Check result.
if (!rhFile)
return ERROR_FROM_NATIVE(errno);
else
return store_E_None;
}
/*
* __store_fread.
*/
inline storeError __store_fread (
HSTORE h, sal_uInt32 offset, void *p, sal_uInt32 n, sal_uInt32 &k)
{
if (::fseek (h, (long)offset, SEEK_SET) < 0)
return ERROR_FROM_NATIVE(errno);
k = (sal_uInt32)::fread (p, (size_t)1, (size_t)n, h);
if (k == (sal_uInt32)(-1))
return ERROR_FROM_NATIVE(errno);
else
return store_E_None;
}
/*
* __store_fwrite.
*/
inline storeError __store_fwrite (
HSTORE h, sal_uInt32 offset, const void *p, sal_uInt32 n, sal_uInt32 &k)
{
if (::fseek (h, (long)offset, SEEK_SET) < 0)
return ERROR_FROM_NATIVE(errno);
k = (sal_uInt32)::fwrite (p, (size_t)1, (size_t)n, h);
if (k == (sal_uInt32)(-1))
return ERROR_FROM_NATIVE(errno);
else
return store_E_None;
}
/*
* __store_fseek.
*/
inline storeError __store_fseek (HSTORE h, sal_uInt32 n)
{
if (::fseek (h, (long)n, SEEK_SET) < 0)
return ERROR_FROM_NATIVE(errno);
else
return store_E_None;
}
/*
* __store_fsize.
*/
inline storeError __store_fsize (HSTORE h, sal_uInt32 &k)
{
if (::fseek (h, 0, SEEK_END) < 0)
return ERROR_FROM_NATIVE(errno);
k = (sal_uInt32)::ftell (h);
if (k == (sal_uInt32)(-1))
return ERROR_FROM_NATIVE(errno);
else
return store_E_None;
}
/*
* __store_ftrunc (unsupported).
*/
inline storeError __store_ftrunc (HSTORE h, sal_uInt32 n)
{
return store_E_None;
}
/*
* __store_fsync.
*/
inline void __store_fsync (HSTORE h)
{
::fflush (h);
}
/*
* __store_fclose.
*/
inline void __store_fclose (HSTORE h)
{
::fclose (h);
}
#endif /* INCLUDED_STORE_FILESTD_HXX */

423
store/source/fileunx.hxx Normal file
View File

@@ -0,0 +1,423 @@
/*************************************************************************
*
* $RCSfile: fileunx.hxx,v $
*
* $Revision: 1.2 $
*
* last change: $Author: hr $ $Date: 2003-03-27 14:06:33 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#ifndef INCLUDED_STORE_FILEUNX_HXX
#define INCLUDED_STORE_FILEUNX_HXX
#define _USE_UNIX98 /* _XOPEN_SOURCE=500 */
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#if defined(FREEBSD) || defined(NETBSD)
#define EDEADLOCK EDEADLK
#endif /* FREEBSD || NETBSD */
typedef int HSTORE;
/*========================================================================
*
* File I/O (inline) implementation.
*
*======================================================================*/
/*
* __store_errcode_map.
*/
static const __store_errcode_mapping_st __store_errcode_map[] =
{
{ 0, store_E_None },
{ ENOENT, store_E_NotExists },
{ EACCES, store_E_AccessViolation },
{ EPERM, store_E_AccessViolation },
{ EAGAIN, store_E_LockingViolation },
#if defined(EDEADLOCK)
{ EDEADLOCK, store_E_LockingViolation },
#endif /* EDEADLOCK */
{ EBADF, store_E_InvalidHandle },
{ EINVAL, store_E_InvalidParameter },
};
/*
* __store_errno.
*/
inline sal_Int32 __store_errno (void)
{
return (sal_Int32)errno;
}
/*
* __store_malign.
*/
#if defined(FREEBSD) || defined(LINUX)
inline sal_uInt32 __store_malign (void)
{
return (sal_uInt32)::getpagesize();
}
#elif defined(IRIX) || defined(SOLARIS)
inline sal_uInt32 __store_malign (void)
{
return (sal_uInt32)::sysconf (_SC_PAGESIZE);
}
#else
inline sal_uInt32 __store_malign (void)
{
return (sal_uInt32)(-1);
}
#endif /* FREEBSD || IRIX || LINUX || SOLARIS */
/*
* __store_fmap (readonly).
*/
inline HSTORE __store_fmap (HSTORE hFile)
{
// Avoid hMap = dup (hFile); may result in EMFILE.
return hFile;
}
/*
* __store_funmap.
*/
inline void __store_funmap (HSTORE hMap)
{
// Nothing to do, see '__store_fmap()'.
}
/*
* __store_mmap (readonly, shared).
*/
inline sal_uInt8* __store_mmap (HSTORE h, sal_uInt32 k, sal_uInt32 n)
{
void * p = ::mmap (NULL, (size_t)n, PROT_READ, MAP_SHARED, h, (off_t)k);
return ((p != MAP_FAILED) ? (sal_uInt8*)p : 0);
}
/*
* __store_munmap.
*/
inline void __store_munmap (sal_uInt8 *p, sal_uInt32 n)
{
::munmap ((char *)p, (size_t)n);
}
/*
* __store_fopen.
*/
inline storeError __store_fopen (
const sal_Char *pszName, sal_uInt32 nMode, HSTORE &rhFile)
{
// Access mode.
int nAccessMode = O_RDONLY;
if (nMode & store_File_OpenWrite)
nAccessMode = O_RDWR;
if (nAccessMode == O_RDONLY)
nMode |= store_File_OpenNoCreate;
if ((!(nMode & store_File_OpenNoCreate)) && (!(nAccessMode == O_RDONLY)))
nAccessMode |= O_CREAT;
if (nMode & store_File_OpenTruncate)
nAccessMode |= O_TRUNC;
// Share mode.
int nShareMode = S_IREAD | S_IROTH | S_IRGRP;
if (nMode & store_File_OpenWrite)
nShareMode |= (S_IWRITE | S_IWOTH | S_IWGRP);
// Create file handle.
if ((rhFile = ::open (pszName, nAccessMode, nShareMode)) < 0)
{
rhFile = 0;
return ERROR_FROM_NATIVE(errno);
}
#ifdef SOLARIS /* see workaround comment below */
/*
* Workaround for SunOS <= 5.7:
*
* 'mmap()' fails on posix (advisory) locked (F_SETLK) NFS file handles.
* Using non-posix F_SHARE / F_UNSHARE instead.
*/
// Acquire (advisory) Share Access (Multiple Reader | Single Writer)
struct fshare share;
if (nMode & store_File_OpenWrite)
{
share.f_access = F_RWACC; /* Request own read and write access */
share.f_deny = F_RWDNY; /* Deny other's read and write access */
}
else
{
share.f_access = F_RDACC; /* Request own read-only access */
share.f_deny = F_WRDNY; /* Deny other's write access */
}
share.f_id = 0;
if (::fcntl (rhFile, F_SHARE, &share) < 0)
{
// Save original result.
storeError result;
if ((errno == EACCES) || (errno == EAGAIN))
result = store_E_LockingViolation;
else
result = ERROR_FROM_NATIVE(errno);
// Close file handle.
::close (rhFile); rhFile = 0;
// Finish.
return (result);
}
#else /* POSIX */
// Acquire (advisory) Lock (Multiple Reader | Single Writer)
struct flock lock;
if (nMode & store_File_OpenWrite)
lock.l_type = F_WRLCK;
else
lock.l_type = F_RDLCK;
lock.l_whence = SEEK_SET;
lock.l_start = 0;
lock.l_len = 0;
if (::fcntl (rhFile, F_SETLK, &lock) < 0)
{
// Save original result.
storeError result;
if ((errno == EACCES) || (errno == EAGAIN))
result = store_E_LockingViolation;
else
result = ERROR_FROM_NATIVE(errno);
// Close file handle.
::close (rhFile); rhFile = 0;
// Finish.
return (result);
}
#endif /* SOLARIS || POSIX */
int nFlags = ::fcntl (rhFile, F_GETFD, 0);
if (!(nFlags < 0))
{
// Set close-on-exec flag.
nFlags |= FD_CLOEXEC;
::fcntl (rhFile, F_SETFD, nFlags);
}
return store_E_None;
}
/*
* __store_fread.
*/
inline storeError __store_fread (
HSTORE h, sal_uInt32 offset, void *p, sal_uInt32 n, sal_uInt32 &k)
{
#if defined(LINUX) || defined(SOLARIS)
k = (sal_uInt32)::pread (h, (char*)p, (size_t)n, (off_t)offset);
if ((k == (sal_uInt32)(-1)) && (errno == EOVERFLOW))
{
/*
* Workaround for 'pread()' failure at end-of-file:
*
* Some 'pread()'s fail with EOVERFLOW when reading at (or past)
* end-of-file, different from 'lseek() + read()' behaviour.
* Returning '0 bytes read' and 'store_E_None' instead.
*/
k = 0;
}
#else /* LINUX || SOLARIS */
if (::lseek (h, (off_t)offset, SEEK_SET) < 0)
return ERROR_FROM_NATIVE(errno);
k = (sal_uInt32)::read (h, (char *)p, (size_t)n);
#endif /* LINUX || SOLARIS */
if (k == (sal_uInt32)(-1))
return ERROR_FROM_NATIVE(errno);
else
return store_E_None;
}
/*
* __store_fwrite.
*/
inline storeError __store_fwrite (
HSTORE h, sal_uInt32 offset, const void *p, sal_uInt32 n, sal_uInt32 &k)
{
#if defined(LINUX) || defined(SOLARIS)
k = (sal_uInt32)::pwrite (h, (char*)p, (size_t)n, (off_t)offset);
#else /* LINUX || SOLARIS */
if (::lseek (h, (off_t)offset, SEEK_SET) < 0)
return ERROR_FROM_NATIVE(errno);
k = (sal_uInt32)::write (h, (char *)p, (size_t)n);
#endif /* LINUX || SOLARIS */
if (k == (sal_uInt32)(-1))
return ERROR_FROM_NATIVE(errno);
else
return store_E_None;
}
/*
* __store_fsize.
*/
inline storeError __store_fsize (HSTORE h, sal_uInt32 &k)
{
k = (sal_uInt32)::lseek (h, (off_t)0, SEEK_END);
if (k == (sal_uInt32)(-1))
return ERROR_FROM_NATIVE(errno);
else
return store_E_None;
}
/*
* __store_ftrunc.
*/
inline storeError __store_ftrunc (HSTORE h, sal_uInt32 n)
{
if (::ftruncate (h, (off_t)n) < 0)
{
// Save original result.
storeError result = ERROR_FROM_NATIVE(errno);
// Check against current size. Fail upon 'shrink'.
sal_uInt32 k = (sal_uInt32)::lseek (h, (off_t)0, SEEK_END);
if (k == (sal_uInt32)(-1))
return (result);
if ((0 <= n) && (n <= k))
return (result);
// Try 'expand' via 'lseek()' and 'write()'.
if (::lseek (h, (off_t)(n - 1), SEEK_SET) < 0)
return (result);
if (::write (h, (char*)"", (size_t)1) < 0)
return (result);
}
return store_E_None;
}
/*
* __store_fsync.
*/
inline void __store_fsync (HSTORE h)
{
::fsync (h);
}
/*
* __store_fclose.
*/
inline void __store_fclose (HSTORE h)
{
#ifdef SOLARIS /* see comment in __store_fopen() */
// Release (advisory) Share Access (Multiple Reader | Single Writer)
struct fshare share;
share.f_access = 0;
share.f_deny = 0;
share.f_id = 0;
::fcntl (h, F_UNSHARE, &share);
#else /* POSIX */
// Release (advisory) Lock (Multiple Reader | Single Writer)
struct flock lock;
lock.l_type = F_UNLCK;
lock.l_whence = SEEK_SET;
lock.l_start = 0;
lock.l_len = 0;
::fcntl (h, F_SETLK, &lock);
#endif /* SOLARIS || POSIX */
// Close file handle.
::close (h);
}
#endif /* INCLUDED_STORE_FILEUNX_HXX */

291
store/source/filew32.hxx Normal file
View File

@@ -0,0 +1,291 @@
/*************************************************************************
*
* $RCSfile: filew32.hxx,v $
*
* $Revision: 1.2 $
*
* last change: $Author: hr $ $Date: 2003-03-27 14:06:34 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): Matthias Huetsch <matthias.huetsch@sun.com>
*
*
************************************************************************/
#ifndef INCLUDED_STORE_FILEW32_HXX
#define INCLUDED_STORE_FILEW32_HXX
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
typedef HANDLE HSTORE;
/*========================================================================
*
* File I/O (inline) implementation.
*
*======================================================================*/
/*
* __store_errcode_map.
*/
static const __store_errcode_mapping_st __store_errcode_map[] =
{
{ ERROR_SUCCESS, store_E_None },
{ ERROR_FILE_NOT_FOUND, store_E_NotExists },
{ ERROR_ACCESS_DENIED, store_E_AccessViolation },
{ ERROR_LOCK_FAILED, store_E_LockingViolation },
{ ERROR_LOCK_VIOLATION, store_E_LockingViolation },
{ ERROR_INVALID_HANDLE, store_E_InvalidHandle },
{ ERROR_INVALID_PARAMETER, store_E_InvalidParameter },
};
/*
* __store_errno.
*/
inline sal_uInt32 __store_errno (void)
{
return (sal_uInt32)::GetLastError();
}
/*
* __store_malign.
*/
inline sal_uInt32 __store_malign (void)
{
// Check Win32 platform.
OSVERSIONINFO osinfo;
osinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
::GetVersionEx (&osinfo);
if (osinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
// Determine memory allocation granularity.
SYSTEM_INFO info;
::GetSystemInfo (&info);
return ((sal_uInt32)(info.dwAllocationGranularity));
}
return (sal_uInt32)(-1);
}
/*
* __store_fmap (readonly).
*/
inline HSTORE __store_fmap (HSTORE hFile)
{
return ::CreateFileMapping (
hFile, NULL, SEC_COMMIT | PAGE_READONLY, 0, 0, NULL);
}
/*
* __store_funmap.
*/
inline void __store_funmap (HSTORE hMap)
{
::CloseHandle (hMap);
}
/*
* __store_mmap (readonly).
*/
inline sal_uInt8* __store_mmap (HSTORE h, sal_uInt32 k, sal_uInt32 n)
{
return (sal_uInt8*)::MapViewOfFile (h, FILE_MAP_READ, 0, k, n);
}
/*
* __store_munmap.
*/
inline void __store_munmap (sal_uInt8 *p, sal_uInt32 n)
{
::UnmapViewOfFile (p);
}
/*
* __store_fopen.
*/
inline storeError __store_fopen (
const sal_Char *pszName, sal_uInt32 nMode, HSTORE &rhFile)
{
// Access mode.
DWORD nAccessMode = GENERIC_READ;
if (nMode & store_File_OpenWrite)
nAccessMode |= GENERIC_WRITE;
if (nAccessMode == GENERIC_READ)
nMode |= store_File_OpenNoCreate;
// Share mode.
DWORD nShareMode = FILE_SHARE_READ;
if (!(nMode & store_File_OpenWrite))
nShareMode |= FILE_SHARE_WRITE;
// Open action.
DWORD nOpenAction = 0;
if (!(nMode & store_File_OpenNoCreate))
{
// Open always.
if (nMode & store_File_OpenTruncate)
nOpenAction = CREATE_ALWAYS;
else
nOpenAction = OPEN_ALWAYS;
}
else
{
// Open existing.
if (nMode & store_File_OpenTruncate)
nOpenAction = TRUNCATE_EXISTING;
else
nOpenAction = OPEN_EXISTING;
}
// Create file handle.
rhFile = ::CreateFile (
pszName,
nAccessMode,
nShareMode,
(LPSECURITY_ATTRIBUTES)NULL,
nOpenAction,
(FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS),
(HANDLE)NULL);
// Check result and finish.
if (rhFile == INVALID_HANDLE_VALUE)
{
rhFile = 0;
return ERROR_FROM_NATIVE(::GetLastError());
}
return store_E_None;
}
/*
* __store_fread.
*/
inline storeError __store_fread (
HSTORE h, sal_uInt32 offset, void *p, sal_uInt32 n, sal_uInt32 &k)
{
if (::SetFilePointer (h, offset, NULL, FILE_BEGIN) == (DWORD)(-1))
return ERROR_FROM_NATIVE(::GetLastError());
if (!::ReadFile (h, p, n, &k, NULL))
return ERROR_FROM_NATIVE(::GetLastError());
else
return store_E_None;
}
/*
* __store_fwrite.
*/
inline storeError __store_fwrite (
HSTORE h, sal_uInt32 offset, const void *p, sal_uInt32 n, sal_uInt32 &k)
{
if (::SetFilePointer (h, offset, NULL, FILE_BEGIN) == (DWORD)(-1))
return ERROR_FROM_NATIVE(::GetLastError());
if (!::WriteFile (h, p, n, &k, NULL))
return ERROR_FROM_NATIVE(::GetLastError());
else
return store_E_None;
}
/*
* __store_fseek.
*/
inline storeError __store_fseek (HSTORE h, sal_uInt32 n)
{
DWORD k = ::SetFilePointer (h, n, NULL, FILE_BEGIN);
if (k == (DWORD)(-1))
return ERROR_FROM_NATIVE(::GetLastError());
else
return store_E_None;
}
/*
* __store_fsize.
*/
inline storeError __store_fsize (HSTORE h, sal_uInt32 &k)
{
k = (sal_uInt32)::GetFileSize (h, NULL);
if (k == (sal_uInt32)(-1))
return ERROR_FROM_NATIVE(::GetLastError());
else
return store_E_None;
}
/*
* __store_ftrunc.
*/
inline storeError __store_ftrunc (HSTORE h, sal_uInt32 n)
{
if (::SetFilePointer (h, n, NULL, FILE_BEGIN) == (DWORD)(-1))
return ERROR_FROM_NATIVE(::GetLastError());
if (!::SetEndOfFile (h))
return ERROR_FROM_NATIVE(::GetLastError());
else
return store_E_None;
}
/*
* __store_fsync.
*/
inline void __store_fsync (HSTORE h)
{
::FlushFileBuffers (h);
}
/*
* __store_fclose.
*/
inline void __store_fclose (HSTORE h)
{
::CloseHandle (h);
}
#endif /* INCLUDED_STORE_FILEW32_HXX */

View File

@@ -2,9 +2,9 @@
#
# $RCSfile: makefile.mk,v $
#
# $Revision: 1.1.1.1 $
# $Revision: 1.2 $
#
# last change: $Author: hr $ $Date: 2000-09-18 15:18:31 $
# last change: $Author: hr $ $Date: 2003-03-27 14:06:34 $
#
# The Contents of this file are made available subject to the terms of
# either of the following licenses
@@ -67,9 +67,7 @@ TARGET=store
# --- Settings ---
.INCLUDE : svpre.mk
.INCLUDE : settings.mk
.INCLUDE : sv.mk
# --- Files ---
@@ -80,7 +78,6 @@ SLOFILES= \
$(SLO)$/storbase.obj \
$(SLO)$/storcach.obj \
$(SLO)$/stordata.obj \
$(SLO)$/stordmon.obj \
$(SLO)$/storlckb.obj \
$(SLO)$/stortree.obj \
$(SLO)$/storpage.obj \
@@ -94,7 +91,6 @@ OBJFILES= \
$(OBJ)$/storbase.obj \
$(OBJ)$/storcach.obj \
$(OBJ)$/stordata.obj \
$(OBJ)$/stordmon.obj \
$(OBJ)$/storlckb.obj \
$(OBJ)$/stortree.obj \
$(OBJ)$/storpage.obj \

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: memlckb.cxx,v $
*
* $Revision: 1.3 $
* $Revision: 1.4 $
*
* last change: $Author: mhu $ $Date: 2002-08-17 17:00:08 $
* last change: $Author: hr $ $Date: 2003-03-27 14:06:34 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -59,7 +59,17 @@
*
************************************************************************/
#define _STORE_MEMLCKB_CXX_ "$Revision: 1.3 $"
#include <store/memlckb.hxx>
#ifndef INCLUDED_STDDEF_H
#include <stddef.h>
#define INCLUDED_STDDEF_H
#endif
#ifndef INCLUDED_STRING_H
#include <string.h>
#define INCLUDED_STRING_H
#endif
#ifndef _SAL_TYPES_H_
#include <sal/types.h>
@@ -76,29 +86,15 @@
#include <osl/mutex.hxx>
#endif
#ifndef _STORE_TYPES_H_
#include <store/types.h>
#endif
#ifndef _STORE_OBJECT_HXX_
#include <store/object.hxx>
#endif
#ifndef _STORE_LOCKBYTE_HXX_
#include <store/lockbyte.hxx>
#endif
#ifndef _STORE_MEMLCKB_HXX_
#include <store/memlckb.hxx>
#endif
#ifndef _STORE_TYPES_H_
#include <store/types.h>
#endif
#ifndef INCLUDED_CSTDDEF
#include <cstddef>
#define INCLUDED_CSTDDEF
#endif
#ifndef INCLUDED_CSTRING
#include <cstring>
#define INCLUDED_CSTRING
#endif
using namespace store;
@@ -107,13 +103,6 @@ using namespace store;
* OMemoryLockBytes internals.
*
*======================================================================*/
/* MSVC 6.0 still has std functions in global namespace */
#if defined(_MSC_VER) && (_MSC_VER <= 1200)
#define __STORE_CSTD
#else
#define __STORE_CSTD std
#endif /* _MSC_VER */
#ifdef DEBUG
#define inline static
#endif /* DEBUG */
@@ -123,7 +112,7 @@ using namespace store;
*/
inline void __store_memcpy (void * dst, const void * src, sal_uInt32 n)
{
__STORE_CSTD::memcpy (dst, src, n);
::memcpy (dst, src, n);
}
/*
@@ -131,7 +120,7 @@ inline void __store_memcpy (void * dst, const void * src, sal_uInt32 n)
*/
inline void __store_memset (void * dst, int val, sal_uInt32 n)
{
__STORE_CSTD::memset (dst, val, n);
::memset (dst, val, n);
}
#ifdef DEBUG
@@ -155,11 +144,11 @@ class OMemoryLockBytes_Impl
sal_uInt32 m_nSize;
public:
static void * operator new (std::size_t n) SAL_THROW(())
static void * operator new (size_t n) SAL_THROW(())
{
return rtl_allocateMemory (sal_uInt32(n));
}
static void operator delete (void * p, std::size_t) SAL_THROW(())
static void operator delete (void * p, size_t) SAL_THROW(())
{
rtl_freeMemory (p);
}
@@ -294,10 +283,8 @@ inline storeError OMemoryLockBytes_Impl::stat (sal_uInt32 &rnSize)
* OMemoryLockBytes.
*/
OMemoryLockBytes::OMemoryLockBytes (void)
: m_pImpl (new OMemoryLockBytes_Impl())
{
// Acquire exclusive access.
osl::MutexGuard aGuard (m_aMutex);
m_pImpl = new OMemoryLockBytes_Impl();
}
/*
@@ -305,8 +292,6 @@ OMemoryLockBytes::OMemoryLockBytes (void)
*/
OMemoryLockBytes::~OMemoryLockBytes (void)
{
// Acquire exclusive access.
osl::MutexGuard aGuard (m_aMutex);
delete m_pImpl;
}

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: storbase.hxx,v $
*
* $Revision: 1.4 $
* $Revision: 1.5 $
*
* last change: $Author: mhu $ $Date: 2002-08-17 17:06:37 $
* last change: $Author: hr $ $Date: 2003-03-27 14:06:35 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -60,7 +60,7 @@
************************************************************************/
#ifndef _STORE_STORBASE_HXX_
#define _STORE_STORBASE_HXX_ "$Revision: 1.4 $"
#define _STORE_STORBASE_HXX_ "$Revision: 1.5 $"
#ifndef _SAL_TYPES_H_
#include <sal/types.h>
@@ -109,7 +109,7 @@
*
*======================================================================*/
/* MSVC 6.0 still has std functions in global namespace */
#if defined(_MSC_VER) && (_MSC_VER <= 1200)
#if defined(_MSC_VER) && (_MSC_VER <= 1300)
#define __STORE_CSTD
#else
#define __STORE_CSTD std

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: storcach.hxx,v $
*
* $Revision: 1.3 $
* $Revision: 1.4 $
*
* last change: $Author: mhu $ $Date: 2002-08-17 17:29:04 $
* last change: $Author: hr $ $Date: 2003-03-27 14:06:35 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -60,7 +60,7 @@
************************************************************************/
#ifndef _STORE_STORCACH_HXX
#define _STORE_STORCACH_HXX "$Revision: 1.3 $"
#define _STORE_STORCACH_HXX "$Revision: 1.4 $"
#ifndef _SAL_TYPES_H_
#include <sal/types.h>
@@ -92,8 +92,8 @@ class OStorePageBIOS;
* (OStorePageData in external representation)
*
*======================================================================*/
#define STORE_DEFAULT_CACHEPAGES 128
#define STORE_LIMIT_CACHEPAGES 256
#define STORE_DEFAULT_CACHEPAGES STORE_LIMIT_CACHEPAGES
struct OStorePageCacheEntry;

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: storpage.cxx,v $
*
* $Revision: 1.2 $
* $Revision: 1.3 $
*
* last change: $Author: mhu $ $Date: 2001-03-13 20:45:39 $
* last change: $Author: hr $ $Date: 2003-03-27 14:06:37 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -59,7 +59,7 @@
*
************************************************************************/
#define _STORE_STORPAGE_CXX_ "$Revision: 1.2 $"
#include <storpage.hxx>
#ifndef _SAL_TYPES_H_
#include <sal/types.h>
@@ -98,9 +98,6 @@
#ifndef _STORE_STORCACH_HXX_
#include <storcach.hxx>
#endif
#ifndef _STORE_STORDMON_HXX_
#include <stordmon.hxx>
#endif
#ifndef _STORE_STORDATA_HXX_
#include <stordata.hxx>
#endif
@@ -108,10 +105,6 @@
#include <stortree.hxx>
#endif
#ifndef _STORE_STORPAGE_HXX_
#include <storpage.hxx>
#endif
using namespace store;
/*========================================================================
@@ -125,8 +118,7 @@ const sal_uInt32 OStorePageManager::m_nTypeId = sal_uInt32(0x62190120);
* OStorePageManager.
*/
OStorePageManager::OStorePageManager (void)
: m_xDaemon (NULL),
m_pCache (NULL),
: m_pCache (NULL),
m_pDirect (NULL),
m_pData (NULL),
m_nPageSize (0)
@@ -140,9 +132,6 @@ OStorePageManager::OStorePageManager (void)
m_pLink[0] = NULL;
m_pLink[1] = NULL;
m_pLink[2] = NULL;
// Daemon (kflushd :-).
OStorePageDaemon::getOrCreate (m_xDaemon);
}
/*
@@ -150,13 +139,6 @@ OStorePageManager::OStorePageManager (void)
*/
OStorePageManager::~OStorePageManager (void)
{
osl::MutexGuard aGuard (*this);
if (m_xDaemon.is())
{
m_xDaemon->remove (this);
m_xDaemon.clear();
}
delete m_pCache;
delete m_pDirect;
delete m_pData;
@@ -240,12 +222,6 @@ storeError OStorePageManager::initialize (
{
m_pNode[1] = new(m_nPageSize) page(m_nPageSize);
m_pNode[2] = new(m_nPageSize) page(m_nPageSize);
if (m_xDaemon.is())
{
// Request to be flushed.
m_xDaemon->insert (this);
}
}
// Initialize page cache.
@@ -1437,9 +1413,6 @@ storeError OStorePageManager::rebuild (
if (eErrCode != store_E_None)
return eErrCode;
// Prevent flush() attempt from daemon during exclusive access.
m_xDaemon.clear();
// Initialize as 'Destination' with 'Source' page size.
eErrCode = self::initialize (pDstLB, store_AccessCreate, nPageSize);
if (eErrCode != store_E_None)

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: storpage.hxx,v $
*
* $Revision: 1.2 $
* $Revision: 1.3 $
*
* last change: $Author: mhu $ $Date: 2001-03-13 20:45:39 $
* last change: $Author: hr $ $Date: 2003-03-27 14:06:37 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -60,16 +60,12 @@
************************************************************************/
#ifndef _STORE_STORPAGE_HXX_
#define _STORE_STORPAGE_HXX_ "$Revision: 1.2 $"
#define _STORE_STORPAGE_HXX_ "$Revision: 1.3 $"
#ifndef _SAL_TYPES_H_
#include <sal/types.h>
#endif
#ifndef _RTL_REF_HXX_
#include <rtl/ref.hxx>
#endif
#ifndef _STORE_OBJECT_HXX_
#include <store/object.hxx>
#endif
@@ -80,9 +76,6 @@
#ifndef _STORE_STORBASE_HXX_
#include <storbase.hxx>
#endif
#ifndef _STORE_STORDMON_HXX_
#include <stordmon.hxx>
#endif
namespace store
{
@@ -228,9 +221,7 @@ private:
/** Representation.
*/
rtl::Reference<OStorePageDaemon> m_xDaemon;
OStorePageCache *m_pCache;
OStorePageCache *m_pCache;
page *m_pNode[3];
inode *m_pDirect;
indirect *m_pLink[3];

View File

@@ -2,9 +2,9 @@
#
# $RCSfile: makefile.mk,v $
#
# $Revision: 1.7 $
# $Revision: 1.8 $
#
# last change: $Author: mhu $ $Date: 2002-08-22 15:31:09 $
# last change: $Author: hr $ $Date: 2003-03-27 14:06:40 $
#
# The Contents of this file are made available subject to the terms of
# either of the following licenses
@@ -99,9 +99,12 @@ SHL1VERSIONMAP= $(TARGET).map
.ENDIF
SHL1STDLIBS= $(SALLIB)
.IF "$(COM)"=="GCC"
SHL1STDLIBS+= -lsupc++
.ENDIF # GCC
# On gcc3 __Unwind_SetIP is not in supc++ but in libgcc_s.so
.IF "$(COMID)"=="gcc3"
SHL1STDLIBS+= -lsupc++ -lgcc_s
.ENDIF
SHL1DEF= $(MISC)$/$(SHL1TARGET).def
SHL1DEPN= $(L)$/isal.lib