Changeset 3432ddb in mainline
- Timestamp:
- 2013-08-07T20:37:22Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 81bd5f4
- Parents:
- 781408e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/df/df.c
r781408e r3432ddb 47 47 #define NAME "df" 48 48 49 #define HEADER_TABLE "Filesystem %4u-blocks Used Available Used%% Mounted on\n" 49 #define HEADER_TABLE "Filesystem %4u-blocks Used Available Used%% Mounted on" 50 #define HEADER_TABLE_HR "Filesystem Size Used Available Used%% Mounted on" 50 51 51 52 #define PERCENTAGE(x, tot) ((unsigned long long) (100L * (x) / (tot))) … … 56 57 57 58 static unsigned int unit_size; 59 static unsigned int human_readable; 58 60 61 static int size_to_human_readable(char buf[], uint64_t bytes) 62 static void print_header(void); 59 63 static void print_statfs(struct statfs *, char *, char *); 60 64 static void print_usage(void); … … 66 70 67 71 unit_size = 512; 72 human_readable = 0; 68 73 69 74 /******************************************/ … … 73 78 switch(optres) { 74 79 case 'h': 80 human_readable = 1; 75 81 break; 76 82 … … 111 117 LIST_INITIALIZE(mtab_list); 112 118 get_mtab_list(&mtab_list); 113 print f(HEADER_TABLE, unit_size);119 print_header(); 114 120 list_foreach(mtab_list, cur) { 115 121 mtab_ent_t *mtab_ent = list_get_instance(cur, mtab_ent_t, … … 122 128 } 123 129 130 static int size_to_human_readable(char buf[], uint64_t bytes) 131 { 132 const char *units = "BkMGTPEZY"; 133 int i = 0; 134 int limit; 135 136 limit = str_length(units); 137 while (bytes >= 1024) { 138 if (i >= limit) 139 return -1; 140 bytes /= 1024; 141 i++; 142 } 143 snprintf(buf, 6, "%4llu%c", (unsigned long long)bytes, units[i]); 144 145 return 0; 146 } 147 148 static void print_header(void) 149 { 150 if (human_readable) 151 printf(HEADER_TABLE_HR); 152 else 153 printf(HEADER_TABLE, unit_size); 154 putchar('\n'); 155 } 156 124 157 static void print_statfs(struct statfs *st, char *name, char *mountpoint) 125 158 { 126 159 printf("%10s", name); 127 printf(" %15llu %14llu %14llu %4llu%% %s\n", 128 FSBK_TO_BK(st->f_blocks, st->f_bsize, unit_size), /* Blocks */ 129 FSBK_TO_BK(st->f_blocks - st->f_bfree, st->f_bsize, unit_size), /* Used */ 130 FSBK_TO_BK(st->f_bfree, st->f_bsize, unit_size), /* Available */ 131 (st->f_blocks)?PERCENTAGE(st->f_blocks - st->f_bfree, st->f_blocks):0L, /* Used% */ 132 mountpoint /* Mounted on */ 133 ); 160 161 if (human_readable) { 162 char tmp[1024]; 163 size_to_human_readable(tmp, st->f_blocks * st->f_bsize); 164 printf(" %14s", tmp); /* Size */ 165 size_to_human_readable(tmp, (st->f_blocks - st->f_bfree) * st->f_bsize); 166 printf(" %14s", tmp); /* Used */ 167 size_to_human_readable(tmp, st->f_bfree * st->f_bsize); 168 printf(" %14s", tmp); /* Available */ 169 printf(" %4llu%% %s\n", 170 (st->f_blocks)?PERCENTAGE(st->f_blocks - st->f_bfree, st->f_blocks):0L, /* Used% */ 171 mountpoint /* Mounted on */ 172 ); 173 } 174 else 175 printf(" %15llu %14llu %14llu %4llu%% %s\n", 176 FSBK_TO_BK(st->f_blocks, st->f_bsize, unit_size), /* Blocks */ 177 FSBK_TO_BK(st->f_blocks - st->f_bfree, st->f_bsize, unit_size), /* Used */ 178 FSBK_TO_BK(st->f_bfree, st->f_bsize, unit_size), /* Available */ 179 (st->f_blocks)?PERCENTAGE(st->f_blocks - st->f_bfree, st->f_blocks):0L, /* Used% */ 180 mountpoint /* Mounted on */ 181 ); 182 134 183 } 135 184
Note:
See TracChangeset
for help on using the changeset viewer.