use statfs instead of reading superblock to get space threshold
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Fri, 23 Mar 1990 11:55:56 +0000 (03:55 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Fri, 23 Mar 1990 11:55:56 +0000 (03:55 -0800)
SCCS-vsn: sbin/savecore/savecore.c 5.21

usr/src/sbin/savecore/savecore.c

index ec8c6bd..afaf229 100644 (file)
@@ -22,7 +22,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)savecore.c 5.20 (Berkeley) %G%";
+static char sccsid[] = "@(#)savecore.c 5.21 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -30,11 +30,12 @@ static char sccsid[] = "@(#)savecore.c      5.20 (Berkeley) %G%";
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
-#include <sys/dir.h>
+#include <sys/mount.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/file.h>
 #include <sys/syslog.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/file.h>
 #include <sys/syslog.h>
+#include <dirent.h>
 #include <stdio.h>
 #include <nlist.h>
 #include <paths.h>
 #include <stdio.h>
 #include <nlist.h>
 #include <paths.h>
@@ -332,26 +333,20 @@ path(file)
 
 check_space()
 {
 
 check_space()
 {
-       struct stat dsb;
-       register char *ddev;
-       int dfd, spacefree;
-       struct fs fs;
+       long minfree, spacefree;
+       struct statfs fsbuf;
 
 
-       if (stat(dirname, &dsb) < 0) {
+       if (statfs(dirname, &fsbuf) < 0) {
                Perror(LOG_ERR, "%s: %m\n", dirname);
                exit(1);
        }
                Perror(LOG_ERR, "%s: %m\n", dirname);
                exit(1);
        }
-       ddev = find_dev(dsb.st_dev, S_IFBLK);
-       dfd = Open(ddev, O_RDONLY);
-       Lseek(dfd, SBOFF, L_SET);
-       Read(dfd, (char *)&fs, sizeof (fs));
-       close(dfd);
-       spacefree = freespace(&fs, fs.fs_minfree) * fs.fs_fsize / 1024;
-       if (spacefree < read_number("minfree")) {
+       spacefree = fsbuf.f_bavail * fsbuf.f_fsize / 1024;
+       minfree = read_number("minfree");
+       if (minfree > 0 && spacefree - dumpsize < minfree) {
                log(LOG_WARNING, "Dump omitted, not enough space on device\n");
                return (0);
        }
                log(LOG_WARNING, "Dump omitted, not enough space on device\n");
                return (0);
        }
-       if (freespace(&fs, fs.fs_minfree) < 0)
+       if (spacefree - dumpsize < minfree)
                log(LOG_WARNING,
                    "Dump performed, but free space threshold crossed\n");
        return (1);
                log(LOG_WARNING,
                    "Dump performed, but free space threshold crossed\n");
        return (1);