OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / user / sash / df.c
1 /* df.c:
2  *
3  * Copyright (C) 1998  Kenneth Albanowski <kjahds@kjahds.com>,
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  */
10
11 #include "sash.h"
12
13 #include <linux/autoconf.h>
14
15 #include <fcntl.h>
16 #include <sys/types.h>
17 #include <sys/vfs.h>
18
19 #include <sys/stat.h>
20 #include <dirent.h>
21 #include <pwd.h>
22 #include <grp.h>
23 #include <time.h>
24 #include <linux/major.h>
25 #ifdef __UC_LIBC__
26 #include <linux/types.h>
27 #endif
28 #include <sys/time.h>
29 #include <sys/param.h>
30 #include <errno.h>
31
32 void
33 do_df(int argc, char * argv[])
34 {
35         char * name;
36         struct statfs stbuf;
37
38 #if 0
39         fclose(stdin);
40 #endif
41
42         if (argc<2)
43                 name = "/";
44         else
45                 name = argv[1];
46         
47         if (statfs(name, &stbuf) == -1) {
48                 printf("Unable to get disk space of %s: %s\n", name, strerror(errno));
49                 return;
50         }
51         
52         printf("Total Kbytes: %ld\n", (stbuf.f_bsize / 256) * (stbuf.f_blocks / 4));
53         printf("Free  Kbytes: %ld\n", (stbuf.f_bsize / 256) * (stbuf.f_bfree / 4));
54         printf("Total  nodes: %ld\n", stbuf.f_files);
55         printf("Free   nodes: %ld\n", stbuf.f_ffree);
56 }
57