diff --git a/lib/clcomm.c b/lib/clcomm.c index 28484489..5d9525c6 100644 --- a/lib/clcomm.c +++ b/lib/clcomm.c @@ -471,20 +471,30 @@ unsigned long sequencer() */ int enoughspace(unsigned long needed) { - char *buf, *res; - int rc = 3; + char *buf, *res; + int rc = 3, cnt; + unsigned long avail = 0L; buf = calloc(SS_BUFSIZE, sizeof(char)); sprintf(buf, "DSPC:1,%ld;", needed); if (socket_send(buf) == 0) { - free(buf); - buf = socket_receive(); - res = strtok(buf, ","); - res = strtok(NULL, ";"); - rc = atoi(res); + sprintf(buf, "%s", socket_receive()); + res = strtok(buf, ":"); + cnt = atoi(strtok(NULL, ",")); + if (cnt == 1) { + rc = atoi(strtok(NULL, ";")); + } else if (cnt == 2) { + rc = atoi(strtok(NULL, ",")); + avail = atol(strtok(NULL, ";")); + if (rc == 0) + Syslog('+', "Only %ld MBytes diskspace, need %ld MBytes", avail, needed); + } else { + Syslog('-', "Error in enoughspace()"); + } } + free(buf); return rc; } diff --git a/mbcico/mbcico.c b/mbcico/mbcico.c index 45ecd983..25a3ed36 100644 --- a/mbcico/mbcico.c +++ b/mbcico/mbcico.c @@ -346,10 +346,8 @@ int main(int argc, char *argv[]) /* * Don't do outbound calls if low diskspace */ - if (enoughspace(CFG.freespace) == 0) { - WriteError("Low diskspace, abort"); + if (enoughspace(CFG.freespace) == 0) die(MBERR_DISK_FULL); - } if (addr == NULL) { WriteError("Calling mbcico without node address not supported anymore"); diff --git a/mbfido/mbaff.c b/mbfido/mbaff.c index dfb1ffb6..459231a8 100644 --- a/mbfido/mbaff.c +++ b/mbfido/mbaff.c @@ -143,10 +143,8 @@ int main(int argc, char **argv) if (!do_quiet) printf("\n"); - if (enoughspace(CFG.freespace) == 0) { - Syslog('+', "Low diskspace, abort"); + if (enoughspace(CFG.freespace) == 0) die(MBERR_DISK_FULL); - } if (lockprogram((char *)"mbaff")) { if (!do_quiet) diff --git a/mbfido/mbdiff.c b/mbfido/mbdiff.c index 6d3ead74..7f2be384 100644 --- a/mbfido/mbdiff.c +++ b/mbfido/mbdiff.c @@ -167,10 +167,8 @@ int main(int argc, char **argv) printf("\n"); } - if (enoughspace(CFG.freespace) == 0) { - Syslog('+', "Low diskspace, abort"); + if (enoughspace(CFG.freespace) == 0) die(MBERR_DISK_FULL); - } /* * Extract work directory from the first commandline parameter diff --git a/mbfido/mbfido.c b/mbfido/mbfido.c index 632921cf..9762b756 100644 --- a/mbfido/mbfido.c +++ b/mbfido/mbfido.c @@ -424,10 +424,8 @@ int main(int argc, char **argv) /* * Not yet locked, if anything goes wrong, exit with die(MBERR_NO_PROGLOCK) */ - if (enoughspace(CFG.freespace) == 0) { - Syslog('+', "Low diskspace, abort"); + if (enoughspace(CFG.freespace) == 0) die(MBERR_DISK_FULL); - } if (do_mail) { /* diff --git a/mbfido/mbfile.c b/mbfido/mbfile.c index 58c8aab5..5d8878fb 100644 --- a/mbfido/mbfile.c +++ b/mbfido/mbfile.c @@ -234,10 +234,8 @@ int main(int argc, char **argv) if (!do_quiet) printf("\n"); - if (enoughspace(CFG.freespace) == 0) { - Syslog('+', "Low diskspace, abort"); + if (enoughspace(CFG.freespace) == 0) die(MBERR_DISK_FULL); - } if (lockprogram((char *)"mbfile")) { if (!do_quiet) diff --git a/mbfido/mbfimport.c b/mbfido/mbfimport.c index b4aec552..d1afe684 100644 --- a/mbfido/mbfimport.c +++ b/mbfido/mbfimport.c @@ -173,10 +173,8 @@ void ImportFiles(int Area) /* * Check diskspace */ - if (enoughspace(CFG.freespace) == 0) { - Syslog('+', "Low diskspace, abort"); + if (enoughspace(CFG.freespace) == 0) die(MBERR_DISK_FULL); - } Files++; memset(&f_db, 0, sizeof(f_db)); diff --git a/mbfido/mbfindex.c b/mbfido/mbfindex.c index 9655bbda..c1300fe2 100644 --- a/mbfido/mbfindex.c +++ b/mbfido/mbfindex.c @@ -358,10 +358,8 @@ void ReqIndex(void) if (area.Available) { - if (enoughspace(CFG.freespace) == 0) { - Syslog('+', "Low diskspace, abort"); + if (enoughspace(CFG.freespace) == 0) die(MBERR_DISK_FULL); - } if (!do_quiet) { printf("\r%4ld => %-44s \b\b\b\b", i, area.Name); @@ -599,10 +597,8 @@ void HtmlIndex(char *Lang) if (area.Available) { - if (enoughspace(CFG.freespace) == 0) { - Syslog('+', "Low diskspace, abort"); + if (enoughspace(CFG.freespace) == 0) die(MBERR_DISK_FULL); - } if (!do_quiet) { printf("\r%4ld => %-44s \b\b\b\b", i, area.Name); diff --git a/mbfido/mbfkill.c b/mbfido/mbfkill.c index 52872646..a3e220de 100644 --- a/mbfido/mbfkill.c +++ b/mbfido/mbfkill.c @@ -86,10 +86,8 @@ void Kill(void) if ((area.Available) && (area.DLdays || area.FDdays) && (!area.CDrom)) { - if (enoughspace(CFG.freespace) == 0) { - Syslog('+', "Low diskspace, abort"); + if (enoughspace(CFG.freespace) == 0) die(MBERR_DISK_FULL); - } if (!do_quiet) { printf("\r%4d => %-44s \b\b\b\b", i, area.Name); diff --git a/mbfido/mbfpack.c b/mbfido/mbfpack.c index ee2b0367..a392e5ff 100644 --- a/mbfido/mbfpack.c +++ b/mbfido/mbfpack.c @@ -79,10 +79,8 @@ void PackFileBase(void) if (area.Available && !area.CDrom) { - if (enoughspace(CFG.freespace) == 0) { - Syslog('+', "Low diskspace, abort"); + if (enoughspace(CFG.freespace) == 0) die(MBERR_DISK_FULL); - } if (!do_quiet) { printf("\r%4d => %-44s", i, area.Name); diff --git a/mbfido/mbfsort.c b/mbfido/mbfsort.c index 9d53fd67..801dc424 100644 --- a/mbfido/mbfsort.c +++ b/mbfido/mbfsort.c @@ -158,10 +158,8 @@ void SortFileBase(int Area) if (area.Available) { - if (enoughspace(CFG.freespace) == 0) { - Syslog('+', "Low diskspace, abort"); + if (enoughspace(CFG.freespace) == 0) die(MBERR_DISK_FULL); - } if (!do_quiet) { printf("Sorting area %d: %-44s", Area, area.Name); diff --git a/mbfido/mbindex.c b/mbfido/mbindex.c index e51f258b..04f64fa6 100644 --- a/mbfido/mbindex.c +++ b/mbfido/mbindex.c @@ -177,10 +177,8 @@ int main(int argc,char *argv[]) Syslog(' ', cmd); free(cmd); - if (enoughspace(CFG.freespace) == 0) { - Syslog('+', "Low diskspace, abort"); + if (enoughspace(CFG.freespace) == 0) die(MBERR_DISK_FULL); - } if (lockprogram((char *)"mbindex")) { if (!do_quiet) diff --git a/mbfido/mbmsg.c b/mbfido/mbmsg.c index ac19ec37..53c43e1e 100644 --- a/mbfido/mbmsg.c +++ b/mbfido/mbmsg.c @@ -277,10 +277,8 @@ void DoMsgBase() fread(&msgs, msgshdr.recsize, 1, pAreas); if (msgs.Active) { - if (enoughspace(CFG.freespace) == 0) { - Syslog('+', "Low diskspace, abort"); + if (enoughspace(CFG.freespace) == 0) die(MBERR_DISK_FULL); - } if (!do_quiet) { colour(3, 0); @@ -308,10 +306,8 @@ void DoMsgBase() arearec++; if (msgs.Active) { - if (enoughspace(CFG.freespace) == 0) { - Syslog('+', "Low diskspace, abort"); + if (enoughspace(CFG.freespace) == 0) die(MBERR_DISK_FULL); - } Nopper(); if (!do_quiet) { diff --git a/mbmon/mbmon.c b/mbmon/mbmon.c index f470951e..84624540 100644 --- a/mbmon/mbmon.c +++ b/mbmon/mbmon.c @@ -268,7 +268,7 @@ void system_stat(void) mvprintw(12,62, "Load avg"); hor_lin(13,30,8); hor_lin(13,45,8); - mvprintw(13,62, "Disk stat"); + mvprintw(13,62, "Diskspace"); mvprintw(14, 6, "Client connects"); mvprintw(15, 6, "Peak connections"); mvprintw(16, 6, "Protocol syntax errors"); diff --git a/mbsebbs/mbuser.c b/mbsebbs/mbuser.c index bf7126bd..9948041f 100644 --- a/mbsebbs/mbuser.c +++ b/mbsebbs/mbuser.c @@ -100,10 +100,8 @@ int main(int argc, char **argv) Syslog(' ', cmd); free(cmd); - if (enoughspace(CFG.freespace) == 0) { - Syslog('+', "Low diskspace, abort"); + if (enoughspace(CFG.freespace) == 0) ExitClient(MBERR_DISK_FULL); - } if (lockprogram((char *)"mbuser")) { if (!do_quiet) diff --git a/mbtask/taskcomm.c b/mbtask/taskcomm.c index bf0d8c09..348615d5 100644 --- a/mbtask/taskcomm.c +++ b/mbtask/taskcomm.c @@ -378,8 +378,8 @@ char *exe_cmd(char *in) /* * DSPC:1,n; Check free space in MBytes - * 100:1,0; No - * 100:1,1; Yes + * 100:2,0,n; No, n = lowest size in MBytes + * 100:2,1,n; Yes, n = lowest size in MBytes * 100:1,2; Unknown * 100:1,3; Error */ diff --git a/mbtask/taskdisk.c b/mbtask/taskdisk.c index 9b15337e..7266ff65 100644 --- a/mbtask/taskdisk.c +++ b/mbtask/taskdisk.c @@ -40,6 +40,7 @@ typedef struct _mfs_list { char *fstype; /* FS type */ unsigned long size; /* Size in MB */ unsigned long avail; /* Available in MB */ + unsigned ro : 1; /* Read-Only fs. */ } mfs_list; mfs_list *mfs = NULL; /* List of filesystems */ @@ -72,6 +73,7 @@ void tidy_mfslist(mfs_list **fap) for (tmp = *fap; tmp; tmp = old) { old = tmp->next; free(tmp->mountpoint); + free(tmp->fstype); free(tmp); } *fap = NULL; @@ -105,6 +107,7 @@ void fill_mfslist(mfs_list **fap, char *mountpoint, char *fstype) tmp->fstype = xstrcpy(fstype); tmp->size = 0L; tmp->avail = 0L; + tmp->ro = TRUE; // Read-only, statfs will set real value. *fap = tmp; } @@ -132,20 +135,12 @@ char *disk_check(char *token) { static char buf[SS_BUFSIZE]; mfs_list *tmp; - unsigned long needed; + unsigned long needed, lowest = 0xffffffff; int rc; strtok(token, ","); needed = atol(strtok(NULL, ";")); - if (! needed) { - /* - * Answer enough space - */ - sprintf(buf, "100:1,1"); - return buf; - } - if (mfs == NULL) { /* * Answer Error @@ -158,24 +153,18 @@ char *disk_check(char *token) Syslog('!', "disk_check() mutex_lock failed rc=%d", rc); for (tmp = mfs; tmp; tmp = tmp->next) { - if (tmp->avail < needed) { - /* - * Answer Not enough space - */ - if ((rc = pthread_mutex_unlock(&a_mutex))) - Syslog('!', "disk_check() mutex_unlock failed rc=%d", rc); - sprintf(buf, "100:1,0"); - return buf; - } + if (!tmp->ro && (tmp->avail < lowest)) + lowest = tmp->avail; } if ((rc = pthread_mutex_unlock(&a_mutex))) Syslog('!', "disk_check() mutex_unlock failed rc=%d", rc); - /* - * Enough space - */ - sprintf(buf, "100:1,1"); + if (lowest < needed) { + sprintf(buf, "100:2,0,%ld;", lowest); + } else { + sprintf(buf, "100:2,1,%ld;", lowest); + } return buf; } @@ -247,6 +236,16 @@ void update_diskstat(void) temp = (unsigned long)(sfs.f_bsize / 512L); tmp->size = (unsigned long)(sfs.f_blocks * temp) / 2048L; tmp->avail = (unsigned long)(sfs.f_bavail * temp) / 2048L; +#if defined(__linux__) + /* + * The struct statfs (or statvfs) seems to have no information + * about read-only filesystems, so we guess it based on fstype. + * See man 2 statvfs about what approximately is defined. + */ + tmp->ro = (strstr(tmp->fstype, "iso") != NULL); +#elif defined(__FreeBSD__) || defined(__NetBSD__) + Syslog('-', "%s %d", tmp->mountpoint, sfs.f_flags); +#endif } } @@ -283,6 +282,7 @@ void add_path(char *path) if (S_ISDIR(sb.st_mode)) { #if defined(__linux__) + if ((fp = fopen((char *)"/etc/mtab", "r"))) { mtab = calloc(PATH_MAX, sizeof(char)); fsname = calloc(PATH_MAX, sizeof(char)); @@ -297,7 +297,6 @@ void add_path(char *path) * mounted filesystem that matches must be the one we seek. */ if (strncmp(fs, path, strlen(fs)) == 0) { - Syslog('d', "Found fs %s", fs); sprintf(fsname, "%s", fs); fs = strtok(NULL, " \t"); sprintf(fstype, "%s", fs); @@ -318,9 +317,7 @@ void add_path(char *path) fstype = calloc(PATH_MAX, sizeof(char)); for (i = 0; i < mntsize; i++) { - Syslog('d', "Check fs %s", mntbuf[i].f_mntonname); if (strncmp(mntbuf[i].f_mntonname, path, strlen(mntbuf[i].f_mntonname)) == 0) { - Syslog('d', "Found fs %s", mntbuf[i].f_mntonname); sprintf(fsname, "%s", mntbuf[i].f_mntonname); sprintf(fstype, "%s", mntbuf[i].f_fstypename); } @@ -331,10 +328,18 @@ void add_path(char *path) free(fstype); } +#else +#error "Unknow OS - don't know what to do" #endif } else { - Syslog('d', "**** Is not a dir"); + /* + * Not a directory, maybe a file. + */ + if ((p = strrchr(path, '/'))) + *p = '\0'; + Syslog('d', "Recursive add name %s", path); + add_path(path); } } else { /* @@ -513,7 +518,7 @@ void *disk_thread(void) Syslog('d', "All directories added"); for (tmp = mfs; tmp; tmp = tmp->next) { - Syslog('+', "%s %s %ld %ld", tmp->mountpoint, tmp->fstype, tmp->size, tmp->avail); + Syslog('+', "Found filesystem: %s type: %s", tmp->mountpoint, tmp->fstype); } if ((rc = pthread_mutex_unlock(&a_mutex)))