Ignore:
Timestamp:
Aug 26, 2016, 7:04:49 PM (9 years ago)
Author:
Yuri Dario
Message:

Store samba data in dynamic allocated memory for new caching code. Added
deallocator code. ticket#274.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/client/src/ndpsmb.c

    r970 r976  
    236236// and add the result to Netdrive internal list
    237237//
    238 int addFindInfoL(Connection * pConn, void * plist, smbwrp_fileinfo * finfo, ULONG ulAttribute, char * mask)
    239 {
     238int addFindInfoL(Resource * pRes, void * plist, smbwrp_fileinfo * finfo, ULONG ulAttribute, char * mask)
     239{
     240        debuglocal(pRes, 9, "addFindInfoL finfo %p, fname %s\n", finfo, finfo->fname);
    240241        FILESTATUS3L stat = {0};
    241242        char * name = ph->fsphStrRChr(finfo->fname, '\\');
     
    245246           name = finfo->fname;
    246247
    247         if (!*name)
    248            name = pConn->pRes->srv.share_name;
     248        if (!*name && pRes != NULL)
     249           name = pRes->srv.share_name;
    249250
    250251        if (mask && (!ph->fsphAttrMatch(ulAttribute, finfo->attr & 0x37) || !ph->fsphWildMatch(mask, name, ND_IGNORE_CASE)))
     
    255256        stat.attrFile = (finfo->attr & 0x37);
    256257
    257         fsphUnixTimeToDosDate(pConn->pRes, finfo->mtime, &stat.fdateLastWrite, &stat.ftimeLastWrite);
    258         fsphUnixTimeToDosDate(pConn->pRes, finfo->ctime, &stat.fdateCreation, &stat.ftimeCreation);
    259         fsphUnixTimeToDosDate(pConn->pRes, finfo->atime, &stat.fdateLastAccess, &stat.ftimeLastAccess);
    260         debuglocal(pConn->pRes, 9, "fname %s\n", finfo->fname);
    261         debuglocal(pConn->pRes, 9, "mtime %d %s", finfo->mtime, ctime( (time_t*)&finfo->mtime));
    262         debuglocal(pConn->pRes, 9, "ftimeLastAccess %02d:%02d:%02d\n", stat.ftimeLastWrite.hours, stat.ftimeLastWrite.minutes, stat.ftimeLastWrite.twosecs*2);
     258        fsphUnixTimeToDosDate(pRes, finfo->mtime, &stat.fdateLastWrite, &stat.ftimeLastWrite);
     259        fsphUnixTimeToDosDate(pRes, finfo->ctime, &stat.fdateCreation, &stat.ftimeCreation);
     260        fsphUnixTimeToDosDate(pRes, finfo->atime, &stat.fdateLastAccess, &stat.ftimeLastAccess);
     261        debuglocal(pRes, 9, "fname %s\n", finfo->fname);
     262        debuglocal(pRes, 9, "mtime %d %s", finfo->mtime, ctime( (time_t*)&finfo->mtime));
     263        debuglocal(pRes, 9, "ftimeLastAccess %02d:%02d:%02d\n", stat.ftimeLastWrite.hours, stat.ftimeLastWrite.minutes, stat.ftimeLastWrite.twosecs*2);
    263264
    264265        ph->fsphAddFile32L(plist, &stat, name, strlen(name), finfo, sizeof(*finfo), 0);
    265266        return 1;
     267}
     268
     269//
     270// maps smbwrp_fileinfo data fields into a native OS/2 file informations
     271// and add the result to Netdrive internal list
     272//
     273void addFindInfoCachedL(void *plist, void* custom)
     274{
     275   smbwrp_fileinfo* finfo = (smbwrp_fileinfo*)custom;
     276   debuglocal(NULL, 9, "addFindInfoCachedL finfo %p, fname %s\n", finfo, finfo->fname);
     277
     278   // convert STATUS fields
     279   FILESTATUS3L stat = {0};
     280   stat.cbFile = finfo->size;
     281   stat.cbFileAlloc = stat.cbFile;
     282   stat.attrFile = (finfo->attr & 0x37);
     283
     284   // convert timestamps
     285   fsphUnixTimeToDosDate(NULL, finfo->mtime, &stat.fdateLastWrite, &stat.ftimeLastWrite);
     286   fsphUnixTimeToDosDate(NULL, finfo->ctime, &stat.fdateCreation, &stat.ftimeCreation);
     287   fsphUnixTimeToDosDate(NULL, finfo->atime, &stat.fdateLastAccess, &stat.ftimeLastAccess);
     288
     289   // add to netdrive plist
     290   ph->fsphAddFile32L(plist, &stat, finfo->fname, strlen(finfo->fname),
     291                      finfo, sizeof(smbwrp_fileinfo), 0);
    266292}
    267293
     
    320346         *d++ = 0;
    321347         return;
     348}
     349
     350/* callback for caching code used to free resources allocated when
     351 * calling dircache_write_entry() in smbwrp.c
     352 */
     353static void cacheFreeEntry( void*custom)
     354{
     355   smbwrp_fileinfo* finfo = (smbwrp_fileinfo*)custom;
     356   debuglocal(NULL, 9, "cacheFreeEntry finfo %p -> %s\n", finfo, finfo->fname);
     357   // release memory
     358   free( finfo);
    322359}
    323360
     
    478515        */
    479516        dircache_create(&pRes->pdc, (void*) pRes,
    480                         pRes->cachetimeout, pRes->cachedepth);
     517                        pRes->cachetimeout, pRes->cachedepth, cacheFreeEntry);
    481518
    482519        return rc;
     
    940977           // First check if there is information in the directory cache.
    941978           unsigned long ulAge = 0;
    942            if (dircache_find_path(pRes->pdc, szPath, &finfo, &ulAge))
     979           void* _finfo;
     980           if (dircache_find_path(pRes->pdc, szPath, &_finfo, &ulAge))
    943981           {
    944982              if (ulAge <= 15) /* @todo configurable. */
    945983              {
    946984                 rc = NO_ERROR;
    947                  finfo.easize = -1;
    948                  addFindInfoL(pConn, plist, &finfo, 0, NULL);
     985                 ((smbwrp_fileinfo*)_finfo)->easize = -1;
     986                 addFindInfoCachedL(plist, _finfo);
    949987                 break;
    950988              }
     
    10051043           {
    10061044              finfo.easize = -1;
    1007               addFindInfoL(pConn, plist, &finfo, 0, NULL);
     1045              addFindInfoL(pRes, plist, &finfo, 0, NULL);
    10081046           }
    10091047           else if (rc == ERROR_FILE_NOT_FOUND)
     
    10501088        Connection *pConn = (Connection *)conn;
    10511089        Resource *pRes = pConn->pRes;
    1052         int rc = NO_ERROR, count = 0;
     1090        int rc = NO_ERROR;
    10531091        unsigned long action;
    10541092        char *mask = "*";
    10551093        char dir[CCHMAXPATH+1] = {0};
    10561094        char path[CCHMAXPATH+1] = {0};
    1057         smbwrp_fileinfo * data;
    10581095        NDPATHELEMENT *pel = ph->fsphNameElem(0);
    10591096        filelist_state state;
     
    11371174        }
    11381175
    1139         debuglocal(pRes, 9, "NdpFindStart <%s> (%s) cnt %d %d\n", szPath, path, count, rc);
     1176        debuglocal(pRes, 9, "NdpFindStart <%s> (%s) rc %d\n", szPath, path, rc);
    11401177
    11411178        LEAVE();
     
    18161853           {
    18171854              finfo.easize = -1;
    1818               addFindInfoL(pConn, plist, &finfo, 0, NULL);
     1855              addFindInfoL(pRes, plist, &finfo, 0, NULL);
    18191856           }
    18201857        } while (0);
Note: See TracChangeset for help on using the changeset viewer.