Changeset be99d30 in mainline
- Timestamp:
- 2013-07-18T22:20:11Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8a8a08d1
- Parents:
- e2f706e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/df/df.c
re2f706e rbe99d30 39 39 #include <unistd.h> 40 40 #include <stdint.h> 41 #include <getopt.h> 41 42 #include <sys/statfs.h> 42 43 #include <errno.h> … … 46 47 #define NAME "df" 47 48 48 #define HEADER_TABLE "Filesystem 512-blocks Used Available Used%Mounted on"49 #define HEADER_TABLE "Filesystem 512-blocks Used Available Used% Mounted on" 49 50 50 51 #define PERCENTAGE(x, tot) ((unsigned long long) (100L * (x) / (tot))) 52 #define FSBK_TO_BK(x, fsbk, bk) \ 53 (((fsbk) != 0 && (fsbk) < (bk)) ? \ 54 (unsigned long long) ((x) / ((bk) / (fsbk))) : \ 55 (unsigned long long) ((x) * ((fsbk) / (bk)))) 56 57 static void print_statfs(struct statfs *, char *, char *); 58 static void print_usage(void); 51 59 52 60 int main(int argc, char *argv[]) 53 61 { 62 int optres, errflg = 0; 54 63 struct statfs st; 64 65 /******************************************/ 66 /* Parse command line options... */ 67 /******************************************/ 68 while ((optres = getopt(argc, argv, ":hi")) != -1) { 69 switch(optres) { 70 case 'h': 71 break; 72 case 'i': 73 break; 74 75 case ':': 76 fprintf(stderr, "Option -%c requires an operand\n", optopt); 77 errflg++; 78 break; 55 79 80 case '?': 81 fprintf(stderr, "Unrecognized option: -%c\n", optopt); 82 errflg++; 83 break; 84 85 default: 86 fprintf(stderr, "Unknown error while parsing command line options."); 87 errflg++; 88 break; 89 } 90 } 91 92 if (optind > argc) { 93 fprintf(stderr, "Too many input parameter\n"); 94 errflg++; 95 } 96 97 if (errflg) { 98 print_usage(); 99 return 1; 100 } 101 56 102 LIST_INITIALIZE(mtab_list); 57 103 get_mtab_list(&mtab_list); … … 61 107 link); 62 108 statfs(mtab_ent->mp, &st); 63 printf("block size:%lu\n", (unsigned long)st.f_bsize); 64 printf("%13s %15llu %9llu %9llu %3llu%% %s\n", 65 mtab_ent->fs_name, 66 (unsigned long long) st.f_blocks * st.f_bsize, 67 (unsigned long long) (st.f_blocks - st.f_bfree) * st.f_bsize, 68 (unsigned long long) st.f_bfree * st.f_bsize, 69 (st.f_blocks)?PERCENTAGE(st.f_blocks - st.f_bfree, st.f_blocks):0L, 70 mtab_ent->mp); 109 print_statfs(&st, mtab_ent->fs_name, mtab_ent->mp); 71 110 } 72 111 putchar('\n'); … … 74 113 } 75 114 115 static void print_statfs(struct statfs *st, char *name, char *mountpoint) 116 { 117 printf("%10s", name); 118 printf(" %14llu %14llu %14llu %4llu%% %s\n", 119 FSBK_TO_BK(st->f_blocks, st->f_bsize, 512), /* Blocks */ 120 FSBK_TO_BK(st->f_blocks - st->f_bfree, st->f_bsize, 512), /* Used */ 121 FSBK_TO_BK(st->f_bfree, st->f_bsize, 512), /* Available */ 122 (st->f_blocks)?PERCENTAGE(st->f_blocks - st->f_bfree, st->f_blocks):0L, /* Used% */ 123 mountpoint /* Mounted on */ 124 ); 125 } 126 127 static void print_usage(void) 128 { 129 printf("syntax: %s [-h] [-i]\n", NAME); 130 printf(" h : \"Human-redable\" output.\n"); 131 printf(" i : Include statistics on the number of free inodes. \n"); 132 printf("\n"); 133 } 134 76 135 /** @} 77 136 */
Note:
See TracChangeset
for help on using the changeset viewer.