Implemented -k
This commit is contained in:
parent
800ca47f3e
commit
440a7559fc
30
src/df.c
30
src/df.c
|
@ -5,20 +5,26 @@
|
||||||
#include <sys/statvfs.h>
|
#include <sys/statvfs.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* Prefs */
|
||||||
|
typedef int Prefs;
|
||||||
|
#define PREFS_k 1
|
||||||
|
|
||||||
|
|
||||||
/* df */
|
/* df */
|
||||||
static int _df_error(char const * message, int ret);
|
static int _df_error(char const * message, int ret);
|
||||||
static int _df_do(char const * file);
|
static int _df_do(Prefs * prefs, char const * file);
|
||||||
static int _df(int filec, char * filev[])
|
static int _df(Prefs * prefs, int filec, char * filev[])
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* FIXME */
|
printf("%s%s%s", "Filesystem ", *prefs & PREFS_k ? "1024" : " 512",
|
||||||
printf("%s", "Filesystem 512-blocks Used Available Capacity Mounted on\n");
|
"-blocks Used Available Capacity Mounted on\n");
|
||||||
for(i = 0; i < filec; i++)
|
for(i = 0; i < filec; i++)
|
||||||
ret |= _df_do(filev[i]);
|
ret |= _df_do(prefs, filev[i]);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,14 +35,17 @@ static int _df_error(char const * message, int ret)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _df_do(char const * file)
|
static int _df_do(Prefs * prefs, char const * file)
|
||||||
{
|
{
|
||||||
struct statvfs f;
|
struct statvfs f;
|
||||||
|
int mod;
|
||||||
|
|
||||||
if(statvfs(file, &f) != 0)
|
if(statvfs(file, &f) != 0)
|
||||||
return _df_error(file, 1);
|
return _df_error(file, 1);
|
||||||
printf("%10s %10d %10d %10d %7d%% %s\n", "", f.f_blocks,
|
mod = f.f_bsize / ((*prefs & PREFS_k) ? 1024 : 512);
|
||||||
f.f_blocks-f.f_bfree, f.f_bavail,
|
/* FIXME round up "Use%" result */
|
||||||
|
printf("%11s %10lu %10lu %10lu %7lu%% %s\n", "", f.f_blocks * mod,
|
||||||
|
(f.f_blocks-f.f_bfree) * mod, f.f_bavail * mod,
|
||||||
((f.f_blocks-f.f_bfree)*100)/((f.f_blocks-f.f_bfree)
|
((f.f_blocks-f.f_bfree)*100)/((f.f_blocks-f.f_bfree)
|
||||||
+f.f_bavail), "");
|
+f.f_bavail), "");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -55,11 +64,14 @@ static int _usage(void)
|
||||||
int main(int argc, char * argv[])
|
int main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
int o;
|
int o;
|
||||||
|
Prefs prefs;
|
||||||
|
|
||||||
|
memset(&prefs, sizeof(prefs), 0);
|
||||||
while((o = getopt(argc, argv, "kPT")) != -1)
|
while((o = getopt(argc, argv, "kPT")) != -1)
|
||||||
switch(o)
|
switch(o)
|
||||||
{
|
{
|
||||||
case 'k':
|
case 'k':
|
||||||
|
prefs |= PREFS_k;
|
||||||
break;
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
break;
|
break;
|
||||||
|
@ -68,5 +80,5 @@ int main(int argc, char * argv[])
|
||||||
default:
|
default:
|
||||||
return _usage();
|
return _usage();
|
||||||
}
|
}
|
||||||
return _df(argc - optind, &argv[optind]) == 0 ? 0 : 2;
|
return _df(&prefs, argc - optind, &argv[optind]) == 0 ? 0 : 2;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user