* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
"@(#) Copyright (c) 1980 Regents of the University of California.\n\
static char sccsid
[] = "@(#)df.c 5.1 (Berkeley) %G%";
struct mtab mtab
[NMOUNT
];
while (argc
> 1 && argv
[1][0]=='-') {
fprintf(stderr
, "usage: df [ -i ] [ filsys... ]\n");
i
= open("/etc/mtab", 0);
(void) read(i
, (char *)mtab
, sizeof (mtab
));
printf("Filesystem kbytes used avail capacity");
printf(" iused ifree %%iused");
while (fsp
= getfsent()) {
if (strcmp(fsp
->fs_type
, FSTAB_RW
) &&
strcmp(fsp
->fs_type
, FSTAB_RO
) &&
strcmp(fsp
->fs_type
, FSTAB_RQ
))
(void) strcpy(root
, fsp
->fs_spec
);
long totalblks
, availblks
, avail
, free
, used
;
if (stat(file
, &stbuf
) == 0 &&
(stbuf
.st_mode
&S_IFMT
) != S_IFCHR
&&
(stbuf
.st_mode
&S_IFMT
) != S_IFBLK
) {
fprintf(stderr
, "%s: screwy /etc/fstab entry\n", file
);
while (fsp
= getfsent()) {
if (stat(fsp
->fs_spec
, &stb
) == 0 &&
stb
.st_rdev
== stbuf
.st_dev
) {
fprintf(stderr
, "%s: mounted on unknown device\n", file
);
if (bread(SBLOCK
, (char *)&sblock
, SBSIZE
) == 0) {
printf("%-12.12s", file
);
totalblks
= sblock
.fs_dsize
;
free
= sblock
.fs_cstotal
.cs_nbfree
* sblock
.fs_frag
+
sblock
.fs_cstotal
.cs_nffree
;
availblks
= totalblks
* (100 - sblock
.fs_minfree
) / 100;
avail
= availblks
> used
? availblks
- used
: 0;
printf("%8d%8d%8d", totalblks
* sblock
.fs_fsize
/ 1024,
used
* sblock
.fs_fsize
/ 1024, avail
* sblock
.fs_fsize
/ 1024);
availblks
== 0 ? 0.0 : (double) used
/ (double) availblks
* 100.0);
int inodes
= sblock
.fs_ncg
* sblock
.fs_ipg
;
used
= inodes
- sblock
.fs_cstotal
.cs_nifree
;
printf("%8ld%8ld%6.0f%% ", used
, sblock
.fs_cstotal
.cs_nifree
,
inodes
== 0 ? 0.0 : (double)used
/ (double)inodes
* 100.0);
printf(" %s\n", mpath(file
));
(void) lseek(fi
, (long)(bno
* DEV_BSIZE
), 0);
if ((n
=read(fi
, buf
, cnt
)) != cnt
) {
/* probably a dismounted disk if errno == EIO */
printf("\nread error bno = %ld\n", bno
);
printf("count = %d; errno = %d\n", n
, errno
);
* Given a name like /dev/rrp0h, returns the mounted path, like /usr.
register struct mtab
*mp
;
for (mp
= mtab
; mp
< mtab
+ NMOUNT
; mp
++)
if (eq(file
, mp
->m_dname
))
if (strncmp(f1
, "/dev/", 5) == 0)
if (strncmp(f2
, "/dev/", 5) == 0)
if (*f1
== 'r' && !strcmp(f1
+1, f2
))
if (*f2
== 'r' && !strcmp(f1
, f2
+1))
if (*f1
== 'r' && *f2
== 'r' && strcmp(f1
+1, f2
+1) == 0)