Completed mbtask new disk watcher
This commit is contained in:
89
lib/mbfile.c
89
lib/mbfile.c
@@ -252,95 +252,6 @@ int mkdirs(char *name, mode_t mode)
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Check free diskspace on most filesystems. Exclude check on floppyies,
|
||||
* CD's and /boot partition. The amount of needed space is given in MBytes.
|
||||
*/
|
||||
int diskfree(int needed)
|
||||
{
|
||||
int RetVal = TRUE;
|
||||
struct statfs sfs;
|
||||
unsigned long temp;
|
||||
#if defined(__linux__)
|
||||
char *mtab, *dev, *fs, *type;
|
||||
FILE *fp;
|
||||
#elif defined(__FreeBSD__) || defined(__NetBSD__)
|
||||
struct statfs *mntbuf;
|
||||
long mntsize;
|
||||
int i;
|
||||
#endif
|
||||
|
||||
if (! needed)
|
||||
return TRUE;
|
||||
|
||||
#if defined(__linux__)
|
||||
|
||||
if ((fp = fopen((char *)"/etc/mtab", "r")) == 0) {
|
||||
WriteError("$Can't open /etc/mtab");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
mtab = calloc(PATH_MAX, sizeof(char));
|
||||
while (fgets(mtab, PATH_MAX, fp)) {
|
||||
dev = strtok(mtab, " \t");
|
||||
fs = strtok(NULL, " \t");
|
||||
type = strtok(NULL, " \t");
|
||||
if (strncmp((char *)"/dev/", dev, 5) == 0) {
|
||||
/*
|
||||
* Filter out unwanted filesystems, floppy.
|
||||
* 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) ||
|
||||
!strncmp((char *)"ext3", type, 4))) {
|
||||
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);
|
||||
|
||||
#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_mntfromname, (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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Give a directory path and a filename, locate that filename in that
|
||||
* directory and return the filename with the correct case. This is
|
||||
|
@@ -2206,7 +2206,6 @@ long file_size(char *path);
|
||||
long file_crc(char *path, int);
|
||||
time_t file_time(char *path);
|
||||
int mkdirs(char *name, mode_t);
|
||||
int diskfree(int);
|
||||
int getfilecase(char *, char *);
|
||||
|
||||
|
||||
|
@@ -41,7 +41,6 @@ int termy = 24;
|
||||
|
||||
void TermInit(int mode, int x, int y)
|
||||
{
|
||||
Syslog('-', "Terminit(%d, %d, %d)", mode, x, y);
|
||||
termmode = mode;
|
||||
termx = x;
|
||||
termy = y;
|
||||
|
Reference in New Issue
Block a user