openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/mtd-utils/2.1.0+AUTOINC+b5027be5f4-r0/git/ubifs-utils/mkfs.ubifs/lpt.c
int calc_dflt_lpt_geom(struct ubifs_info* c, int* main_lebs, int* big_lpt)
{
    int i, lebs_needed;
    long long sz;

    /* Start by assuming the minimum number of LPT LEBs */
    c->lpt_lebs = UBIFS_MIN_LPT_LEBS;
    c->main_lebs = *main_lebs - c->lpt_lebs;
    if (c->main_lebs <= 0)
        return -EINVAL;

    /* And assume we will use the small LPT model */
    c->big_lpt = 0;

    /*
     * Calculate the geometry based on assumptions above and then see if it
     * makes sense
     */
    do_calc_lpt_geom(c);

    /* Small LPT model must have lpt_sz < leb_size */
    if (c->lpt_sz > c->leb_size)
    {
        /* Nope, so try again using big LPT model */
        c->big_lpt = 1;
        do_calc_lpt_geom(c);
    }

    /* Now check there are enough LPT LEBs */
    for (i = 0; i < 64; i++)
    {
        sz = c->lpt_sz * 4; /* Allow 4 times the size */
        sz += c->leb_size - 1;
        do_div(sz, c->leb_size);
        lebs_needed = sz;
        if (lebs_needed > c->lpt_lebs)
        {
            /* Not enough LPT LEBs so try again with more */
            c->lpt_lebs = lebs_needed;
            c->main_lebs = *main_lebs - c->lpt_lebs;
            if (c->main_lebs <= 0)
                return -EINVAL;
            do_calc_lpt_geom(c);
            continue;
        }
        if (c->ltab_sz > c->leb_size)
        {
            err_msg("LPT ltab too big");
            return -EINVAL;
        }
        *main_lebs = c->main_lebs;
        *big_lpt = c->big_lpt;
        return 0;
    }
    return -EINVAL;
}
/**
 * calc_dflt_lpt_geom - calculate default LPT geometry.
 * @c: the UBIFS file-system description object
 * @main_lebs: number of main area LEBs is passed and returned here
 * @big_lpt: whether the LPT area is "big" is returned here
 *
 * The size of the LPT area depends on parameters that themselves are dependent
 * on the size of the LPT area. This function, successively recalculates the LPT
 * area geometry until the parameters and resultant geometry are consistent.
 *
 * This function returns %0 on success and a negative error code on failure.
 */
calculate default LPT geometry.
@c: the UBIFS file-system description object
@main_lebs: number of main area LEBs is passed and returned here
@big_lpt: whether the LPT area is "big" is returned here

The size of the LPT area depends on parameters that themselves are dependent
on the size of the LPT area. This function, successively recalculates the LPT
area geometry until the parameters and resultant geometry are consistent.

This function returns %0 on success and a negative error code on failure.
calculate default LPT geometry . @c : the UBIFS file - system description object @main_lebs : number of main area LEBs is passed and returned here @big_lpt : whether the LPT area is " big " is returned here The size of the LPT area depends on parameters that themselves are dependent on the size of the LPT area . This function successively recalculates the LPT area geometry until the parameters and resultant geometry are consistent . This function returns %0 on success and a negative error code on failure .
int calc_dflt_lpt_geom(struct ubifs_info* c, int* main_lebs, int* big_lpt)
{
    int i, lebs_needed;
    long long sz;
    c->lpt_lebs = UBIFS_MIN_LPT_LEBS;
    c->main_lebs = *main_lebs - c->lpt_lebs;
    if (c->main_lebs <= 0)
        return -EINVAL;
    c->big_lpt = 0;
    do_calc_lpt_geom(c);
    if (c->lpt_sz > c->leb_size)
    {
        c->big_lpt = 1;
        do_calc_lpt_geom(c);
    }
    for (i = 0; i < 64; i++)
    {
        sz = c->lpt_sz * 4; 
        sz += c->leb_size - 1;
        do_div(sz, c->leb_size);
        lebs_needed = sz;
        if (lebs_needed > c->lpt_lebs)
        {
            c->lpt_lebs = lebs_needed;
            c->main_lebs = *main_lebs - c->lpt_lebs;
            if (c->main_lebs <= 0)
                return -EINVAL;
            do_calc_lpt_geom(c);
            continue;
        }
        if (c->ltab_sz > c->leb_size)
        {
            err_msg("LPT ltab too big");
            return -EINVAL;
        }
        *main_lebs = c->main_lebs;
        *big_lpt = c->big_lpt;
        return 0;
    }
    return -EINVAL;
}
int calc_dflt_lpt_geom ( struct ubifs_info * c , int * main_lebs , int * big_lpt ) { int i , lebs_needed ; long long sz ; c -> lpt_lebs = UBIFS_MIN_LPT_LEBS ; c -> main_lebs = * main_lebs - c -> lpt_lebs ; if ( c -> main_lebs <= 0 ) return - EINVAL ; c -> big_lpt = 0 ; do_calc_lpt_geom ( c ) ; if ( c -> lpt_sz > c -> leb_size ) { c -> big_lpt = 1 ; do_calc_lpt_geom ( c ) ; } for ( i = 0 ; i < 64 ; i ++ ) { sz = c -> lpt_sz * 4 ; sz += c -> leb_size - 1 ; do_div ( sz , c -> leb_size ) ; lebs_needed = sz ; if ( lebs_needed > c -> lpt_lebs ) { c -> lpt_lebs = lebs_needed ; c -> main_lebs = * main_lebs - c -> lpt_lebs ; if ( c -> main_lebs <= 0 ) return - EINVAL ; do_calc_lpt_geom ( c ) ; continue ; } if ( c -> ltab_sz > c -> leb_size ) { err_msg ( " " ) ; return - EINVAL ; } * main_lebs = c -> main_lebs ; * big_lpt = c -> big_lpt ; return 0 ; } return - EINVAL ; }
calc_dflt_lpt_geom - calculate default LPT geometry.
calc_dflt_lpt_geom - calculate default LPT geometry .
/* Start by assuming the minimum number of LPT LEBs */ /* And assume we will use the small LPT model */ /*
     * Calculate the geometry based on assumptions above and then see if it
     * makes sense
     */ /* Small LPT model must have lpt_sz < leb_size */ /* Nope, so try again using big LPT model */ /* Now check there are enough LPT LEBs */ /* Allow 4 times the size */ /* Not enough LPT LEBs so try again with more */