Ignore:
Timestamp:
Dec 30, 2016, 9:42:50 AM (9 years ago)
Author:
Paul Smedley
Message:

client-3.0: revert mistaken commit of dircache.c, add cache support to list_files_smb2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/client-3.0/src/dircache.c

    r1002 r1003  
    1 /*
    2    Directory caching code for Netdrive plugins.
    3    Copyright (C) netlabs.org 2010-2016
    4 */
    5 
    61#include <stdio.h>
    72#include <stdlib.h>
     
    105#include <time.h>
    116
    12 #include "dircache.h"
    13 
    14 PLUGINHELPERTABLE2L *ph;
     7#define NDPL_LARGEFILES
     8#define INCL_LONGLONG
     9#include <ndextpl2.h>
     10
     11#include "smbwrp.h"
     12
     13extern PLUGINHELPERTABLE2L *ph;
    1514
    1615/*
    17  * An entry holds file name and a pointer to custom data
     16 * Static helpers.
    1817 */
    19 typedef struct DirectoryCacheEntryData
    20 {
    21     const char  fname[PATH_MAX];
    22     const void* customData;
    23 } DirectoryCacheEntryData;
     18static int lockCreate (NDMUTEX *pMutex)
     19{
     20    return ph->fsphCreateMutex (pMutex);
     21}
     22       
     23static void lockDelete (NDMUTEX mutex)
     24{
     25    ph->fsphCloseMutex (mutex);
     26}
     27       
     28static int lockRequest (NDMUTEX mutex)
     29{
     30    return ph->fsphRequestMutex (mutex, 10000);
     31}
     32
     33void lockRelease (NDMUTEX mutex)
     34{
     35    ph->fsphReleaseMutex (mutex);
     36}
     37
     38static ULONG Hash (const char *pData, ULONG ulLen)
     39{
     40    ULONG hash = 0ul, g;
     41    static ULONG ulHashModule = 30031ul;
     42   
     43    const char *p;
     44    int i;
     45    for( p = pData, i = 0; i < ulLen; i++, p++ )
     46    {
     47        hash = ( hash << 4 ) + (*p);
     48        g = hash & 0xf0000000ul;
     49        if ( g )
     50        {
     51            hash ^= ( g >> 24 );
     52            hash ^= g;
     53        }
     54    }
     55    return ( hash % ulHashModule );
     56}
     57
     58static unsigned long timesec (void)
     59{
     60    ULONG ul = 0;
     61    DosQuerySysInfo (QSV_TIME_LOW, QSV_TIME_LOW, &ul, sizeof (ul));
     62    return ul;
     63}
     64
     65static unsigned long computehash (const char *s)
     66{
     67    return s? Hash ((char *)s, strlen (s)): 0;
     68}
     69
     70
    2471
    2572/*
     
    3178    struct DirectoryCacheEntry *pPrev;
    3279
    33     DirectoryCacheEntryData *aInfos;
     80    struct DirectoryCache *pdc;
     81   
     82    smbwrp_fileinfo *aInfos;
    3483    int cInfos;
    3584    int cInfosAllocated;
     
    4897    DirectoryCacheEntry *pEntriesTail;
    4998    int cEntries;
     99
    50100    int fEnabled;
    51101    unsigned long ulExpirationTime;
    52102    int cMaxEntries;
    53     // resource handle, used only for per-share logging
    54     void* resource;
    55     // callback called to release data structures
    56     PFNFREEDIRENTRY release;
    57 
    58103} DirectoryCache;
    59104
     
    62107    CacheOk = 1
    63108};
    64 
    65 /*
    66  * Static helpers.
    67  */
    68 static int lockCreate (NDMUTEX *pMutex)
    69 {
    70     return ph->fsphCreateMutex (pMutex);
    71 }
    72        
    73 static void lockDelete (NDMUTEX mutex)
    74 {
    75     ph->fsphCloseMutex (mutex);
    76 }
    77        
    78 static int lockRequest (NDMUTEX mutex)
    79 {
    80     return ph->fsphRequestMutex (mutex, 10000);
    81 }
    82 
    83 void lockRelease (NDMUTEX mutex)
    84 {
    85     ph->fsphReleaseMutex (mutex);
    86 }
    87 
    88 static ULONG Hash (const char *pData, ULONG ulLen)
    89 {
    90     ULONG hash = 0ul, g;
    91     static ULONG ulHashModule = 30031ul;
    92    
    93     const char *p;
    94     int i;
    95     for( p = pData, i = 0; i < ulLen; i++, p++ )
    96     {
    97         hash = ( hash << 4 ) + (*p);
    98         g = hash & 0xf0000000ul;
    99         if ( g )
    100         {
    101             hash ^= ( g >> 24 );
    102             hash ^= g;
    103         }
    104     }
    105     return ( hash % ulHashModule );
    106 }
    107 
    108 static unsigned long timesec (void)
    109 {
    110     ULONG ul = 0;
    111     DosQuerySysInfo (QSV_TIME_LOW, QSV_TIME_LOW, &ul, sizeof (ul));
    112     return ul;
    113 }
    114 
    115 static unsigned long computehash (const char *s)
    116 {
    117     return s? Hash ((char *)s, strlen (s)): 0;
    118 }
    119 
    120 static int dceCreate (DirectoryCacheEntry **ppdce, DirectoryCache* pdc, const char *path, int cFiles)
     109       
     110
     111static int dceCreate (DirectoryCacheEntry **ppdce, DirectoryCache *pdc, const char *path, int cFiles)
    121112{
    122113    DirectoryCacheEntry *pdce = (DirectoryCacheEntry *)malloc(sizeof(DirectoryCacheEntry));
     
    127118    }
    128119
    129     pdce->aInfos = (DirectoryCacheEntryData *)
    130             malloc(cFiles * sizeof (DirectoryCacheEntryData));
     120    pdce->aInfos = (smbwrp_fileinfo *)malloc(cFiles * sizeof (smbwrp_fileinfo));
    131121    if (!pdce->aInfos)
    132122    {
     
    138128    pdce->ulHash = computehash (path);
    139129    pdce->ulLastUpdateTime = 0;
     130    pdce->pdc = pdc;
    140131    pdce->fInvalid = 0;
    141132
     
    152143}
    153144
    154 static void dceDelete (DirectoryCache *pdc, DirectoryCacheEntry *pdce)
    155 {
    156     int i;
    157 
    158     debuglocal(pdc->resource, 9, "dceDelete: pdc %p, pdce %p\n", pdc, pdce);
    159 
    160     /* use plugin callback to deallocate memory stored into aInfos */
    161     if (pdc->release)
    162        for (i = 0; i < pdce->cInfos; i++)
    163        {
    164           debuglocal(pdc->resource, 9, "dceDelete: #%d->%s->%p\n",
    165                      i, pdce->aInfos[i].fname, pdce->aInfos[i].customData);
    166           pdc->release( (void*)pdce->aInfos[i].customData);
    167        }
    168 
    169     /* now free dce local data */
     145static void dceDelete (DirectoryCacheEntry *pdce)
     146{
    170147    free(pdce->aInfos);
    171148    free(pdce->pszPath);
     
    178155}
    179156
    180 static void dceWriteEntry (DirectoryCache *pdc, DirectoryCacheEntry *pdce,
    181                            const char *fname, const void *finfo)
     157static void dceWriteEntry (DirectoryCacheEntry *pdce, const smbwrp_fileinfo *finfo)
    182158{
    183159    if (pdce->cInfos >= pdce->cInfosAllocated)
     
    186162        int cNewAllocated = pdce->cInfosAllocated + pdce->cInfosAllocated / 2 + 1;
    187163
    188         DirectoryCacheEntryData *pNewInfos = (DirectoryCacheEntryData *)
    189                 realloc(pdce->aInfos, cNewAllocated *
    190                         sizeof (DirectoryCacheEntryData));
    191 
    192         debuglocal(pdc->resource, 9, "dceWriteEntry: [%s] realloc %d -> %d\n", pdce->pszPath, pdce->cInfosAllocated, cNewAllocated);
     164        smbwrp_fileinfo *pNewInfos = (smbwrp_fileinfo *)realloc(pdce->aInfos,
     165                                                                cNewAllocated * sizeof (smbwrp_fileinfo));
     166
     167        debuglocal(9, "dceWriteEntry: [%s] realloc %d -> %d\n", pdce->pszPath, pdce->cInfosAllocated, cNewAllocated);
    193168        if (pNewInfos)
    194169        {
     
    204179    }
    205180
    206     // store entry name and custom data
    207     strcpy( (char*)pdce->aInfos[pdce->cInfos].fname, fname);
    208     pdce->aInfos[pdce->cInfos].customData = finfo;
     181    pdce->aInfos[pdce->cInfos] = *finfo;
    209182    pdce->cInfos++;
    210183}
    211184
    212 static void dceAdjust (DirectoryCache *pdc, DirectoryCacheEntry *pdce)
     185static void dceAdjust (DirectoryCacheEntry *pdce)
    213186{
    214187    /* If the entry has too many preallocated info structures, adjust the memory allocation */
     
    220193        int cNewAllocated = pdce->cInfos + cFree / 2;
    221194
    222         DirectoryCacheEntryData *pNewInfos = (DirectoryCacheEntryData *)
    223                 realloc(pdce->aInfos,
    224                         cNewAllocated * sizeof (DirectoryCacheEntryData));
    225 
    226         debuglocal(pdc->resource, 9, "dceAdjust: [%s] realloc %d -> %d\n", pdce->pszPath, pdce->cInfosAllocated, cNewAllocated);
     195        smbwrp_fileinfo *pNewInfos = (smbwrp_fileinfo *)realloc(pdce->aInfos,
     196                                                                cNewAllocated * sizeof (smbwrp_fileinfo));
     197
     198        debuglocal(9, "dceAdjust: [%s] realloc %d -> %d\n", pdce->pszPath, pdce->cInfosAllocated, cNewAllocated);
    227199        if (pNewInfos)
    228200        {
     
    237209}
    238210
    239 static int dcePathEqualsTo (DirectoryCache *pdc, DirectoryCacheEntry *pdce, const char *path)
    240 {
    241     debuglocal(pdc->resource, 9, "dcePathEqualTo: [%s] [%s]\n", path, pdce->pszPath);
     211static int dcePathEqualsTo (DirectoryCacheEntry *pdce, const char *path)
     212{
     213    debuglocal(9, "dcePathEqualTo: [%s] [%s]\n", path, pdce->pszPath);
    242214    return ph->fsphStrICmp (path, pdce->pszPath) == 0;
    243215}
     
    253225}
    254226               
    255 static struct DirectoryCacheEntry *dcFindDirCache (DirectoryCache *pdc, const char *path, int fPrefix)
     227static struct DirectoryCacheEntry *dcFindDirCache (struct DirectoryCache *pdc, const char *path, int fPrefix)
    256228{
    257229    unsigned long hash = computehash (path);
     
    259231    DirectoryCacheEntry *iter = pdc->pEntriesHead;
    260232
    261     debuglocal(pdc->resource, 9, "dcFindDirCache: [%s]\n", path);
    262     debuglocal(pdc->resource, 9, "dcFindDirCache: iter [%p]\n", iter);
     233    debuglocal(9, "findDirCache: [%s]\n", path);
    263234
    264235    while (iter != NULL)
    265236    {
    266         debuglocal(pdc->resource, 9, "dcFindDirCache: entry [%s]\n", iter->pszPath);
     237        debuglocal(9, "findDirCache: entry [%s]\n", iter->pszPath);
    267238        if (fPrefix)
    268239        {
     
    275246        {
    276247            if (    iter->ulHash == hash
    277                  && dcePathEqualsTo (pdc, iter, path)
     248                 && dcePathEqualsTo (iter, path)
    278249               )
    279250            {
     
    284255    }
    285256
    286     debuglocal(pdc->resource, 9, "dcFindDirCache: %p\n", iter);
     257    debuglocal(9, "findDirCache: %p\n", iter);
    287258
    288259    return iter;
    289260}
    290261
    291 static int dcCreate (struct DirectoryCache **ppdc, void* pRes)
     262static int dcCreate (struct DirectoryCache **ppdc)
    292263{
    293264    int rc;
    294265
    295266    DirectoryCache *pdc = (DirectoryCache *)malloc(sizeof (DirectoryCache));
     267   
    296268    if (!pdc)
    297269    {
     
    300272
    301273    rc = lockCreate (&pdc->mutex);
     274
    302275    if (rc != NO_ERROR)
    303276    {
     
    312285    pdc->fEnabled = 0;
    313286    pdc->ulExpirationTime = -1;
    314     pdc->resource = pRes;
    315287   
    316288    *ppdc = pdc;
     
    322294{
    323295    DirectoryCacheEntry *iter = pdc->pEntriesHead;
    324     debuglocal(pdc->resource, 9, "dcDelete: pdc %p, iter %p\n", pdc, iter);
    325296
    326297    while (iter != NULL)
     
    328299        DirectoryCacheEntry *next = iter->pNext;
    329300
    330         dceDelete (pdc, iter);
     301        dceDelete (iter);
    331302       
    332303        iter = next;
     
    337308}
    338309
    339 static void dcRemoveEntry (DirectoryCache *pdc, DirectoryCacheEntry *pdce)
    340 {
     310static void dcRemoveEntry (DirectoryCacheEntry *pdce)
     311{
     312    DirectoryCache *pdc = pdce->pdc;
     313
    341314    if (pdce->pNext)
    342315    {
     
    356329        pdc->pEntriesHead = pdce->pNext;
    357330    }
    358    
     331
    359332    pdce->pNext = NULL;
    360333    pdce->pPrev = NULL;
    361 
     334   
    362335    pdc->cEntries--;
    363336}
    364337
    365 static void dcInsertEntry (DirectoryCache *pdc, DirectoryCacheEntry *pdce)
    366 {
     338static void dcInsertEntry (DirectoryCacheEntry *pdce)
     339{
     340    DirectoryCache *pdc = pdce->pdc;
     341
    367342    pdce->pNext = pdc->pEntriesHead;
    368343
     
    399374        }
    400375       
    401         debuglocal(pdc->resource, 9, "ExistsInCache: [%s], %d\n", path, rc);
     376        debuglocal(9, "ExistsInCache: [%s], %d\n", path, rc);
    402377    }
    403378   
     
    407382static int dcRead (DirectoryCache *pdc, const char *path,
    408383                   PFNADDDIRENTRY fn,
    409                    void* plist,
     384                   filelist_state *state,
    410385                   int *ptotal_received, int fForceCache)
    411386{
    412387    int i;
     388   
    413389    int rc = CacheFault;
    414 
     390       
    415391    if (pdc->fEnabled)
    416392    {
     
    421397        if (pdce)
    422398        {
    423             debuglocal(pdc->resource, 9, "dcRead: entry %p found for [%s]\n", pdce, path);
     399            debuglocal(9, "CacheRead: entry %p found for [%s]\n", pdce, path);
    424400           
    425401            if (fForceCache)
     
    427403                for (i = 0; i < pdce->cInfos; i++)
    428404                {
    429                     fn (plist, (void*)pdce->aInfos[i].customData);
     405                    fn ("", &pdce->aInfos[i], path, state);
    430406                }
    431407
     
    436412                if (dceExpired (pdce, pdc->ulExpirationTime))
    437413                {
    438                     debuglocal(pdc->resource, 9, "dcRead: expired\n");
    439                     dcRemoveEntry (pdc, pdce);
    440                     dceDelete (pdc, pdce);
     414                    debuglocal(9, "CacheRead: expired\n");
     415                    dcRemoveEntry (pdce);
     416                    dceDelete (pdce);
    441417                }
    442418                else
    443419                {
    444                     debuglocal(pdc->resource, 9, "dcRead: adding %d entries from cache\n", pdce->cInfos);
    445420                    for (i = 0; i < pdce->cInfos; i++)
    446421                    {
    447                         debuglocal(pdc->resource, 9, "dcRead: #%d->%s->%p\n",
    448                                    i, pdce->aInfos[i].fname, pdce->aInfos[i].customData);
    449                         fn (plist, (void*)pdce->aInfos[i].customData);
     422                        fn ("", &pdce->aInfos[i], path, state);
    450423                    }
    451424
     
    460433        }
    461434       
    462         debuglocal(pdc->resource, 9, "dcRead: [%s], %d\n", path, rc);
     435        debuglocal(9, "CacheRead: [%s], %d\n", path, rc);
    463436    }
    464437   
     
    484457            dceClear (pdce);
    485458            /* Remove the entry from list. It will be added again in dircache_write_end. */
    486             dcRemoveEntry (pdc, pdce);
     459            dcRemoveEntry (pdce);
    487460        }
    488461
     
    492465        }
    493466       
    494         debuglocal(pdc->resource, 9, "CacheWriteBegin: %s\n", path);
     467        debuglocal(9, "CacheWriteBegin: %s\n", path);
    495468    }
    496469   
     
    503476    DirectoryCacheEntry *pdce;
    504477   
    505     debuglocal(pdc->resource, 9, "CacheInvalidate: [%s]\n", path);
     478    debuglocal(9, "CacheInvalidate: [%s]\n", path);
    506479
    507480    pdce = dcFindDirCache (pdc, path, fPrefix);
     
    509482    while (pdce)
    510483    {
    511         dcRemoveEntry (pdc, pdce);
    512         dceDelete (pdc, pdce);
     484        dcRemoveEntry (pdce);
     485        dceDelete (pdce);
    513486       
    514487        pdce = dcFindDirCache (pdc, path, fPrefix);
     
    520493                       const char *parent,
    521494                       const char *name,
    522                        void **finfo,
     495                       smbwrp_fileinfo *finfo,
    523496                       unsigned long *pulAge)
    524497{
     
    527500    unsigned long hash = computehash (parent);
    528501
    529     debuglocal(pdc->resource, 9, "dcFindPath: [%s][%s]\n", parent, name);
     502    debuglocal(9, "dcFindPath: [%s][%s]\n", parent, name);
    530503
    531504    while (pdce != NULL)
    532505    {
    533         debuglocal(pdc->resource, 9, "dcFindPath: entry [%s]\n", pdce->pszPath);
     506        debuglocal(9, "dcFindPath: entry [%s]\n", pdce->pszPath);
    534507
    535508        if (   pdce->ulHash == hash
    536             && dcePathEqualsTo (pdc, pdce, parent))
     509            && dcePathEqualsTo (pdce, parent))
    537510        {
    538511            /* This entry should contain the path. */
     
    542515                if (ph->fsphStrICmp (pdce->aInfos[i].fname, name) == 0)
    543516                {
    544                     *finfo = (void*) pdce->aInfos[i].customData;
     517                    *finfo = pdce->aInfos[i];
    545518                    *pulAge = timesec () - pdce->ulLastUpdateTime;
    546                     debuglocal(pdc->resource, 9, "dcFindPath: FindPath %s found, age %d\n", path, *pulAge);
     519                    debuglocal(9, "dircache: FindPath %s found, age %d\n", path, *pulAge);
    547520                    return 1;
    548521                }
     
    553526    }
    554527
    555     debuglocal(pdc->resource, 9, "dcFindPath: FindPath %s not found\n", path);
     528    debuglocal(9, "dircache: FindPath %s not found\n", path);
    556529    return 0;
    557530}
    558531
    559 static int dcCreateDirPath(char *path, int cbPath, char* dir_mask, char* fullpath)
     532static int dcCreateDirPath(char *path, int cbPath, filelist_state *state)
    560533{
    561534    /* State contains the original path passed to the plugin (fullpath) and
     
    565538     */
    566539    int cbDir;
    567     int cbMask = strlen(dir_mask) + 1;
     540    int cbMask = strlen(state->dir_mask) + 1;
    568541    if (cbMask > cbPath)
    569542    {
     
    577550    {
    578551       cbDir--; /* Exclude the slash. */
    579        memcpy(path, fullpath, cbDir);
     552       memcpy(path, state->fullpath, cbDir);
    580553    }
    581554    path[cbDir] = 0;
     
    588561 */
    589562
    590 int dircache_create( DirectoryCache **ppdc, void* pRes,
    591                      int cachetimeout, int cachedepth, PFNFREEDIRENTRY _release,
    592                      PLUGINHELPERTABLE2L *_ph)
    593 {
    594     unsigned long ulExpirationTime = cachetimeout;
    595     int cMaxEntries = cachedepth;
     563int dircache_create(DirectoryCache **ppdc, unsigned long ulExpirationTime, int cMaxEntries)
     564{
    596565    int rc;
    597566
    598     debuglocal( pRes, 9, "dircache_create: %u seconds, %d entries\n", ulExpirationTime, cMaxEntries);
    599 
    600     // save pointer to helpers
    601     ph = _ph;
    602 
    603     rc = dcCreate(ppdc, pRes);
     567    debuglocal(9, "dircache_create: %u seconds, %d entries\n", ulExpirationTime, cMaxEntries);
     568
     569    rc = dcCreate(ppdc);
     570
    604571    if (rc == NO_ERROR)
    605572    {
    606         (*ppdc)->release = _release;
    607573        dcEnable (*ppdc, 1, ulExpirationTime, cMaxEntries);
    608 
    609     }
    610 
    611     debuglocal( (*ppdc)->resource, 9, "dircache_create: %p, rc = %d\n", *ppdc, rc);
     574    }
     575
     576    debuglocal(9, "dircache_create: %p, rc = %d\n", *ppdc, rc);
    612577    return rc;
    613578}
     
    615580void dircache_delete(DirectoryCache *pdc)
    616581{
    617     debuglocal(pdc->resource, 9, "dircache_delete: %p\n", pdc);
     582    debuglocal(9, "dircache_delete: %p\n", pdc);
    618583
    619584    if (pdc)
     
    623588}
    624589
    625 int dircache_list_files(DirectoryCache *pdc, PFNADDDIRENTRY fn,
    626                         void* plist,
    627                         char* dir_mask, char* fullpath,
     590
     591int dircache_list_files(PFNADDDIRENTRY fn,
     592                        filelist_state *state,
    628593                        int *ptotal_received)
    629594{
    630595    int rc;
    631 
    632     int cbPath = strlen(fullpath) + 1;
    633     char *path = (char*) alloca(cbPath);
    634     debuglocal(pdc->resource, 9, "dircache_list_files pdc %p, dir_mask [%s], fullpath [%s]\n",
    635                pdc, dir_mask, fullpath);
    636 
    637     if (!dcCreateDirPath(path, cbPath, dir_mask, fullpath))
    638     {
    639         debuglocal(pdc->resource, 9, "dircache_list_files pdc %p, dcCreateDirPath failed\n",
    640                    pdc);
     596    DirectoryCache *pdc = state->pConn->pRes->pdc;
     597
     598    int cbPath = strlen(state->fullpath) + 1;
     599    char *path = alloca(cbPath);
     600    if (!dcCreateDirPath(path, cbPath, state))
     601    {
    641602        return 0;
    642603    }
    643604
    644     debuglocal(pdc->resource, 9, "dircache_list_files [%s]\n", path);
     605    debuglocal(9, "dircache_list_files [%s]\n", path);
     606
    645607    if (!pdc)
    646608    {
     
    650612    lockRequest (pdc->mutex);
    651613
    652     rc = dcRead (pdc, path, fn, plist, ptotal_received, 0);
     614    rc = dcRead (pdc, path, fn, state, ptotal_received, 0);
    653615
    654616    lockRelease (pdc->mutex);
    655617
    656     debuglocal(pdc->resource, 9, "dircache_list_files rc=%d\n", (rc == CacheOk));
    657618    return (rc == CacheOk);
    658619}
    659620
    660 void *dircache_write_begin(DirectoryCache *pdc,
    661                            char* dir_mask, char* fullpath,
     621void *dircache_write_begin(filelist_state *state,
    662622                           int cFiles)
    663623{
     624    DirectoryCache *pdc = state->pConn->pRes->pdc;
    664625    DirectoryCacheEntry *pdce = NULL;
    665     debuglocal(pdc->resource, 9, "dircache_write_begin pdc %p path [%s]\n", pdc, fullpath);
    666 
    667     int cbPath = strlen(fullpath) + 1;
    668     char *path = (char*) alloca(cbPath);
    669     if (!dcCreateDirPath(path, cbPath, dir_mask, fullpath))
    670     {
    671         debuglocal(pdc->resource, 9, "dircache_write_begin dcCreateDirPath failed\n");
     626
     627    int cbPath = strlen(state->fullpath) + 1;
     628    char *path = alloca(cbPath);
     629    if (!dcCreateDirPath(path, cbPath, state))
     630    {
     631        return NULL;
     632    }
     633
     634    debuglocal(9, "dircache_write_begin pdc %p path [%s]\n", pdc, path);
     635
     636    if (!pdc)
     637    {
    672638        return NULL;
    673639    }
     
    679645        /* Remove oldest entry. */
    680646        pdce = pdc->pEntriesTail;
    681         dcRemoveEntry (pdc, pdce);
    682         dceDelete (pdc, pdce);
     647        dcRemoveEntry (pdce);
     648        dceDelete (pdce);
    683649        pdce = NULL;
    684650    }
     
    688654    lockRelease (pdc->mutex);
    689655
    690     debuglocal(pdc->resource, 9, "dircache_write_begin returning ctx %p\n", pdce);
     656    debuglocal(9, "dircache_write_begin returning ctx %p\n", pdce);
    691657    return (void *)pdce;
    692658}
    693659
    694 void dircache_write_entry(DirectoryCache *pdc, void *dircachectx,
    695                           const char *fname, const void *finfo)
     660void dircache_write_entry(void *dircachectx, const smbwrp_fileinfo *finfo)
    696661{
    697662    DirectoryCacheEntry *pdce = (DirectoryCacheEntry *)dircachectx;
    698663
    699     debuglocal(pdc->resource, 9, "dircache_write_entry %p\n", pdce);
     664    debuglocal(9, "dircache_write_entry %p\n", pdce);
    700665   
    701666    if (!pdce)
     
    704669    }
    705670   
     671    lockRequest (pdce->pdc->mutex);
     672   
     673    dceWriteEntry (pdce, finfo);
     674   
     675    lockRelease (pdce->pdc->mutex);
     676}
     677
     678void dircache_write_end(void *dircachectx)
     679{
     680    DirectoryCacheEntry *pdce = (DirectoryCacheEntry *)dircachectx;
     681    DirectoryCache *pdc;
     682
     683    debuglocal(9, "dircache_write_end: pdce %p\n", pdce);
     684
     685    if (!pdce)
     686    {
     687        return;
     688    }
     689   
     690    pdc = pdce->pdc;
     691   
    706692    lockRequest (pdc->mutex);
    707693   
    708     dceWriteEntry (pdc, pdce, fname, finfo);
     694    if (pdce->fInvalid)
     695    {
     696        /* Something happened during writing to the entry. Delete it. */
     697        dceDelete (pdce);
     698    }
     699    else
     700    {
     701        dceAdjust (pdce);
     702        dcInsertEntry (pdce);
     703    }
    709704   
    710705    lockRelease (pdc->mutex);
    711706}
    712707
    713 void dircache_write_end(DirectoryCache *pdc, void *dircachectx)
    714 {
    715     DirectoryCacheEntry *pdce = (DirectoryCacheEntry *)dircachectx;
    716 
    717     debuglocal(pdc->resource, 9, "dircache_write_end: pdce %p\n", pdce);
    718 
    719     if (!pdce)
    720     {
    721         return;
    722     }
    723    
    724     lockRequest (pdc->mutex);
    725    
    726     if (pdce->fInvalid)
    727     {
    728         /* Something happened during writing to the entry. Delete it. */
    729         dceDelete (pdc, pdce);
    730     }
    731     else
    732     {
    733         dceAdjust (pdc, pdce);
    734         dcInsertEntry (pdc, pdce);
    735     }
    736    
    737     lockRelease (pdc->mutex);
    738 }
    739 
    740 void dircache_invalidate(DirectoryCache *pdc,
    741                          const char *path,
     708void dircache_invalidate(const char *path,
     709                         struct DirectoryCache *pdc,
    742710                         int fParent)
    743711{
    744     debuglocal(pdc->resource, 9, "dircache_invalidate [%s], parent %d\n", path, fParent);
     712    debuglocal(9, "dircache_invalidate [%s], parent %d\n", path, fParent);
    745713
    746714    if (!pdc)
     
    757725        memcpy(p, path, cb);
    758726        char *lastSlash = ph->fsphStrRChr(p, '\\');
    759         if (!lastSlash)
    760             lastSlash = ph->fsphStrRChr(p, '/');
    761727        if (lastSlash)
    762728        {
     
    779745}
    780746
    781 int dircache_find_path(DirectoryCache *pdc,
     747int dircache_find_path(struct DirectoryCache *pdc,
    782748                       const char *path,
    783                        void **finfo,
     749                       smbwrp_fileinfo *finfo,
    784750                       unsigned long *pulAge)
    785751{
     
    789755    int fFound = 0;
    790756
    791     debuglocal(pdc->resource, 9, "dircache_find_path [%s]\n", path);
     757    debuglocal(9, "dircache_find_path [%s]\n", path);
    792758
    793759    if (!pdc)
     
    809775    memcpy(p, path, cb);
    810776    lastSlash = ph->fsphStrRChr(p, '\\');
    811     if (!lastSlash)
    812         lastSlash = ph->fsphStrRChr(p, '/');
    813777    if (lastSlash)
    814778    {
     
    824788    lockRelease (pdc->mutex);
    825789
    826     debuglocal(pdc->resource, 9, "dircache_find_path fFound %d\n", fFound);
    827790    return fFound;
    828791}
Note: See TracChangeset for help on using the changeset viewer.