* Copyright (c) 1980 The Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1980 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)df.c 5.8 (Berkeley) %G%";
extern int errno
, optind
;
struct statfs statfsbuf
, *mntbuf
;
while ((ch
= getopt(argc
, argv
, "io")) != EOF
)
fprintf(stderr
, "usage: df [-i] [filsys ...]\n");
printf("Filesystem kbytes used avail capacity");
printf(" iused ifree %%iused");
mntsize
= getmntinfo(&mntbuf
);
for (i
= 0; i
< mntsize
; i
++)
if (stat(*argv
, &stbuf
) < 0) {
if ((mntpt
= getmntpt(*argv
)) == 0)
} else if ((stbuf
.st_mode
& S_IFMT
) == S_IFBLK
) {
if ((mntpt
= getmntpt(*argv
)) == 0)
if (statfs(mntpt
, &statfsbuf
) < 0) {
static struct statfs
*mntbuf
= 0;
if ((mntsize
= getfsstat((struct statfs
*)0, 0)) < 0) {
i
= (mntsize
+ 1) * sizeof(struct statfs
);
if ((mntbuf
= (struct statfs
*)malloc((unsigned)i
)) == 0) {
"no space for mount table buffer\n");
if ((mntsize
= getfsstat(mntbuf
, i
)) < 0) {
} while (i
== mntsize
* sizeof(struct statfs
));
mntsize
= getmntinfo(&mntbuf
);
for (i
= 0; i
< mntsize
; i
++) {
if (!strcmp(mntbuf
[i
].f_mntfromname
, name
))
return (mntbuf
[i
].f_mntonname
);
* Print out status about a filesystem.
register struct statfs
*sfsp
;
long used
, availblks
, inodes
;
printf("%-12.12s", sfsp
->f_mntfromname
);
used
= sfsp
->f_blocks
- sfsp
->f_bfree
;
availblks
= sfsp
->f_bavail
+ used
;
printf("%8ld%8ld%8ld", sfsp
->f_blocks
* sfsp
->f_fsize
/ 1024,
used
* sfsp
->f_fsize
/ 1024, sfsp
->f_bavail
* sfsp
->f_fsize
/ 1024);
availblks
== 0 ? 100.0 : (double)used
/ (double)availblks
* 100.0);
used
= inodes
- sfsp
->f_ffree
;
printf("%8ld%8ld%6.0f%% ", used
, sfsp
->f_ffree
,
inodes
== 0 ? 100.0 : (double)used
/ (double)inodes
* 100.0);
printf(" %s\n", sfsp
->f_mntonname
);
* This code constitutes the old df code for extracting
* information from filesystem superblocks.
perror(_PATH_FSTAB
), exit(1);
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
);
register struct statfs
*sfsp
;
char *mntpt
, *strerror();
if (stat(file
, &stbuf
) == 0 &&
(stbuf
.st_mode
&S_IFMT
) != S_IFCHR
&&
(stbuf
.st_mode
&S_IFMT
) != S_IFBLK
) {
fprintf(stderr
, "%s: screwy 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 ((fi
= open(file
, 0)) < 0) {
fprintf(stderr
, "df: %s: %s\n", file
, strerror(errno
));
if (bread((long)SBOFF
, (char *)&sblock
, SBSIZE
) == 0) {
sfsp
->f_type
= MOUNT_UFS
;
sfsp
->f_fsize
= sblock
.fs_fsize
;
sfsp
->f_bsize
= sblock
.fs_bsize
;
sfsp
->f_blocks
= sblock
.fs_dsize
;
sfsp
->f_bfree
= sblock
.fs_cstotal
.cs_nbfree
* sblock
.fs_frag
+
sblock
.fs_cstotal
.cs_nffree
;
sfsp
->f_bavail
= (sblock
.fs_dsize
* (100 - sblock
.fs_minfree
) / 100) -
(sblock
.fs_dsize
- sfsp
->f_bfree
);
sfsp
->f_files
= sblock
.fs_ncg
* sblock
.fs_ipg
;
sfsp
->f_ffree
= sblock
.fs_cstotal
.cs_nifree
;
if ((mntpt
= getmntpt(file
)) == 0)
bcopy((caddr_t
)mntpt
, (caddr_t
)&sfsp
->f_mntonname
[0], MNAMELEN
);
bcopy((caddr_t
)file
, (caddr_t
)&sfsp
->f_mntfromname
[0], MNAMELEN
);
(void) lseek(fi
, off
, 0);
if ((n
=read(fi
, buf
, cnt
)) != cnt
) {
/* probably a dismounted disk if errno == EIO */
printf("\nread error off = %ld\n", off
);
printf("count = %d; errno = %d\n", n
, errno
);