Changes in uspace/app/df/df.c [651c8db:332513a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/df/df.c
r651c8db r332513a 50 50 #define HEADER_TABLE_HR "Filesystem Size Used Available Used%% Mounted on" 51 51 52 #define PERCENTAGE(x, tot) ( tot ? (100ULL * (x) / (tot)) : 0)52 #define PERCENTAGE(x, tot) ((unsigned long long) (100L * (x) / (tot))) 53 53 #define FSBK_TO_BK(x, fsbk, bk) \ 54 54 (((fsbk) != 0 && (fsbk) < (bk)) ? \ … … 59 59 static unsigned int human_readable; 60 60 61 static void size_to_human_readable(char *buf, uint64_t bytes);61 static int size_to_human_readable(char buf[], uint64_t bytes); 62 62 static void print_header(void); 63 63 static void print_statfs(struct statfs *, char *, char *); … … 90 90 91 91 case ':': 92 fprintf(stderr, "Option -%c requires an operand\n", 93 optopt); 92 fprintf(stderr, "Option -%c requires an operand\n", optopt); 94 93 errflg++; 95 94 break; … … 101 100 102 101 default: 103 fprintf(stderr, 104 "Unknown error while parsing command line options"); 102 fprintf(stderr, "Unknown error while parsing command line options."); 105 103 errflg++; 106 104 break; … … 109 107 110 108 if (optind > argc) { 111 fprintf(stderr, "Too many input parameter s\n");109 fprintf(stderr, "Too many input parameter\n"); 112 110 errflg++; 113 111 } … … 120 118 LIST_INITIALIZE(mtab_list); 121 119 get_mtab_list(&mtab_list); 122 123 120 print_header(); 124 121 list_foreach(mtab_list, link, mtab_ent_t, mtab_ent) { … … 126 123 print_statfs(&st, mtab_ent->fs_name, mtab_ent->mp); 127 124 } 128 129 125 putchar('\n'); 130 126 return 0; 131 127 } 132 128 133 static void size_to_human_readable(char *buf, uint64_t bytes)129 static int size_to_human_readable(char buf[], uint64_t bytes) 134 130 { 135 131 const char *units = "BkMGTPEZY"; 136 132 int i = 0; 133 int limit; 137 134 135 limit = str_length(units); 138 136 while (bytes >= 1024) { 137 if (i >= limit) 138 return -1; 139 139 bytes /= 1024; 140 140 i++; 141 141 } 142 snprintf(buf, 6, "%4llu%c", (unsigned long long)bytes, units[i]); 142 143 143 snprintf(buf, 6, "%4llu%c", (unsigned long long) bytes, units[i]);144 return 0; 144 145 } 145 146 … … 150 151 else 151 152 printf(HEADER_TABLE, unit_size); 152 153 153 putchar('\n'); 154 154 } … … 156 156 static void print_statfs(struct statfs *st, char *name, char *mountpoint) 157 157 { 158 uint64_t const used_blocks = st->f_blocks - st->f_bfree;159 unsigned const perc_used = PERCENTAGE(used_blocks, st->f_blocks);160 161 158 printf("%10s", name); 162 159 163 160 if (human_readable) { 164 161 char tmp[1024]; 165 166 /* Print size */167 162 size_to_human_readable(tmp, st->f_blocks * st->f_bsize); 168 printf(" %14s", tmp); 169 170 /* Number of used blocks */ 171 size_to_human_readable(tmp, used_blocks * st->f_bsize); 172 printf(" %14s", tmp); 173 174 /* Number of available blocks */ 163 printf(" %14s", tmp); /* Size */ 164 size_to_human_readable(tmp, (st->f_blocks - st->f_bfree) * st->f_bsize); 165 printf(" %14s", tmp); /* Used */ 175 166 size_to_human_readable(tmp, st->f_bfree * st->f_bsize); 176 printf(" %14s", tmp); 177 178 /* Percentage of used blocks */ 179 printf(" %4u%%", perc_used); 180 181 /* Mount point */ 182 printf(" %s\n", mountpoint); 183 } else { 184 /* Blocks / Used blocks / Available blocks / Used% / Mounted on */ 185 printf(" %15llu %14llu %14llu %4u%% %s\n", 186 FSBK_TO_BK(st->f_blocks, st->f_bsize, unit_size), 187 FSBK_TO_BK(used_blocks, st->f_bsize, unit_size), 188 FSBK_TO_BK(st->f_bfree, st->f_bsize, unit_size), 189 perc_used, 190 mountpoint); 167 printf(" %14s", tmp); /* Available */ 168 printf(" %4llu%% %s\n", 169 (st->f_blocks)?PERCENTAGE(st->f_blocks - st->f_bfree, st->f_blocks):0L, /* Used% */ 170 mountpoint /* Mounted on */ 171 ); 191 172 } 173 else 174 printf(" %15llu %14llu %14llu %4llu%% %s\n", 175 FSBK_TO_BK(st->f_blocks, st->f_bsize, unit_size), /* Blocks */ 176 FSBK_TO_BK(st->f_blocks - st->f_bfree, st->f_bsize, unit_size), /* Used */ 177 FSBK_TO_BK(st->f_bfree, st->f_bsize, unit_size), /* Available */ 178 (st->f_blocks)?PERCENTAGE(st->f_blocks - st->f_bfree, st->f_blocks):0L, /* Used% */ 179 mountpoint /* Mounted on */ 180 ); 192 181 193 182 }
Note:
See TracChangeset
for help on using the changeset viewer.