Changeset c111da2 in mainline for uspace/app/df


Ignore:
Timestamp:
2025-10-09T15:44:52Z (3 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
cfd04c4
Parents:
1a96db9
Message:

Create non-zero size file in Navigator, new newfile utility.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/df/df.c

    r1a96db9 rc111da2  
    11/*
     2 * Copyright (c) 2025 Jiri Svoboda
    23 * Copyright (c) 2013 Manuele Conti
    34 * All rights reserved.
     
    5657static bool display_blocks;
    5758
    58 static errno_t size_to_human_readable(uint64_t, size_t, char **);
    5959static void print_header(void);
    60 static errno_t print_statfs(vfs_statfs_t *, char *, char *);
     60static void print_statfs(vfs_statfs_t *, char *, char *);
    6161static void print_usage(void);
    6262
     
    6565        int optres, errflg = 0;
    6666        vfs_statfs_t st;
    67         errno_t rc;
    6867
    6968        display_blocks = false;
     
    109108        list_foreach(mtab_list, link, mtab_ent_t, mtab_ent) {
    110109                if (vfs_statfs_path(mtab_ent->mp, &st) == 0) {
    111                         rc = print_statfs(&st, mtab_ent->fs_name, mtab_ent->mp);
    112                         if (rc != EOK)
    113                                 return 1;
     110                        print_statfs(&st, mtab_ent->fs_name, mtab_ent->mp);
    114111                } else {
    115112                        fprintf(stderr, "Cannot get information for '%s' (%s).\n",
     
    120117        putchar('\n');
    121118        return 0;
    122 }
    123 
    124 static errno_t size_to_human_readable(uint64_t nblocks, size_t block_size, char **rptr)
    125 {
    126         capa_spec_t capa;
    127 
    128         capa_from_blocks(nblocks, block_size, &capa);
    129         capa_simplify(&capa);
    130         return capa_format(&capa, rptr);
    131119}
    132120
     
    141129}
    142130
    143 static errno_t print_statfs(vfs_statfs_t *st, char *name, char *mountpoint)
     131static void print_statfs(vfs_statfs_t *st, char *name, char *mountpoint)
    144132{
    145133        uint64_t const used_blocks = st->f_blocks - st->f_bfree;
    146134        unsigned const perc_used = PERCENTAGE(used_blocks, st->f_blocks);
    147         char *str;
    148         errno_t rc;
     135        char str[CAPA_BLOCKS_BUFSIZE];
    149136
    150137        printf("%10s", name);
     
    152139        if (!display_blocks) {
    153140                /* Print size */
    154                 rc = size_to_human_readable(st->f_blocks, st->f_bsize, &str);
    155                 if (rc != EOK)
    156                         goto error;
     141                capa_blocks_format_buf(st->f_blocks, st->f_bsize, str,
     142                    sizeof(str));
    157143                printf(" %14s", str);
    158                 free(str);
    159144
    160145                /* Number of used blocks */
    161                 rc = size_to_human_readable(used_blocks, st->f_bsize, &str);
    162                 if (rc != EOK)
    163                         goto error;
     146                capa_blocks_format_buf(used_blocks, st->f_bsize, str,
     147                    sizeof(str));
    164148                printf(" %14s", str);
    165                 free(str);
    166149
    167150                /* Number of available blocks */
    168                 rc = size_to_human_readable(st->f_bfree, st->f_bsize, &str);
    169                 if (rc != EOK)
    170                         goto error;
     151                capa_blocks_format_buf(st->f_bfree, st->f_bsize, str,
     152                    sizeof(str));
    171153                printf(" %14s", str);
    172                 free(str);
    173154
    174155                /* Percentage of used blocks */
     
    183164                    perc_used, mountpoint);
    184165        }
    185 
    186         return EOK;
    187 error:
    188         printf("\nError: Out of memory.\n");
    189         return ENOMEM;
    190166}
    191167
Note: See TracChangeset for help on using the changeset viewer.