summary |
tags |
clone url |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
2704d3a)
SCCS-vsn: bin/df/df.c 4.3
-static char *sccsid = "@(#)df.c 4.2 (Berkeley) %G%";
+static char *sccsid = "@(#)df.c 4.3 (Berkeley) %G%";
#include <stdio.h>
#include <fstab.h>
#include <sys/param.h>
#include <sys/filsys.h>
#include <sys/fblk.h>
#include <stdio.h>
#include <fstab.h>
#include <sys/param.h>
#include <sys/filsys.h>
#include <sys/fblk.h>
+#include <sys/stat.h>
+/*
+ * df
+ */
#define NFS 20 /* Max number of filesystems */
#define NFS 20 /* Max number of filesystems */
struct {
char path[32];
char spec[32];
struct {
char path[32];
char spec[32];
- FILE *f = fopen(FSTAB, "r");
while (argc >= 1 && argv[1][0]=='-') {
switch(argv[1][1]) {
while (argc >= 1 && argv[1][0]=='-') {
switch(argv[1][1]) {
printf("\tiused\tifree\t%%iused");
putchar('\n');
if(argc <= 1) {
printf("\tiused\tifree\t%%iused");
putchar('\n');
if(argc <= 1) {
+ struct fstab *fsp;
+ if (setfsent() == 0)
- while (!feof(f)){
- fscanf(f, FSTABFMT, FSTABARG(&fs));
- if (strcmp(fs.fs_type, "rw") && strcmp(fs.fs_type, "ro"))
+ while( (fsp = getfsent()) != 0){
+ if ( (strcmp(fsp->fs_type, FSTAB_RW) != 0)
+ &&(strcmp(fsp->fs_type, FSTAB_RO) != 0) )
continue;
if (root[0] == 0)
continue;
if (root[0] == 0)
- strcpy(root, fs.fs_spec);
- dfree(fs.fs_spec);
+ strcpy(root, fsp->fs_spec);
+ dfree(fsp->fs_spec);
- if (f){
- fscanf(f, FSTABFMT, FSTABARG(&fs));
- strcpy(root, fs.fs_spec);
- }
for(i=1; i<argc; i++) {
dfree(argv[i]);
}
for(i=1; i<argc; i++) {
dfree(argv[i]);
}
long used;
long hardway;
char *mp;
long used;
long hardway;
char *mp;
+ struct stat stbuf;
+
+ if(stat(file, &stbuf) == 0 && (stbuf.st_mode&S_IFMT) != S_IFCHR
+ && (stbuf.st_mode&S_IFMT) != S_IFBLK) {
+ int mt = open("/etc/mtab", 0), len;
+ char *str = "/dev/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
+ char mtab[32];
+ struct stat mstbuf;
+ while((len = read(mt, mtab, 32)) == 32) {
+ read(mt, &str[5], 32);
+ if(stat(str, &mstbuf) == 0 && mstbuf.st_rdev == stbuf.st_dev) {
+ file = str;
+ break;
+ }
+ }
+ close(mt);
+ if(len == 0) {
+ fprintf(stderr, "%s: mounted on unknown device\n", file);
+ return;
+ }
+ }
fi = open(file, 0);
if(fi < 0) {
fprintf(stderr,"cannot open %s\n", file);
fi = open(file, 0);
if(fi < 0) {
fprintf(stderr,"cannot open %s\n", file);