Changeset 783 for trunk/dll/dirsize.c


Ignore:
Timestamp:
Aug 14, 2007, 6:09:54 AM (18 years ago)
Author:
Steven Levine
Message:

Rework DosFindFirst/Next loops to optimize memory allocation and code paths
Adjust FilesToGet limits
Update configuration notebook scanning page
Start updating #pragma alloc_text positioning for OpenWatcom compatibility

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/dirsize.c

    r781 r783  
    2828  03 Aug 07 SHL DirSizeProc; correct sizing and positioning to be deterministic
    2929  06 Aug 07 GKY Reduce DosSleep times (ticket 148)
    30   11 Aug 07 SHL ProcessDir: remove unneeded reallocs
     30  13 Aug 07 SHL ProcessDir: remove unneeded reallocs.  Sanitize code
     31  13 Aug 07 SHL Move #pragma alloc_text to end for OpenWatcom compat
    3132
    3233***********************************************************************/
     
    6869static PSZ pszSrcFile = __FILE__;
    6970
    70 #pragma alloc_text(DIRSIZE,ProcessDir,FillCnrThread,DirSizeProc)
    71 #pragma alloc_text(DIRSIZE2,PrintToFile,FillInRecSizes,SortSizeCnr)
    72 
    73 static SHORT APIENTRY SortSizeCnr(PMINIRECORDCORE p1, PMINIRECORDCORE p2,
     71static SHORT APIENTRY SortSizeCnr(PMINIRECORDCORE p1,
     72                                  PMINIRECORDCORE p2,
    7473                                  PVOID SortFlags)
    7574{
     
    9594  register char *sp;
    9695  register char *pp;
    97   ULONG nm;
     96  ULONG ulFindCnt;
    9897  ULONGLONG ullCurDirBytes = 0;
    9998  ULONGLONG ullSubDirBytes = 0;
    10099  ULONGLONG ull;
    101100  HDIR hdir;
    102   FILEFINDBUF4 *pffb;
     101  PFILEFINDBUF4 pffbArray;
    103102  APIRET rc;
    104103  RECORDINSERT ri;
    105104  PCNRITEM pci;
    106 
    107   // fixme to report errors
     105  ULONG ulBufBytes;
     106
    108107  *pullTotalBytes = 0;                  // In case we fail
    109108
    110   pffb = xmalloc(sizeof(FILEFINDBUF4) * FilesToGet, pszSrcFile, __LINE__);
    111   if (!pffb)
     109  ulBufBytes = sizeof(FILEFINDBUF4) * FilesToGet;
     110  pffbArray = xmalloc(ulBufBytes, pszSrcFile, __LINE__);
     111  if (!pffbArray)
    112112    return FALSE;                       // Error already reported
    113113
     
    119119
    120120  hdir = HDIR_CREATE;
    121   nm = 1;
    122   // 11 Aug 07 SHL fixme to know if we can bypass memset
    123   memset(pffb, 0, sizeof(FILEFINDBUF4));
     121  ulFindCnt = 1;
     122  // memset(pffbArray, 0, sizeof(FILEFINDBUF4));        // 11 Aug 07 SHL bypass memset
    124123  DosError(FERR_DISABLEHARDERR);
    125124  // Check directory exists
     
    127126                    FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED |
    128127                    FILE_SYSTEM | FILE_HIDDEN | MUST_HAVE_DIRECTORY,
    129                     pffb, sizeof(FILEFINDBUF4), &nm, FIL_QUERYEASIZE);
     128                    pffbArray, ulBufBytes, &ulFindCnt, FIL_QUERYEASIZE);
    130129
    131130  if (!rc)
     
    137136   * requesting EASIZE.  sheesh.
    138137   */
    139   if ((!rc && (pffb->attrFile & FILE_DIRECTORY)) || strlen(pszFileName) < 4) {
     138  if ((!rc && (pffbArray->attrFile & FILE_DIRECTORY)) || strlen(pszFileName) < 4) {
    140139    if (*pchStopFlag) {
    141       free(pffb);
     140      free(pffbArray);
    142141      return FALSE;
    143142    }
     
    145144                     MPFROMLONG(1));
    146145    if (!pci) {
    147       free(pffb);
     146      Win_Error(hwndCnr, HWND_DESKTOP, pszSrcFile, __LINE__, "CM_ALLOCRECORD");
     147      free(pffbArray);
    148148      return FALSE;
    149149    }
    150150    if (!rc) {
    151       ullCurDirBytes = pffb->cbFile;
    152       ullCurDirBytes += CBLIST_TO_EASIZE(pffb->cbList);
     151      ullCurDirBytes = pffbArray->cbFile;
     152      ullCurDirBytes += CBLIST_TO_EASIZE(pffbArray->cbList);
    153153    }
    154154    else
     
    161161  else {
    162162    // No match
    163     free(pffb);
     163    free(pffbArray);
    164164    Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
    165165              GetPString(IDS_CANTFINDDIRTEXT), pszFileName);
     
    186186    pci->pszFileName = xstrdup(szBuf, pszSrcFile, __LINE__);
    187187  }
    188   // fixme to know why - it appears to be indirectly saving length, but why?
     188  // fixme to understand this - appears to be indirectly saving length, but why?
    189189  pci->pszDisplayName = pci->pszFileName + strlen(pci->pszFileName);
    190190  pci->pszLongName = pci->pszFileName;  // fixme to be sure?
     
    204204  ri.fInvalidateRecord = TRUE;
    205205  if (!WinSendMsg(hwndCnr, CM_INSERTRECORD, MPFROMP(pci), MPFROMP(&ri))) {
    206     free(pffb);
     206    free(pffbArray);
    207207    return FALSE;
    208208  }
     
    210210  // Find files and directories in this directory
    211211  hdir = HDIR_CREATE;
    212   nm = FilesToGet;
     212  // 13 Aug 07 SHL fixme to know if need to support fRemoteBug here like objcnr.c?
     213  ulFindCnt = FilesToGet;
    213214  rc = DosFindFirst(maskstr, &hdir,
    214215                    FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED |
    215216                    FILE_SYSTEM | FILE_HIDDEN | FILE_DIRECTORY,
    216                     pffb, nm * sizeof(FILEFINDBUF4), &nm, FIL_QUERYEASIZE);
     217                    pffbArray, ulBufBytes, &ulFindCnt, FIL_QUERYEASIZE);
    217218  if (!rc) {
    218     PBYTE fb = (PBYTE)pffb;
    219     FILEFINDBUF4 *pffbFile;
     219    PFILEFINDBUF4 pffbFile;
    220220    ULONG x;
    221221
    222222    while (!rc) {
     223
     224#if 0 // 13 Aug 07 SHL fixme to be gone
     225      {
     226        static ULONG ulMaxCnt = 1;
     227        if (ulFindCnt > ulMaxCnt) {
     228          ulMaxCnt = ulFindCnt;
     229          DbgMsg(pszSrcFile, __LINE__, "ulMaxCnt %u/%u", ulMaxCnt, FilesToGet);
     230        }
     231      }
     232#endif
     233
    223234      priority_normal();
    224       for (x = 0; x < nm; x++) {
    225         pffbFile = (FILEFINDBUF4 *)fb;
     235      pffbFile = pffbArray;
     236      for (x = 0; x < ulFindCnt; x++) {
    226237        // Total size skipping . and ..
    227238        if ((~pffbFile->attrFile & FILE_DIRECTORY) ||
     
    232243          ullCurDirBytes += CBLIST_TO_EASIZE(pffbFile->cbList) & 0x3ff;
    233244
    234           if (!(pffbFile->attrFile & FILE_DIRECTORY))
    235             pci->attrFile++;            // Bump file count
    236245          if (*pchStopFlag)
    237246            break;
    238           if (pffbFile->attrFile & FILE_DIRECTORY) {
     247          if (~pffbFile->attrFile & FILE_DIRECTORY)
     248            pci->attrFile++;            // Bump file count
     249          else {
    239250            // Recurse into subdir
    240251            strcpy(pEndMask, pffbFile->achName);        // Append dirname to base dirname
    241             if (!*pchStopFlag) {
    242               ProcessDir(hwndCnr, maskstr, pci, pchStopFlag, FALSE, &ull);
    243               ullSubDirBytes += ull;
    244             }
     252            ProcessDir(hwndCnr, maskstr, pci, pchStopFlag, FALSE, &ull);
     253            ullSubDirBytes += ull;
    245254          }
    246255        }
    247256        if (!pffbFile->oNextEntryOffset)
    248257          break;
    249         fb += pffbFile->oNextEntryOffset;
     258        pffbFile = (PFILEFINDBUF4)((PBYTE)pffbFile + pffbFile->oNextEntryOffset);
     259
     260#if 0 // 13 Aug 07 SHL fixme to be gone
     261        {
     262          static ULONG ulMaxBytes = 65535;
     263          ULONG ul = (PBYTE)pffbFile - (PBYTE)pffbArray;
     264          if (ul > ulMaxBytes) {
     265            ulMaxBytes = ul;
     266            DbgMsg(pszSrcFile, __LINE__, "ulFindCnt %u/%u ulMaxBytes %u/%u",
     267                   ulFindCnt, FilesToGet, ulMaxBytes, ulBufBytes);
     268          }
     269        }
     270#endif
     271
    250272      } // for matches
    251273      if (*pchStopFlag)
    252274        break;
    253       DosSleep(1);
    254       nm = FilesToGet;
     275      DosSleep(0);
     276      ulFindCnt = FilesToGet;
    255277      DosError(FERR_DISABLEHARDERR);
    256       rc = DosFindNext(hdir, pffb, sizeof(FILEFINDBUF4) * FilesToGet, &nm);
     278      rc = DosFindNext(hdir, pffbArray, ulBufBytes, &ulFindCnt);
    257279    } // while more found
    258 
    259     if (rc != ERROR_NO_MORE_FILES) {
    260       Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
    261                 GetPString(IDS_CANTFINDDIRTEXT), pszFileName);
    262     }
    263280
    264281    DosFindClose(hdir);
     
    266283  } // if got files or directories
    267284
    268   free(pffb);
     285  if (rc && rc != ERROR_NO_MORE_FILES) {
     286    Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
     287              GetPString(IDS_CANTFINDDIRTEXT), pszFileName);
     288  }
     289
     290  free(pffbArray);
    269291
    270292  pci->cbFile = ullCurDirBytes;
     
    407429}
    408430
    409 static VOID FillCnrThread(VOID * args)
     431static VOID FillCnrThread(VOID *args)
    410432{
    411433  HAB hab;
    412434  HMQ hmq;
    413   DIRSIZE *dirsize = (DIRSIZE *) args;
     435  DIRSIZE *dirsize = (DIRSIZE *)args;
    414436  HWND hwndCnr;
    415437  ULONGLONG ull;
    416438
    417   if (!dirsize)
     439  if (!dirsize) {
     440    Runtime_Error(pszSrcFile, __LINE__, "no data");
    418441    return;
     442  }
     443
    419444  hwndCnr = dirsize->hwndCnr;
    420445
     
    965990  return WinDefDlgProc(hwnd, msg, mp1, mp2);
    966991}
     992
     993#pragma alloc_text(DIRSIZE,ProcessDir,FillCnrThread,DirSizeProc)
     994#pragma alloc_text(DIRSIZE2,PrintToFile,FillInRecSizes,SortSizeCnr)
     995
Note: See TracChangeset for help on using the changeset viewer.