openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/util-linux/2.33.2-r0/util-linux-2.33.2/disk-utils/cfdisk.c
static int lines_refresh(struct cfdisk* cf)
{
    int rc;
    char* p;
    size_t i;

    assert(cf);

    DBG(TABLE, ul_debug("refreshing buffer"));

    free(cf->linesbuf);
    cfdisk_free_lines(cf);
    cf->linesbuf = NULL;
    cf->linesbufsz = 0;
    cf->lines = NULL;
    cf->nlines = 0;

    fdisk_unref_table(cf->table);
    cf->table = NULL;

    /* read partitions and free spaces into cf->table */
    rc = fdisk_get_partitions(cf->cxt, &cf->table);
    if (!rc)
        rc = fdisk_get_freespaces(cf->cxt, &cf->table);
    if (rc)
        return rc;

    cf->linesbuf = table_to_string(cf, cf->table);
    if (!cf->linesbuf)
        return -ENOMEM;

    cf->linesbufsz = strlen(cf->linesbuf);
    cf->nlines = fdisk_table_get_nents(cf->table) + 1; /* 1 for header line */
    cf->page_sz = 0;
    cf->wrong_order = fdisk_table_wrong_order(cf->table) ? 1 : 0;

    if (MENU_START_LINE - TABLE_START_LINE < cf->nlines)
        cf->page_sz = MENU_START_LINE - TABLE_START_LINE - 1;

    cf->lines = xcalloc(cf->nlines, sizeof(struct cfdisk_line));

    for (p = cf->linesbuf, i = 0; p && i < cf->nlines; i++)
    {
        cf->lines[i].data = p;
        p = strchr(p, '\n');
        if (p)
        {
            *p = '\0';
            p++;
        }
        cf->lines[i].extra = scols_new_table();
        scols_table_enable_noheadings(cf->lines[i].extra, 1);
        scols_table_new_column(cf->lines[i].extra, NULL, 0, SCOLS_FL_RIGHT);
        scols_table_new_column(cf->lines[i].extra, NULL, 0, SCOLS_FL_TRUNC);
    }

    return 0;
}
/*
 * Read data about partitions from libfdisk and prepare output lines.
 */
Read data about partitions from libfdisk and prepare output lines.
Read data about partitions from libfdisk and prepare output lines .
static int lines_refresh(struct cfdisk* cf)
{
    int rc;
    char* p;
    size_t i;
    assert(cf);
    DBG(TABLE, ul_debug("refreshing buffer"));
    free(cf->linesbuf);
    cfdisk_free_lines(cf);
    cf->linesbuf = NULL;
    cf->linesbufsz = 0;
    cf->lines = NULL;
    cf->nlines = 0;
    fdisk_unref_table(cf->table);
    cf->table = NULL;
    rc = fdisk_get_partitions(cf->cxt, &cf->table);
    if (!rc)
        rc = fdisk_get_freespaces(cf->cxt, &cf->table);
    if (rc)
        return rc;
    cf->linesbuf = table_to_string(cf, cf->table);
    if (!cf->linesbuf)
        return -ENOMEM;
    cf->linesbufsz = strlen(cf->linesbuf);
    cf->nlines = fdisk_table_get_nents(cf->table) + 1; 
    cf->page_sz = 0;
    cf->wrong_order = fdisk_table_wrong_order(cf->table) ? 1 : 0;
    if (MENU_START_LINE - TABLE_START_LINE < cf->nlines)
        cf->page_sz = MENU_START_LINE - TABLE_START_LINE - 1;
    cf->lines = xcalloc(cf->nlines, sizeof(struct cfdisk_line));
    for (p = cf->linesbuf, i = 0; p && i < cf->nlines; i++)
    {
        cf->lines[i].data = p;
        p = strchr(p, '\n');
        if (p)
        {
            *p = '\0';
            p++;
        }
        cf->lines[i].extra = scols_new_table();
        scols_table_enable_noheadings(cf->lines[i].extra, 1);
        scols_table_new_column(cf->lines[i].extra, NULL, 0, SCOLS_FL_RIGHT);
        scols_table_new_column(cf->lines[i].extra, NULL, 0, SCOLS_FL_TRUNC);
    }
    return 0;
}
static int lines_refresh ( struct cfdisk * cf ) { int rc ; char * p ; size_t i ; assert ( cf ) ; DBG ( TABLE , ul_debug ( " " ) ) ; free ( cf -> linesbuf ) ; cfdisk_free_lines ( cf ) ; cf -> linesbuf = NULL ; cf -> linesbufsz = 0 ; cf -> lines = NULL ; cf -> nlines = 0 ; fdisk_unref_table ( cf -> table ) ; cf -> table = NULL ; rc = fdisk_get_partitions ( cf -> cxt , & cf -> table ) ; if ( ! rc ) rc = fdisk_get_freespaces ( cf -> cxt , & cf -> table ) ; if ( rc ) return rc ; cf -> linesbuf = table_to_string ( cf , cf -> table ) ; if ( ! cf -> linesbuf ) return - ENOMEM ; cf -> linesbufsz = strlen ( cf -> linesbuf ) ; cf -> nlines = fdisk_table_get_nents ( cf -> table ) + 1 ; cf -> page_sz = 0 ; cf -> wrong_order = fdisk_table_wrong_order ( cf -> table ) ? 1 : 0 ; if ( MENU_START_LINE - TABLE_START_LINE < cf -> nlines ) cf -> page_sz = MENU_START_LINE - TABLE_START_LINE - 1 ; cf -> lines = xcalloc ( cf -> nlines , sizeof ( struct cfdisk_line ) ) ; for ( p = cf -> linesbuf , i = 0 ; p && i < cf -> nlines ; i ++ ) { cf -> lines [ i ] . data = p ; p = strchr ( p , ' \n ' ) ; if ( p ) { * p = ' \0 ' ; p ++ ; } cf -> lines [ i ] . extra = scols_new_table ( ) ; scols_table_enable_noheadings ( cf -> lines [ i ] . extra , 1 ) ; scols_table_new_column ( cf -> lines [ i ] . extra , NULL , 0 , SCOLS_FL_RIGHT ) ; scols_table_new_column ( cf -> lines [ i ] . extra , NULL , 0 , SCOLS_FL_TRUNC ) ; } return 0 ; }
Read data about partitions from libfdisk and prepare output lines.
Read data about partitions from libfdisk and prepare output lines .
/* read partitions and free spaces into cf->table */ /* 1 for header line */