dir.cpp revision 69758b10eaf375c6a792694a3881bc17cd58a1a3
4346537134a6c1454fc906711dbe4e987ebe9f33vboxsync * IPRT - Directory Manipulation.
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
4346537134a6c1454fc906711dbe4e987ebe9f33vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
4346537134a6c1454fc906711dbe4e987ebe9f33vboxsync * available from http://www.virtualbox.org. This file is free software;
4346537134a6c1454fc906711dbe4e987ebe9f33vboxsync * you can redistribute it and/or modify it under the terms of the GNU
4346537134a6c1454fc906711dbe4e987ebe9f33vboxsync * General Public License (GPL) as published by the Free Software
4346537134a6c1454fc906711dbe4e987ebe9f33vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
4346537134a6c1454fc906711dbe4e987ebe9f33vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
4346537134a6c1454fc906711dbe4e987ebe9f33vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
4346537134a6c1454fc906711dbe4e987ebe9f33vboxsync * The contents of this file may alternatively be used under the terms
4346537134a6c1454fc906711dbe4e987ebe9f33vboxsync * of the Common Development and Distribution License Version 1.0
4346537134a6c1454fc906711dbe4e987ebe9f33vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
4346537134a6c1454fc906711dbe4e987ebe9f33vboxsync * VirtualBox OSE distribution, in which case the provisions of the
4346537134a6c1454fc906711dbe4e987ebe9f33vboxsync * CDDL are applicable instead of those of the GPL.
4346537134a6c1454fc906711dbe4e987ebe9f33vboxsync * You may elect to license modified versions of this file under the
4346537134a6c1454fc906711dbe4e987ebe9f33vboxsync * terms and conditions of either the GPL or the CDDL or both.
172ae196da38208e5f1e3485715a89f2d53c6880vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
aa4bcf0a4b2db3ac352b56a291d49cb8d4b66d32vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
172ae196da38208e5f1e3485715a89f2d53c6880vboxsync * additional information or have any questions.
aa4bcf0a4b2db3ac352b56a291d49cb8d4b66d32vboxsync/*******************************************************************************
172ae196da38208e5f1e3485715a89f2d53c6880vboxsync* Header Files *
172ae196da38208e5f1e3485715a89f2d53c6880vboxsync*******************************************************************************/
de6e321f351aa489a6a62bed474390a0056e8093vboxsync#ifdef RT_OS_WINDOWS /* PORTME: Assumes everyone else is using dir-posix.cpp */
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsyncstatic DECLCALLBACK(bool) rtDirFilterWinNtMatch(PRTDIR pDir, const char *pszName);
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsyncstatic DECLCALLBACK(bool) rtDirFilterWinNtMatchNoWildcards(PRTDIR pDir, const char *pszName);
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsyncDECLINLINE(bool) rtDirFilterWinNtMatchEon(PCRTUNICP puszFilter);
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsyncstatic bool rtDirFilterWinNtMatchDosStar(unsigned iDepth, RTUNICP uc, const char *pszNext, PCRTUNICP puszFilter);
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsyncstatic bool rtDirFilterWinNtMatchStar(unsigned iDepth, RTUNICP uc, const char *pszNext, PCRTUNICP puszFilter);
044af0d1e6474076366759db86f101778c5f20ccvboxsyncstatic bool rtDirFilterWinNtMatchBase(unsigned iDepth, const char *pszName, PCRTUNICP puszFilter);
044af0d1e6474076366759db86f101778c5f20ccvboxsyncRTDECL(int) RTDirCreateFullPath(const char *pszPath, RTFMODE fMode)
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync * Resolve the path.
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync int rc = RTPathAbs(pszPath, szAbsPath, sizeof(szAbsPath));
044af0d1e6474076366759db86f101778c5f20ccvboxsync * Iterate the path components making sure each of them exists.
044af0d1e6474076366759db86f101778c5f20ccvboxsync /* skip volume name */
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync char *psz = &szAbsPath[rtPathVolumeSpecLen(szAbsPath)];
044af0d1e6474076366759db86f101778c5f20ccvboxsync /* skip the root slash if any */
de6e321f351aa489a6a62bed474390a0056e8093vboxsync /* iterate over path components. */
044af0d1e6474076366759db86f101778c5f20ccvboxsync /* the next component is NULL, stop iterating */
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync * ASSUME that RTDirCreate will return VERR_ALREADY_EXISTS and not VERR_ACCESS_DENIED in those cases
de6e321f351aa489a6a62bed474390a0056e8093vboxsync * where the directory exists but we don't have write access to the parent directory.
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync * Filter a the filename in the against a filter.
044af0d1e6474076366759db86f101778c5f20ccvboxsync * @returns true if the name matches the filter.
044af0d1e6474076366759db86f101778c5f20ccvboxsync * @returns false if the name doesn't match filter.
044af0d1e6474076366759db86f101778c5f20ccvboxsync * @param pDir The directory handle.
044af0d1e6474076366759db86f101778c5f20ccvboxsync * @param pszName The path to match to the filter.
044af0d1e6474076366759db86f101778c5f20ccvboxsyncstatic DECLCALLBACK(bool) rtDirFilterWinNtMatchNoWildcards(PRTDIR pDir, const char *pszName)
de6e321f351aa489a6a62bed474390a0056e8093vboxsync * Walk the string and compare.
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync return false;
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync return true;
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync * Matches end of name.
044af0d1e6474076366759db86f101778c5f20ccvboxsyncDECLINLINE(bool) rtDirFilterWinNtMatchEon(PCRTUNICP puszFilter)
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync * Recursive star matching.
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync * Practically the same as normal star, except that the dos star stops
172ae196da38208e5f1e3485715a89f2d53c6880vboxsync * when hitting the last dot.
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync * @returns true on match.
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync * @returns false on miss.
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsyncstatic bool rtDirFilterWinNtMatchDosStar(unsigned iDepth, RTUNICP uc, const char *pszNext, PCRTUNICP puszFilter)
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync * If there is no dos star, we should work just like the NT star.
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync * Since that's generally faster algorithms, we jump down to there if we can.
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync return rtDirFilterWinNtMatchStar(iDepth, uc, pszNext, puszFilter);
044af0d1e6474076366759db86f101778c5f20ccvboxsync * Inspect the next filter char(s) until we find something to work on.
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync * The star expression is the last in the pattern.
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync * We're fine if the name ends with a dot.
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync * Simplified by brute force.
044af0d1e6474076366759db86f101778c5f20ccvboxsync if (rtDirFilterWinNtMatchBase(iDepth, pszNext, puszFilter))
044af0d1e6474076366759db86f101778c5f20ccvboxsync return true;
044af0d1e6474076366759db86f101778c5f20ccvboxsync int rc = RTStrGetCpEx(&pszNext, &uc); AssertRCReturn(rc, false);
044af0d1e6474076366759db86f101778c5f20ccvboxsync } while ((intptr_t)pszDosDot - (intptr_t)pszNext >= -1);
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync /* backtrack and do the current char. */
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync pszNext = RTStrPrevCp(NULL, pszStart); AssertReturn(pszNext, false);
df8e6a449f00e1884fbf4a1fc67143614d7d528dvboxsync return rtDirFilterWinNtMatchBase(iDepth, pszNext, puszFilter);
044af0d1e6474076366759db86f101778c5f20ccvboxsync * Ok, we've got zero or more characters.
044af0d1e6474076366759db86f101778c5f20ccvboxsync * We'll try match starting at each occurence of this character.
044af0d1e6474076366759db86f101778c5f20ccvboxsync && rtDirFilterWinNtMatchBase(iDepth, pszNext, puszFilter))
044af0d1e6474076366759db86f101778c5f20ccvboxsync return true;
044af0d1e6474076366759db86f101778c5f20ccvboxsync int rc = RTStrGetCpEx(&pszNext, &uc); AssertRCReturn(rc, false);
044af0d1e6474076366759db86f101778c5f20ccvboxsync && rtDirFilterWinNtMatchBase(iDepth, pszNext, puszFilter))
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync return true;
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync } while ((intptr_t)pszDosDot - (intptr_t)pszNext >= -1);
044af0d1e6474076366759db86f101778c5f20ccvboxsync return false;
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync /* won't ever get here! */
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync * Recursive star matching.
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync * @returns true on match.
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync * @returns false on miss.
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsyncstatic bool rtDirFilterWinNtMatchStar(unsigned iDepth, RTUNICP uc, const char *pszNext, PCRTUNICP puszFilter)
044af0d1e6474076366759db86f101778c5f20ccvboxsync * Inspect the next filter char(s) until we find something to work on.
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync * The star expression is the last in the pattern.
044af0d1e6474076366759db86f101778c5f20ccvboxsync * Cool, that means we're done!
044af0d1e6474076366759db86f101778c5f20ccvboxsync return true;
044af0d1e6474076366759db86f101778c5f20ccvboxsync * Just in case (doubt we ever get here), just merge it with the current one.
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync * Skip a fixed number of chars.
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync * Figure out how many by walking the filter ignoring '*'s.
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync while ((ucFilter = *puszFilter) == '*' || ucFilter == '?')
a1df400bbe9d64aad400442e56eb637019300a5evboxsync return false;
de6e321f351aa489a6a62bed474390a0056e8093vboxsync int rc = RTStrGetCpEx(&pszNext, &uc); AssertRCReturn(rc, false);
044af0d1e6474076366759db86f101778c5f20ccvboxsync } while (--cQms > 0);
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync /* done? */
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync return true;
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync * The simple way is to try char by char and match the remaining
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync * expression. If it's trailing we're done.
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync return true;
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync if (rtDirFilterWinNtMatchBase(iDepth, pszNext, puszFilter))
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync return true;
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync int rc = RTStrGetCpEx(&pszNext, &uc); AssertRCReturn(rc, false);
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync /* backtrack and do the current char. */
044af0d1e6474076366759db86f101778c5f20ccvboxsync pszNext = RTStrPrevCp(NULL, pszStart); AssertReturn(pszNext, false);
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync return rtDirFilterWinNtMatchBase(iDepth, pszNext, puszFilter);
de6e321f351aa489a6a62bed474390a0056e8093vboxsync * This bugger is interesting.
de6e321f351aa489a6a62bed474390a0056e8093vboxsync * Time for brute force. Iterate the name char by char.
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync if (rtDirFilterWinNtMatchDosStar(iDepth, uc, pszNext, puszFilter))
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync return true;
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync int rc = RTStrGetCpEx(&pszNext, &uc); AssertRCReturn(rc, false);
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync return false;
a1df400bbe9d64aad400442e56eb637019300a5evboxsync * This guy matches a '.' or the end of the name.
044af0d1e6474076366759db86f101778c5f20ccvboxsync * It's very simple if the rest of the filter expression also matches eon.
a1df400bbe9d64aad400442e56eb637019300a5evboxsync return true;
044af0d1e6474076366759db86f101778c5f20ccvboxsync /* fall thru */
044af0d1e6474076366759db86f101778c5f20ccvboxsync * Ok, we've got zero or more characters.
044af0d1e6474076366759db86f101778c5f20ccvboxsync * We'll try match starting at each occurence of this character.
044af0d1e6474076366759db86f101778c5f20ccvboxsync && rtDirFilterWinNtMatchBase(iDepth, pszNext, puszFilter))
a1df400bbe9d64aad400442e56eb637019300a5evboxsync return true;
172ae196da38208e5f1e3485715a89f2d53c6880vboxsync int rc = RTStrGetCpEx(&pszNext, &uc); AssertRCReturn(rc, false);
172ae196da38208e5f1e3485715a89f2d53c6880vboxsync return false;
044af0d1e6474076366759db86f101778c5f20ccvboxsync } /* for (;;) */
044af0d1e6474076366759db86f101778c5f20ccvboxsync /* won't ever get here! */
044af0d1e6474076366759db86f101778c5f20ccvboxsync * Filter a the filename in the against a filter.
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync * The rules are as follows:
044af0d1e6474076366759db86f101778c5f20ccvboxsync * '?' Matches exactly one char.
044af0d1e6474076366759db86f101778c5f20ccvboxsync * '*' Matches zero or more chars.
172ae196da38208e5f1e3485715a89f2d53c6880vboxsync * '<' The dos star, matches zero or more chars except the DOS dot.
044af0d1e6474076366759db86f101778c5f20ccvboxsync * '>' The dos question mark, matches one char, but dots and end-of-name eats them.
7af218a7441de38fc9e814919db04bae3e917664vboxsync * '"' The dos dot, matches a dot or end-of-name.
7af218a7441de38fc9e814919db04bae3e917664vboxsync * @returns true if the name matches the filter.
7af218a7441de38fc9e814919db04bae3e917664vboxsync * @returns false if the name doesn't match filter.
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync * @param iDepth The recursion depth.
7af218a7441de38fc9e814919db04bae3e917664vboxsync * @param pszName The path to match to the filter.
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync * @param puszFilter The filter string.
7af218a7441de38fc9e814919db04bae3e917664vboxsyncstatic bool rtDirFilterWinNtMatchBase(unsigned iDepth, const char *pszName, PCRTUNICP puszFilter)
7af218a7441de38fc9e814919db04bae3e917664vboxsync * Walk the string and match it up char by char.
7af218a7441de38fc9e814919db04bae3e917664vboxsync int rc = RTStrGetCpEx(&pszName, &uc); AssertRCReturn(rc, false);
044af0d1e6474076366759db86f101778c5f20ccvboxsync /* Exactly one char. */
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync return false;
7af218a7441de38fc9e814919db04bae3e917664vboxsync /* One char, but the dos dot and end-of-name eats '>' and '<'. */
044af0d1e6474076366759db86f101778c5f20ccvboxsync while ((ucFilter = *puszFilter) == '>' || ucFilter == '<')
044af0d1e6474076366759db86f101778c5f20ccvboxsync if (ucFilter == '"' || ucFilter == '.') /* not 100% sure about the last dot */
044af0d1e6474076366759db86f101778c5f20ccvboxsync else /* the does question mark doesn't match '.'s, so backtrack. */
044af0d1e6474076366759db86f101778c5f20ccvboxsync /* Match a dot or the end-of-name. */
044af0d1e6474076366759db86f101778c5f20ccvboxsync return false;
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync /* zero or more */
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync return rtDirFilterWinNtMatchStar(iDepth, uc, pszName, puszFilter);
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync return rtDirFilterWinNtMatchDosStar(iDepth, uc, pszName, puszFilter);
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync /* uppercased match */
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync return false;
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync return true;
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync * Filter a the filename in the against a filter.
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync * @returns true if the name matches the filter.
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync * @returns false if the name doesn't match filter.
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync * @param pDir The directory handle.
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync * @param pszName The path to match to the filter.
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsyncstatic DECLCALLBACK(bool) rtDirFilterWinNtMatch(PRTDIR pDir, const char *pszName)
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync return rtDirFilterWinNtMatchBase(0, pszName, pDir->puszFilter);
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync * Initializes a WinNt like wildcard filter.
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync * @returns Pointer to the filter function.
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync * @returns NULL if the filter doesn't filter out anything.
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync * @param pDir The directory handle (not yet opened).
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsyncstatic PFNRTDIRFILTER rtDirFilterWinNtInit(PRTDIR pDir)
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync * Check for the usual * and <"< (*.* in DOS language) patterns.
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync if ( (pDir->cchFilter == 1 && pDir->pszFilter[0] == '*')
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync || (pDir->cchFilter == 3 && !memcmp(pDir->pszFilter, "<\".>", 3))
9e47fe1a0782e9d50791ff47b79ca81c52855774vboxsync * Uppercase the expression, also do a little optimizations when possible.
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync unsigned iRead = 0;
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync unsigned iWrite = 0;
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync /* remove extra stars. */
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync else if (uc == '?' || uc == '>' || uc == '<' || uc == '"')
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync * Common worker for opening a directory.
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync * @returns IPRT status code.
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync * @param ppDir Where to store the directory handle.
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync * @param pszPath The specified path.
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync * @param pszFilter Pointer to where the filter start in the path. NULL if no filter.
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync * @param enmFilter The type of filter to apply.
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsyncstatic int rtDirOpenCommon(PRTDIR *ppDir, const char *pszPath, const char *pszFilter, RTDIRFILTER enmFilter)
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync * Expand the path.
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync * The purpose of this exercise to have the abs path around
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync * for querying extra information about the objects we list.
88acfa6629a7976c0583c1712d2b5b22a87a5121vboxsync * As a sideeffect we also validate the path here.
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync size_t cbFilter; /* includes '\0' (thus cb and not cch). */
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync rc = RTPathReal(pszPath, szRealPath, sizeof(szRealPath) - 1);
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync /* yea, I'm lazy. sue me. */
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync rc = RTPathReal(pszTmp, szRealPath, sizeof(szRealPath) - 1);
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync rc = RTPathReal(".", szRealPath, sizeof(szRealPath) - 1);
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync /* add trailing '/' if missing. */
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync * Allocate and initialize the directory handle.
9e47fe1a0782e9d50791ff47b79ca81c52855774vboxsync * The posix definition of Data.d_name allows it to be < NAME_MAX + 1,
9e47fe1a0782e9d50791ff47b79ca81c52855774vboxsync * thus the horrible uglyness here. Solaris uses d_name[1] for instance.
9e47fe1a0782e9d50791ff47b79ca81c52855774vboxsync long cbNameMax = pathconf(szRealPath, _PC_NAME_MAX);
9e47fe1a0782e9d50791ff47b79ca81c52855774vboxsync if (cbNameMax < NAME_MAX) /* This is plain paranoia, but it doesn't hurt. */
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync size_t cbDir = RT_OFFSETOF(RTDIR, Data.d_name[cbNameMax + 1]);
7af218a7441de38fc9e814919db04bae3e917664vboxsync /* initialize it */
172ae196da38208e5f1e3485715a89f2d53c6880vboxsync rc = RTStrToUniEx(pszFilter, RTSTR_MAX, &pDir->puszFilter, cucFilter0, &pDir->cucFilter);
de6e321f351aa489a6a62bed474390a0056e8093vboxsync pDir->pszFilter = (char *)memcpy(pb, pszFilter, cbFilter);
de6e321f351aa489a6a62bed474390a0056e8093vboxsync pDir->pszPath = (char *)memcpy(pb, szRealPath, cchRealPath + 1);
de6e321f351aa489a6a62bed474390a0056e8093vboxsync Assert(pb - (uint8_t *)pDir + cchRealPath + 1 <= cbAllocated);
172ae196da38208e5f1e3485715a89f2d53c6880vboxsync pDir->cbMaxName = cbDir - RT_OFFSETOF(RTDIR, Data.d_name);
4e47bb772df0d04d1ded3e06354de547d52e2d06vboxsync * Hand it over to the native part.
172ae196da38208e5f1e3485715a89f2d53c6880vboxsyncRTDECL(int) RTDirOpen(PRTDIR *ppDir, const char *pszPath)
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync * Validate input.
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync AssertMsgReturn(VALID_PTR(ppDir), ("%p\n", ppDir), VERR_INVALID_POINTER);
2bb12e589d2c280ad042e4e70635ae7224c7eceevboxsync AssertMsgReturn(VALID_PTR(pszPath), ("%p\n", pszPath), VERR_INVALID_POINTER);
172ae196da38208e5f1e3485715a89f2d53c6880vboxsync * Take common cause with RTDirOpenFiltered().
044af0d1e6474076366759db86f101778c5f20ccvboxsync int rc = rtDirOpenCommon(ppDir, pszPath, NULL, RTDIRFILTER_NONE);
172ae196da38208e5f1e3485715a89f2d53c6880vboxsync LogFlow(("RTDirOpen(%p:{%p}, %p:{%s}): return %Rrc\n", ppDir, *ppDir, pszPath, pszPath, rc));
044af0d1e6474076366759db86f101778c5f20ccvboxsyncRTDECL(int) RTDirOpenFiltered(PRTDIR *ppDir, const char *pszPath, RTDIRFILTER enmFilter)
172ae196da38208e5f1e3485715a89f2d53c6880vboxsync * Validate input.
172ae196da38208e5f1e3485715a89f2d53c6880vboxsync AssertMsgReturn(VALID_PTR(ppDir), ("%p\n", ppDir), VERR_INVALID_POINTER);
de6e321f351aa489a6a62bed474390a0056e8093vboxsync AssertMsgReturn(VALID_PTR(pszPath), ("%p\n", pszPath), VERR_INVALID_POINTER);
de6e321f351aa489a6a62bed474390a0056e8093vboxsync AssertMsgFailed(("%d is not implemented!\n", enmFilter));
de6e321f351aa489a6a62bed474390a0056e8093vboxsync AssertMsgFailedReturn(("%d\n", enmFilter), VERR_INVALID_PARAMETER);
de6e321f351aa489a6a62bed474390a0056e8093vboxsync * Find the last component, i.e. where the filter criteria starts and the dir name ends.
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync const char *pszFilter = enmFilter != RTDIRFILTER_NONE
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync * Call worker common with RTDirOpen which will verify the path, allocate
044af0d1e6474076366759db86f101778c5f20ccvboxsync * and initialize the handle, and finally call the backend.
de6e321f351aa489a6a62bed474390a0056e8093vboxsync int rc = rtDirOpenCommon(ppDir, pszPath, pszFilter, enmFilter);
de6e321f351aa489a6a62bed474390a0056e8093vboxsync LogFlow(("RTDirOpenFiltered(%p:{%p}, %p:{%s}, %d): return %Rrc\n",
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsyncRTDECL(int) RTDirRemoveRecursive(const char *pszPath)
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync /** @todo use RTPathReal here instead? */
c0e27f622f9bd6d9e77d2d959aab71d69dabf0d3vboxsync rc = RTPathAbs(pszPath, szAbsPath, sizeof(szAbsPath));
while ((rc = RTDirRead(pDir, &dirEntry, NULL /* Passing an argument won't work here yet. */)) == VINF_SUCCESS)
case RTDIRENTRYTYPE_FILE:
case RTDIRENTRYTYPE_DIRECTORY:
return rc;