Changeset c111da2 in mainline for uspace/app/df
- Timestamp:
- 2025-10-09T15:44:52Z (3 months ago)
- Branches:
- master
- Children:
- cfd04c4
- Parents:
- 1a96db9
- File:
-
- 1 edited
-
uspace/app/df/df.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/df/df.c
r1a96db9 rc111da2 1 1 /* 2 * Copyright (c) 2025 Jiri Svoboda 2 3 * Copyright (c) 2013 Manuele Conti 3 4 * All rights reserved. … … 56 57 static bool display_blocks; 57 58 58 static errno_t size_to_human_readable(uint64_t, size_t, char **);59 59 static void print_header(void); 60 static errno_tprint_statfs(vfs_statfs_t *, char *, char *);60 static void print_statfs(vfs_statfs_t *, char *, char *); 61 61 static void print_usage(void); 62 62 … … 65 65 int optres, errflg = 0; 66 66 vfs_statfs_t st; 67 errno_t rc;68 67 69 68 display_blocks = false; … … 109 108 list_foreach(mtab_list, link, mtab_ent_t, mtab_ent) { 110 109 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); 114 111 } else { 115 112 fprintf(stderr, "Cannot get information for '%s' (%s).\n", … … 120 117 putchar('\n'); 121 118 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);131 119 } 132 120 … … 141 129 } 142 130 143 static errno_tprint_statfs(vfs_statfs_t *st, char *name, char *mountpoint)131 static void print_statfs(vfs_statfs_t *st, char *name, char *mountpoint) 144 132 { 145 133 uint64_t const used_blocks = st->f_blocks - st->f_bfree; 146 134 unsigned const perc_used = PERCENTAGE(used_blocks, st->f_blocks); 147 char *str; 148 errno_t rc; 135 char str[CAPA_BLOCKS_BUFSIZE]; 149 136 150 137 printf("%10s", name); … … 152 139 if (!display_blocks) { 153 140 /* 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)); 157 143 printf(" %14s", str); 158 free(str);159 144 160 145 /* 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)); 164 148 printf(" %14s", str); 165 free(str);166 149 167 150 /* 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)); 171 153 printf(" %14s", str); 172 free(str);173 154 174 155 /* Percentage of used blocks */ … … 183 164 perc_used, mountpoint); 184 165 } 185 186 return EOK;187 error:188 printf("\nError: Out of memory.\n");189 return ENOMEM;190 166 } 191 167
Note:
See TracChangeset
for help on using the changeset viewer.
