Changeset 1002 for branches


Ignore:
Timestamp:
Dec 30, 2016, 5:22:31 AM (9 years ago)
Author:
Paul Smedley
Message:

Simplify NdpFileRead code

Location:
branches/client-3.0/src
Files:
2 edited

Legend:

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

    r998 r1002  
     1/*
     2   Directory caching code for Netdrive plugins.
     3   Copyright (C) netlabs.org 2010-2016
     4*/
     5
    16#include <stdio.h>
    27#include <stdlib.h>
     
    510#include <time.h>
    611
    7 #define NDPL_LARGEFILES
    8 #define INCL_LONGLONG
    9 #include <ndextpl2.h>
    10 
    11 #include "smbwrp.h"
    12 
    13 extern PLUGINHELPERTABLE2L *ph;
     12#include "dircache.h"
     13
     14PLUGINHELPERTABLE2L *ph;
    1415
    1516/*
    16  * Static helpers.
     17 * An entry holds file name and a pointer to custom data
    1718 */
    18 static int lockCreate (NDMUTEX *pMutex)
    19 {
    20     return ph->fsphCreateMutex (pMutex);
    21 }
    22        
    23 static void lockDelete (NDMUTEX mutex)
    24 {
    25     ph->fsphCloseMutex (mutex);
    26 }
    27        
    28 static int lockRequest (NDMUTEX mutex)
    29 {
    30     return ph->fsphRequestMutex (mutex, 10000);
    31 }
    32 
    33 void lockRelease (NDMUTEX mutex)
    34 {
    35     ph->fsphReleaseMutex (mutex);
    36 }
    37 
    38 static 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 
    58 static 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 
    65 static unsigned long computehash (const char *s)
    66 {
    67     return s? Hash ((char *)s, strlen (s)): 0;
    68 }
    69 
    70 
     19typedef struct DirectoryCacheEntryData
     20{
     21    const char  fname[PATH_MAX];
     22    const void* customData;
     23} DirectoryCacheEntryData;
    7124
    7225/*
     
    7831    struct DirectoryCacheEntry *pPrev;
    7932
    80     struct DirectoryCache *pdc;
    81    
    82     smbwrp_fileinfo *aInfos;
     33    DirectoryCacheEntryData *aInfos;
    8334    int cInfos;
    8435    int cInfosAllocated;
     
    9748    DirectoryCacheEntry *pEntriesTail;
    9849    int cEntries;
    99 
    10050    int fEnabled;
    10151    unsigned long ulExpirationTime;
    10252    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
    10358} DirectoryCache;
    10459
     
    10762    CacheOk = 1
    10863};
    109        
    110 
    111 static int dceCreate (DirectoryCacheEntry **ppdce, DirectoryCache *pdc, const char *path, int cFiles)
     64
     65/*
     66 * Static helpers.
     67 */
     68static int lockCreate (NDMUTEX *pMutex)
     69{
     70    return ph->fsphCreateMutex (pMutex);
     71}
     72       
     73static void lockDelete (NDMUTEX mutex)
     74{
     75    ph->fsphCloseMutex (mutex);
     76}
     77       
     78static int lockRequest (NDMUTEX mutex)
     79{
     80    return ph->fsphRequestMutex (mutex, 10000);
     81}
     82
     83void lockRelease (NDMUTEX mutex)
     84{
     85    ph->fsphReleaseMutex (mutex);
     86}
     87
     88static 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
     108static 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
     115static unsigned long computehash (const char *s)
     116{
     117    return s? Hash ((char *)s, strlen (s)): 0;
     118}
     119
     120static int dceCreate (DirectoryCacheEntry **ppdce, DirectoryCache* pdc, const char *path, int cFiles)
    112121{
    113122    DirectoryCacheEntry *pdce = (DirectoryCacheEntry *)malloc(sizeof(DirectoryCacheEntry));
     
    118127    }
    119128
    120     pdce->aInfos = (smbwrp_fileinfo *)malloc(cFiles * sizeof (smbwrp_fileinfo));
     129    pdce->aInfos = (DirectoryCacheEntryData *)
     130            malloc(cFiles * sizeof (DirectoryCacheEntryData));
    121131    if (!pdce->aInfos)
    122132    {
     
    128138    pdce->ulHash = computehash (path);
    129139    pdce->ulLastUpdateTime = 0;
    130     pdce->pdc = pdc;
    131140    pdce->fInvalid = 0;
    132141
     
    143152}
    144153
    145 static void dceDelete (DirectoryCacheEntry *pdce)
    146 {
     154static 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 */
    147170    free(pdce->aInfos);
    148171    free(pdce->pszPath);
     
    155178}
    156179
    157 static void dceWriteEntry (DirectoryCacheEntry *pdce, const smbwrp_fileinfo *finfo)
     180static void dceWriteEntry (DirectoryCache *pdc, DirectoryCacheEntry *pdce,
     181                           const char *fname, const void *finfo)
    158182{
    159183    if (pdce->cInfos >= pdce->cInfosAllocated)
     
    162186        int cNewAllocated = pdce->cInfosAllocated + pdce->cInfosAllocated / 2 + 1;
    163187
    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);
     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);
    168193        if (pNewInfos)
    169194        {
     
    179204    }
    180205
    181     pdce->aInfos[pdce->cInfos] = *finfo;
     206    // store entry name and custom data
     207    strcpy( (char*)pdce->aInfos[pdce->cInfos].fname, fname);
     208    pdce->aInfos[pdce->cInfos].customData = finfo;
    182209    pdce->cInfos++;
    183210}
    184211
    185 static void dceAdjust (DirectoryCacheEntry *pdce)
     212static void dceAdjust (DirectoryCache *pdc, DirectoryCacheEntry *pdce)
    186213{
    187214    /* If the entry has too many preallocated info structures, adjust the memory allocation */
     
    193220        int cNewAllocated = pdce->cInfos + cFree / 2;
    194221
    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);
     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);
    199227        if (pNewInfos)
    200228        {
     
    209237}
    210238
    211 static int dcePathEqualsTo (DirectoryCacheEntry *pdce, const char *path)
    212 {
    213     debuglocal(9, "dcePathEqualTo: [%s] [%s]\n", path, pdce->pszPath);
     239static int dcePathEqualsTo (DirectoryCache *pdc, DirectoryCacheEntry *pdce, const char *path)
     240{
     241    debuglocal(pdc->resource, 9, "dcePathEqualTo: [%s] [%s]\n", path, pdce->pszPath);
    214242    return ph->fsphStrICmp (path, pdce->pszPath) == 0;
    215243}
     
    225253}
    226254               
    227 static struct DirectoryCacheEntry *dcFindDirCache (struct DirectoryCache *pdc, const char *path, int fPrefix)
     255static struct DirectoryCacheEntry *dcFindDirCache (DirectoryCache *pdc, const char *path, int fPrefix)
    228256{
    229257    unsigned long hash = computehash (path);
     
    231259    DirectoryCacheEntry *iter = pdc->pEntriesHead;
    232260
    233     debuglocal(9, "findDirCache: [%s]\n", path);
     261    debuglocal(pdc->resource, 9, "dcFindDirCache: [%s]\n", path);
     262    debuglocal(pdc->resource, 9, "dcFindDirCache: iter [%p]\n", iter);
    234263
    235264    while (iter != NULL)
    236265    {
    237         debuglocal(9, "findDirCache: entry [%s]\n", iter->pszPath);
     266        debuglocal(pdc->resource, 9, "dcFindDirCache: entry [%s]\n", iter->pszPath);
    238267        if (fPrefix)
    239268        {
     
    246275        {
    247276            if (    iter->ulHash == hash
    248                  && dcePathEqualsTo (iter, path)
     277                 && dcePathEqualsTo (pdc, iter, path)
    249278               )
    250279            {
     
    255284    }
    256285
    257     debuglocal(9, "findDirCache: %p\n", iter);
     286    debuglocal(pdc->resource, 9, "dcFindDirCache: %p\n", iter);
    258287
    259288    return iter;
    260289}
    261290
    262 static int dcCreate (struct DirectoryCache **ppdc)
     291static int dcCreate (struct DirectoryCache **ppdc, void* pRes)
    263292{
    264293    int rc;
    265294
    266295    DirectoryCache *pdc = (DirectoryCache *)malloc(sizeof (DirectoryCache));
    267    
    268296    if (!pdc)
    269297    {
     
    272300
    273301    rc = lockCreate (&pdc->mutex);
    274 
    275302    if (rc != NO_ERROR)
    276303    {
     
    285312    pdc->fEnabled = 0;
    286313    pdc->ulExpirationTime = -1;
     314    pdc->resource = pRes;
    287315   
    288316    *ppdc = pdc;
     
    294322{
    295323    DirectoryCacheEntry *iter = pdc->pEntriesHead;
     324    debuglocal(pdc->resource, 9, "dcDelete: pdc %p, iter %p\n", pdc, iter);
    296325
    297326    while (iter != NULL)
     
    299328        DirectoryCacheEntry *next = iter->pNext;
    300329
    301         dceDelete (iter);
     330        dceDelete (pdc, iter);
    302331       
    303332        iter = next;
     
    308337}
    309338
    310 static void dcRemoveEntry (DirectoryCacheEntry *pdce)
    311 {
    312     DirectoryCache *pdc = pdce->pdc;
    313 
     339static void dcRemoveEntry (DirectoryCache *pdc, DirectoryCacheEntry *pdce)
     340{
    314341    if (pdce->pNext)
    315342    {
     
    329356        pdc->pEntriesHead = pdce->pNext;
    330357    }
    331 
     358   
    332359    pdce->pNext = NULL;
    333360    pdce->pPrev = NULL;
    334    
     361
    335362    pdc->cEntries--;
    336363}
    337364
    338 static void dcInsertEntry (DirectoryCacheEntry *pdce)
    339 {
    340     DirectoryCache *pdc = pdce->pdc;
    341 
     365static void dcInsertEntry (DirectoryCache *pdc, DirectoryCacheEntry *pdce)
     366{
    342367    pdce->pNext = pdc->pEntriesHead;
    343368
     
    374399        }
    375400       
    376         debuglocal(9, "ExistsInCache: [%s], %d\n", path, rc);
     401        debuglocal(pdc->resource, 9, "ExistsInCache: [%s], %d\n", path, rc);
    377402    }
    378403   
     
    382407static int dcRead (DirectoryCache *pdc, const char *path,
    383408                   PFNADDDIRENTRY fn,
    384                    filelist_state *state,
     409                   void* plist,
    385410                   int *ptotal_received, int fForceCache)
    386411{
    387412    int i;
    388    
    389413    int rc = CacheFault;
    390        
     414
    391415    if (pdc->fEnabled)
    392416    {
     
    397421        if (pdce)
    398422        {
    399             debuglocal(9, "CacheRead: entry %p found for [%s]\n", pdce, path);
     423            debuglocal(pdc->resource, 9, "dcRead: entry %p found for [%s]\n", pdce, path);
    400424           
    401425            if (fForceCache)
     
    403427                for (i = 0; i < pdce->cInfos; i++)
    404428                {
    405                     fn ("", &pdce->aInfos[i], path, state);
     429                    fn (plist, (void*)pdce->aInfos[i].customData);
    406430                }
    407431
     
    412436                if (dceExpired (pdce, pdc->ulExpirationTime))
    413437                {
    414                     debuglocal(9, "CacheRead: expired\n");
    415                     dcRemoveEntry (pdce);
    416                     dceDelete (pdce);
     438                    debuglocal(pdc->resource, 9, "dcRead: expired\n");
     439                    dcRemoveEntry (pdc, pdce);
     440                    dceDelete (pdc, pdce);
    417441                }
    418442                else
    419443                {
     444                    debuglocal(pdc->resource, 9, "dcRead: adding %d entries from cache\n", pdce->cInfos);
    420445                    for (i = 0; i < pdce->cInfos; i++)
    421446                    {
    422                         fn ("", &pdce->aInfos[i], path, state);
     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);
    423450                    }
    424451
     
    433460        }
    434461       
    435         debuglocal(9, "CacheRead: [%s], %d\n", path, rc);
     462        debuglocal(pdc->resource, 9, "dcRead: [%s], %d\n", path, rc);
    436463    }
    437464   
     
    457484            dceClear (pdce);
    458485            /* Remove the entry from list. It will be added again in dircache_write_end. */
    459             dcRemoveEntry (pdce);
     486            dcRemoveEntry (pdc, pdce);
    460487        }
    461488
     
    465492        }
    466493       
    467         debuglocal(9, "CacheWriteBegin: %s\n", path);
     494        debuglocal(pdc->resource, 9, "CacheWriteBegin: %s\n", path);
    468495    }
    469496   
     
    476503    DirectoryCacheEntry *pdce;
    477504   
    478     debuglocal(9, "CacheInvalidate: [%s]\n", path);
     505    debuglocal(pdc->resource, 9, "CacheInvalidate: [%s]\n", path);
    479506
    480507    pdce = dcFindDirCache (pdc, path, fPrefix);
     
    482509    while (pdce)
    483510    {
    484         dcRemoveEntry (pdce);
    485         dceDelete (pdce);
     511        dcRemoveEntry (pdc, pdce);
     512        dceDelete (pdc, pdce);
    486513       
    487514        pdce = dcFindDirCache (pdc, path, fPrefix);
     
    493520                       const char *parent,
    494521                       const char *name,
    495                        smbwrp_fileinfo *finfo,
     522                       void **finfo,
    496523                       unsigned long *pulAge)
    497524{
     
    500527    unsigned long hash = computehash (parent);
    501528
    502     debuglocal(9, "dcFindPath: [%s][%s]\n", parent, name);
     529    debuglocal(pdc->resource, 9, "dcFindPath: [%s][%s]\n", parent, name);
    503530
    504531    while (pdce != NULL)
    505532    {
    506         debuglocal(9, "dcFindPath: entry [%s]\n", pdce->pszPath);
     533        debuglocal(pdc->resource, 9, "dcFindPath: entry [%s]\n", pdce->pszPath);
    507534
    508535        if (   pdce->ulHash == hash
    509             && dcePathEqualsTo (pdce, parent))
     536            && dcePathEqualsTo (pdc, pdce, parent))
    510537        {
    511538            /* This entry should contain the path. */
     
    515542                if (ph->fsphStrICmp (pdce->aInfos[i].fname, name) == 0)
    516543                {
    517                     *finfo = pdce->aInfos[i];
     544                    *finfo = (void*) pdce->aInfos[i].customData;
    518545                    *pulAge = timesec () - pdce->ulLastUpdateTime;
    519                     debuglocal(9, "dircache: FindPath %s found, age %d\n", path, *pulAge);
     546                    debuglocal(pdc->resource, 9, "dcFindPath: FindPath %s found, age %d\n", path, *pulAge);
    520547                    return 1;
    521548                }
     
    526553    }
    527554
    528     debuglocal(9, "dircache: FindPath %s not found\n", path);
     555    debuglocal(pdc->resource, 9, "dcFindPath: FindPath %s not found\n", path);
    529556    return 0;
    530557}
    531558
    532 static int dcCreateDirPath(char *path, int cbPath, filelist_state *state)
     559static int dcCreateDirPath(char *path, int cbPath, char* dir_mask, char* fullpath)
    533560{
    534561    /* State contains the original path passed to the plugin (fullpath) and
     
    538565     */
    539566    int cbDir;
    540     int cbMask = strlen(state->dir_mask) + 1;
     567    int cbMask = strlen(dir_mask) + 1;
    541568    if (cbMask > cbPath)
    542569    {
     
    550577    {
    551578       cbDir--; /* Exclude the slash. */
    552        memcpy(path, state->fullpath, cbDir);
     579       memcpy(path, fullpath, cbDir);
    553580    }
    554581    path[cbDir] = 0;
     
    561588 */
    562589
    563 int dircache_create(DirectoryCache **ppdc, unsigned long ulExpirationTime, int cMaxEntries)
    564 {
     590int 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;
    565596    int rc;
    566597
    567     debuglocal(9, "dircache_create: %u seconds, %d entries\n", ulExpirationTime, cMaxEntries);
    568 
    569     rc = dcCreate(ppdc);
    570 
     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);
    571604    if (rc == NO_ERROR)
    572605    {
     606        (*ppdc)->release = _release;
    573607        dcEnable (*ppdc, 1, ulExpirationTime, cMaxEntries);
    574     }
    575 
    576     debuglocal(9, "dircache_create: %p, rc = %d\n", *ppdc, rc);
     608
     609    }
     610
     611    debuglocal( (*ppdc)->resource, 9, "dircache_create: %p, rc = %d\n", *ppdc, rc);
    577612    return rc;
    578613}
     
    580615void dircache_delete(DirectoryCache *pdc)
    581616{
    582     debuglocal(9, "dircache_delete: %p\n", pdc);
     617    debuglocal(pdc->resource, 9, "dircache_delete: %p\n", pdc);
    583618
    584619    if (pdc)
     
    588623}
    589624
    590 
    591 int dircache_list_files(PFNADDDIRENTRY fn,
    592                         filelist_state *state,
     625int dircache_list_files(DirectoryCache *pdc, PFNADDDIRENTRY fn,
     626                        void* plist,
     627                        char* dir_mask, char* fullpath,
    593628                        int *ptotal_received)
    594629{
    595630    int rc;
    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     {
     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);
    602641        return 0;
    603642    }
    604643
    605     debuglocal(9, "dircache_list_files [%s]\n", path);
    606 
     644    debuglocal(pdc->resource, 9, "dircache_list_files [%s]\n", path);
    607645    if (!pdc)
    608646    {
     
    612650    lockRequest (pdc->mutex);
    613651
    614     rc = dcRead (pdc, path, fn, state, ptotal_received, 0);
     652    rc = dcRead (pdc, path, fn, plist, ptotal_received, 0);
    615653
    616654    lockRelease (pdc->mutex);
    617655
     656    debuglocal(pdc->resource, 9, "dircache_list_files rc=%d\n", (rc == CacheOk));
    618657    return (rc == CacheOk);
    619658}
    620659
    621 void *dircache_write_begin(filelist_state *state,
     660void *dircache_write_begin(DirectoryCache *pdc,
     661                           char* dir_mask, char* fullpath,
    622662                           int cFiles)
    623663{
    624     DirectoryCache *pdc = state->pConn->pRes->pdc;
    625664    DirectoryCacheEntry *pdce = NULL;
    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     {
     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");
    638672        return NULL;
    639673    }
     
    645679        /* Remove oldest entry. */
    646680        pdce = pdc->pEntriesTail;
    647         dcRemoveEntry (pdce);
    648         dceDelete (pdce);
     681        dcRemoveEntry (pdc, pdce);
     682        dceDelete (pdc, pdce);
    649683        pdce = NULL;
    650684    }
     
    654688    lockRelease (pdc->mutex);
    655689
    656     debuglocal(9, "dircache_write_begin returning ctx %p\n", pdce);
     690    debuglocal(pdc->resource, 9, "dircache_write_begin returning ctx %p\n", pdce);
    657691    return (void *)pdce;
    658692}
    659693
    660 void dircache_write_entry(void *dircachectx, const smbwrp_fileinfo *finfo)
     694void dircache_write_entry(DirectoryCache *pdc, void *dircachectx,
     695                          const char *fname, const void *finfo)
    661696{
    662697    DirectoryCacheEntry *pdce = (DirectoryCacheEntry *)dircachectx;
    663698
    664     debuglocal(9, "dircache_write_entry %p\n", pdce);
     699    debuglocal(pdc->resource, 9, "dircache_write_entry %p\n", pdce);
    665700   
    666701    if (!pdce)
     
    669704    }
    670705   
    671     lockRequest (pdce->pdc->mutex);
    672    
    673     dceWriteEntry (pdce, finfo);
    674    
    675     lockRelease (pdce->pdc->mutex);
    676 }
    677 
    678 void dircache_write_end(void *dircachectx)
     706    lockRequest (pdc->mutex);
     707   
     708    dceWriteEntry (pdc, pdce, fname, finfo);
     709   
     710    lockRelease (pdc->mutex);
     711}
     712
     713void dircache_write_end(DirectoryCache *pdc, void *dircachectx)
    679714{
    680715    DirectoryCacheEntry *pdce = (DirectoryCacheEntry *)dircachectx;
    681     DirectoryCache *pdc;
    682 
    683     debuglocal(9, "dircache_write_end: pdce %p\n", pdce);
     716
     717    debuglocal(pdc->resource, 9, "dircache_write_end: pdce %p\n", pdce);
    684718
    685719    if (!pdce)
     
    688722    }
    689723   
    690     pdc = pdce->pdc;
    691    
    692724    lockRequest (pdc->mutex);
    693725   
     
    695727    {
    696728        /* Something happened during writing to the entry. Delete it. */
    697         dceDelete (pdce);
     729        dceDelete (pdc, pdce);
    698730    }
    699731    else
    700732    {
    701         dceAdjust (pdce);
    702         dcInsertEntry (pdce);
     733        dceAdjust (pdc, pdce);
     734        dcInsertEntry (pdc, pdce);
    703735    }
    704736   
     
    706738}
    707739
    708 void dircache_invalidate(const char *path,
    709                          struct DirectoryCache *pdc,
     740void dircache_invalidate(DirectoryCache *pdc,
     741                         const char *path,
    710742                         int fParent)
    711743{
    712     debuglocal(9, "dircache_invalidate [%s], parent %d\n", path, fParent);
     744    debuglocal(pdc->resource, 9, "dircache_invalidate [%s], parent %d\n", path, fParent);
    713745
    714746    if (!pdc)
     
    725757        memcpy(p, path, cb);
    726758        char *lastSlash = ph->fsphStrRChr(p, '\\');
     759        if (!lastSlash)
     760            lastSlash = ph->fsphStrRChr(p, '/');
    727761        if (lastSlash)
    728762        {
     
    745779}
    746780
    747 int dircache_find_path(struct DirectoryCache *pdc,
     781int dircache_find_path(DirectoryCache *pdc,
    748782                       const char *path,
    749                        smbwrp_fileinfo *finfo,
     783                       void **finfo,
    750784                       unsigned long *pulAge)
    751785{
     
    755789    int fFound = 0;
    756790
    757     debuglocal(9, "dircache_find_path [%s]\n", path);
     791    debuglocal(pdc->resource, 9, "dircache_find_path [%s]\n", path);
    758792
    759793    if (!pdc)
     
    775809    memcpy(p, path, cb);
    776810    lastSlash = ph->fsphStrRChr(p, '\\');
     811    if (!lastSlash)
     812        lastSlash = ph->fsphStrRChr(p, '/');
    777813    if (lastSlash)
    778814    {
     
    788824    lockRelease (pdc->mutex);
    789825
     826    debuglocal(pdc->resource, 9, "dircache_find_path fFound %d\n", fFound);
    790827    return fFound;
    791828}
  • branches/client-3.0/src/ndpsmb.c

    r1000 r1002  
    22182218}
    22192219
    2220 #define NDPSMB_READ_MAX_SIZE (65536 - 4096)
    2221 //TODO simplify this code
    22222220int APIENTRY NdpFileRead (HCONNECTION conn, NDFILEHANDLE handle, void *pBuffer, ULONG ulRead, ULONG *pulActual)
    22232221{
     
    22252223        Resource *pRes = pConn->pRes;
    22262224        int rc = 0;
    2227         unsigned long done = 0;
    2228         unsigned long onedone;
    2229         unsigned long action;
    2230         ULONG ulReadCompleted = 0;
    2231 
    2232         ENTER();
    2233 
    2234         debuglocal(9,"NdpFileRead in [%p]\n", pConn);
    2235 
    2236         do {
    2237                 if (pConn->file.fd < 0)
    2238                 {
    2239                         rc = ERROR_INVALID_HANDLE;
    2240                         break;
    2241                 }
    2242                 while (ulReadCompleted < ulRead)
    2243                 {
    2244                         ULONG ulActual;
    2245                         ULONG ulToRead = ulRead - ulReadCompleted;
    2246                         debuglocal(9,"NdpFileRead completed %d, to read %d\n", ulReadCompleted, ulToRead);
    2247                         if (ulToRead > NDPSMB_READ_MAX_SIZE)
    2248                         {
    2249                                 ulToRead = NDPSMB_READ_MAX_SIZE;
    2250                         }
    2251                         rc = smbwrp_read(pConn->cli, &pConn->file, (char *)pBuffer + ulReadCompleted, ulToRead, &ulActual);
    2252                         if (ulActual == 0 || rc != NO_ERROR)
    2253                         {
    2254                                 break;
    2255                         }
    2256                         ulReadCompleted += ulActual;
    2257                 }
    2258                 //*pulActual = ulRead;
    2259                 //DosSleep(0);
    2260 
    2261         } while (0);
    2262 
    2263         if (ulReadCompleted > 0)
     2225
     2226        ENTER();
     2227
     2228        debuglocal(9,"NdpFileRead in [%p], ulRead = %d\n", pConn, ulRead);
     2229
     2230        ULONG ulActual;
     2231        rc = smbwrp_read(pConn->cli, &pConn->file, (char *)pBuffer, ulRead, &ulActual);
     2232
     2233        if (ulActual > 0)
    22642234        {
    22652235                rc = NO_ERROR; /* Still were able to read some data. */
     
    22682238        if (rc == NO_ERROR)
    22692239        {
    2270                 *pulActual = ulReadCompleted;
     2240                *pulActual = ulActual;
    22712241        }
    22722242
Note: See TracChangeset for help on using the changeset viewer.