Do not overflow when calculating file system size.
Reported by: Hyeongseok Kim <hyeongseok kim lge com> Reviewed by: cem, Hyeongseok Kim MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D24603
This commit is contained in:
parent
60a2823c66
commit
85f4f80c42
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=360428
@ -54,6 +54,8 @@ checkfilesys(const char *fname)
|
|||||||
int finish_dosdirsection=0;
|
int finish_dosdirsection=0;
|
||||||
int mod = 0;
|
int mod = 0;
|
||||||
int ret = 8;
|
int ret = 8;
|
||||||
|
int64_t freebytes;
|
||||||
|
int64_t badbytes;
|
||||||
|
|
||||||
rdonly = alwaysno;
|
rdonly = alwaysno;
|
||||||
if (!preen)
|
if (!preen)
|
||||||
@ -129,37 +131,33 @@ checkfilesys(const char *fname)
|
|||||||
mod |= FSERROR;
|
mod |= FSERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
freebytes = (int64_t)boot.NumFree * boot.ClusterSize;
|
||||||
|
badbytes = (int64_t)boot.NumBad * boot.ClusterSize;
|
||||||
|
|
||||||
#ifdef HAVE_LIBUTIL_H
|
#ifdef HAVE_LIBUTIL_H
|
||||||
char freestr[7], badstr[7];
|
char freestr[7], badstr[7];
|
||||||
|
|
||||||
int64_t freebytes = boot.NumFree * boot.ClusterSize;
|
|
||||||
humanize_number(freestr, sizeof(freestr), freebytes, "",
|
humanize_number(freestr, sizeof(freestr), freebytes, "",
|
||||||
HN_AUTOSCALE, HN_DECIMAL | HN_IEC_PREFIXES);
|
HN_AUTOSCALE, HN_DECIMAL | HN_IEC_PREFIXES);
|
||||||
if (boot.NumBad) {
|
if (boot.NumBad) {
|
||||||
int64_t badbytes = boot.NumBad * boot.ClusterSize;
|
|
||||||
|
|
||||||
humanize_number(badstr, sizeof(badstr), badbytes, "",
|
humanize_number(badstr, sizeof(badstr), badbytes, "",
|
||||||
HN_AUTOSCALE, HN_B | HN_DECIMAL | HN_IEC_PREFIXES);
|
HN_AUTOSCALE, HN_B | HN_DECIMAL | HN_IEC_PREFIXES);
|
||||||
|
|
||||||
pwarn("%d files, %sB free (%d clusters), %sB bad (%d clusters)\n",
|
pwarn("%d files, %sB free (%d clusters), %sB bad (%d clusters)\n",
|
||||||
boot.NumFiles,
|
boot.NumFiles, freestr, boot.NumFree,
|
||||||
freestr, boot.NumFree,
|
|
||||||
badstr, boot.NumBad);
|
badstr, boot.NumBad);
|
||||||
} else {
|
} else {
|
||||||
pwarn("%d files, %sB free (%d clusters)\n",
|
pwarn("%d files, %sB free (%d clusters)\n",
|
||||||
boot.NumFiles,
|
boot.NumFiles, freestr, boot.NumFree);
|
||||||
freestr, boot.NumFree);
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (boot.NumBad)
|
if (boot.NumBad)
|
||||||
pwarn("%d files, %d KiB free (%d clusters), %d KiB bad (%d clusters)\n",
|
pwarn("%d files, %jd KiB free (%d clusters), %jd KiB bad (%d clusters)\n",
|
||||||
boot.NumFiles,
|
boot.NumFiles, (intmax_t)freebytes / 1024, boot.NumFree,
|
||||||
boot.NumFree * boot.ClusterSize / 1024, boot.NumFree,
|
(intmax_t)badbytes / 1024, boot.NumBad);
|
||||||
boot.NumBad * boot.ClusterSize / 1024, boot.NumBad);
|
|
||||||
else
|
else
|
||||||
pwarn("%d files, %d KiB free (%d clusters)\n",
|
pwarn("%d files, %jd KiB free (%d clusters)\n",
|
||||||
boot.NumFiles,
|
boot.NumFiles, (intmax_t)freebytes / 1024, boot.NumFree);
|
||||||
boot.NumFree * boot.ClusterSize / 1024, boot.NumFree);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (mod && (mod & FSERROR) == 0) {
|
if (mod && (mod & FSERROR) == 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user