VirtualBox

Changeset 2967 in kBuild


Ignore:
Timestamp:
Sep 26, 2016 6:14:13 PM (8 years ago)
Author:
bird
Message:

kFsCache: Implemented object names changing to a longer ones.

Location:
trunk/src/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/msc_buffered_printf.c

    r2910 r2967  
    4747#pragma warning(disable: 4273) /* inconsistent dll linkage*/
    4848
     49#ifndef KWORKER
     50# define DLL_IMPORT __declspec(dllexport)
     51#else
     52# define DLL_IMPORT
     53#endif
     54
    4955extern size_t maybe_con_fwrite(void const *pvBuf, size_t cbUnit, size_t cUnits, FILE *pFile);
    5056
     
    5763 * @param   ...                 Format arguments.
    5864 */
    59 __declspec(dllexport)
     65DLL_IMPORT
    6066int __cdecl printf(const char *pszFormat, ...)
    6167{
     
    7682 * @param   va                  Format arguments.
    7783 */
    78 __declspec(dllexport)
     84DLL_IMPORT
    7985int __cdecl vprintf(const char *pszFormat, va_list va)
    8086{
     
    114120 * @param   va                  Format arguments.
    115121 */
    116 __declspec(dllexport)
     122DLL_IMPORT
    117123int __cdecl fprintf(FILE *pFile, const char *pszFormat, ...)
    118124{
     
    160166 * @param   pszString           The string to write. (newline is appended)
    161167 */
    162 __declspec(dllexport)
     168DLL_IMPORT
    163169int __cdecl puts(const char *pszString)
    164170{
     
    235241 * @param   pFile               The output file.
    236242 */
    237 __declspec(dllexport)
     243DLL_IMPORT
    238244int __cdecl fputs(const char *pszString, FILE *pFile)
    239245{
  • trunk/src/lib/nt/kFsCache.c

    r2948 r2967  
    597597        pObj->uNameHash     = 0;
    598598        pObj->pNextNameHash = NULL;
     599        pObj->pNameAlloc    = NULL;
    599600        pObj->pUserDataHead = NULL;
    600601
     
    804805}
    805806
     807
     808/**
     809 * Does the growing of names.
     810 *
     811 * @returns pCur
     812 * @param   pCache          The cache.
     813 * @param   pCur            The object.
     814 * @param   pchName         The name (not necessarily terminated).
     815 * @param   cchName         Name length.
     816 * @param   pwcName         The UTF-16 name (not necessarily terminated).
     817 * @param   cwcName         The length of the UTF-16 name in wchar_t's.
     818 * @param   pchShortName    The short name.
     819 * @param   cchShortName    The length of the short name.  This is 0 if no short
     820 *                          name.
     821 * @param   pwcShortName    The short UTF-16 name.
     822 * @param   cwcShortName    The length of the short UTF-16 name.  This is 0 if
     823 *                          no short name.
     824 */
     825static PKFSOBJ kFsCacheRefreshGrowNames(PKFSCACHE pCache, PKFSOBJ pCur,
     826                                        const char *pchName, KU32 cchName,
     827                                        wchar_t const *pwcName, KU32 cwcName
     828#ifdef KFSCACHE_CFG_SHORT_NAMES
     829                                        , const char *pchShortName, KU32 cchShortName,
     830                                        wchar_t const *pwcShortName, KU32 cwcShortName
     831#endif
     832                                        )
     833{
     834    PKFSOBJNAMEALLOC    pNameAlloc;
     835    char               *pch;
     836    KU32                cbNeeded;
     837
     838    pCache->cNameGrowths++;
     839
     840    /*
     841     * Figure out our requirements.
     842     */
     843    cbNeeded = sizeof(KU32) + cchName + 1;
     844#ifdef KFSCACHE_CFG_UTF16
     845    cbNeeded += (cwcName + 1) * sizeof(wchar_t);
     846#endif
     847#ifdef KFSCACHE_CFG_SHORT_NAMES
     848    cbNeeded += cchShortName + !!cchShortName;
     849# ifdef KFSCACHE_CFG_UTF16
     850    cbNeeded += (cwcShortName + !!cwcShortName) * sizeof(wchar_t);
     851# endif
     852#endif
     853    cbNeeded = K_ALIGN_Z(cbNeeded, 8); /* Memory will likely be 8 or 16 byte aligned, so we might just claim it. */
     854
     855    /*
     856     * Allocate memory.
     857     */
     858    pNameAlloc = pCur->pNameAlloc;
     859    if (!pNameAlloc)
     860    {
     861        pNameAlloc = (PKFSOBJNAMEALLOC)kHlpAlloc(cbNeeded);
     862        if (!pNameAlloc)
     863            return pCur;
     864        pCache->cbObjects += cbNeeded;
     865        pCur->pNameAlloc = pNameAlloc;
     866        pNameAlloc->cb = cbNeeded;
     867    }
     868    else if (pNameAlloc->cb < cbNeeded)
     869    {
     870        pNameAlloc = (PKFSOBJNAMEALLOC)kHlpRealloc(pNameAlloc, cbNeeded);
     871        if (!pNameAlloc)
     872            return pCur;
     873        pCache->cbObjects += cbNeeded - pNameAlloc->cb;
     874        pCur->pNameAlloc = pNameAlloc;
     875        pNameAlloc->cb = cbNeeded;
     876    }
     877
     878    /*
     879     * Copy out the new names, starting with the wide char ones to avoid misaligning them.
     880     */
     881    pch = &pNameAlloc->abSpace[0];
     882
     883#ifdef KFSCACHE_CFG_UTF16
     884    pCur->pwszName = (wchar_t *)pch;
     885    pCur->cwcName  = cwcName;
     886    pch = kHlpMemPCopy(pch, pwcName, cwcName * sizeof(wchar_t));
     887    *pch++ = '\0';
     888    *pch++ = '\0';
     889
     890# ifdef KFSCACHE_CFG_SHORT_NAMES
     891    if (cwcShortName == 0)
     892    {
     893        pCur->pwszShortName = pCur->pwszName;
     894        pCur->cwcShortName  = pCur->cwcName;
     895    }
     896    else
     897    {
     898        pCur->pwszShortName = (wchar_t *)pch;
     899        pCur->cwcShortName  = cwcShortName;
     900        pch = kHlpMemPCopy(pch, pwcShortName, cwcShortName * sizeof(wchar_t));
     901        *pch++ = '\0';
     902        *pch++ = '\0';
     903    }
     904# endif
     905#endif
     906
     907    pCur->pszName = pch;
     908    pCur->cchName = cchName;
     909    pch = kHlpMemPCopy(pch, pchName, cchShortName);
     910    *pch++ = '\0';
     911
     912#ifdef KFSCACHE_CFG_SHORT_NAMES
     913    if (cchShortName == 0)
     914    {
     915        pCur->pszShortName = pCur->pszName;
     916        pCur->cchShortName = pCur->cchName;
     917    }
     918    else
     919    {
     920        pCur->pszShortName = pch;
     921        pCur->cchShortName = cchShortName;
     922        pch = kHlpMemPCopy(pch, pchShortName, cchShortName);
     923        *pch++ = '\0';
     924    }
     925#endif
     926
     927    return pCur;
     928}
     929
     930
    806931/**
    807932 * Worker for kFsCacheDirFindOldChild that refreshes the file ID value on an
    808933 * object found by name.
    809934 *
    810  * @returns Pointer to the existing object if found, NULL if not.
     935 * @returns pCur.
    811936 * @param   pDirRePop       Repopulation data.
    812937 * @param   pCur            The object to check the names of.
     
    828953 * has been found the file ID.
    829954 *
    830  * @returns Pointer to the existing object if found, NULL if not.
     955 * @returns pCur.
    831956 * @param   pDirRePop       Repopulation data.
    832957 * @param   pCur            The object to check the names of.
     
    842967                                              )
    843968{
     969    char szName[KFSCACHE_CFG_MAX_ANSI_NAME];
     970    int  cchName;
     971
     972    pDirRePop->pCache->cNameChanges++;
     973
    844974    /*
    845975     * Convert the names to ANSI first, that way we know all the lengths.
    846976     */
    847     char szName[KFSCACHE_CFG_MAX_ANSI_NAME];
    848     int  cchName = WideCharToMultiByte(CP_ACP, 0, pwcName, cwcName, szName, sizeof(szName) - 1, NULL, NULL);
     977    cchName = WideCharToMultiByte(CP_ACP, 0, pwcName, cwcName, szName, sizeof(szName) - 1, NULL, NULL);
    849978    if (cchName >= 0)
    850979    {
     
    9161045                }
    9171046            }
    918         }
    919     }
    920 
    921 
    922     fprintf(stderr,
    923             "kFsCacheDirRefreshOldChildName - not implemented!\n"
    924             "  Old name:  %#x '%ls'\n"
    925             "  New name:  %#x '%*.*ls'\n"
    926             "  Old short: %#x '%ls'\n"
    927             "  New short: %#x '%*.*ls'\n",
    928             pCur->cwcName, pCur->pwszName,
    929             cwcName, cwcName, cwcName, pwcName,
    930             pCur->cwcShortName, pCur->pwszShortName,
    931             cwcShortName, cwcShortName, cwcShortName, pwcShortName);
    932     __debugbreak();
    933     /** @todo implement this.  It's not entirely straight forward, especially if
    934      *        the name increases!  Also, it's something that may happend during
    935      *        individual object refresh and we might want to share code... */
    936 
     1047
     1048            return kFsCacheRefreshGrowNames(pDirRePop->pCache, pCur, szName, cchName, pwcName, cwcName,
     1049#ifdef KFSCACHE_CFG_SHORT_NAMES
     1050                                            szShortName, cchShortName, pwcShortName, cwcShortName
     1051#endif
     1052                                            );
     1053        }
     1054    }
     1055
     1056    fprintf(stderr, "kFsCacheDirRefreshOldChildName: WideCharToMultiByte error\n");
    9371057    return pCur;
    9381058}
     
    9411061/**
    9421062 * Worker for kFsCacheDirFindOldChild that checks the names after an old object
    943  * has been found the file ID.
    944  *
    945  * @returns Pointer to the existing object if found, NULL if not.
     1063 * has been found by the file ID.
     1064 *
     1065 * @returns pCur.
    9461066 * @param   pDirRePop       Repopulation data.
    9471067 * @param   pCur            The object to check the names of.
     
    37673887    pCache->cObjects--;
    37683888
     3889    if (pObj->pNameAlloc)
     3890    {
     3891        pCache->cbObjects -= pObj->pNameAlloc->cb;
     3892        kHlpFree(pObj->pNameAlloc);
     3893    }
     3894
    37693895    kHlpFree(pObj);
    37703896    return 0;
     
    44374563            pCache->cChildHashEntriesTotal  = pCache->RootDir.fHashTabMask + 1;
    44384564            pCache->cChildHashCollisions    = 0;
     4565            pCache->cNameChanges            = 0;
     4566            pCache->cNameGrowths            = 0;
    44394567            pCache->cAnsiPaths              = 0;
    44404568            pCache->cAnsiPathCollisions     = 0;
  • trunk/src/lib/nt/kFsCache.h

    r2945 r2967  
    130130
    131131/**
     132 * Storage for name strings for the unlikely event that they should grow in
     133 * length after the KFSOBJ was created.
     134 */
     135typedef struct KFSOBJNAMEALLOC
     136{
     137    /** Size of the allocation. */
     138    KU32        cb;
     139    /** The space for names. */
     140    char        abSpace[1];
     141} KFSOBJNAMEALLOC;
     142/** Name growth allocation. */
     143typedef KFSOBJNAMEALLOC *PKFSOBJNAMEALLOC;
     144
     145
     146/**
    132147 * Base cache node.
    133148 */
     
    201216# endif
    202217#endif
     218
     219    /** Allocation for handling name length increases. */
     220    PKFSOBJNAMEALLOC    pNameAlloc;
    203221
    204222    /** Pointer to the first user data item */
     
    411429    /** Number of children inserted into the hash tables. */
    412430    KSIZE               cChildHashed;
    413     /** Number of collisions in the child hash tables */
     431    /** Number of collisions in the child hash tables. */
    414432    KSIZE               cChildHashCollisions;
     433    /** Number times a object name changed. */
     434    KSIZE               cNameChanges;
     435    /** Number times a object name grew and needed KFSOBJNAMEALLOC.
     436     *  (Subset of cNameChanges) */
     437    KSIZE               cNameGrowths;
    415438
    416439    /** The root directory. */
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