VirtualBox

Changeset 28688 in vbox


Ignore:
Timestamp:
Apr 24, 2010 6:12:55 PM (15 years ago)
Author:
vboxsync
Message:

IPRT: Added RTDirFlush and RTDirFlushParent.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/dir.h

    r27247 r28688  
    125125#define RTDIRRMREC_F_VALID_MASK     UINT32_C(0x00000001)
    126126/** @} */
     127
     128/**
     129 * Flushes the specified directory.
     130 *
     131 * This API is not implemented on all systems.  On some systems it may be
     132 * unnecessary if you've already flushed the file.  If you really care for your
     133 * data and is entering dangerous territories, it doesn't hurt calling it after
     134 * flushing and closing the file.
     135 *
     136 * @returns IPRT status code.
     137 * @retval  VERR_NOT_IMPLEMENTED must be expected.
     138 * @retval  VERR_NOT_SUPPORTED must be expected.
     139 * @param   pszPath     Path to the directory.
     140 */
     141RTDECL(int) RTDirFlush(const char *pszPath);
     142
     143/**
     144 * Flushes the parent directory of the specified file.
     145 *
     146 * This is just a wrapper around RTDirFlush.
     147 *
     148 * @returns IPRT status code, see RTDirFlush for details.
     149 * @param   pszChild    Path to the file which parent should be flushed.
     150 */
     151RTDECL(int) RTDirFlushParent(const char *pszChild);
    127152
    128153
  • trunk/src/VBox/Runtime/r3/dir.cpp

    r27246 r28688  
    55
    66/*
    7  * Copyright (C) 2006-2007 Sun Microsystems, Inc.
     7 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    4343
    4444#include <iprt/dir.h>
     45#include "internal/iprt.h"
     46
     47#include <iprt/assert.h>
    4548#include <iprt/file.h>
     49#include <iprt/err.h>
     50#include <iprt/log.h>
     51#include <iprt/mem.h>
     52#include <iprt/param.h>
    4653#include <iprt/path.h>
    47 #include <iprt/alloc.h>
    48 #include <iprt/log.h>
    49 #include <iprt/param.h>
    5054#include <iprt/string.h>
    51 #include <iprt/err.h>
    52 #include <iprt/assert.h>
    5355#include <iprt/uni.h>
    5456#include "internal/dir.h"
     
    865867}
    866868
     869
     870RTDECL(int) RTDirFlushParent(const char *pszChild)
     871{
     872    char szPath[RTPATH_MAX];
     873    int rc = RTStrCopy(szPath, sizeof(szPath), pszChild);
     874    if (RT_SUCCESS(rc))
     875    {
     876        RTPathStripFilename(szPath);
     877        rc = RTDirFlush(szPath);
     878    }
     879    return rc;
     880}
     881
  • trunk/src/VBox/Runtime/r3/posix/dir-posix.cpp

    r25292 r28688  
    55
    66/*
    7  * Copyright (C) 2006-2007 Sun Microsystems, Inc.
     7 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3838#include <sys/types.h>
    3939#include <sys/stat.h>
     40#include <sys/fcntl.h>
     41#include <fcntl.h>
    4042#include <dirent.h>
    4143#include <stdio.h>
    4244
    4345#include <iprt/dir.h>
    44 #include <iprt/path.h>
    45 #include <iprt/alloc.h>
     46#include "internal/iprt.h"
     47
    4648#include <iprt/alloca.h>
    47 #include <iprt/string.h>
    4849#include <iprt/assert.h>
    4950#include <iprt/err.h>
    5051#include <iprt/log.h>
     52#include <iprt/mem.h>
     53#include <iprt/param.h>
     54#include <iprt/path.h>
     55#include <iprt/string.h>
    5156#include "internal/dir.h"
    5257#include "internal/fs.h"
     
    134139
    135140    LogFlow(("RTDirRemove(%p={%s}): returns %Rrc\n", pszPath, pszPath, rc));
     141    return rc;
     142}
     143
     144
     145RTDECL(int) RTDirFlush(const char *pszPath)
     146{
     147    /*
     148     * Linux: The fsync() man page hints at this being required for ensuring
     149     * consistency between directory and file in case of a crash.
     150     *
     151     * Solaris: No mentioned is made of directories on the fsync man page.
     152     * While rename+fsync will do what we want on ZFS, the code needs more
     153     * careful studying wrt whether the directory entry of a new file is
     154     * implicitly synced when the file is synced (it's very likely for ZFS).
     155     *
     156     * FreeBSD: The FFS fsync code seems to flush the directory entry as well
     157     * in some cases.  Don't know exactly what's up with rename, but from the
     158     * look of things fsync(dir) should work.
     159     */
     160    int rc;
     161    int fd = open(pszPath, O_DIRECTORY | O_RDONLY, 0);
     162    if (fd >= 0)
     163    {
     164        if (fsync(fd) == 0)
     165            rc = VINF_SUCCESS;
     166        else
     167            rc = RTErrConvertFromErrno(errno);
     168        close(fd);
     169    }
     170    else
     171        rc = RTErrConvertFromErrno(errno);
    136172    return rc;
    137173}
  • trunk/src/VBox/Runtime/r3/win/dir-win.cpp

    r25292 r28688  
    128128
    129129
     130RTDECL(int) RTDirFlush(const char *pszPath)
     131{
     132    return VERR_NOT_SUPPORTED;
     133}
     134
     135
    130136int rtOpenDirNative(PRTDIR pDir, char *pszPathBuf)
    131137{
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