Changeset 464


Ignore:
Timestamp:
Jul 28, 2003, 7:59:54 PM (22 years ago)
Author:
bird
Message:

Make intelligent guesses about the page size.

Location:
trunk/src/emx/src/emxomf
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/src/emxomf/emxomf.c

    • Property cvs2svn:cvs-rev changed from 1.14 to 1.15
    r463 r464  
    3131#include <sys/param.h>
    3232#include <sys/emxload.h>
     33#include <sys/types.h>
     34#include <sys/stat.h>
    3335#include <ar.h>
    3436
     
    261263/* This is the page size for OMF libraries.  It is set by the -p
    262264   option. */
    263 static int page_size = 16;
     265static int page_size = 0;
    264266
    265267/* The index of the next OMF name, used by find_lname().  Name indices
     
    35483550      if (!opt_x)
    35493551        {
     3552          /* calculate a page size based on the size of the aout library.
     3553             Since we don't yet know the number of files it contains, we'll
     3554             assum the converted library isn't more than the double it's size.
     3555             Or at least we can hope it's not... */
     3556          struct stat s;
     3557          int calculated_page_size = page_size;
     3558          if (calculated_page_size <= 0)
     3559            { /* For a better calculation we would need the file count. */
     3560              calculated_page_size = 16;
     3561              if (!stat(src_fname, &s))
     3562                {
     3563                  int cbPage = (s.st_size * 2) / 65536;
     3564                  while (calculated_page_size < cbPage)
     3565                      calculated_page_size <<= 1;
     3566                }
     3567              if (1)
     3568                printf("calculated page size %d\n", calculated_page_size);
     3569            }
     3570
    35503571          make_out_fname (dst_fname, inp_fname, ".lib");
    3551           out_lib = omflib_create (out_fname, page_size, lib_errmsg);
     3572          out_lib = omflib_create (out_fname, calculated_page_size, lib_errmsg);
    35523573          if (out_lib == NULL)
    35533574            error (lib_errmsg);
  • trunk/src/emx/src/emxomf/emxomfar.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r463 r464  
    2424#include <string.h>
    2525#include <io.h>
     26#include <sys/types.h>
     27#include <sys/stat.h>
    2628#include <sys/omflib.h>
     29
    2730
    2831#define FALSE 0
     
    154157
    155158
     159
     160/**
     161 * Calculate the expected page size for a library based on the
     162 * parameters which is specified.
     163 *
     164 * @returns
     165 * @param   papszFiles  Pointer to a vector of files.
     166 * @param   chCmd       The command we're processing.
     167 * @remark  Only applies when creating a new library.
     168 */
     169static int calc_pagesize(char **papszFiles, const char chCmd)
     170{
     171    unsigned    cFiles;
     172    size_t      cbFiles;
     173    int         cbPage;
     174    int         i;
     175
     176    /* if it's not a replace command return default size. */
     177    if (chCmd != 'r')
     178        return 16;
     179
     180    /*
     181     * Count the files and sum their sizes.
     182     */
     183    for (i = 0, cFiles = 0, cbFiles = 0; papszFiles[i]; i++)
     184    {
     185        struct stat s;
     186        cFiles++;
     187        if (!stat(papszFiles[i], &s))
     188            cbFiles += s.st_size;
     189        else
     190            cbFiles += 128 * 1024;      /* file not found? just guess a size, 128kb. */
     191    }
     192
     193    /*
     194     * We'll need an approximation of this formula:
     195     * cbPage = (cbPage * cFiles + cbFiles) / 65535;
     196     *
     197     * Let's do the calculation assuming cbPage being 256.
     198     * We'll also add a few files (just for case that any of these were a library),
     199     * and a couple extra of bytes too.
     200     */
     201    cbFiles += cFiles * 4096;
     202    cFiles += 64;
     203    cbPage = (256 * cFiles + cbFiles) / 65536;
     204    for (i = 16; i < cbPage; )
     205        i <<= 1;
     206
     207    if (verbose)
     208        printf("calculated page size %d\n", i);
     209    return i;
     210}
     211
    156212/* Cleanup, for atexit. */
    157213
     
    196252  _wildcard (&argc, &argv);
    197253
    198   /* The default page size is 16. */
    199 
    200   page_size = 16;
     254  /* The default page size was 16, now we'll calculate one with
     255     a minimum of 16. */
     256
     257  page_size = 0;
    201258
    202259  /* Parse the command line.  First, check for an -p# option. */
     
    358415  if (cmd == 'r' || cmd == 'd')
    359416    {
     417      if (page_size <= 0)
     418        page_size = calc_pagesize(&argv[i], cmd);
    360419      new_lib = omflib_create (new_fname, page_size, error);
    361420      if (new_lib == NULL)
Note: See TracChangeset for help on using the changeset viewer.