Diskspace check changed for FreeBSD and NetBSD

This commit is contained in:
Michiel Broek 2002-02-04 22:03:50 +00:00
parent 54df4da730
commit 3d96ef57b7
2 changed files with 75 additions and 43 deletions

View File

@ -4284,6 +4284,8 @@ v0.33.19 26-Oct-2001
The nodelist information now also holds the Txx flags. The nodelist information now also holds the Txx flags.
The mkdirs function now needs a mode parameter for directory The mkdirs function now needs a mode parameter for directory
creation. creation.
The filesystem space check is now reliable on FreeBSD and
NetBSD.
lang: lang:
Changed language prompts 6, 71, 429. Changed language prompts 6, 71, 429.

View File

@ -260,54 +260,84 @@ int mkdirs(char *name, mode_t mode)
*/ */
int diskfree(int needed) int diskfree(int needed)
{ {
char *mtab, *dev, *fs, *type; int RetVal = TRUE;
FILE *fp; struct statfs sfs;
struct statfs sfs; unsigned long temp;
int RetVal = TRUE; #if defined(__linux__)
unsigned long temp; char *mtab, *dev, *fs, *type;
FILE *fp;
if (! needed) #elif defined(__FreeBSD__) || defined(__NetBSD__)
return TRUE; struct statfs *mntbuf;
long mntsize;
mtab = calloc(PATH_MAX, sizeof(char)); int i;
#ifdef __linux__
if ((fp = fopen((char *)"/etc/mtab", "r")) == 0) {
WriteError("$Can't open /etc/mtab");
#elif __FreeBSD__ || __NetBSD__
if ((fp = fopen((char *)"/etc/fstab", "r")) == 0) {
WriteError("$Can't open /etc/fstab");
#endif #endif
return TRUE;
}
while (fgets(mtab, PATH_MAX, fp)) { if (! needed)
dev = strtok(mtab, " \t"); return TRUE;
fs = strtok(NULL, " \t");
type = strtok(NULL, " \t"); #if defined(__linux__)
if (strncmp((char *)"/dev/", dev, 5) == 0) {
/* if ((fp = fopen((char *)"/etc/mtab", "r")) == 0) {
* Filter out unwanted filesystems, floppy. WriteError("$Can't open /etc/mtab");
* Also filter out the /boot file system. return TRUE;
*/ }
if (strncmp((char *)"/dev/fd", dev, 7) && strncmp((char *)"/boot", fs, 5) &&
(!strncmp((char *)"ext2", type, 4) || !strncmp((char *)"reiserfs", type, 8) || mtab = calloc(PATH_MAX, sizeof(char));
!strncmp((char *)"ufs", type, 3) || !strncmp((char *)"ffs", type, 3) || while (fgets(mtab, PATH_MAX, fp)) {
!strncmp((char *)"vfat", type, 4) || !strncmp((char *)"msdos", type, 5))) { dev = strtok(mtab, " \t");
if (statfs(fs, &sfs) == 0) { fs = strtok(NULL, " \t");
temp = (unsigned long)(sfs.f_bsize / 512L); type = strtok(NULL, " \t");
if (((unsigned long)(sfs.f_bavail * temp) / 2048L) < needed) { if (strncmp((char *)"/dev/", dev, 5) == 0) {
RetVal = FALSE; /*
WriteError("On \"%s\" only %d kb left, need %d kb", fs, * Filter out unwanted filesystems, floppy.
(sfs.f_bavail * sfs.f_bsize) / 1024, needed * 1024); * Also filter out the /boot file system.
} */
} if (strncmp((char *)"/dev/fd", dev, 7) && strncmp((char *)"/boot", fs, 5) &&
} (!strncmp((char *)"ext2", type, 4) || !strncmp((char *)"reiserfs", type, 8) ||
!strncmp((char *)"vfat", type, 4) || !strncmp((char *)"msdos", type, 5))) {
if (statfs(fs, &sfs) == 0) {
temp = (unsigned long)(sfs.f_bsize / 512L);
if (((unsigned long)(sfs.f_bavail * temp) / 2048L) < needed) {
RetVal = FALSE;
WriteError("On \"%s\" only %d kb left, need %d kb", fs,
(sfs.f_bavail * sfs.f_bsize) / 1024, needed * 1024);
}
} }
}
} }
fclose(fp); }
free(mtab); fclose(fp);
free(mtab);
return RetVal; #elif defined(__FreeBSD__) || defined(__NetBSD__)
if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) {
WriteError("Huh, no filesystems mounted??");
return TRUE;
}
for (i = 0; i < mntsize; i++) {
/*
* Don't check kernfs (NetBSD) and procfs (FreeBSD), floppy and CD.
*/
if ((strncmp(mntbuf[i].f_fstypename, (char *)"kernfs", 6)) &&
(strncmp(mntbuf[i].f_fstypename, (char *)"procfs", 6)) &&
(strncmp(mntbuf[i].f_fsfromname, (char *)"/dev/fd", 7)) &&
(strncmp(mntbuf[i].f_fstypename, (char *)"cd9660", 6)) &&
(strncmp(mntbuf[i].f_fstypename, (char *)"msdos", 5)) &&
(statfs(mntbuf[i].f_mntonname, &sfs) == 0)) {
temp = (unsigned long)(sfs.f_bsize / 512L);
if (((unsigned long)(sfs.f_bavail * temp) / 2048L) < needed) {
RetVal = FALSE;
WriteError("On \"%s\" only %d kb left, need %d kb", mntbuf[i].f_mntonname,
(sfs.f_bavail * sfs.f_bsize) / 1024, needed * 1024);
}
}
}
#endif
return RetVal;
} }