static int VerifyFreeSpace(char *file, Attributes a, Promise *pp) { struct stat statbuf; long kilobytes; #ifdef MINGW if (!a.volume.check_foreign) { CfOut(cf_verbose, "", "storage.volume.check_foreign is not supported on Windows (checking every mount)"); } #endif /* MINGW */ if (cfstat(file, &statbuf) == -1) { CfOut(cf_error, "stat", "Couldn't stat %s checking diskspace\n", file); return true; } #ifndef MINGW if (!a.volume.check_foreign) { if (IsForeignFileSystem(&statbuf, file)) { CfOut(cf_inform, "", "Filesystem %s is mounted from a foreign system, so skipping it", file); return true; } } #endif /* NOT MINGW */ kilobytes = a.volume.freespace; if (kilobytes < 0) { int free = (int) GetDiskUsage(file, cfpercent); kilobytes = -1 * kilobytes; if (free < (int) kilobytes) { cfPS(cf_error, CF_FAIL, "", pp, a, " !! Free disk space is under %ld%% for volume containing %s (%d%% free)\n", kilobytes, file, free); return false; } } else { off_t free = GetDiskUsage(file, cfabs); kilobytes = kilobytes / 1024; if (free < kilobytes) { cfPS(cf_error, CF_FAIL, "", pp, a, " !! Disk space under %ld kB for volume containing %s (%lld kB free)\n", kilobytes, file, (long long) free); return false; } } return true; }
static PromiseResult VerifyFreeSpace(EvalContext *ctx, char *file, Attributes a, Promise *pp) { struct stat statbuf; #ifdef __MINGW32__ if (!a.volume.check_foreign) { Log(LOG_LEVEL_VERBOSE, "storage.volume.check_foreign is not supported on Windows (checking every mount)"); } #endif /* __MINGW32__ */ if (stat(file, &statbuf) == -1) { Log(LOG_LEVEL_ERR, "Couldn't stat '%s' while checking diskspace. (stat: %s)", file, GetErrorStr()); return PROMISE_RESULT_NOOP; } #ifndef __MINGW32__ if (!a.volume.check_foreign) { if (IsForeignFileSystem(&statbuf, file)) { Log(LOG_LEVEL_INFO, "Filesystem '%s' is mounted from a foreign system, so skipping it", file); return PROMISE_RESULT_NOOP; } } #endif /* !__MINGW32__ */ if (a.volume.freespace < 0) { int threshold_percentage = -a.volume.freespace; int free_percentage = GetDiskUsage(file, cfpercent); if (free_percentage < threshold_percentage) { cfPS(ctx, LOG_LEVEL_ERR, PROMISE_RESULT_FAIL, pp, a, "Free disk space is under %d%% for volume containing '%s', %d%% free", threshold_percentage, file, free_percentage); return PROMISE_RESULT_FAIL; } } else { off_t threshold = a.volume.freespace; off_t free_bytes = GetDiskUsage(file, cfabs); if (free_bytes < threshold) { cfPS(ctx, LOG_LEVEL_ERR, PROMISE_RESULT_FAIL, pp, a, "Disk space under %jd kB for volume containing '%s' (%jd kB free)", (intmax_t) (threshold / 1024), file, (intmax_t) (free_bytes / 1024)); return PROMISE_RESULT_FAIL; } } return PROMISE_RESULT_NOOP; }
static int VerifyFreeSpace(EvalContext *ctx, char *file, Attributes a, Promise *pp) { struct stat statbuf; #ifdef __MINGW32__ if (!a.volume.check_foreign) { CfOut(OUTPUT_LEVEL_VERBOSE, "", "storage.volume.check_foreign is not supported on Windows (checking every mount)"); } #endif /* __MINGW32__ */ if (cfstat(file, &statbuf) == -1) { CfOut(OUTPUT_LEVEL_ERROR, "stat", "Couldn't stat %s checking diskspace\n", file); return true; } #ifndef __MINGW32__ if (!a.volume.check_foreign) { if (IsForeignFileSystem(&statbuf, file)) { CfOut(OUTPUT_LEVEL_INFORM, "", "Filesystem %s is mounted from a foreign system, so skipping it", file); return true; } } #endif /* !__MINGW32__ */ if (a.volume.freespace < 0) { int threshold_percentage = -a.volume.freespace; int free_percentage = GetDiskUsage(file, cfpercent); if (free_percentage < threshold_percentage) { cfPS(ctx, OUTPUT_LEVEL_ERROR, PROMISE_RESULT_FAIL, "", pp, a, " !! Free disk space is under %d%% for volume containing %s (%d%% free)\n", threshold_percentage, file, free_percentage); return false; } } else { off_t threshold = a.volume.freespace; off_t free_bytes = GetDiskUsage(file, cfabs); if (free_bytes < threshold) { cfPS(ctx, OUTPUT_LEVEL_ERROR, PROMISE_RESULT_FAIL, "", pp, a, " !! Disk space under %jd kB for volume containing %s (%jd kB free)\n", (intmax_t) (threshold / 1024), file, (intmax_t) (free_bytes / 1024)); return false; } } return true; }