VirtualBox

Changeset 59511 in vbox


Ignore:
Timestamp:
Jan 28, 2016 2:02:39 PM (9 years ago)
Author:
vboxsync
Message:

IPRT: RTFileSetAllocationSize() implementation for POSIX compatible systems using posix_fallocate() (used only on Solaris for now)

Location:
trunk/src/VBox/Runtime
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/Makefile.kmk

    r59461 r59511  
    11261126        generic/RTDirSetTimes-generic.cpp \
    11271127        generic/RTFileMove-generic.cpp \
    1128         generic/RTFileSetAllocationSize-generic.cpp \
    11291128        generic/RTLogWriteDebugger-generic.cpp \
    11301129        generic/RTPathAbs-generic.cpp \
     
    11441143        r3/generic/allocex-r3-generic.cpp \
    11451144        r3/posix/RTFileQueryFsSizes-posix.cpp \
     1145        r3/posix/RTFileSetAllocationSize-posix.cpp \
    11461146        r3/posix/RTHandleGetStandard-posix.cpp \
    11471147        r3/posix/RTMemProtect-posix.cpp \
  • trunk/src/VBox/Runtime/r3/posix/RTFileSetAllocationSize-posix.cpp

    r59505 r59511  
    3939#include <errno.h>
    4040#include <unistd.h>
    41 #include <sys/fcntl.h>
     41#include <fcntl.h>
    4242
    4343/**
    44  * The Linux specific fallocate() method.
     44 * The posix_fallocate() method.
    4545 */
    46 typedef int (*PFNLNXFALLOCATE) (int iFd, int fMode, off_t offStart, off_t cb);
    47 /** Flag to specify that the file size should not be extended. */
    48 #define LNX_FALLOC_FL_KEEP_SIZE 1
     46typedef int (*PFNPOSIXFALLOCATE) (int iFd, off_t offStart, off_t cb);
    4947
    5048RTDECL(int) RTFileSetAllocationSize(RTFILE hFile, uint64_t cbSize, uint32_t fFlags)
     
    5755     */
    5856    if (    sizeof(off_t) < sizeof(cbSize)
    59         &&  (cbSize >> 32) != 0)
     57        &&  RT_HIDWORD(cbSize) != 0)
    6058    {
    6159        AssertMsgFailed(("64-bit filesize not supported! cbSize=%lld\n", cbSize));
     
    6361    }
    6462
     63    if (fFlags & RTFILE_ALLOC_SIZE_F_KEEP_SIZE)
     64        return VERR_NOT_SUPPORTED;
     65
    6566    int rc = VINF_SUCCESS;
    66     PFNLNXFALLOCATE pfnLnxFAllocate = (PFNLNXFALLOCATE)(uintptr_t)dlsym(RTLD_DEFAULT, "fallocate");
    67     if (VALID_PTR(pfnLnxFAllocate))
     67    PFNPOSIXFALLOCATE pfnPosixFAllocate = (PFNPOSIXFALLOCATE)(uintptr_t)dlsym(RTLD_DEFAULT, "posix_fallocate");
     68    if (VALID_PTR(pfnPosixFAllocate))
    6869    {
    69         int fLnxFlags = (fFlags & RTFILE_ALLOC_SIZE_F_KEEP_SIZE) ? LNX_FALLOC_FL_KEEP_SIZE : 0;
    70         int rcLnx = pfnLnxFAllocate(RTFileToNative(hFile), fLnxFlags, 0, cbSize);
    71         if (rcLnx != 0)
     70        int rcPosix = pfnPosixFAllocate(RTFileToNative(hFile), 0, cbSize);
     71        if (rcPosix != 0)
    7272        {
    7373            if (errno == EOPNOTSUPP)
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette